Coding standards and readability spacing for WP_Customize_Widgets.

Also explicitly re-mark `_capture_filter_pre_update_option()` and `_capture_filter_pre_get_option()` as public.

See #27534.

Built from https://develop.svn.wordpress.org/trunk@27904


git-svn-id: http://core.svn.wordpress.org/trunk@27735 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Drew Jaynes 2014-04-02 06:12:16 +00:00
parent 44c886045f
commit 12e182d929
1 changed files with 110 additions and 102 deletions

View File

@ -27,19 +27,9 @@ final class WP_Customize_Widgets {
* @var array * @var array
*/ */
protected $core_widget_id_bases = array( protected $core_widget_id_bases = array(
'archives', 'archives', 'calendar', 'categories', 'links', 'meta',
'calendar', 'nav_menu', 'pages', 'recent-comments', 'recent-posts',
'categories', 'rss', 'search', 'tag_cloud', 'text',
'links',
'meta',
'nav_menu',
'pages',
'recent-comments',
'recent-posts',
'rss',
'search',
'tag_cloud',
'text',
); );
/** /**
@ -126,6 +116,7 @@ final class WP_Customize_Widgets {
*/ */
public function setup_widget_addition_previews() { public function setup_widget_addition_previews() {
$is_customize_preview = false; $is_customize_preview = false;
if ( ! empty( $this->manager ) && ! is_admin() && 'on' === $this->get_post_value( 'wp_customize' ) ) { if ( ! empty( $this->manager ) && ! is_admin() && 'on' === $this->get_post_value( 'wp_customize' ) ) {
$is_customize_preview = check_ajax_referer( 'preview-customize_' . $this->manager->get_stylesheet(), 'nonce', false ); $is_customize_preview = check_ajax_referer( 'preview-customize_' . $this->manager->get_stylesheet(), 'nonce', false );
} }
@ -148,10 +139,7 @@ final class WP_Customize_Widgets {
// Input from customizer preview. // Input from customizer preview.
if ( isset( $_POST['customized'] ) ) { if ( isset( $_POST['customized'] ) ) {
$customized = json_decode( $this->get_post_value( 'customized' ), true ); $customized = json_decode( $this->get_post_value( 'customized' ), true );
} } else { // Input from ajax widget update request.
// Input from ajax widget update request.
else {
$customized = array(); $customized = array();
$id_base = $this->get_post_value( 'id_base' ); $id_base = $this->get_post_value( 'id_base' );
$widget_number = (int) $this->get_post_value( 'widget_number' ); $widget_number = (int) $this->get_post_value( 'widget_number' );
@ -258,9 +246,7 @@ final class WP_Customize_Widgets {
if ( false === $instance && empty( $value ) ) { if ( false === $instance && empty( $value ) ) {
$instance = array(); $instance = array();
} }
} } else if ( false === $instance || ! isset( $instance[$widget_number] ) ) { // Multi widget
// Multi widget
else if ( false === $instance || ! isset( $instance[$widget_number] ) ) {
if ( empty( $instance ) ) { if ( empty( $instance ) ) {
$instance = array( '_multiwidget' => 1 ); $instance = array( '_multiwidget' => 1 );
} }
@ -351,9 +337,12 @@ final class WP_Customize_Widgets {
foreach ( array_keys( $wp_registered_widgets ) as $widget_id ) { foreach ( array_keys( $wp_registered_widgets ) as $widget_id ) {
$setting_id = $this->get_setting_id( $widget_id ); $setting_id = $this->get_setting_id( $widget_id );
$setting_args = $this->get_setting_args( $setting_id ); $setting_args = $this->get_setting_args( $setting_id );
$setting_args['sanitize_callback'] = array( $this, 'sanitize_widget_instance' ); $setting_args['sanitize_callback'] = array( $this, 'sanitize_widget_instance' );
$setting_args['sanitize_js_callback'] = array( $this, 'sanitize_widget_js_instance' ); $setting_args['sanitize_js_callback'] = array( $this, 'sanitize_widget_js_instance' );
$this->manager->add_setting( $setting_id, $setting_args ); $this->manager->add_setting( $setting_id, $setting_args );
$new_setting_ids[] = $setting_id; $new_setting_ids[] = $setting_id;
} }
@ -361,6 +350,7 @@ final class WP_Customize_Widgets {
if ( empty( $sidebar_widget_ids ) ) { if ( empty( $sidebar_widget_ids ) ) {
$sidebar_widget_ids = array(); $sidebar_widget_ids = array();
} }
$is_registered_sidebar = isset( $GLOBALS['wp_registered_sidebars'][$sidebar_id] ); $is_registered_sidebar = isset( $GLOBALS['wp_registered_sidebars'][$sidebar_id] );
$is_inactive_widgets = ( 'wp_inactive_widgets' === $sidebar_id ); $is_inactive_widgets = ( 'wp_inactive_widgets' === $sidebar_id );
$is_active_sidebar = ( $is_registered_sidebar && ! $is_inactive_widgets ); $is_active_sidebar = ( $is_registered_sidebar && ! $is_inactive_widgets );
@ -369,14 +359,17 @@ final class WP_Customize_Widgets {
if ( $is_registered_sidebar || $is_inactive_widgets ) { if ( $is_registered_sidebar || $is_inactive_widgets ) {
$setting_id = sprintf( 'sidebars_widgets[%s]', $sidebar_id ); $setting_id = sprintf( 'sidebars_widgets[%s]', $sidebar_id );
$setting_args = $this->get_setting_args( $setting_id ); $setting_args = $this->get_setting_args( $setting_id );
$setting_args['sanitize_callback'] = array( $this, 'sanitize_sidebar_widgets' ); $setting_args['sanitize_callback'] = array( $this, 'sanitize_sidebar_widgets' );
$setting_args['sanitize_js_callback'] = array( $this, 'sanitize_sidebar_widgets_js_instance' ); $setting_args['sanitize_js_callback'] = array( $this, 'sanitize_sidebar_widgets_js_instance' );
$this->manager->add_setting( $setting_id, $setting_args ); $this->manager->add_setting( $setting_id, $setting_args );
$new_setting_ids[] = $setting_id; $new_setting_ids[] = $setting_id;
// Add section to contain controls. // Add section to contain controls.
$section_id = sprintf( 'sidebar-widgets-%s', $sidebar_id ); $section_id = sprintf( 'sidebar-widgets-%s', $sidebar_id );
if ( $is_active_sidebar ) { if ( $is_active_sidebar ) {
$section_args = array( $section_args = array(
/* translators: %s: sidebar name */ /* translators: %s: sidebar name */
'title' => sprintf( __( 'Widgets: %s' ), $GLOBALS['wp_registered_sidebars'][$sidebar_id]['name'] ), 'title' => sprintf( __( 'Widgets: %s' ), $GLOBALS['wp_registered_sidebars'][$sidebar_id]['name'] ),
@ -384,18 +377,16 @@ final class WP_Customize_Widgets {
'priority' => 1000 + array_search( $sidebar_id, array_keys( $wp_registered_sidebars ) ), 'priority' => 1000 + array_search( $sidebar_id, array_keys( $wp_registered_sidebars ) ),
); );
$section_args = apply_filters( 'customizer_widgets_section_args', $section_args, $section_id, $sidebar_id ); $section_args = apply_filters( 'customizer_widgets_section_args', $section_args, $section_id, $sidebar_id );
$this->manager->add_section( $section_id, $section_args ); $this->manager->add_section( $section_id, $section_args );
$control = new WP_Widget_Area_Customize_Control( $control = new WP_Widget_Area_Customize_Control( $this->manager, $setting_id, array(
$this->manager, 'section' => $section_id,
$setting_id, 'sidebar_id' => $sidebar_id,
array( 'priority' => count( $sidebar_widget_ids ), // place 'Add Widget' and 'Reorder' buttons at end.
'section' => $section_id, ) );
'sidebar_id' => $sidebar_id,
'priority' => count( $sidebar_widget_ids ), // place Add Widget & Reorder buttons at end
)
);
$new_setting_ids[] = $setting_id; $new_setting_ids[] = $setting_id;
$this->manager->add_control( $control ); $this->manager->add_control( $control );
} }
} }
@ -407,25 +398,24 @@ final class WP_Customize_Widgets {
if ( ! $is_active_sidebar || ! isset( $GLOBALS['wp_registered_widgets'][$widget_id] ) ) { if ( ! $is_active_sidebar || ! isset( $GLOBALS['wp_registered_widgets'][$widget_id] ) ) {
continue; continue;
} }
$registered_widget = $GLOBALS['wp_registered_widgets'][$widget_id]; $registered_widget = $GLOBALS['wp_registered_widgets'][$widget_id];
$setting_id = $this->get_setting_id( $widget_id ); $setting_id = $this->get_setting_id( $widget_id );
$id_base = $GLOBALS['wp_registered_widget_controls'][$widget_id]['id_base']; $id_base = $GLOBALS['wp_registered_widget_controls'][$widget_id]['id_base'];
assert( false !== is_active_widget( $registered_widget['callback'], $registered_widget['id'], false, false ) ); assert( false !== is_active_widget( $registered_widget['callback'], $registered_widget['id'], false, false ) );
$control = new WP_Widget_Form_Customize_Control(
$this->manager, $control = new WP_Widget_Form_Customize_Control( $this->manager, $setting_id, array(
$setting_id, 'label' => $registered_widget['name'],
array( 'section' => $section_id,
'label' => $registered_widget['name'], 'sidebar_id' => $sidebar_id,
'section' => $section_id, 'widget_id' => $widget_id,
'sidebar_id' => $sidebar_id, 'widget_id_base' => $id_base,
'widget_id' => $widget_id, 'priority' => $i,
'widget_id_base' => $id_base, 'width' => $wp_registered_widget_controls[$widget_id]['width'],
'priority' => $i, 'height' => $wp_registered_widget_controls[$widget_id]['height'],
'width' => $wp_registered_widget_controls[$widget_id]['width'], 'is_wide' => $this->is_wide_widget( $widget_id ),
'height' => $wp_registered_widget_controls[$widget_id]['height'], ) );
'is_wide' => $this->is_wide_widget( $widget_id ),
)
);
$this->manager->add_control( $control ); $this->manager->add_control( $control );
} }
} }
@ -439,7 +429,6 @@ final class WP_Customize_Widgets {
$this->manager->get_setting( $new_setting_id )->preview(); $this->manager->get_setting( $new_setting_id )->preview();
} }
} }
$this->remove_prepreview_filters(); $this->remove_prepreview_filters();
} }
@ -454,7 +443,8 @@ final class WP_Customize_Widgets {
*/ */
public function get_setting_id( $widget_id ) { public function get_setting_id( $widget_id ) {
$parsed_widget_id = $this->parse_widget_id( $widget_id ); $parsed_widget_id = $this->parse_widget_id( $widget_id );
$setting_id = sprintf( 'widget_%s', $parsed_widget_id['id_base'] ); $setting_id = sprintf( 'widget_%s', $parsed_widget_id['id_base'] );
if ( ! is_null( $parsed_widget_id['number'] ) ) { if ( ! is_null( $parsed_widget_id['number'] ) ) {
$setting_id .= sprintf( '[%d]', $parsed_widget_id['number'] ); $setting_id .= sprintf( '[%d]', $parsed_widget_id['number'] );
} }
@ -479,10 +469,11 @@ final class WP_Customize_Widgets {
*/ */
public function is_wide_widget( $widget_id ) { public function is_wide_widget( $widget_id ) {
global $wp_registered_widget_controls; global $wp_registered_widget_controls;
$parsed_widget_id = $this->parse_widget_id( $widget_id ); $parsed_widget_id = $this->parse_widget_id( $widget_id );
$width = $wp_registered_widget_controls[$widget_id]['width']; $width = $wp_registered_widget_controls[$widget_id]['width'];
$is_core = in_array( $parsed_widget_id['id_base'], $this->core_widget_id_bases ); $is_core = in_array( $parsed_widget_id['id_base'], $this->core_widget_id_bases );
$is_wide = ( $width > 250 && ! $is_core ); $is_wide = ( $width > 250 && ! $is_core );
/** /**
* Filter whether the given widget is considered "wide". * Filter whether the given widget is considered "wide".
@ -509,6 +500,7 @@ final class WP_Customize_Widgets {
'number' => null, 'number' => null,
'id_base' => null, 'id_base' => null,
); );
if ( preg_match( '/^(.+)-(\d+)$/', $widget_id, $matches ) ) { if ( preg_match( '/^(.+)-(\d+)$/', $widget_id, $matches ) ) {
$parsed['id_base'] = $matches[1]; $parsed['id_base'] = $matches[1];
$parsed['number'] = intval( $matches[2] ); $parsed['number'] = intval( $matches[2] );
@ -536,6 +528,7 @@ final class WP_Customize_Widgets {
$id_base = $matches[2]; $id_base = $matches[2];
$number = isset( $matches[3] ) ? intval( $matches[3] ) : null; $number = isset( $matches[3] ) ? intval( $matches[3] ) : null;
return compact( 'id_base', 'number' ); return compact( 'id_base', 'number' );
} }
@ -554,6 +547,7 @@ final class WP_Customize_Widgets {
* since plugins need templates to be in the DOM. * since plugins need templates to be in the DOM.
*/ */
$available_widgets = array(); $available_widgets = array();
foreach ( $this->get_available_widgets() as $available_widget ) { foreach ( $this->get_available_widgets() as $available_widget ) {
unset( $available_widget['control_tpl'] ); unset( $available_widget['control_tpl'] );
$available_widgets[] = $available_widget; $available_widgets[] = $available_widget;
@ -592,24 +586,26 @@ final class WP_Customize_Widgets {
* and it forces values into strings. * and it forces values into strings.
*/ */
global $wp_scripts; global $wp_scripts;
$exports = array( $exports = array(
'nonce' => wp_create_nonce( 'update-widget' ), 'nonce' => wp_create_nonce( 'update-widget' ),
'registered_sidebars' => array_values( $GLOBALS['wp_registered_sidebars'] ), 'registered_sidebars' => array_values( $GLOBALS['wp_registered_sidebars'] ),
'registered_widgets' => $GLOBALS['wp_registered_widgets'], 'registered_widgets' => $GLOBALS['wp_registered_widgets'],
'available_widgets' => $available_widgets, // @todo Merge this with registered_widgets 'available_widgets' => $available_widgets, // @todo Merge this with registered_widgets
'i18n' => array( 'i18n' => array(
'save_btn_label' => __( 'Apply' ), 'save_btn_label' => __( 'Apply' ),
// @todo translate? do we want these tooltips? // @todo translate? do we want these tooltips?
'save_btn_tooltip' => ( 'Save and preview changes before publishing them.' ), 'save_btn_tooltip' => ( 'Save and preview changes before publishing them.' ),
'remove_btn_label' => __( 'Remove' ), 'remove_btn_label' => __( 'Remove' ),
'remove_btn_tooltip' => ( 'Trash widget by moving it to the inactive widgets sidebar.' ), 'remove_btn_tooltip' => ( 'Trash widget by moving it to the inactive widgets sidebar.' ),
'error' => __( 'An error has occurred. Please reload the page and try again.' ), 'error' => __( 'An error has occurred. Please reload the page and try again.' ),
), ),
'tpl' => array( 'tpl' => array(
'widget_reorder_nav' => $widget_reorder_nav_tpl, 'widget_reorder_nav' => $widget_reorder_nav_tpl,
'move_widget_area' => $move_widget_area_tpl, 'move_widget_area' => $move_widget_area_tpl,
), ),
); );
foreach ( $exports['registered_widgets'] as &$registered_widget ) { foreach ( $exports['registered_widgets'] as &$registered_widget ) {
unset( $registered_widget['callback'] ); // may not be JSON-serializeable unset( $registered_widget['callback'] ); // may not be JSON-serializeable
} }
@ -657,10 +653,10 @@ final class WP_Customize_Widgets {
*/ */
public function get_setting_args( $id, $overrides = array() ) { public function get_setting_args( $id, $overrides = array() ) {
$args = array( $args = array(
'type' => 'option', 'type' => 'option',
'capability' => 'edit_theme_options', 'capability' => 'edit_theme_options',
'transport' => 'refresh', 'transport' => 'refresh',
'default' => array(), 'default' => array(),
); );
$args = array_merge( $args, $overrides ); $args = array_merge( $args, $overrides );
@ -690,8 +686,10 @@ final class WP_Customize_Widgets {
*/ */
public function sanitize_sidebar_widgets( $widget_ids ) { public function sanitize_sidebar_widgets( $widget_ids ) {
global $wp_registered_widgets; global $wp_registered_widgets;
$widget_ids = array_map( 'strval', (array) $widget_ids );
$widget_ids = array_map( 'strval', (array) $widget_ids );
$sanitized_widget_ids = array(); $sanitized_widget_ids = array();
foreach ( $widget_ids as $widget_id ) { foreach ( $widget_ids as $widget_id ) {
if ( array_key_exists( $widget_id, $wp_registered_widgets ) ) { if ( array_key_exists( $widget_id, $wp_registered_widgets ) ) {
$sanitized_widget_ids[] = $widget_id; $sanitized_widget_ids[] = $widget_id;
@ -739,24 +737,21 @@ final class WP_Customize_Widgets {
unset( $available_widget['callback'] ); // not serializable to JSON unset( $available_widget['callback'] ); // not serializable to JSON
$args = array( $args = array(
'widget_id' => $widget['id'], 'widget_id' => $widget['id'],
'widget_name' => $widget['name'], 'widget_name' => $widget['name'],
'_display' => 'template', '_display' => 'template',
); );
$is_disabled = false; $is_disabled = false;
$is_multi_widget = ( $is_multi_widget = ( isset( $wp_registered_widget_controls[$widget['id']]['id_base'] ) && isset( $widget['params'][0]['number'] ) );
isset( $wp_registered_widget_controls[$widget['id']]['id_base'] )
&&
isset( $widget['params'][0]['number'] )
);
if ( $is_multi_widget ) { if ( $is_multi_widget ) {
$id_base = $wp_registered_widget_controls[$widget['id']]['id_base']; $id_base = $wp_registered_widget_controls[$widget['id']]['id_base'];
$args['_temp_id'] = "$id_base-__i__"; $args['_temp_id'] = "$id_base-__i__";
$args['_multi_num'] = next_widget_id_number( $id_base ); $args['_multi_num'] = next_widget_id_number( $id_base );
$args['_add'] = 'multi'; $args['_add'] = 'multi';
} else { } else {
$args['_add'] = 'single'; $args['_add'] = 'single';
if ( $sidebar && 'wp_inactive_widgets' !== $sidebar ) { if ( $sidebar && 'wp_inactive_widgets' !== $sidebar ) {
$is_disabled = true; $is_disabled = true;
} }
@ -767,21 +762,18 @@ final class WP_Customize_Widgets {
$control_tpl = $this->get_widget_control( $list_widget_controls_args ); $control_tpl = $this->get_widget_control( $list_widget_controls_args );
// The properties here are mapped to the Backbone Widget model. // The properties here are mapped to the Backbone Widget model.
$available_widget = array_merge( $available_widget = array_merge( $available_widget, array(
$available_widget, 'temp_id' => isset( $args['_temp_id'] ) ? $args['_temp_id'] : null,
array( 'is_multi' => $is_multi_widget,
'temp_id' => isset( $args['_temp_id'] ) ? $args['_temp_id'] : null, 'control_tpl' => $control_tpl,
'is_multi' => $is_multi_widget, 'multi_number' => ( $args['_add'] === 'multi' ) ? $args['_multi_num'] : false,
'control_tpl' => $control_tpl, 'is_disabled' => $is_disabled,
'multi_number' => ( $args['_add'] === 'multi' ) ? $args['_multi_num'] : false, 'id_base' => $id_base,
'is_disabled' => $is_disabled, 'transport' => 'refresh',
'id_base' => $id_base, 'width' => $wp_registered_widget_controls[$widget['id']]['width'],
'transport' => 'refresh', 'height' => $wp_registered_widget_controls[$widget['id']]['height'],
'width' => $wp_registered_widget_controls[$widget['id']]['width'], 'is_wide' => $this->is_wide_widget( $widget['id'] ),
'height' => $wp_registered_widget_controls[$widget['id']]['height'], ) );
'is_wide' => $this->is_wide_widget( $widget['id'] ),
)
);
$available_widgets[] = $available_widget; $available_widgets[] = $available_widget;
} }
@ -814,13 +806,17 @@ final class WP_Customize_Widgets {
*/ */
public function get_widget_control( $args ) { public function get_widget_control( $args ) {
ob_start(); ob_start();
call_user_func_array( 'wp_widget_control', $args ); call_user_func_array( 'wp_widget_control', $args );
$replacements = array( $replacements = array(
'<form action="" method="post">' => '<div class="form">', '<form action="" method="post">' => '<div class="form">',
'</form>' => '</div><!-- .form -->', '</form>' => '</div><!-- .form -->',
); );
$control_tpl = ob_get_clean(); $control_tpl = ob_get_clean();
$control_tpl = str_replace( array_keys( $replacements ), array_values( $replacements ), $control_tpl ); $control_tpl = str_replace( array_keys( $replacements ), array_values( $replacements ), $control_tpl );
return $control_tpl; return $control_tpl;
} }
@ -899,6 +895,7 @@ final class WP_Customize_Widgets {
* @access public * @access public
*/ */
public function export_preview_data() { public function export_preview_data() {
// Prepare customizer settings to pass to Javascript. // Prepare customizer settings to pass to Javascript.
$settings = array( $settings = array(
'renderedSidebars' => array_fill_keys( array_unique( $this->rendered_sidebars ), true ), 'renderedSidebars' => array_fill_keys( array_unique( $this->rendered_sidebars ), true ),
@ -1019,21 +1016,21 @@ final class WP_Customize_Widgets {
if ( $value === array() ) { if ( $value === array() ) {
return $value; return $value;
} }
$invalid = (
empty( $value['is_widget_customizer_js_value'] ) if ( empty( $value['is_widget_customizer_js_value'] )
|| || empty( $value['instance_hash_key'] )
empty( $value['instance_hash_key'] ) || empty( $value['encoded_serialized_instance'] ) )
|| {
empty( $value['encoded_serialized_instance'] )
);
if ( $invalid ) {
return null; return null;
} }
$decoded = base64_decode( $value['encoded_serialized_instance'], true ); $decoded = base64_decode( $value['encoded_serialized_instance'], true );
if ( false === $decoded ) { if ( false === $decoded ) {
return null; return null;
} }
$instance = unserialize( $decoded ); $instance = unserialize( $decoded );
if ( false === $instance ) { if ( false === $instance ) {
return null; return null;
} }
@ -1055,11 +1052,12 @@ final class WP_Customize_Widgets {
public function sanitize_widget_js_instance( $value ) { public function sanitize_widget_js_instance( $value ) {
if ( empty( $value['is_widget_customizer_js_value'] ) ) { if ( empty( $value['is_widget_customizer_js_value'] ) ) {
$serialized = serialize( $value ); $serialized = serialize( $value );
$value = array( $value = array(
'encoded_serialized_instance' => base64_encode( $serialized ), 'encoded_serialized_instance' => base64_encode( $serialized ),
'title' => empty( $value['title'] ) ? '' : $value['title'], 'title' => empty( $value['title'] ) ? '' : $value['title'],
'is_widget_customizer_js_value' => true, 'is_widget_customizer_js_value' => true,
'instance_hash_key' => $this->get_instance_hash_key( $value ), 'instance_hash_key' => $this->get_instance_hash_key( $value ),
); );
} }
return $value; return $value;
@ -1166,14 +1164,17 @@ final class WP_Customize_Widgets {
// Obtain the widget control with the updated instance in place. // Obtain the widget control with the updated instance in place.
ob_start(); ob_start();
$form = $wp_registered_widget_controls[$widget_id]; $form = $wp_registered_widget_controls[$widget_id];
if ( $form ) { if ( $form ) {
call_user_func_array( $form['callback'], $form['params'] ); call_user_func_array( $form['callback'], $form['params'] );
} }
$form = ob_get_clean(); $form = ob_get_clean();
// Obtain the widget instance. // Obtain the widget instance.
$option = get_option( $option_name ); $option = get_option( $option_name );
if ( null !== $parsed_id['number'] ) { if ( null !== $parsed_id['number'] ) {
$instance = $option[$parsed_id['number']]; $instance = $option[$parsed_id['number']];
} else { } else {
@ -1181,6 +1182,7 @@ final class WP_Customize_Widgets {
} }
$this->stop_capturing_option_updates(); $this->stop_capturing_option_updates();
return compact( 'instance', 'form' ); return compact( 'instance', 'form' );
} }
@ -1314,19 +1316,22 @@ final class WP_Customize_Widgets {
} }
$this->_is_capturing_option_updates = true; $this->_is_capturing_option_updates = true;
add_filter( 'pre_update_option', array( $this, '_capture_filter_pre_update_option' ), 10, 3 ); add_filter( 'pre_update_option', array( $this, '_capture_filter_pre_update_option' ), 10, 3 );
} }
/** /**
* Pre-filter captured option values before updating. * Pre-filter captured option values before updating.
* *
* @access private * @since 3.9.0
* @access public
*
* @param mixed $new_value * @param mixed $new_value
* @param string $option_name * @param string $option_name
* @param mixed $old_value * @param mixed $old_value
* @return mixed * @return mixed
*/ */
private function _capture_filter_pre_update_option( $new_value, $option_name, $old_value ) { public function _capture_filter_pre_update_option( $new_value, $option_name, $old_value ) {
if ( $this->is_option_capture_ignored( $option_name ) ) { if ( $this->is_option_capture_ignored( $option_name ) ) {
return; return;
} }
@ -1343,12 +1348,15 @@ final class WP_Customize_Widgets {
/** /**
* Pre-filter captured option values before retrieving. * Pre-filter captured option values before retrieving.
* *
* @access private * @since 3.9.0
* @access public
*
* @param mixed $value Option * @param mixed $value Option
* @return mixed * @return mixed
*/ */
private function _capture_filter_pre_get_option( $value ) { public function _capture_filter_pre_get_option( $value ) {
$option_name = preg_replace( '/^pre_option_/', '', current_filter() ); $option_name = preg_replace( '/^pre_option_/', '', current_filter() );
if ( isset( $this->_captured_options[$option_name] ) ) { if ( isset( $this->_captured_options[$option_name] ) ) {
$value = $this->_captured_options[$option_name]; $value = $this->_captured_options[$option_name];
$value = apply_filters( 'option_' . $option_name, $value ); $value = apply_filters( 'option_' . $option_name, $value );