mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-12 04:40:26 +00:00
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. git-svn-id: https://develop.svn.wordpress.org/trunk@42343 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -169,15 +169,15 @@ class WP_Customize_Setting {
|
||||
}
|
||||
|
||||
$this->manager = $manager;
|
||||
$this->id = $id;
|
||||
$this->id = $id;
|
||||
|
||||
// Parse the ID for array keys.
|
||||
$this->id_data['keys'] = preg_split( '/\[/', str_replace( ']', '', $this->id ) );
|
||||
$this->id_data['base'] = array_shift( $this->id_data['keys'] );
|
||||
|
||||
// Rebuild the ID.
|
||||
$this->id = $this->id_data[ 'base' ];
|
||||
if ( ! empty( $this->id_data[ 'keys' ] ) ) {
|
||||
$this->id = $this->id_data['base'];
|
||||
if ( ! empty( $this->id_data['keys'] ) ) {
|
||||
$this->id .= '[' . implode( '][', $this->id_data['keys'] ) . ']';
|
||||
}
|
||||
|
||||
@@ -311,8 +311,8 @@ class WP_Customize_Setting {
|
||||
return true;
|
||||
}
|
||||
|
||||
$id_base = $this->id_data['base'];
|
||||
$is_multidimensional = ! empty( $this->id_data['keys'] );
|
||||
$id_base = $this->id_data['base'];
|
||||
$is_multidimensional = ! empty( $this->id_data['keys'] );
|
||||
$multidimensional_filter = array( $this, '_multidimensional_preview_filter' );
|
||||
|
||||
/*
|
||||
@@ -321,19 +321,19 @@ class WP_Customize_Setting {
|
||||
* then the preview short-circuits because there is nothing that needs
|
||||
* to be previewed.
|
||||
*/
|
||||
$undefined = new stdClass();
|
||||
$undefined = new stdClass();
|
||||
$needs_preview = ( $undefined !== $this->post_value( $undefined ) );
|
||||
$value = null;
|
||||
$value = null;
|
||||
|
||||
// Since no post value was defined, check if we have an initial value set.
|
||||
if ( ! $needs_preview ) {
|
||||
if ( $this->is_multidimensional_aggregated ) {
|
||||
$root = self::$aggregated_multidimensionals[ $this->type ][ $id_base ]['root_value'];
|
||||
$root = self::$aggregated_multidimensionals[ $this->type ][ $id_base ]['root_value'];
|
||||
$value = $this->multidimensional_get( $root, $this->id_data['keys'], $undefined );
|
||||
} else {
|
||||
$default = $this->default;
|
||||
$default = $this->default;
|
||||
$this->default = $undefined; // Temporarily set default to undefined so we can detect if existing value is set.
|
||||
$value = $this->value();
|
||||
$value = $this->value();
|
||||
$this->default = $default;
|
||||
}
|
||||
$needs_preview = ( $undefined === $value ); // Because the default needs to be supplied.
|
||||
@@ -348,7 +348,7 @@ class WP_Customize_Setting {
|
||||
}
|
||||
|
||||
switch ( $this->type ) {
|
||||
case 'theme_mod' :
|
||||
case 'theme_mod':
|
||||
if ( ! $is_multidimensional ) {
|
||||
add_filter( "theme_mod_{$id_base}", array( $this, '_preview_filter' ) );
|
||||
} else {
|
||||
@@ -359,7 +359,7 @@ class WP_Customize_Setting {
|
||||
self::$aggregated_multidimensionals[ $this->type ][ $id_base ]['previewed_instances'][ $this->id ] = $this;
|
||||
}
|
||||
break;
|
||||
case 'option' :
|
||||
case 'option':
|
||||
if ( ! $is_multidimensional ) {
|
||||
add_filter( "pre_option_{$id_base}", array( $this, '_preview_filter' ) );
|
||||
} else {
|
||||
@@ -371,8 +371,7 @@ class WP_Customize_Setting {
|
||||
self::$aggregated_multidimensionals[ $this->type ][ $id_base ]['previewed_instances'][ $this->id ] = $this;
|
||||
}
|
||||
break;
|
||||
default :
|
||||
|
||||
default:
|
||||
/**
|
||||
* Fires when the WP_Customize_Setting::preview() method is called for settings
|
||||
* not handled as theme_mods or options.
|
||||
@@ -436,7 +435,7 @@ class WP_Customize_Setting {
|
||||
return $original;
|
||||
}
|
||||
|
||||
$undefined = new stdClass(); // Symbol hack.
|
||||
$undefined = new stdClass(); // Symbol hack.
|
||||
$post_value = $this->post_value( $undefined );
|
||||
if ( $undefined !== $post_value ) {
|
||||
$value = $post_value;
|
||||
@@ -483,8 +482,8 @@ class WP_Customize_Setting {
|
||||
|
||||
// Do the replacements of the posted/default sub value into the root value.
|
||||
$value = $previewed_setting->post_value( $previewed_setting->default );
|
||||
$root = self::$aggregated_multidimensionals[ $previewed_setting->type ][ $id_base ]['root_value'];
|
||||
$root = $previewed_setting->multidimensional_replace( $root, $previewed_setting->id_data['keys'], $value );
|
||||
$root = self::$aggregated_multidimensionals[ $previewed_setting->type ][ $id_base ]['root_value'];
|
||||
$root = $previewed_setting->multidimensional_replace( $root, $previewed_setting->id_data['keys'], $value );
|
||||
self::$aggregated_multidimensionals[ $previewed_setting->type ][ $id_base ]['root_value'] = $root;
|
||||
|
||||
// Mark this setting having been applied so that it will be skipped when the filter is called again.
|
||||
@@ -720,7 +719,7 @@ class WP_Customize_Setting {
|
||||
* @return mixed The value.
|
||||
*/
|
||||
public function value() {
|
||||
$id_base = $this->id_data['base'];
|
||||
$id_base = $this->id_data['base'];
|
||||
$is_core_type = ( 'option' === $this->type || 'theme_mod' === $this->type );
|
||||
|
||||
if ( ! $is_core_type && ! $this->is_multidimensional_aggregated ) {
|
||||
@@ -753,7 +752,7 @@ class WP_Customize_Setting {
|
||||
$value = apply_filters( "customize_value_{$id_base}", $value, $this );
|
||||
} elseif ( $this->is_multidimensional_aggregated ) {
|
||||
$root_value = self::$aggregated_multidimensionals[ $this->type ][ $id_base ]['root_value'];
|
||||
$value = $this->multidimensional_get( $root_value, $this->id_data['keys'], $this->default );
|
||||
$value = $this->multidimensional_get( $root_value, $this->id_data['keys'], $this->default );
|
||||
|
||||
// Ensure that the post value is used if the setting is previewed, since preview filters aren't applying on cached $root_value.
|
||||
if ( $this->is_previewed ) {
|
||||
@@ -786,8 +785,9 @@ class WP_Customize_Setting {
|
||||
*/
|
||||
$value = apply_filters( "customize_sanitize_js_{$this->id}", $this->value(), $this );
|
||||
|
||||
if ( is_string( $value ) )
|
||||
return html_entity_decode( $value, ENT_QUOTES, 'UTF-8');
|
||||
if ( is_string( $value ) ) {
|
||||
return html_entity_decode( $value, ENT_QUOTES, 'UTF-8' );
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
@@ -816,11 +816,13 @@ class WP_Customize_Setting {
|
||||
* @return bool False if theme doesn't support the setting or user can't change setting, otherwise true.
|
||||
*/
|
||||
final public function check_capabilities() {
|
||||
if ( $this->capability && ! call_user_func_array( 'current_user_can', (array) $this->capability ) )
|
||||
if ( $this->capability && ! call_user_func_array( 'current_user_can', (array) $this->capability ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( $this->theme_supports && ! call_user_func_array( 'current_theme_supports', (array) $this->theme_supports ) )
|
||||
if ( $this->theme_supports && ! call_user_func_array( 'current_theme_supports', (array) $this->theme_supports ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -836,21 +838,25 @@ class WP_Customize_Setting {
|
||||
* @return array|void Keys are 'root', 'node', and 'key'.
|
||||
*/
|
||||
final protected function multidimensional( &$root, $keys, $create = false ) {
|
||||
if ( $create && empty( $root ) )
|
||||
if ( $create && empty( $root ) ) {
|
||||
$root = array();
|
||||
}
|
||||
|
||||
if ( ! isset( $root ) || empty( $keys ) )
|
||||
if ( ! isset( $root ) || empty( $keys ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$last = array_pop( $keys );
|
||||
$node = &$root;
|
||||
|
||||
foreach ( $keys as $key ) {
|
||||
if ( $create && ! isset( $node[ $key ] ) )
|
||||
if ( $create && ! isset( $node[ $key ] ) ) {
|
||||
$node[ $key ] = array();
|
||||
}
|
||||
|
||||
if ( ! is_array( $node ) || ! isset( $node[ $key ] ) )
|
||||
if ( ! is_array( $node ) || ! isset( $node[ $key ] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$node = &$node[ $key ];
|
||||
}
|
||||
@@ -865,8 +871,9 @@ class WP_Customize_Setting {
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! isset( $node[ $last ] ) )
|
||||
if ( ! isset( $node[ $last ] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
return array(
|
||||
'root' => &$root,
|
||||
@@ -886,15 +893,17 @@ class WP_Customize_Setting {
|
||||
* @return mixed
|
||||
*/
|
||||
final protected function multidimensional_replace( $root, $keys, $value ) {
|
||||
if ( ! isset( $value ) )
|
||||
if ( ! isset( $value ) ) {
|
||||
return $root;
|
||||
elseif ( empty( $keys ) ) // If there are no keys, we're replacing the root.
|
||||
} elseif ( empty( $keys ) ) { // If there are no keys, we're replacing the root.
|
||||
return $value;
|
||||
}
|
||||
|
||||
$result = $this->multidimensional( $root, $keys, true );
|
||||
|
||||
if ( isset( $result ) )
|
||||
if ( isset( $result ) ) {
|
||||
$result['node'][ $result['key'] ] = $value;
|
||||
}
|
||||
|
||||
return $root;
|
||||
}
|
||||
@@ -910,8 +919,9 @@ class WP_Customize_Setting {
|
||||
* @return mixed The requested value or the default value.
|
||||
*/
|
||||
final protected function multidimensional_get( $root, $keys, $default = null ) {
|
||||
if ( empty( $keys ) ) // If there are no keys, test the root.
|
||||
if ( empty( $keys ) ) { // If there are no keys, test the root.
|
||||
return isset( $root ) ? $root : $default;
|
||||
}
|
||||
|
||||
$result = $this->multidimensional( $root, $keys );
|
||||
return isset( $result ) ? $result['node'][ $result['key'] ] : $default;
|
||||
|
||||
Reference in New Issue
Block a user