WordPress.org

Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (3 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/class-wp-customize-setting.php

    r41162 r42343  
    170170
    171171        $this->manager = $manager;
    172         $this->id = $id;
     172        $this->id      = $id;
    173173
    174174        // Parse the ID for array keys.
     
    177177
    178178        // Rebuild the ID.
    179         $this->id = $this->id_data[ 'base' ];
    180         if ( ! empty( $this->id_data[ 'keys' ] ) ) {
     179        $this->id = $this->id_data['base'];
     180        if ( ! empty( $this->id_data['keys'] ) ) {
    181181            $this->id .= '[' . implode( '][', $this->id_data['keys'] ) . ']';
    182182        }
     
    312312        }
    313313
    314         $id_base = $this->id_data['base'];
    315         $is_multidimensional = ! empty( $this->id_data['keys'] );
     314        $id_base                 = $this->id_data['base'];
     315        $is_multidimensional     = ! empty( $this->id_data['keys'] );
    316316        $multidimensional_filter = array( $this, '_multidimensional_preview_filter' );
    317317
     
    322322         * to be previewed.
    323323         */
    324         $undefined = new stdClass();
     324        $undefined     = new stdClass();
    325325        $needs_preview = ( $undefined !== $this->post_value( $undefined ) );
    326         $value = null;
     326        $value         = null;
    327327
    328328        // Since no post value was defined, check if we have an initial value set.
    329329        if ( ! $needs_preview ) {
    330330            if ( $this->is_multidimensional_aggregated ) {
    331                 $root = self::$aggregated_multidimensionals[ $this->type ][ $id_base ]['root_value'];
     331                $root  = self::$aggregated_multidimensionals[ $this->type ][ $id_base ]['root_value'];
    332332                $value = $this->multidimensional_get( $root, $this->id_data['keys'], $undefined );
    333333            } else {
    334                 $default = $this->default;
     334                $default       = $this->default;
    335335                $this->default = $undefined; // Temporarily set default to undefined so we can detect if existing value is set.
    336                 $value = $this->value();
     336                $value         = $this->value();
    337337                $this->default = $default;
    338338            }
     
    349349
    350350        switch ( $this->type ) {
    351             case 'theme_mod' :
     351            case 'theme_mod':
    352352                if ( ! $is_multidimensional ) {
    353353                    add_filter( "theme_mod_{$id_base}", array( $this, '_preview_filter' ) );
     
    360360                }
    361361                break;
    362             case 'option' :
     362            case 'option':
    363363                if ( ! $is_multidimensional ) {
    364364                    add_filter( "pre_option_{$id_base}", array( $this, '_preview_filter' ) );
     
    372372                }
    373373                break;
    374             default :
    375 
     374            default:
    376375                /**
    377376                 * Fires when the WP_Customize_Setting::preview() method is called for settings
     
    437436        }
    438437
    439         $undefined = new stdClass(); // Symbol hack.
     438        $undefined  = new stdClass(); // Symbol hack.
    440439        $post_value = $this->post_value( $undefined );
    441440        if ( $undefined !== $post_value ) {
     
    484483            // Do the replacements of the posted/default sub value into the root value.
    485484            $value = $previewed_setting->post_value( $previewed_setting->default );
    486             $root = self::$aggregated_multidimensionals[ $previewed_setting->type ][ $id_base ]['root_value'];
    487             $root = $previewed_setting->multidimensional_replace( $root, $previewed_setting->id_data['keys'], $value );
     485            $root  = self::$aggregated_multidimensionals[ $previewed_setting->type ][ $id_base ]['root_value'];
     486            $root  = $previewed_setting->multidimensional_replace( $root, $previewed_setting->id_data['keys'], $value );
    488487            self::$aggregated_multidimensionals[ $previewed_setting->type ][ $id_base ]['root_value'] = $root;
    489488
     
    721720     */
    722721    public function value() {
    723         $id_base = $this->id_data['base'];
     722        $id_base      = $this->id_data['base'];
    724723        $is_core_type = ( 'option' === $this->type || 'theme_mod' === $this->type );
    725724
     
    754753        } elseif ( $this->is_multidimensional_aggregated ) {
    755754            $root_value = self::$aggregated_multidimensionals[ $this->type ][ $id_base ]['root_value'];
    756             $value = $this->multidimensional_get( $root_value, $this->id_data['keys'], $this->default );
     755            $value      = $this->multidimensional_get( $root_value, $this->id_data['keys'], $this->default );
    757756
    758757            // Ensure that the post value is used if the setting is previewed, since preview filters aren't applying on cached $root_value.
     
    787786        $value = apply_filters( "customize_sanitize_js_{$this->id}", $this->value(), $this );
    788787
    789         if ( is_string( $value ) )
    790             return html_entity_decode( $value, ENT_QUOTES, 'UTF-8');
     788        if ( is_string( $value ) ) {
     789            return html_entity_decode( $value, ENT_QUOTES, 'UTF-8' );
     790        }
    791791
    792792        return $value;
     
    817817     */
    818818    final public function check_capabilities() {
    819         if ( $this->capability && ! call_user_func_array( 'current_user_can', (array) $this->capability ) )
     819        if ( $this->capability && ! call_user_func_array( 'current_user_can', (array) $this->capability ) ) {
    820820            return false;
    821 
    822         if ( $this->theme_supports && ! call_user_func_array( 'current_theme_supports', (array) $this->theme_supports ) )
     821        }
     822
     823        if ( $this->theme_supports && ! call_user_func_array( 'current_theme_supports', (array) $this->theme_supports ) ) {
    823824            return false;
     825        }
    824826
    825827        return true;
     
    837839     */
    838840    final protected function multidimensional( &$root, $keys, $create = false ) {
    839         if ( $create && empty( $root ) )
     841        if ( $create && empty( $root ) ) {
    840842            $root = array();
    841 
    842         if ( ! isset( $root ) || empty( $keys ) )
     843        }
     844
     845        if ( ! isset( $root ) || empty( $keys ) ) {
    843846            return;
     847        }
    844848
    845849        $last = array_pop( $keys );
     
    847851
    848852        foreach ( $keys as $key ) {
    849             if ( $create && ! isset( $node[ $key ] ) )
     853            if ( $create && ! isset( $node[ $key ] ) ) {
    850854                $node[ $key ] = array();
    851 
    852             if ( ! is_array( $node ) || ! isset( $node[ $key ] ) )
     855            }
     856
     857            if ( ! is_array( $node ) || ! isset( $node[ $key ] ) ) {
    853858                return;
     859            }
    854860
    855861            $node = &$node[ $key ];
     
    866872        }
    867873
    868         if ( ! isset( $node[ $last ] ) )
     874        if ( ! isset( $node[ $last ] ) ) {
    869875            return;
     876        }
    870877
    871878        return array(
     
    887894     */
    888895    final protected function multidimensional_replace( $root, $keys, $value ) {
    889         if ( ! isset( $value ) )
     896        if ( ! isset( $value ) ) {
    890897            return $root;
    891         elseif ( empty( $keys ) ) // If there are no keys, we're replacing the root.
     898        } elseif ( empty( $keys ) ) { // If there are no keys, we're replacing the root.
    892899            return $value;
     900        }
    893901
    894902        $result = $this->multidimensional( $root, $keys, true );
    895903
    896         if ( isset( $result ) )
     904        if ( isset( $result ) ) {
    897905            $result['node'][ $result['key'] ] = $value;
     906        }
    898907
    899908        return $root;
     
    911920     */
    912921    final protected function multidimensional_get( $root, $keys, $default = null ) {
    913         if ( empty( $keys ) ) // If there are no keys, test the root.
     922        if ( empty( $keys ) ) { // If there are no keys, test the root.
    914923            return isset( $root ) ? $root : $default;
     924        }
    915925
    916926        $result = $this->multidimensional( $root, $keys );
Note: See TracChangeset for help on using the changeset viewer.