WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 years ago

#13043 closed defect (bug) (fixed)

get_site_option should use wpdb->get_row

Reported by: laceous Owned by:
Milestone: 3.0 Priority: normal
Severity: normal Version: 3.0
Component: Multisite Keywords: has-patch
Focuses: Cc:

Description

get_option uses the following code when pulling data from the database:

$row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = '%s' LIMIT 1", $option ) );
// Has to be get_row instead of get_var because of funkiness with 0, false, null values
if ( is_object( $row ) ) {

get_site_option uses get_var directly which leads to the funkiness that get_option tries to avoid:

$value = $wpdb->get_var( $wpdb->prepare("SELECT meta_value FROM $wpdb->sitemeta WHERE meta_key = %s AND site_id = %d", $option, $wpdb->siteid ) );
if ( is_null($value) )
  $value = $default;

get_site_option should use get_row instead of get_var

(This was tested with the latest nightly build)

Attachments (1)

functions.php.diff (886 bytes) - added by laceous 4 years ago.
change get_var to get_row

Download all attachments as: .zip

Change History (5)

laceous4 years ago

change get_var to get_row

comment:1 laceous4 years ago

  • Keywords has-patch added

comment:2 scribu4 years ago

  • Component changed from General to Multisite

comment:3 technosailor4 years ago

Still applies cleanly.

comment:4 nacin4 years ago

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

(In [14410]) Use get_row instead of get_var in get_site_option, aligning it with get_option, due to funkiness with 0/false/null. fixes #13043. props laceous.

Note: See TracTickets for help on using tickets.