Make WordPress Core

Opened 14 years ago

Closed 11 years ago

#16762 closed defect (bug) (fixed)

wpdb::$base_prefix is not documented

Reported by: hakre's profile hakre Owned by: nacin's profile 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)

clipboard.patch (4.6 KB) - added by hakre 14 years ago.
I'm a bit unsure for the first change in user.php, the second and the other two files look good to me.
16762.diff (461 bytes) - added by pento 11 years ago.

Download all attachments as: .zip

Change History (11)

@hakre
14 years ago

I'm a bit unsure for the first change in user.php, the second and the other two files look good to me.

#1 @hakre
14 years ago

Related: #16764

#2 @SergeyBiryukov
12 years ago

  • Component changed from General to Database
  • Milestone changed from Unassigned to Awaiting Review

#3 @nacin
12 years ago

  • Type changed from defect to defect (bug)

#4 @jdgrimes
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.

#5 @SergeyBiryukov
11 years ago

#26887 was marked as a duplicate.

#6 @SergeyBiryukov
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.

@pento
11 years ago

#8 @DavidAnderson
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.

#9 @nacin
11 years ago

  • Owner set to nacin
  • Resolution set to fixed
  • Status changed from new to closed

In 27249:

Declare $wpdb->base_prefix.

props DavidAnderson.
fixes #16762.

Note: See TracTickets for help on using tickets.