Make WordPress Core

Opened 15 years ago

Closed 11 years ago

Last modified 11 years ago

#11549 closed feature request (wontfix)

Enable loading of the WordPress environment from external php script

Reported by: mp2300's profile 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)

wp-settings.php.diff (333 bytes) - added by mp2300 15 years ago.
Diff file to settings.php

Download all attachments as: .zip

Change History (7)

@mp2300
15 years ago

Diff file to settings.php

#1 @Denis-de-Bernardy
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: @mp2300
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 @hakre
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 @mp2300
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.

#5 @c3mdigital
11 years ago

  • Keywords needs-patch close removed
  • Resolution set to wontfix
  • Status changed from new to closed

4 years no activity. Closing as wontfix. If anyone thinks this is an issue and wants to discuss, please reopen.

#6 @SergeyBiryukov
11 years ago

  • Milestone Future Release deleted
Note: See TracTickets for help on using tickets.