Make WordPress Core

Opened 11 years ago

Closed 11 years ago

#26867 closed defect (bug) (fixed)

Explicitly globalize some missing query globals in wp-settings.php

Reported by: nbachiyski's profile nbachiyski Owned by: nbachiyski's profile nbachiyski
Milestone: 3.9 Priority: normal
Severity: normal Version:
Component: Unit Tests Keywords: has-patch
Focuses: Cc:

Description

When WordPress is loaded in a function (e.g. unit tests) the variables initialized at the top level aren't globals, but we expect them to be.

For example, if in a unit test there is no way to access $wp_query, either directly or via get_query_var() before some other part of the code has initialized it.

This happens especially when we are testing a plugin and it uses $wp_query in its initialization routine.

Attachments (2)

globalize-query-vars.diff (753 bytes) - added by nbachiyski 11 years ago.
globalize-wp.diff (371 bytes) - added by xknown 11 years ago.

Download all attachments as: .zip

Change History (6)

#1 @nacin
11 years ago

  • Milestone changed from Awaiting Review to 3.9

Looks good.

#2 @nbachiyski
11 years ago

  • Owner set to nbachiyski
  • Resolution set to fixed
  • Status changed from new to closed

In 26996:

Explicitly globalize some missing query globals in wp-settings.php

When WordPress is loaded in a function (e.g. unit tests) the variables initialized at the top level aren't globals, but we expect them to be.

Fixes #26867

#3 @xknown
11 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

The $wp->init() call in line 334 (wp-settings.php) should be transformed to $GLOBALS['wp']->init(). Otherwise unit tests that don't call global $wp; on their config file fail with a PHP fatal error due to the fact that $wp isn't defined.

@xknown
11 years ago

#4 @nbachiyski
11 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In 26997:

Excplitcly globalized call to $wp later in wp-settings.php

Props xknown, fixes #26867.

Note: See TracTickets for help on using tickets.