Opened 9 months ago
Last modified 9 months ago
#21612 closed defect (bug)
wp-settings loads plugins before pluggable.php is included — at Version 1
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | General | Version: | 3.4.1 |
| Severity: | normal | Keywords: | |
| Cc: |
Description (last modified by SergeyBiryukov)
When manually initializing WordPress (like in a page that handles AJAX requests) to access all WordPress functions, it is typical to begin the file with:
define('WP_USE_THEMES', FALSE);
require($_SERVER['DOCUMENT_ROOT'] . '/wp-blog-header.php');
However, if a plugin calls the get_userdata() function, the page will deliver this fatal error:
Fatal error: Call to undefined function get_userdata() in [...]/wp-includes/user.php on line 1402
The "Maintenance" plugin is an example of one that causes this issue.
When the plugin is loaded in wp-settings.php line 198, it calls the get_userdata() function. But the get_userdata() function is not defined until wp-includes/pluggable.php is included on line 202 of wp-settings.
So this issue is not limited to calling get_userdata(), but any function defined in wp-includes/pluggable.php.
A simple fix to this, assuming wp-includes/pluggable.php does not depend on the plugins being loaded (which it very may well), is to swap the order of loading in wp-settings.php
