Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (9 years ago)
Author:
pento
Message:

Code is Poetry.
WordPress' code just... wasn't.
This is now dealt with.

Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS.
Fixes #41057.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/option.php

    r42228 r42343  
    3232
    3333        $option = trim( $option );
    34         if ( empty( $option ) )
     34        if ( empty( $option ) ) {
    3535                return false;
     36        }
    3637
    3738        /**
     
    4647         * @since 4.4.0 The `$option` parameter was added.
    4748         * @since 4.9.0 The `$default` parameter was added.
    48          *
    4949         *
    5050         * @param bool|mixed $pre_option The value to return instead of the option value. This differs from
     
    5858        $pre = apply_filters( "pre_option_{$option}", false, $option, $default );
    5959
    60         if ( false !== $pre )
     60        if ( false !== $pre ) {
    6161                return $pre;
    62 
    63         if ( defined( 'WP_SETUP_CONFIG' ) )
     62        }
     63
     64        if ( defined( 'WP_SETUP_CONFIG' ) ) {
    6465                return false;
     66        }
    6567
    6668        // Distinguish between `false` as a default, and not passing one.
     
    9092                $alloptions = wp_load_alloptions();
    9193
    92                 if ( isset( $alloptions[$option] ) ) {
    93                         $value = $alloptions[$option];
     94                if ( isset( $alloptions[ $option ] ) ) {
     95                        $value = $alloptions[ $option ];
    9496                } else {
    9597                        $value = wp_cache_get( $option, 'options' );
     
    106108                                                $notoptions = array();
    107109                                        }
    108                                         $notoptions[$option] = true;
     110                                        $notoptions[ $option ] = true;
    109111                                        wp_cache_set( 'notoptions', $notoptions, 'options' );
    110112
     
    116118        } else {
    117119                $suppress = $wpdb->suppress_errors();
    118                 $row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", $option ) );
     120                $row      = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", $option ) );
    119121                $wpdb->suppress_errors( $suppress );
    120122                if ( is_object( $row ) ) {
     
    127129
    128130        // If home is not set use siteurl.
    129         if ( 'home' == $option && '' == $value )
     131        if ( 'home' == $option && '' == $value ) {
    130132                return get_option( 'siteurl' );
    131 
    132         if ( in_array( $option, array('siteurl', 'home', 'category_base', 'tag_base') ) )
     133        }
     134
     135        if ( in_array( $option, array( 'siteurl', 'home', 'category_base', 'tag_base' ) ) ) {
    133136                $value = untrailingslashit( $value );
     137        }
    134138
    135139        /**
     
    160164 */
    161165function wp_protect_special_option( $option ) {
    162         if ( 'alloptions' === $option || 'notoptions' === $option )
     166        if ( 'alloptions' === $option || 'notoptions' === $option ) {
    163167                wp_die( sprintf( __( '%s is a protected WP option and may not be modified' ), esc_html( $option ) ) );
     168        }
    164169}
    165170
     
    202207                $alloptions = array();
    203208                foreach ( (array) $alloptions_db as $o ) {
    204                         $alloptions[$o->option_name] = $o->option_value;
     209                        $alloptions[ $o->option_name ] = $o->option_value;
    205210                }
    206211
     
    240245        global $wpdb;
    241246
    242         if ( ! is_multisite() || wp_using_ext_object_cache() || wp_installing() )
     247        if ( ! is_multisite() || wp_using_ext_object_cache() || wp_installing() ) {
    243248                return;
    244 
    245         if ( empty($network_id) )
     249        }
     250
     251        if ( empty( $network_id ) ) {
    246252                $network_id = get_current_network_id();
    247 
    248         $core_options = array('site_name', 'siteurl', 'active_sitewide_plugins', '_site_transient_timeout_theme_roots', '_site_transient_theme_roots', 'site_admins', 'can_compress_scripts', 'global_terms_enabled', 'ms_files_rewriting' );
    249 
    250         $core_options_in = "'" . implode("', '", $core_options) . "'";
    251         $options = $wpdb->get_results( $wpdb->prepare( "SELECT meta_key, meta_value FROM $wpdb->sitemeta WHERE meta_key IN ($core_options_in) AND site_id = %d", $network_id ) );
     253        }
     254
     255        $core_options = array( 'site_name', 'siteurl', 'active_sitewide_plugins', '_site_transient_timeout_theme_roots', '_site_transient_theme_roots', 'site_admins', 'can_compress_scripts', 'global_terms_enabled', 'ms_files_rewriting' );
     256
     257        $core_options_in = "'" . implode( "', '", $core_options ) . "'";
     258        $options         = $wpdb->get_results( $wpdb->prepare( "SELECT meta_key, meta_value FROM $wpdb->sitemeta WHERE meta_key IN ($core_options_in) AND site_id = %d", $network_id ) );
    252259
    253260        foreach ( $options as $option ) {
    254                 $key = $option->meta_key;
    255                 $cache_key = "{$network_id}:$key";
     261                $key                = $option->meta_key;
     262                $cache_key          = "{$network_id}:$key";
    256263                $option->meta_value = maybe_unserialize( $option->meta_value );
    257264
     
    286293        global $wpdb;
    287294
    288         $option = trim($option);
    289         if ( empty($option) )
     295        $option = trim( $option );
     296        if ( empty( $option ) ) {
    290297                return false;
     298        }
    291299
    292300        wp_protect_special_option( $option );
    293301
    294         if ( is_object( $value ) )
     302        if ( is_object( $value ) ) {
    295303                $value = clone $value;
    296 
    297         $value = sanitize_option( $option, $value );
     304        }
     305
     306        $value     = sanitize_option( $option, $value );
    298307        $old_value = get_option( $option );
    299308
     
    368377
    369378        $result = $wpdb->update( $wpdb->options, $update_args, array( 'option_name' => $option ) );
    370         if ( ! $result )
     379        if ( ! $result ) {
    371380                return false;
     381        }
    372382
    373383        $notoptions = wp_cache_get( 'notoptions', 'options' );
    374         if ( is_array( $notoptions ) && isset( $notoptions[$option] ) ) {
    375                 unset( $notoptions[$option] );
     384        if ( is_array( $notoptions ) && isset( $notoptions[ $option ] ) ) {
     385                unset( $notoptions[ $option ] );
    376386                wp_cache_set( 'notoptions', $notoptions, 'options' );
    377387        }
     
    379389        if ( ! wp_installing() ) {
    380390                $alloptions = wp_load_alloptions();
    381                 if ( isset( $alloptions[$option] ) ) {
     391                if ( isset( $alloptions[ $option ] ) ) {
    382392                        $alloptions[ $option ] = $serialized_value;
    383393                        wp_cache_set( 'alloptions', $alloptions, 'options' );
     
    440450        global $wpdb;
    441451
    442         if ( !empty( $deprecated ) )
     452        if ( ! empty( $deprecated ) ) {
    443453                _deprecated_argument( __FUNCTION__, '2.3.0' );
    444 
    445         $option = trim($option);
    446         if ( empty($option) )
     454        }
     455
     456        $option = trim( $option );
     457        if ( empty( $option ) ) {
    447458                return false;
     459        }
    448460
    449461        wp_protect_special_option( $option );
    450462
    451         if ( is_object($value) )
     463        if ( is_object( $value ) ) {
    452464                $value = clone $value;
     465        }
    453466
    454467        $value = sanitize_option( $option, $value );
     
    456469        // Make sure the option doesn't already exist. We can check the 'notoptions' cache before we ask for a db query
    457470        $notoptions = wp_cache_get( 'notoptions', 'options' );
    458         if ( !is_array( $notoptions ) || !isset( $notoptions[$option] ) )
     471        if ( ! is_array( $notoptions ) || ! isset( $notoptions[ $option ] ) ) {
    459472                /** This filter is documented in wp-includes/option.php */
    460                 if ( apply_filters( "default_option_{$option}", false, $option, false ) !== get_option( $option ) )
     473                if ( apply_filters( "default_option_{$option}", false, $option, false ) !== get_option( $option ) ) {
    461474                        return false;
     475                }
     476        }
    462477
    463478        $serialized_value = maybe_serialize( $value );
    464         $autoload = ( 'no' === $autoload || false === $autoload ) ? 'no' : 'yes';
     479        $autoload         = ( 'no' === $autoload || false === $autoload ) ? 'no' : 'yes';
    465480
    466481        /**
     
    475490
    476491        $result = $wpdb->query( $wpdb->prepare( "INSERT INTO `$wpdb->options` (`option_name`, `option_value`, `autoload`) VALUES (%s, %s, %s) ON DUPLICATE KEY UPDATE `option_name` = VALUES(`option_name`), `option_value` = VALUES(`option_value`), `autoload` = VALUES(`autoload`)", $option, $serialized_value, $autoload ) );
    477         if ( ! $result )
     492        if ( ! $result ) {
    478493                return false;
     494        }
    479495
    480496        if ( ! wp_installing() ) {
    481497                if ( 'yes' == $autoload ) {
    482                         $alloptions = wp_load_alloptions();
     498                        $alloptions            = wp_load_alloptions();
    483499                        $alloptions[ $option ] = $serialized_value;
    484500                        wp_cache_set( 'alloptions', $alloptions, 'options' );
     
    490506        // This option exists now
    491507        $notoptions = wp_cache_get( 'notoptions', 'options' ); // yes, again... we need it to be fresh
    492         if ( is_array( $notoptions ) && isset( $notoptions[$option] ) ) {
    493                 unset( $notoptions[$option] );
     508        if ( is_array( $notoptions ) && isset( $notoptions[ $option ] ) ) {
     509                unset( $notoptions[ $option ] );
    494510                wp_cache_set( 'notoptions', $notoptions, 'options' );
    495511        }
     
    534550
    535551        $option = trim( $option );
    536         if ( empty( $option ) )
     552        if ( empty( $option ) ) {
    537553                return false;
     554        }
    538555
    539556        wp_protect_special_option( $option );
     
    541558        // Get the ID, if no ID then return
    542559        $row = $wpdb->get_row( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", $option ) );
    543         if ( is_null( $row ) )
     560        if ( is_null( $row ) ) {
    544561                return false;
     562        }
    545563
    546564        /**
     
    557575                if ( 'yes' == $row->autoload ) {
    558576                        $alloptions = wp_load_alloptions();
    559                         if ( is_array( $alloptions ) && isset( $alloptions[$option] ) ) {
    560                                 unset( $alloptions[$option] );
     577                        if ( is_array( $alloptions ) && isset( $alloptions[ $option ] ) ) {
     578                                unset( $alloptions[ $option ] );
    561579                                wp_cache_set( 'alloptions', $alloptions, 'options' );
    562580                        }
     
    616634        } else {
    617635                $option_timeout = '_transient_timeout_' . $transient;
    618                 $option = '_transient_' . $transient;
    619                 $result = delete_option( $option );
    620                 if ( $result )
     636                $option         = '_transient_' . $transient;
     637                $result         = delete_option( $option );
     638                if ( $result ) {
    621639                        delete_option( $option_timeout );
     640                }
    622641        }
    623642
     
    667686         */
    668687        $pre = apply_filters( "pre_transient_{$transient}", false, $transient );
    669         if ( false !== $pre )
     688        if ( false !== $pre ) {
    670689                return $pre;
     690        }
    671691
    672692        if ( wp_using_ext_object_cache() ) {
     
    677697                        // If option is not in alloptions, it is not autoloaded and thus has a timeout
    678698                        $alloptions = wp_load_alloptions();
    679                         if ( !isset( $alloptions[$transient_option] ) ) {
     699                        if ( ! isset( $alloptions[ $transient_option ] ) ) {
    680700                                $transient_timeout = '_transient_timeout_' . $transient;
    681                                 $timeout = get_option( $transient_timeout );
     701                                $timeout           = get_option( $transient_timeout );
    682702                                if ( false !== $timeout && $timeout < time() ) {
    683                                         delete_option( $transient_option  );
     703                                        delete_option( $transient_option );
    684704                                        delete_option( $transient_timeout );
    685705                                        $value = false;
     
    688708                }
    689709
    690                 if ( ! isset( $value ) )
     710                if ( ! isset( $value ) ) {
    691711                        $value = get_option( $transient_option );
     712                }
    692713        }
    693714
     
    757778        } else {
    758779                $transient_timeout = '_transient_timeout_' . $transient;
    759                 $transient_option = '_transient_' . $transient;
     780                $transient_option  = '_transient_' . $transient;
    760781                if ( false === get_option( $transient_option ) ) {
    761782                        $autoload = 'yes';
     
    834855        }
    835856
    836         $wpdb->query( $wpdb->prepare(
    837                 "DELETE a, b FROM {$wpdb->options} a, {$wpdb->options} b
     857        $wpdb->query(
     858                $wpdb->prepare(
     859                        "DELETE a, b FROM {$wpdb->options} a, {$wpdb->options} b
    838860                        WHERE a.option_name LIKE %s
    839861                        AND a.option_name NOT LIKE %s
    840862                        AND b.option_name = CONCAT( '_transient_timeout_', SUBSTRING( a.option_name, 12 ) )
    841863                        AND b.option_value < %d",
    842                 $wpdb->esc_like( '_transient_' ) . '%',
    843                 $wpdb->esc_like( '_transient_timeout_' ) . '%',
    844                 time()
    845         ) );
     864                        $wpdb->esc_like( '_transient_' ) . '%',
     865                        $wpdb->esc_like( '_transient_timeout_' ) . '%',
     866                        time()
     867                )
     868        );
    846869
    847870        if ( ! is_multisite() ) {
    848871                // non-Multisite stores site transients in the options table.
    849                 $wpdb->query( $wpdb->prepare(
    850                         "DELETE a, b FROM {$wpdb->options} a, {$wpdb->options} b
     872                $wpdb->query(
     873                        $wpdb->prepare(
     874                                "DELETE a, b FROM {$wpdb->options} a, {$wpdb->options} b
    851875                                WHERE a.option_name LIKE %s
    852876                                AND a.option_name NOT LIKE %s
    853877                                AND b.option_name = CONCAT( '_site_transient_timeout_', SUBSTRING( a.option_name, 17 ) )
    854878                                AND b.option_value < %d",
    855                         $wpdb->esc_like( '_site_transient_' ) . '%',
    856                         $wpdb->esc_like( '_site_transient_timeout_' ) . '%',
    857                         time()
    858                 ) );
     879                                $wpdb->esc_like( '_site_transient_' ) . '%',
     880                                $wpdb->esc_like( '_site_transient_timeout_' ) . '%',
     881                                time()
     882                        )
     883                );
    859884        } elseif ( is_multisite() && is_main_site() && is_main_network() ) {
    860885                // Multisite stores site transients in the sitemeta table.
    861                 $wpdb->query( $wpdb->prepare(
    862                         "DELETE a, b FROM {$wpdb->sitemeta} a, {$wpdb->sitemeta} b
     886                $wpdb->query(
     887                        $wpdb->prepare(
     888                                "DELETE a, b FROM {$wpdb->sitemeta} a, {$wpdb->sitemeta} b
    863889                                WHERE a.meta_key LIKE %s
    864890                                AND a.meta_key NOT LIKE %s
    865891                                AND b.meta_key = CONCAT( '_site_transient_timeout_', SUBSTRING( a.meta_key, 17 ) )
    866892                                AND b.meta_value < %d",
    867                         $wpdb->esc_like( '_site_transient_' ) . '%',
    868                         $wpdb->esc_like( '_site_transient_timeout_' ) . '%',
    869                         time()
    870                 ) );
     893                                $wpdb->esc_like( '_site_transient_' ) . '%',
     894                                $wpdb->esc_like( '_site_transient_timeout_' ) . '%',
     895                                time()
     896                        )
     897                );
    871898        }
    872899}
     
    897924        $settings = (string) get_user_option( 'user-settings', $user_id );
    898925
    899         if ( isset( $_COOKIE['wp-settings-' . $user_id] ) ) {
    900                 $cookie = preg_replace( '/[^A-Za-z0-9=&_]/', '', $_COOKIE['wp-settings-' . $user_id] );
     926        if ( isset( $_COOKIE[ 'wp-settings-' . $user_id ] ) ) {
     927                $cookie = preg_replace( '/[^A-Za-z0-9=&_]/', '', $_COOKIE[ 'wp-settings-' . $user_id ] );
    901928
    902929                // No change or both empty
    903                 if ( $cookie == $settings )
     930                if ( $cookie == $settings ) {
    904931                        return;
     932                }
    905933
    906934                $last_saved = (int) get_user_option( 'user-settings-time', $user_id );
    907                 $current = isset( $_COOKIE['wp-settings-time-' . $user_id]) ? preg_replace( '/[^0-9]/', '', $_COOKIE['wp-settings-time-' . $user_id] ) : 0;
     935                $current    = isset( $_COOKIE[ 'wp-settings-time-' . $user_id ] ) ? preg_replace( '/[^0-9]/', '', $_COOKIE[ 'wp-settings-time-' . $user_id ] ) : 0;
    908936
    909937                // The cookie is newer than the saved value. Update the user_option and leave the cookie as-is
     
    919947        setcookie( 'wp-settings-' . $user_id, $settings, time() + YEAR_IN_SECONDS, SITECOOKIEPATH, null, $secure );
    920948        setcookie( 'wp-settings-time-' . $user_id, time(), time() + YEAR_IN_SECONDS, SITECOOKIEPATH, null, $secure );
    921         $_COOKIE['wp-settings-' . $user_id] = $settings;
     949        $_COOKIE[ 'wp-settings-' . $user_id ] = $settings;
    922950}
    923951
     
    934962        $all_user_settings = get_all_user_settings();
    935963
    936         return isset( $all_user_settings[$name] ) ? $all_user_settings[$name] : $default;
     964        return isset( $all_user_settings[ $name ] ) ? $all_user_settings[ $name ] : $default;
    937965}
    938966
     
    955983        }
    956984
    957         $all_user_settings = get_all_user_settings();
    958         $all_user_settings[$name] = $value;
     985        $all_user_settings          = get_all_user_settings();
     986        $all_user_settings[ $name ] = $value;
    959987
    960988        return wp_set_all_user_settings( $all_user_settings );
     
    9791007
    9801008        $all_user_settings = get_all_user_settings();
    981         $names = (array) $names;
    982         $deleted = false;
     1009        $names             = (array) $names;
     1010        $deleted           = false;
    9831011
    9841012        foreach ( $names as $name ) {
    985                 if ( isset( $all_user_settings[$name] ) ) {
    986                         unset( $all_user_settings[$name] );
     1013                if ( isset( $all_user_settings[ $name ] ) ) {
     1014                        unset( $all_user_settings[ $name ] );
    9871015                        $deleted = true;
    9881016                }
     
    10181046        $user_settings = array();
    10191047
    1020         if ( isset( $_COOKIE['wp-settings-' . $user_id] ) ) {
    1021                 $cookie = preg_replace( '/[^A-Za-z0-9=&_-]/', '', $_COOKIE['wp-settings-' . $user_id] );
     1048        if ( isset( $_COOKIE[ 'wp-settings-' . $user_id ] ) ) {
     1049                $cookie = preg_replace( '/[^A-Za-z0-9=&_-]/', '', $_COOKIE[ 'wp-settings-' . $user_id ] );
    10221050
    10231051                if ( strpos( $cookie, '=' ) ) { // '=' cannot be 1st char
     
    10611089        $settings = '';
    10621090        foreach ( $user_settings as $name => $value ) {
    1063                 $_name = preg_replace( '/[^A-Za-z0-9_-]+/', '', $name );
     1091                $_name  = preg_replace( '/[^A-Za-z0-9_-]+/', '', $name );
    10641092                $_value = preg_replace( '/[^A-Za-z0-9_-]+/', '', $value );
    10651093
     
    12181246        // prevent non-existent options from triggering multiple queries
    12191247        $notoptions_key = "$network_id:notoptions";
    1220         $notoptions = wp_cache_get( $notoptions_key, 'site-options' );
     1248        $notoptions     = wp_cache_get( $notoptions_key, 'site-options' );
    12211249
    12221250        if ( isset( $notoptions[ $option ] ) ) {
     
    12421270                /** This filter is documented in wp-includes/option.php */
    12431271                $default = apply_filters( 'default_site_option_' . $option, $default, $option, $network_id );
    1244                 $value = get_option( $option, $default );
     1272                $value   = get_option( $option, $default );
    12451273        } else {
    12461274                $cache_key = "$network_id:$option";
    1247                 $value = wp_cache_get( $cache_key, 'site-options' );
     1275                $value     = wp_cache_get( $cache_key, 'site-options' );
    12481276
    12491277                if ( ! isset( $value ) || false === $value ) {
     
    13511379
    13521380                $serialized_value = maybe_serialize( $value );
    1353                 $result = $wpdb->insert( $wpdb->sitemeta, array( 'site_id'    => $network_id, 'meta_key'   => $option, 'meta_value' => $serialized_value ) );
     1381                $result           = $wpdb->insert(
     1382                        $wpdb->sitemeta, array(
     1383                                'site_id'    => $network_id,
     1384                                'meta_key'   => $option,
     1385                                'meta_value' => $serialized_value,
     1386                        )
     1387                );
    13541388
    13551389                if ( ! $result ) {
     
    14531487                wp_cache_delete( $cache_key, 'site-options' );
    14541488
    1455                 $result = $wpdb->delete( $wpdb->sitemeta, array( 'meta_key' => $option, 'site_id' => $network_id ) );
     1489                $result = $wpdb->delete(
     1490                        $wpdb->sitemeta, array(
     1491                                'meta_key' => $option,
     1492                                'site_id'  => $network_id,
     1493                        )
     1494                );
    14561495        }
    14571496
     
    15471586
    15481587        $notoptions_key = "$network_id:notoptions";
    1549         $notoptions = wp_cache_get( $notoptions_key, 'site-options' );
     1588        $notoptions     = wp_cache_get( $notoptions_key, 'site-options' );
    15501589        if ( is_array( $notoptions ) && isset( $notoptions[ $option ] ) ) {
    15511590                unset( $notoptions[ $option ] );
     
    15591598
    15601599                $serialized_value = maybe_serialize( $value );
    1561                 $result = $wpdb->update( $wpdb->sitemeta, array( 'meta_value' => $serialized_value ), array( 'site_id' => $network_id, 'meta_key' => $option ) );
     1600                $result           = $wpdb->update(
     1601                        $wpdb->sitemeta, array( 'meta_value' => $serialized_value ), array(
     1602                                'site_id'  => $network_id,
     1603                                'meta_key' => $option,
     1604                        )
     1605                );
    15621606
    15631607                if ( $result ) {
     
    16291673        } else {
    16301674                $option_timeout = '_site_transient_timeout_' . $transient;
    1631                 $option = '_site_transient_' . $transient;
    1632                 $result = delete_site_option( $option );
    1633                 if ( $result )
     1675                $option         = '_site_transient_' . $transient;
     1676                $result         = delete_site_option( $option );
     1677                if ( $result ) {
    16341678                        delete_site_option( $option_timeout );
     1679                }
    16351680        }
    16361681        if ( $result ) {
     
    16821727        $pre = apply_filters( "pre_site_transient_{$transient}", false, $transient );
    16831728
    1684         if ( false !== $pre )
     1729        if ( false !== $pre ) {
    16851730                return $pre;
     1731        }
    16861732
    16871733        if ( wp_using_ext_object_cache() ) {
     
    16891735        } else {
    16901736                // Core transients that do not have a timeout. Listed here so querying timeouts can be avoided.
    1691                 $no_timeout = array('update_core', 'update_plugins', 'update_themes');
     1737                $no_timeout       = array( 'update_core', 'update_plugins', 'update_themes' );
    16921738                $transient_option = '_site_transient_' . $transient;
    16931739                if ( ! in_array( $transient, $no_timeout ) ) {
    16941740                        $transient_timeout = '_site_transient_timeout_' . $transient;
    1695                         $timeout = get_site_option( $transient_timeout );
     1741                        $timeout           = get_site_option( $transient_timeout );
    16961742                        if ( false !== $timeout && $timeout < time() ) {
    1697                                 delete_site_option( $transient_option  );
     1743                                delete_site_option( $transient_option );
    16981744                                delete_site_option( $transient_timeout );
    16991745                                $value = false;
     
    17011747                }
    17021748
    1703                 if ( ! isset( $value ) )
     1749                if ( ! isset( $value ) ) {
    17041750                        $value = get_site_option( $transient_option );
     1751                }
    17051752        }
    17061753
     
    17691816        } else {
    17701817                $transient_timeout = '_site_transient_timeout_' . $transient;
    1771                 $option = '_site_transient_' . $transient;
     1818                $option            = '_site_transient_' . $transient;
    17721819                if ( false === get_site_option( $option ) ) {
    1773                         if ( $expiration )
     1820                        if ( $expiration ) {
    17741821                                add_site_option( $transient_timeout, time() + $expiration );
     1822                        }
    17751823                        $result = add_site_option( $option, $value );
    17761824                } else {
    1777                         if ( $expiration )
     1825                        if ( $expiration ) {
    17781826                                update_site_option( $transient_timeout, time() + $expiration );
     1827                        }
    17791828                        $result = update_site_option( $option, $value );
    17801829                }
     
    18191868 */
    18201869function register_initial_settings() {
    1821         register_setting( 'general', 'blogname', array(
    1822                 'show_in_rest' => array(
    1823                         'name' => 'title',
    1824                 ),
    1825                 'type'         => 'string',
    1826                 'description'  => __( 'Site title.' ),
    1827         ) );
    1828 
    1829         register_setting( 'general', 'blogdescription', array(
    1830                 'show_in_rest' => array(
    1831                         'name' => 'description',
    1832                 ),
    1833                 'type'         => 'string',
    1834                 'description'  => __( 'Site tagline.' ),
    1835         ) );
     1870        register_setting(
     1871                'general', 'blogname', array(
     1872                        'show_in_rest' => array(
     1873                                'name' => 'title',
     1874                        ),
     1875                        'type'         => 'string',
     1876                        'description'  => __( 'Site title.' ),
     1877                )
     1878        );
     1879
     1880        register_setting(
     1881                'general', 'blogdescription', array(
     1882                        'show_in_rest' => array(
     1883                                'name' => 'description',
     1884                        ),
     1885                        'type'         => 'string',
     1886                        'description'  => __( 'Site tagline.' ),
     1887                )
     1888        );
    18361889
    18371890        if ( ! is_multisite() ) {
    1838                 register_setting( 'general', 'siteurl', array(
     1891                register_setting(
     1892                        'general', 'siteurl', array(
     1893                                'show_in_rest' => array(
     1894                                        'name'   => 'url',
     1895                                        'schema' => array(
     1896                                                'format' => 'uri',
     1897                                        ),
     1898                                ),
     1899                                'type'         => 'string',
     1900                                'description'  => __( 'Site URL.' ),
     1901                        )
     1902                );
     1903        }
     1904
     1905        if ( ! is_multisite() ) {
     1906                register_setting(
     1907                        'general', 'admin_email', array(
     1908                                'show_in_rest' => array(
     1909                                        'name'   => 'email',
     1910                                        'schema' => array(
     1911                                                'format' => 'email',
     1912                                        ),
     1913                                ),
     1914                                'type'         => 'string',
     1915                                'description'  => __( 'This address is used for admin purposes, like new user notification.' ),
     1916                        )
     1917                );
     1918        }
     1919
     1920        register_setting(
     1921                'general', 'timezone_string', array(
    18391922                        'show_in_rest' => array(
    1840                                 'name'    => 'url',
    1841                                 'schema'  => array(
    1842                                         'format' => 'uri',
     1923                                'name' => 'timezone',
     1924                        ),
     1925                        'type'         => 'string',
     1926                        'description'  => __( 'A city in the same timezone as you.' ),
     1927                )
     1928        );
     1929
     1930        register_setting(
     1931                'general', 'date_format', array(
     1932                        'show_in_rest' => true,
     1933                        'type'         => 'string',
     1934                        'description'  => __( 'A date format for all date strings.' ),
     1935                )
     1936        );
     1937
     1938        register_setting(
     1939                'general', 'time_format', array(
     1940                        'show_in_rest' => true,
     1941                        'type'         => 'string',
     1942                        'description'  => __( 'A time format for all time strings.' ),
     1943                )
     1944        );
     1945
     1946        register_setting(
     1947                'general', 'start_of_week', array(
     1948                        'show_in_rest' => true,
     1949                        'type'         => 'integer',
     1950                        'description'  => __( 'A day number of the week that the week should start on.' ),
     1951                )
     1952        );
     1953
     1954        register_setting(
     1955                'general', 'WPLANG', array(
     1956                        'show_in_rest' => array(
     1957                                'name' => 'language',
     1958                        ),
     1959                        'type'         => 'string',
     1960                        'description'  => __( 'WordPress locale code.' ),
     1961                        'default'      => 'en_US',
     1962                )
     1963        );
     1964
     1965        register_setting(
     1966                'writing', 'use_smilies', array(
     1967                        'show_in_rest' => true,
     1968                        'type'         => 'boolean',
     1969                        'description'  => __( 'Convert emoticons like :-) and :-P to graphics on display.' ),
     1970                        'default'      => true,
     1971                )
     1972        );
     1973
     1974        register_setting(
     1975                'writing', 'default_category', array(
     1976                        'show_in_rest' => true,
     1977                        'type'         => 'integer',
     1978                        'description'  => __( 'Default post category.' ),
     1979                )
     1980        );
     1981
     1982        register_setting(
     1983                'writing', 'default_post_format', array(
     1984                        'show_in_rest' => true,
     1985                        'type'         => 'string',
     1986                        'description'  => __( 'Default post format.' ),
     1987                )
     1988        );
     1989
     1990        register_setting(
     1991                'reading', 'posts_per_page', array(
     1992                        'show_in_rest' => true,
     1993                        'type'         => 'integer',
     1994                        'description'  => __( 'Blog pages show at most.' ),
     1995                        'default'      => 10,
     1996                )
     1997        );
     1998
     1999        register_setting(
     2000                'discussion', 'default_ping_status', array(
     2001                        'show_in_rest' => array(
     2002                                'schema' => array(
     2003                                        'enum' => array( 'open', 'closed' ),
    18432004                                ),
    18442005                        ),
    18452006                        'type'         => 'string',
    1846                         'description'  => __( 'Site URL.' ),
    1847                 ) );
    1848         }
    1849 
    1850         if ( ! is_multisite() ) {
    1851                 register_setting( 'general', 'admin_email', array(
     2007                        'description'  => __( 'Allow link notifications from other blogs (pingbacks and trackbacks) on new articles.' ),
     2008                )
     2009        );
     2010
     2011        register_setting(
     2012                'discussion', 'default_comment_status', array(
    18522013                        'show_in_rest' => array(
    1853                                 'name'    => 'email',
    1854                                 'schema'  => array(
    1855                                         'format' => 'email',
     2014                                'schema' => array(
     2015                                        'enum' => array( 'open', 'closed' ),
    18562016                                ),
    18572017                        ),
    18582018                        'type'         => 'string',
    1859                         'description'  => __( 'This address is used for admin purposes, like new user notification.' ),
    1860                 ) );
    1861         }
    1862 
    1863         register_setting( 'general', 'timezone_string', array(
    1864                 'show_in_rest' => array(
    1865                         'name' => 'timezone',
    1866                 ),
    1867                 'type'         => 'string',
    1868                 'description'  => __( 'A city in the same timezone as you.' ),
    1869         ) );
    1870 
    1871         register_setting( 'general', 'date_format', array(
    1872                 'show_in_rest' => true,
    1873                 'type'         => 'string',
    1874                 'description'  => __( 'A date format for all date strings.' ),
    1875         ) );
    1876 
    1877         register_setting( 'general', 'time_format', array(
    1878                 'show_in_rest' => true,
    1879                 'type'         => 'string',
    1880                 'description'  => __( 'A time format for all time strings.' ),
    1881         ) );
    1882 
    1883         register_setting( 'general', 'start_of_week', array(
    1884                 'show_in_rest' => true,
    1885                 'type'         => 'integer',
    1886                 'description'  => __( 'A day number of the week that the week should start on.' ),
    1887         ) );
    1888 
    1889         register_setting( 'general', 'WPLANG', array(
    1890                 'show_in_rest' => array(
    1891                         'name' => 'language',
    1892                 ),
    1893                 'type'         => 'string',
    1894                 'description'  => __( 'WordPress locale code.' ),
    1895                 'default'      => 'en_US',
    1896         ) );
    1897 
    1898         register_setting( 'writing', 'use_smilies', array(
    1899                 'show_in_rest' => true,
    1900                 'type'         => 'boolean',
    1901                 'description'  => __( 'Convert emoticons like :-) and :-P to graphics on display.' ),
    1902                 'default'      => true,
    1903         ) );
    1904 
    1905         register_setting( 'writing', 'default_category', array(
    1906                 'show_in_rest' => true,
    1907                 'type'         => 'integer',
    1908                 'description'  => __( 'Default post category.' ),
    1909         ) );
    1910 
    1911         register_setting( 'writing', 'default_post_format', array(
    1912                 'show_in_rest' => true,
    1913                 'type'         => 'string',
    1914                 'description'  => __( 'Default post format.' ),
    1915         ) );
    1916 
    1917         register_setting( 'reading', 'posts_per_page', array(
    1918                 'show_in_rest' => true,
    1919                 'type'         => 'integer',
    1920                 'description'  => __( 'Blog pages show at most.' ),
    1921                 'default'      => 10,
    1922         ) );
    1923 
    1924         register_setting( 'discussion', 'default_ping_status', array(
    1925                 'show_in_rest' => array(
    1926                         'schema'   => array(
    1927                                 'enum' => array( 'open', 'closed' ),
    1928                         ),
    1929                 ),
    1930                 'type'         => 'string',
    1931                 'description'  => __( 'Allow link notifications from other blogs (pingbacks and trackbacks) on new articles.' ),
    1932         ) );
    1933 
    1934         register_setting( 'discussion', 'default_comment_status', array(
    1935                 'show_in_rest' => array(
    1936                         'schema'   => array(
    1937                                 'enum' => array( 'open', 'closed' ),
    1938                         ),
    1939                 ),
    1940                 'type'         => 'string',
    1941                 'description'  => __( 'Allow people to post comments on new articles.' ),
    1942         ) );
     2019                        'description'  => __( 'Allow people to post comments on new articles.' ),
     2020                )
     2021        );
    19432022
    19442023}
     
    19542033 *
    19552034 * @param string $option_group A settings group name. Should correspond to a whitelisted option key name.
    1956  *      Default whitelisted option key names include "general," "discussion," and "reading," among others.
     2035 *  Default whitelisted option key names include "general," "discussion," and "reading," among others.
    19572036 * @param string $option_name The name of an option to sanitize and save.
    19582037 * @param array  $args {
     
    20032082
    20042083        if ( 'misc' == $option_group ) {
    2005                 _deprecated_argument( __FUNCTION__, '3.0.0',
     2084                _deprecated_argument(
     2085                        __FUNCTION__, '3.0.0',
    20062086                        /* translators: %s: misc */
    2007                         sprintf( __( 'The "%s" options group has been removed. Use another settings group.' ),
     2087                        sprintf(
     2088                                __( 'The "%s" options group has been removed. Use another settings group.' ),
    20082089                                'misc'
    20092090                        )
     
    20132094
    20142095        if ( 'privacy' == $option_group ) {
    2015                 _deprecated_argument( __FUNCTION__, '3.5.0',
     2096                _deprecated_argument(
     2097                        __FUNCTION__, '3.5.0',
    20162098                        /* translators: %s: privacy */
    2017                         sprintf( __( 'The "%s" options group has been removed. Use another settings group.' ),
     2099                        sprintf(
     2100                                __( 'The "%s" options group has been removed. Use another settings group.' ),
    20182101                                'privacy'
    20192102                        )
     
    20492132
    20502133        if ( 'misc' == $option_group ) {
    2051                 _deprecated_argument( __FUNCTION__, '3.0.0',
     2134                _deprecated_argument(
     2135                        __FUNCTION__, '3.0.0',
    20522136                        /* translators: %s: misc */
    2053                         sprintf( __( 'The "%s" options group has been removed. Use another settings group.' ),
     2137                        sprintf(
     2138                                __( 'The "%s" options group has been removed. Use another settings group.' ),
    20542139                                'misc'
    20552140                        )
     
    20592144
    20602145        if ( 'privacy' == $option_group ) {
    2061                 _deprecated_argument( __FUNCTION__, '3.5.0',
     2146                _deprecated_argument(
     2147                        __FUNCTION__, '3.5.0',
    20622148                        /* translators: %s: privacy */
    2063                         sprintf( __( 'The "%s" options group has been removed. Use another settings group.' ),
     2149                        sprintf(
     2150                                __( 'The "%s" options group has been removed. Use another settings group.' ),
    20642151                                'privacy'
    20652152                        )
     
    20732160        }
    20742161        if ( '' !== $deprecated ) {
    2075                 _deprecated_argument( __FUNCTION__, '4.7.0',
     2162                _deprecated_argument(
     2163                        __FUNCTION__, '4.7.0',
    20762164                        /* translators: 1: $sanitize_callback, 2: register_setting() */
    2077                         sprintf( __( '%1$s is deprecated. The callback from %2$s is used instead.' ),
     2165                        sprintf(
     2166                                __( '%1$s is deprecated. The callback from %2$s is used instead.' ),
    20782167                                '<code>$sanitize_callback</code>',
    20792168                                '<code>register_setting()</code>'
Note: See TracChangeset for help on using the changeset viewer.