Opened 14 years ago
Closed 11 years ago
#16762 closed defect (bug) (fixed)
wpdb::$base_prefix is not documented
Reported by: | hakre | Owned by: | nacin |
---|---|---|---|
Milestone: | 3.9 | Priority: | normal |
Severity: | normal | Version: | 3.0 |
Component: | Database | Keywords: | has-patch commit |
Focuses: | Cc: |
Description
Probably wpdb::$base_prefix has been merged into from MU and not further specified then.
It genereally can be replaced with wpdb::get_blog_prefix(0)
when the MULTISITE constant is defined. That is are after wp-settings.php has been included (wp-config.php, wp-load.php), even on SHORTINIT.
It might be that this function call does not cover all cases needed because if MULTISITE is not defined when called, it will not return the wpdb::$base_prefix
.
More insight into MU is needed, feedback appreceated. Some places look like that they are not aware of the wpdb::get_blog_prefix() function. Probably legacy MU code.
Related: #16756
Attachments (2)
Change History (11)
#2
@
12 years ago
- Component changed from General to Database
- Milestone changed from Unassigned to Awaiting Review
#4
@
11 years ago
+1 to this. I think we should introduce a wpdb::get_base_prefix()
function instead of relying on wpdb::get_blog_prefix( 0 )
. That maybe belongs on a separate ticket though.
#6
@
11 years ago
- Milestone changed from Awaiting Review to 3.9
- Version set to 3.0
#26887 was marked for 3.9, let's move the patch from there.
#7
@
11 years ago
- Keywords commit added
attachment:16762.diff is a copy of attachment:26887.diff:ticket:26887.
#8
@
11 years ago
Responding to the original report: using wpdb::get_blog_prefix(0) as an alternative to $wpdb->base_prefix is wrong, for the reason given in the original report: "It might be that this function call does not cover all cases needed because if MULTISITE is not defined when called, it will not return the wpdb::$base_prefix."
The "might" can happen, on sites that have been upgraded from old pre-3.0 WPMU setups. In that situation, wpdb::get_blog_prefix(0) returns junk data, because MULTISITE is indeed not set and is_multisite() is still true. I have seen this happen in the wild. Despite the apparent intention inside the code of wpdb::get_blog_prefix(), in fact wpdb::get_blog_prefix(0) is not useful unless you first know that you're not on such a site, and if you are, only wpdb::$base_prefix is useful.
Therefore, the simpler patch that Pento has added in 16762.diff should be used, and the original patch should not. It is better to just make clear that wpdb::$base_prefix is the way to go, by making it explicitly public.
I'm a bit unsure for the first change in user.php, the second and the other two files look good to me.