First of all, I consider it necessary to clarify a few points:
- This article is not about any possible disadvantages of the administration panel interface, themes, ready-made plugins for wordpress or what else might a typical webmaster have? With all this, in my opinion, WordPress is relatively OK. This article is about code.
- The article is largely based on the materials I have collected together, freely translated and from myself significantly supplemented. Links are presented at the end of the article.
- Popularity is not synonymous with quality. No need to use this argument as proof of the quality of technical performance. WordPress is obviously for popular reasons.
Global variables are so cool, aren't they?
Not. Global variables are bad and should be avoided whenever possible. This statement is disclosed in detail in many other articles and is not something new or surprising for an experienced programmer. In short, global variables can be changed at any point in the program, which may affect the operation of other parts of the program. For this reason, global variables have unlimited potential for creating mutual dependencies, which makes the program more complex. Global variables also make it difficult to integrate modules, since the code written earlier may contain global variables with the same names as in the plug-in module.
So WordPress uses them everywhere and for everything. For example, The Loop or
Cycle , if in Russian. Using it, WordPress processes each post to display on the current page. It can be easily broken by introducing the following code:
')
global $post;
$post = null;
. - , .
?
. WordPress - (,
WP_Post, ). ORM ActiveRecord? . ,
WP_Query WP_User_Query. , , , .. , , , (. ). , , ?
,
query_posts()
get_posts()
.
. ,
WP_Query
.
function query_posts($query) {
$GLOBALS['wp_query'] = new WP_Query();
return $GLOBALS['wp_query']->query($query);
}
- WP_Query:

, - . WordPress (, )
wpdb , . .
— WordPress , . - . WordPress 3.8:

WordPress post (post types). WordPress . :
- post — ,
- page —
- attachment — ( , « », WP )
- revision —
- nav_menu_item — (, , )
, « », . 3.0
custom post types.
, posts. postmeta. , , . options WordPress . , , .
, WordPress , . , — PDO MySQL .
, .
mod_rewrite
. mod_rewrite
.htaccess
- , ( ).
,
Symfony. , WordPress , PHP. «»
is_page()
,
is_single()
is_category()
, .. mapping scoping.
,
.
?
WordPress 27 2003 , 11 ( ). MVC , WordPress , , PHP . , PHP : index.php, archive.php, single.php, .. — (. ). , , . ,
, WordPress . 40 , , . , ?
, . style.css, . . scss, , , css app.css build? , style.css . WordPress , . css, . — .
. ( , . ) / . — , . , - mvc .
WordPress wp-includes , . .
,
WordPress? , . , PHP -. , , , . , layout', (partials), .. ..
WordPress 11 . Smarty 12 . Twig 4 . - . ,
get_header()
,
get_sidebar()
,
get_footer()
— .
action filter --
, — , -.
function add_action($tag, $function_to_add, $priority = 10, $accepted_args = 1) {
return add_filter($tag, $function_to_add, $priority, $accepted_args);
}
, , — events, . , «» .
WordPress , , . , , . , , , . , , - , , , . , , , , (
$accepted_args
). ?
.
?
PHP , WordPress . , . , WordPress ( return, throw)
WP_Error
, , , .
— , --
WP_Error
false
. .
WordPress !
, , , , . . : , , , .
, - , WordPress , , , , .
, . : "
FancyBox for WordPress". 500 000 . POST WordPress', , . XSS .
, PHP
PSR PEAR, WordPress
, .
Cron
, cron, WordPress , PHP. , PHP . , . - , cron , - , . , .
, wp_cron . :
Why WP-Cron sucks. WP-Cron .
WordPress . 3 : (150150), (300300), (10241024). , .
add_image_size().
, , functions.php, WordPress:
add_action( 'after_setup_theme', 'foo_theme_setup' );
function foo_theme_setup() {
add_image_size( 'category-thumb', 400, 400, true );
add_image_size( 'homepage-thumb', 220, 180, true );
}
, , foobar.jpg 16001600. - , WordPress wp-uploads : foobar.jpg ( ), foobar-150x150.jpg, foobar-300x300.jpg, foobar-1024x1024.jpg, foobar-400x400.jpg, foobar-220x180.jpg. 6 1 , . 300 , 1800, . , ? 1 ?
, , , . . ,
Regenerate Thumbnails, . - WordPress — .
, WordPress. . CMS 2.* , 2009 , , . WordPress , - , October CMS (CMS PHP Laravel) .
w3techs
2015 — WordPress 23% 10
Alexa. CMS 60%. Joomla 7.5%, . ? WordPress? , , , , , - . , - , . , - , ..
wordpress.com, WordPress, CMS. 60 . 2005 Automattic, WordPress. , , , WordPress , , , , « » . , . , . . , , , , . - .
, October CMS. , , , WordPress:
CMS CMS?
CMS. CMS , . , , . WordPress , , . () PHP . - - , , .
- , , . , , , , .
: