WordPress.org

Make WordPress Core

Ticket #17749: fix-table_prefix-php_self-globalisation.diff

File fix-table_prefix-php_self-globalisation.diff, 2.4 KB (added by mrtorrent, 7 years ago)

Explicitly globalise $table_prefix, fix globalisation of $PHP_SELF by using $_SERVER['PHP_SELF'] instead. Fixes issues with including Wordpress outside the global scope.

  • wp-includes/load.php

    diff --git wp-includes/load.php wp-includes/load.php
    index c70eeeb..8c80f65 100644
    function wp_unregister_GLOBALS() { 
    3939 * @since 3.0.0
    4040 */
    4141function wp_fix_server_vars() {
    42         global $PHP_SELF;
    43 
    4442        $default_server_values = array(
    4543                'SERVER_SOFTWARE' => '',
    4644                'REQUEST_URI' => '',
    function wp_fix_server_vars() { 
    8785                unset( $_SERVER['PATH_INFO'] );
    8886
    8987        // Fix empty PHP_SELF
    90         $PHP_SELF = $_SERVER['PHP_SELF'];
    91         if ( empty( $PHP_SELF ) )
    92                 $_SERVER['PHP_SELF'] = $PHP_SELF = preg_replace( '/(\?.*)?$/', '', $_SERVER["REQUEST_URI"] );
     88        if ( empty( $_SERVER['PHP_SELF'] ) )
     89                $_SERVER['PHP_SELF'] = preg_replace( '/(\?.*)?$/', '', $_SERVER['REQUEST_URI'] );
    9390}
    9491
    9592/**
  • wp-includes/vars.php

    diff --git wp-includes/vars.php wp-includes/vars.php
    index aca78f1..70dff6e 100644
     
    1616if ( is_admin() ) {
    1717        // wp-admin pages are checked more carefully
    1818        if ( is_network_admin() )
    19                 preg_match('#/wp-admin/network/?(.*?)$#i', $PHP_SELF, $self_matches);
     19                preg_match('#/wp-admin/network/?(.*?)$#i', $_SERVER['PHP_SELF'], $self_matches);
    2020        elseif ( is_user_admin() )
    21                 preg_match('#/wp-admin/user/?(.*?)$#i', $PHP_SELF, $self_matches);
     21                preg_match('#/wp-admin/user/?(.*?)$#i', $_SERVER['PHP_SELF'], $self_matches);
    2222        else
    23                 preg_match('#/wp-admin/?(.*?)$#i', $PHP_SELF, $self_matches);
     23                preg_match('#/wp-admin/?(.*?)$#i', $_SERVER['PHP_SELF'], $self_matches);
    2424        $pagenow = $self_matches[1];
    2525        $pagenow = trim($pagenow, '/');
    2626        $pagenow = preg_replace('#\?.*?$#', '', $pagenow);
    if ( is_admin() ) { 
    3333                        $pagenow .= '.php'; // for Options +Multiviews: /wp-admin/themes/index.php (themes.php is queried)
    3434        }
    3535} else {
    36         if ( preg_match('#([^/]+\.php)([?/].*?)?$#i', $PHP_SELF, $self_matches) )
     36        if ( preg_match('#([^/]+\.php)([?/].*?)?$#i', $_SERVER['PHP_SELF'], $self_matches) )
    3737                $pagenow = strtolower($self_matches[1]);
    3838        else
    3939                $pagenow = 'index.php';
  • wp-settings.php

    diff --git wp-settings.php wp-settings.php
    index 6c5346f..7897e73 100644
    require( ABSPATH . WPINC . '/plugin.php' ); 
    7575require_wp_db();
    7676
    7777// Set the database table prefix and the format specifiers for database table columns.
     78$GLOBALS['table_prefix'] = $table_prefix;
    7879wp_set_wpdb_vars();
    7980
    8081// Start the WordPress object cache, or an external object cache if the drop-in is present.