WordPress.org

Make WordPress Core

Opened 7 months ago

Last modified 2 weeks ago

#39419 assigned defect (bug)

Explicitly globalize global variables in ms-settings.php

Reported by: danielbachhuber Owned by: csloisel
Milestone: Future Release Priority: normal
Severity: normal Version:
Component: Bootstrap/Load Keywords: good-first-bug has-patch needs-testing needs-docs
Focuses: multisite Cc:

Description

ms-settings.php uses and sets a few implicitly global variables:

  • $domain
  • $path
  • $blog_id
  • $site_id
  • $public
  • $table_prefix

It would be more correct if these were explicitly globalized in the file header.

Discovered in https://github.com/wp-cli/wp-cli/pull/3695

Attachments (1)

39419.diff (758 bytes) - added by csloisel 2 months ago.
May need phpdoc descriptions

Download all attachments as: .zip

Change History (9)

#1 @flixos90
7 months ago

  • Keywords good-first-bug added

#2 @johnjamesjacoby
7 months ago

Agree. We should definitely do this, and it should lead us down the path of education & awareness around their existence and what their intended purposes are.

Multisite has more than a few dedicated globals, and several of them are very situational (sign-ups, site creation, etc...) so I'm sure they've probably created several hours of work for people who needed to discover them the hard way.

#3 @jeremyfelt
7 months ago

Yeah, I'm on board with explicit.

  • $blog_id is declared in wp-settings.php as of [34961], so that should be okay already.
  • I noted previously that $site_id and $public are no longer used anywhere by core. It'd be great if we could just null these out, but who knows what would break. Note that we kind of accidentally did this with $sites and it only came up once. See #29415.
  • $path is used in validate_another_blog_signup(), probably by other plugins, etc..
  • $domain is used in wpmu_validate_blog_signup(), and possibly elsewhere.
  • $table_prefix is at least used a few times (object cache drop-ins, wp_set_wpdb_vars()). It's first used in wp-settings.php, so should be defined there as well.

@csloisel
2 months ago

May need phpdoc descriptions

#4 @csloisel
2 months ago

  • Keywords has-patch needs-testing added; needs-patch removed

#5 @DrewAPicture
4 weeks ago

  • Owner set to csloisel
  • Status changed from new to assigned

Assigning ownership to mark the good-first-bug as "claimed".

This ticket was mentioned in Slack in #core-multisite by stevenkword. View the logs.


2 weeks ago

#7 @stevenkword
2 weeks ago

  • Keywords needs-docs added

39419.diff applies cleanly against trunk as of July 10, 2017.

PHPdoc descriptions are missing.

@csloisel -- Do you intend on updating the doc to get this one ready for committer's eyes? Do you need any help or have any questions?

#8 @earnjam
2 weeks ago

Created #41285 to have further discussions about removal of $site_id and $public

Note: See TracTickets for help on using tickets.