#11549 closed feature request (wontfix)
Enable loading of the WordPress environment from external php script
Reported by: | mp2300 | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | minor | Version: | |
Component: | General | Keywords: | |
Focuses: | Cc: |
Description
For some integration projects, it is useful to load the WordPress environment from an external php script. This can be done by including wp-load.php
Afterwards all the WordPress functions can be used.
This is only possible if wp-load.php is included from the global scope. If it is included from inside a function, it will fail. This limitation makes it difficult to integrate WordPress with other projects.
wp-load.php fails because of the use of global objects and assign by reference. A simple solution would be to declare $wpdb, $wp_widget_factory, $_wp_deprecated_widgets_callbacks for global in wp-settings.php
The creation of WP_Widget_Factory in wp-settings.php needs to be changed from
$wp_widget_factory =& new WP_Widget_Factory();
to
$wp_widget_factory = new WP_Widget_Factory();
The syntax for creation of WP_Widget_Factory should be conditioned by the PHP version, to maintain backwards compatibility with PHP 4.
Attachments (1)
Change History (7)
#1
@
15 years ago
- Keywords needs-patch close added; assign by reference removed
- Milestone changed from Unassigned to Future Release
- Type changed from enhancement to feature request
Trouble is, you cannot know in advance which plugins and which theme are active and what global variables those might be setting. So which variables ought to be declared as such depends entirely on the site.
Re your patch, it's no big deal if it's assigned with a reference. The worst that happens is a deprecated warning in php 5.3.
Suggesting we close this as wontfix.
#2
follow-up:
↓ 3
@
15 years ago
At least variables from the core could be declared global.
It is a big deal when a object is created in non-global scope and assigned by reference to a global variable. The reference is global, but the object only exists in the local scope. By using the non-deprecated syntax, the object is created in the global scope.
There are better ways to enable loading of wordpress from external scripts, but they require a more extensive refactoring of the code.
#3
in reply to:
↑ 2
@
15 years ago
Replying to mp2300:
At least variables from the core could be declared global.
It is a big deal when a object is created in non-global scope and assigned by reference to a global variable. The reference is global, but the object only exists in the local scope.
use in your function teh $GLOBALS superglobal array and store your reference in there. Then you do not have that problem as discribben in the PHP manual.
#4
@
15 years ago
- Cc mp2300 added
Replying to hakre:
use in your function teh $GLOBALS superglobal array and store your reference in there. Then you do not have that problem as discribben in the PHP manual.
Thanks. Using $GLOBAL seems to solve the assign by reference problem with the deprecated syntax.
Unfortunately the problem is not it my own code, but in WordPress. If all global variables in WordPress were declared in $GLOBAL, then it would be possible to load the WordPress enviroment from a local scope.
Diff file to settings.php