#41936 closed defect (bug) (fixed)
get_main_site_id ignores custom values of $current_site->blog_id
Reported by: | spacedmonkey | Owned by: | flixos90 |
---|---|---|---|
Milestone: | 4.9 | Priority: | normal |
Severity: | normal | Version: | 4.9 |
Component: | Networks and Sites | Keywords: | has-unit-tests has-patch commit |
Focuses: | multisite, performance | Cc: |
Description
The function get_main_site_id
was added in #29684 . This new function adds a way to get the main site id of the current network. This works on site id of the site with the same domain / path of the network. However, before the point of truth main site id was property on $current_site. Some domain mapping plugins build the $current_site
and $current_blog
manually. Build these globally manually means that the $current_site->blog_id will be set. Currently get_main_site_id
ignores these values.
Attachments (8)
Change History (21)
This ticket was mentioned in Slack in #core-multisite by spacedmonkey. View the logs.
7 years ago
#3
@
7 years ago
- Milestone changed from Awaiting Review to 4.9
I agree this can become a bug in some cases, thus should be fixed in 4.9.
41936.diff fixes it, but I still don't like the logic being part of the WP_Network
method, as this is not a common practice. It may very well be the only solution to accomplish this, but I wanna try to think further about another way. This can go in post-beta, so we don't need to rush.
This ticket was mentioned in Slack in #core-multisite by flixos90. View the logs.
7 years ago
#6
@
7 years ago
Changes
- Magic method returns int
- blog_id is now cast to string
- get_main_site_id now returns get_current_blog_id
- Don't return early, on
pre_get_main_site_id
filter, check if not empty, to make sure it value is not a null value.
#7
@
7 years ago
41936.5.diff is a minor update:
- Ensure that the
$blog_id
property is always a string and that theget_main_site_id()
method always returns an int. - Handle the filter separately, i.e. have it not set the
$blog_id
property. - Use an internal variable for the cache key instead of "hard-coding" it twice.
- Keep the
return 1
if not multisite in theget_main_site_id()
function for now, as this should be a separate commit. - Add two extra unit tests, one to ensure the property value is honored correctly, and another to ensure the filter still takes precedence.
This ticket was mentioned in Slack in #core-multisite by jeremyfelt. View the logs.
7 years ago
#9
@
7 years ago
41936.6.diff adjusts the following:
- Fixes access of not existing
$network
variable by using$this
instead. - Only returns value of pre-filter or property if it is positive.
- Adjusts documentation of the pre-filter accordingly.
#10
@
7 years ago
- Keywords commit added
41936.6.diff looks good! I made one small change to the tests in 41936.7.diff and removed the pre filter each time it was used to avoid possible cross-test pollution.
41936-test.diff
This is a test if blog_id is set from another source, such as a sunrise file. Test is currently failing.
41936.diff
This is my solution, the moves the logic of getting blog_id into the WP_Network. It also makes the get_main_site_id method public, so it can be called in the bootstrap process.