Make WordPress Core

Opened 6 years ago

Last modified 4 months ago

#45761 new defect (bug)

consistency between $wpdb->blogid and get_current_blog_id()

Reported by: arena's profile arena Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 3.0
Component: Networks and Sites Keywords: dev-feedback has-patch
Focuses: multisite Cc:

Description

On a single install (not multisite),

you have

$wpdb->blogid => 0

get_current_blog_id() => 1

Must be a very old one !!!

Change History (4)

#1 @johnjamesjacoby
6 years ago

  • Component changed from General to Networks and Sites
  • Focuses multisite added
  • Keywords needs-patch added
  • Version changed from trunk to 3.0

#3 @keraweb
6 years ago

  • Keywords dev-feedback added

A check in the wpdb::__construct() for is_multisite() could fix this. If it's not a multisite then set blogid to 1.

This ticket was mentioned in PR #7316 on WordPress/wordpress-develop by @debarghyabanerjee.


4 months ago
#4

  • Keywords has-patch added; needs-patch removed

Trac Ticket: Core-45761

## Problem Statement:

  • In single-site WordPress installations, there is an inconsistency between the blogid property of the global $wpdb object and the value returned by get_current_blog_id(). Specifically:
$wpdb->blogid returns 0;
get_current_blog_id() returns 1;

This inconsistency is present in older installations and can lead to discrepancies in code that relies on the blogid value, especially in non-multisite environments.

## Fix:

  • To resolve this issue, we have modified the wpdb::__construct constructor method. The fix includes:
  • Adding an is_multisite() check within the constructor.

Setting $wpdb->blogid to 1 if is_multisite() returns false, ensuring consistency with the value returned by get_current_blog_id().

Note: See TracTickets for help on using tickets.