Make WordPress Core

Ticket #37178: 37178.2.diff

File 37178.2.diff, 1.1 KB (added by michalzuber, 8 years ago)

Rewrote a bit :) Don't know in which scenario it could be handy. That one select isn't so perf expensive. If somebody is using get_option he/she needs to know if it exists, that's default consideration for me from the function name.

  • src/wp-includes/option.php

    diff --git a/src/wp-includes/option.php b/src/wp-includes/option.php
    index 3bccd29..2f63fab 100644
    a b  
    2525 *
    2626 * @param string $option  Name of option to retrieve. Expected to not be SQL-escaped.
    2727 * @param mixed  $default Optional. Default value to return if the option does not exist.
     28 * @param mixed  $autoloaded_only Optional. Skip not autoloaded.
    2829 * @return mixed Value set for the option.
    2930 */
    30 function get_option( $option, $default = false ) {
     31function get_option( $option, $default = false, $autoloaded_only = false ) {
    3132        global $wpdb;
    3233
    3334        $option = trim( $option );
    function get_option( $option, $default = false ) { 
    8283                } else {
    8384                        $value = wp_cache_get( $option, 'options' );
    8485
    85                         if ( false === $value ) {
     86                        if ( false === $value && !$autoloaded_only ) {
    8687                                $row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", $option ) );
    8788
    8889                                // Has to be get_row instead of get_var because of funkiness with 0, false, null values