#41684 closed defect (bug) (fixed)
Replace $wpdb->blogid with get_current_blog_id()
Reported by: | spacedmonkey | Owned by: | jeremyfelt |
---|---|---|---|
Milestone: | 4.9 | Priority: | normal |
Severity: | normal | Version: | 3.1 |
Component: | Networks and Sites | Keywords: | good-first-bug has-patch |
Focuses: | multisite | Cc: | |
PR Number: |
Description
Similar to #41507 currently the class level property of blogid is reference through the code. These should be replaced with get_current_blog_id() function calls.
Attachments (9)
Change History (23)
This ticket was mentioned in Slack in #core-multisite by spacedmonkey. View the logs.
2 years ago
#2
@
2 years ago
Thanks for the patches @bnap00 . Some quick notes.
- In the switch_to_blog / restore tests, put the $wpdb->blogid. The test is testing that value has changed. That is one example that we can't remove it, as it invalidates the test.
- Check all functions, if that function no longer needs the global $wpdb and update the documentation. See
wpmu_update_blogs_date
andms_upload_constants
as example. - Restore
wp_get_db_schema
back to $wpdb->blogid. This seems to be a special case where get_current_blog_id will not work as it is loaded early.
This ticket was mentioned in Slack in #core-multisite by spacedmonkey. View the logs.
2 years ago
This ticket was mentioned in Slack in #core-multisite by spacedmonkey. View the logs.
2 years ago
#7
@
2 years ago
- Milestone changed from Future Release to 4.9
- Owner set to bnap00
- Status changed from new to assigned
Thanks for your work on this, @bnap00.
In cases where value is used more than once in a function, and where extra clarity is not needed, I think it's safe to store locally for reuse ($site_id = get_current_blog_id()
) instead of calling the function multiple times. The best (maybe the only) example is probably src/wp-admin/includes/upgrade.php
.
And, less important, return $blogs[get_current_blog_id()];
can be updated to return $blogs[ get_current_blog_id() ];
for coding standards.
This ticket was mentioned in Slack in #core-multisite by jeremyfelt. View the logs.
2 years ago
#9
@
2 years ago
In 41684.2.patch I fixed the last of the formatted issues raised by @jeremyfelt .
#10
@
2 years ago
- Keywords needs-unit-tests removed
- Owner changed from bnap00 to jeremyfelt
- Status changed from assigned to reviewing
This ticket was mentioned in Slack in #core-multisite by spacedmonkey. View the logs.
2 years ago
#12
@
2 years ago
In 41684.3.diff:
- Fix the order of the arguments passed to
$wpdb-prepare()
in the 3rd query. - In
upgrade_280()
, callrefresh_blog_details()
without an argument, which will refresh the current blog anyway. - Move
$site_id = get_current_blog_id()
into conditional blocks where appropriate.
final patch