WordPress.org

Make WordPress Core

Opened 9 months ago

Last modified 31 hours ago

#39419 reviewing defect (bug)

Explicitly globalize global variables in ms-settings.php

Reported by: danielbachhuber Owned by: csloisel
Milestone: 4.9 Priority: normal
Severity: normal Version:
Component: Bootstrap/Load Keywords: good-first-bug needs-docs needs-patch
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 4 months ago.
May need phpdoc descriptions

Download all attachments as: .zip

Change History (13)

#1 @flixos90
9 months ago

  • Keywords good-first-bug added

#2 @johnjamesjacoby
9 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
9 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
4 months ago

May need phpdoc descriptions

#4 @csloisel
4 months ago

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

#5 @DrewAPicture
3 months 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 months ago

#7 @stevenkword
2 months 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 months ago

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

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


9 days ago

#10 @jeremyfelt
9 days ago

  • Milestone changed from Future Release to 4.9
  • Owner changed from csloisel to jeremyfelt
  • Status changed from assigned to reviewing

#11 @jeremyfelt
9 days ago

  • Keywords needs-patch added; has-patch needs-testing removed
  • Owner changed from jeremyfelt to csloisel

It looks like we can do a bit more with the patch. A couple notes:

  • We'll need documentation next to each global that describes its purpose.
  • $table_prefix should be documented in wp-settings.php instead of ms-settings.php.
  • We can remove $site_id and $public. See #41285.

@csloisel - if you are interested, please feel free to update the ticket with a new patch. I'm going to reassign the ticket to you.

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


31 hours ago

Note: See TracTickets for help on using tickets.