<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[27816] trunk/src: Widget Customizer: Convert static WP_Customize_Widgets class into instantiated class and merge Options_Transaction into WP_Customize_Widgets.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://core.trac.wordpress.org/changeset/27816">27816</a></dd>
<dt>Author</dt> <dd>ocean90</dd>
<dt>Date</dt> <dd>2014-03-28 14:06:10 +0000 (Fri, 28 Mar 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>Widget Customizer: Convert static WP_Customize_Widgets class into instantiated class and merge Options_Transaction into WP_Customize_Widgets.
see <a href="http://core.trac.wordpress.org/ticket/27504">#27504</a>.
props westonruter.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpadminincludesajaxactionsphp">trunk/src/wp-admin/includes/ajax-actions.php</a></li>
<li><a href="#trunksrcwpincludesclasswpcustomizecontrolphp">trunk/src/wp-includes/class-wp-customize-control.php</a></li>
<li><a href="#trunksrcwpincludesclasswpcustomizemanagerphp">trunk/src/wp-includes/class-wp-customize-manager.php</a></li>
<li><a href="#trunksrcwpincludesclasswpcustomizewidgetsphp">trunk/src/wp-includes/class-wp-customize-widgets.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpadminincludesajaxactionsphp"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-admin/includes/ajax-actions.php (27815 => 27816)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-admin/includes/ajax-actions.php 2014-03-28 13:56:44 UTC (rev 27815)
+++ trunk/src/wp-admin/includes/ajax-actions.php 2014-03-28 14:06:10 UTC (rev 27816)
</span><span class="lines">@@ -1588,7 +1588,8 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> function wp_ajax_update_widget() {
</span><del>- WP_Customize_Widgets::wp_ajax_update_widget();
</del><ins>+ global $wp_customize;
+ $wp_customize->widgets->wp_ajax_update_widget();
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> function wp_ajax_upload_attachment() {
</span></span></pre></div>
<a id="trunksrcwpincludesclasswpcustomizecontrolphp"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-includes/class-wp-customize-control.php (27815 => 27816)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-includes/class-wp-customize-control.php 2014-03-28 13:56:44 UTC (rev 27815)
+++ trunk/src/wp-includes/class-wp-customize-control.php 2014-03-28 14:06:10 UTC (rev 27816)
</span><span class="lines">@@ -1080,7 +1080,7 @@
</span><span class="cx"> );
</span><span class="cx">
</span><span class="cx"> $args = wp_list_widget_controls_dynamic_sidebar( array( 0 => $args, 1 => $widget['params'][0] ) );
</span><del>- echo WP_Customize_Widgets::get_widget_control( $args );
</del><ins>+ echo $this->manager->widgets->get_widget_control( $args );
</ins><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx">
</span></span></pre></div>
<a id="trunksrcwpincludesclasswpcustomizemanagerphp"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-includes/class-wp-customize-manager.php (27815 => 27816)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-includes/class-wp-customize-manager.php 2014-03-28 13:56:44 UTC (rev 27815)
+++ trunk/src/wp-includes/class-wp-customize-manager.php 2014-03-28 14:06:10 UTC (rev 27816)
</span><span class="lines">@@ -37,6 +37,13 @@
</span><span class="cx"> */
</span><span class="cx"> protected $previewing = false;
</span><span class="cx">
</span><ins>+ /**
+ * Methods and properties deailing with managing widgets in the customizer.
+ *
+ * @var WP_Customize_Widgets
+ */
+ public $widgets;
+
</ins><span class="cx"> protected $settings = array();
</span><span class="cx"> protected $sections = array();
</span><span class="cx"> protected $controls = array();
</span><span class="lines">@@ -63,7 +70,7 @@
</span><span class="cx"> require( ABSPATH . WPINC . '/class-wp-customize-control.php' );
</span><span class="cx"> require( ABSPATH . WPINC . '/class-wp-customize-widgets.php' );
</span><span class="cx">
</span><del>- WP_Customize_Widgets::setup(); // This should be integrated.
</del><ins>+ $this->widgets = new WP_Customize_Widgets( $this );
</ins><span class="cx">
</span><span class="cx"> add_filter( 'wp_die_handler', array( $this, 'wp_die_handler' ) );
</span><span class="cx">
</span></span></pre></div>
<a id="trunksrcwpincludesclasswpcustomizewidgetsphp"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-includes/class-wp-customize-widgets.php (27815 => 27816)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-includes/class-wp-customize-widgets.php 2014-03-28 13:56:44 UTC (rev 27815)
+++ trunk/src/wp-includes/class-wp-customize-widgets.php 2014-03-28 14:06:10 UTC (rev 27816)
</span><span class="lines">@@ -4,23 +4,28 @@
</span><span class="cx"> *
</span><span class="cx"> * Implements widget management in the Customizer.
</span><span class="cx"> *
</span><del>- * @since 3.9.0
</del><span class="cx"> * @package WordPress
</span><span class="cx"> * @subpackage Customize
</span><ins>+ * @since 3.9.0
</ins><span class="cx"> */
</span><del>-class WP_Customize_Widgets {
</del><ins>+final class WP_Customize_Widgets {
</ins><span class="cx"> const UPDATE_WIDGET_AJAX_ACTION = 'update-widget';
</span><span class="cx"> const UPDATE_WIDGET_NONCE_POST_KEY = 'update-sidebar-widgets-nonce';
</span><span class="cx">
</span><span class="cx"> /**
</span><ins>+ * @access public
+ * @var WP_Customize_Manager
+ */
+ public $manager;
+
+ /**
</ins><span class="cx"> * All id_bases for widgets defined in core
</span><span class="cx"> *
</span><span class="cx"> * @since 3.9.0
</span><del>- * @static
</del><span class="cx"> * @access protected
</span><span class="cx"> * @var array
</span><span class="cx"> */
</span><del>- protected static $core_widget_id_bases = array(
</del><ins>+ protected $core_widget_id_bases = array(
</ins><span class="cx"> 'archives',
</span><span class="cx"> 'calendar',
</span><span class="cx"> 'categories',
</span><span class="lines">@@ -38,54 +43,51 @@
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * @since 3.9.0
</span><del>- * @static
</del><span class="cx"> * @access protected
</span><span class="cx"> * @var
</span><span class="cx"> */
</span><del>- protected static $_customized;
</del><ins>+ protected $_customized;
</ins><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * @since 3.9.0
</span><del>- * @static
</del><span class="cx"> * @access protected
</span><span class="cx"> * @var array
</span><span class="cx"> */
</span><del>- protected static $_prepreview_added_filters = array();
</del><ins>+ protected $_prepreview_added_filters = array();
</ins><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * @since 3.9.0
</span><del>- * @static
</del><span class="cx"> * @access protected
</span><span class="cx"> * @var array
</span><span class="cx"> */
</span><del>- static protected $rendered_sidebars = array();
</del><ins>+ protected $rendered_sidebars = array();
</ins><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * @since 3.9.0
</span><del>- * @static
</del><span class="cx"> * @access protected
</span><span class="cx"> * @var array
</span><span class="cx"> */
</span><del>- static protected $rendered_widgets = array();
</del><ins>+ protected $rendered_widgets = array();
</ins><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Initial loader.
</span><span class="cx"> *
</span><span class="cx"> * @since 3.9.0
</span><del>- * @static
</del><span class="cx"> * @access public
</span><span class="cx"> */
</span><del>- static function setup() {
- add_action( 'after_setup_theme', array( __CLASS__, 'setup_widget_addition_previews' ) );
- add_action( 'customize_controls_init', array( __CLASS__, 'customize_controls_init' ) );
- add_action( 'customize_register', array( __CLASS__, 'schedule_customize_register' ), 1 );
- add_action( 'customize_controls_enqueue_scripts', array( __CLASS__, 'customize_controls_enqueue_deps' ) );
- add_action( 'customize_controls_print_footer_scripts', array( __CLASS__, 'output_widget_control_templates' ) );
- add_action( 'customize_preview_init', array( __CLASS__, 'customize_preview_init' ) );
</del><ins>+ public function __construct( WP_Customize_Manager $manager ) {
+ $this->manager = $manager;
</ins><span class="cx">
</span><del>- add_action( 'dynamic_sidebar', array( __CLASS__, 'tally_rendered_widgets' ) );
- add_filter( 'is_active_sidebar', array( __CLASS__, 'tally_sidebars_via_is_active_sidebar_calls' ), 10, 2 );
- add_filter( 'dynamic_sidebar_has_widgets', array( __CLASS__, 'tally_sidebars_via_dynamic_sidebar_calls' ), 10, 2 );
</del><ins>+ add_action( 'after_setup_theme', array( $this, 'setup_widget_addition_previews' ) );
+ add_action( 'customize_controls_init', array( $this, 'customize_controls_init' ) );
+ add_action( 'customize_register', array( $this, 'schedule_customize_register' ), 1 );
+ add_action( 'customize_controls_enqueue_scripts', array( $this, 'customize_controls_enqueue_deps' ) );
+ add_action( 'customize_controls_print_footer_scripts', array( $this, 'output_widget_control_templates' ) );
+ add_action( 'customize_preview_init', array( $this, 'customize_preview_init' ) );
+
+ add_action( 'dynamic_sidebar', array( $this, 'tally_rendered_widgets' ) );
+ add_filter( 'is_active_sidebar', array( $this, 'tally_sidebars_via_is_active_sidebar_calls' ), 10, 2 );
+ add_filter( 'dynamic_sidebar_has_widgets', array( $this, 'tally_sidebars_via_dynamic_sidebar_calls' ), 10, 2 );
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="lines">@@ -93,17 +95,17 @@
</span><span class="cx"> *
</span><span class="cx"> * @since 3.9.0
</span><span class="cx"> *
</span><del>- * @static
- * @access public
</del><ins>+ * @access protected
</ins><span class="cx"> *
</span><span class="cx"> * @param string $name Post value.
</span><span class="cx"> * @param mixed $default Default post value.
</span><span class="cx"> * @return mixed Unslashed post value or default value.
</span><span class="cx"> */
</span><del>- static function get_post_value( $name, $default = null ) {
</del><ins>+ protected function get_post_value( $name, $default = null ) {
</ins><span class="cx"> if ( ! isset( $_POST[ $name ] ) ) {
</span><span class="cx"> return $default;
</span><span class="cx"> }
</span><ins>+
</ins><span class="cx"> return wp_unslash( $_POST[$name] );
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -115,26 +117,24 @@
</span><span class="cx"> *
</span><span class="cx"> * @since 3.9.0
</span><span class="cx"> *
</span><del>- * @static
</del><span class="cx"> * @access public
</span><span class="cx"> * @global WP_Customize_Manager $wp_customize
</span><span class="cx"> */
</span><del>- static function setup_widget_addition_previews() {
- global $wp_customize;
</del><ins>+ public function setup_widget_addition_previews() {
</ins><span class="cx"> $is_customize_preview = (
</span><del>- ( ! empty( $wp_customize ) )
</del><ins>+ ( ! empty( $this->manager ) )
</ins><span class="cx"> &&
</span><span class="cx"> ( ! is_admin() )
</span><span class="cx"> &&
</span><del>- ( 'on' === self::get_post_value( 'wp_customize' ) )
</del><ins>+ ( 'on' === $this->get_post_value( 'wp_customize' ) )
</ins><span class="cx"> &&
</span><del>- check_ajax_referer( 'preview-customize_' . $wp_customize->get_stylesheet(), 'nonce', false )
</del><ins>+ check_ajax_referer( 'preview-customize_' . $this->manager->get_stylesheet(), 'nonce', false )
</ins><span class="cx"> );
</span><span class="cx">
</span><span class="cx"> $is_ajax_widget_update = (
</span><span class="cx"> ( defined( 'DOING_AJAX' ) && DOING_AJAX )
</span><span class="cx"> &&
</span><del>- self::get_post_value( 'action' ) === self::UPDATE_WIDGET_AJAX_ACTION
</del><ins>+ $this->get_post_value( 'action' ) === self::UPDATE_WIDGET_AJAX_ACTION
</ins><span class="cx"> &&
</span><span class="cx"> check_ajax_referer( self::UPDATE_WIDGET_AJAX_ACTION, self::UPDATE_WIDGET_NONCE_POST_KEY, false )
</span><span class="cx"> );
</span><span class="lines">@@ -142,9 +142,9 @@
</span><span class="cx"> $is_ajax_customize_save = (
</span><span class="cx"> ( defined( 'DOING_AJAX' ) && DOING_AJAX )
</span><span class="cx"> &&
</span><del>- self::get_post_value( 'action' ) === 'customize_save'
</del><ins>+ $this->get_post_value( 'action' ) === 'customize_save'
</ins><span class="cx"> &&
</span><del>- check_ajax_referer( 'save-customize_' . $wp_customize->get_stylesheet(), 'nonce' )
</del><ins>+ check_ajax_referer( 'save-customize_' . $this->manager->get_stylesheet(), 'nonce' )
</ins><span class="cx"> );
</span><span class="cx">
</span><span class="cx"> $is_valid_request = ( $is_ajax_widget_update || $is_customize_preview || $is_ajax_customize_save );
</span><span class="lines">@@ -154,14 +154,14 @@
</span><span class="cx">
</span><span class="cx"> // Input from customizer preview.
</span><span class="cx"> if ( isset( $_POST['customized'] ) ) {
</span><del>- $customized = json_decode( self::get_post_value( 'customized' ), true );
</del><ins>+ $customized = json_decode( $this->get_post_value( 'customized' ), true );
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> // Input from ajax widget update request.
</span><span class="cx"> else {
</span><span class="cx"> $customized = array();
</span><del>- $id_base = self::get_post_value( 'id_base' );
- $widget_number = (int) self::get_post_value( 'widget_number' );
</del><ins>+ $id_base = $this->get_post_value( 'id_base' );
+ $widget_number = (int) $this->get_post_value( 'widget_number' );
</ins><span class="cx"> $option_name = 'widget_' . $id_base;
</span><span class="cx"> $customized[$option_name] = array();
</span><span class="cx"> if ( false !== $widget_number ) {
</span><span class="lines">@@ -170,29 +170,35 @@
</span><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx">
</span><del>- $function = array( __CLASS__, 'prepreview_added_sidebars_widgets' );
</del><ins>+ $function = array( $this, 'prepreview_added_sidebars_widgets' );
</ins><span class="cx">
</span><span class="cx"> $hook = 'option_sidebars_widgets';
</span><span class="cx"> add_filter( $hook, $function );
</span><del>- self::$_prepreview_added_filters[] = compact( 'hook', 'function' );
</del><ins>+ $this->_prepreview_added_filters[] = compact( 'hook', 'function' );
</ins><span class="cx">
</span><span class="cx"> $hook = 'default_option_sidebars_widgets';
</span><span class="cx"> add_filter( $hook, $function );
</span><del>- self::$_prepreview_added_filters[] = compact( 'hook', 'function' );
</del><ins>+ $this->_prepreview_added_filters[] = compact( 'hook', 'function' );
</ins><span class="cx">
</span><span class="cx"> foreach ( $customized as $setting_id => $value ) {
</span><span class="cx"> if ( preg_match( '/^(widget_.+?)(\[(\d+)\])?$/', $setting_id, $matches ) ) {
</span><del>- $body = sprintf( 'return %s::prepreview_added_widget_instance( $value, %s );', __CLASS__, var_export( $setting_id, true ) );
</del><ins>+ $body = sprintf( 'global $wp_customize; return $wp_customize->widgets->prepreview_added_widget_instance( $value, %s );', var_export( $setting_id, true ) );
</ins><span class="cx"> $function = create_function( '$value', $body );
</span><ins>+ // @todo replace above two lines with following once PHP 5.3 happens in WordPress
+ // $self = $this; // not needed in PHP 5.4
+ // $function = function ( $value ) use ( $self, $setting_id ) {
+ // return $self->manager->widgets->prepreview_added_widget_instance( $value, $setting_id );
+ //};
+
</ins><span class="cx"> $option = $matches[1];
</span><span class="cx">
</span><span class="cx"> $hook = sprintf( 'option_%s', $option );
</span><span class="cx"> add_filter( $hook, $function );
</span><del>- self::$_prepreview_added_filters[] = compact( 'hook', 'function' );
</del><ins>+ $this->_prepreview_added_filters[] = compact( 'hook', 'function' );
</ins><span class="cx">
</span><span class="cx"> $hook = sprintf( 'default_option_%s', $option );
</span><span class="cx"> add_filter( $hook, $function );
</span><del>- self::$_prepreview_added_filters[] = compact( 'hook', 'function' );
</del><ins>+ $this->_prepreview_added_filters[] = compact( 'hook', 'function' );
</ins><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Make sure the option is registered so that the update_option won't fail due to
</span><span class="lines">@@ -202,7 +208,7 @@
</span><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx">
</span><del>- self::$_customized = $customized;
</del><ins>+ $this->_customized = $customized;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="lines">@@ -213,14 +219,13 @@
</span><span class="cx"> * which is too late for the widgets to be set up properly.
</span><span class="cx"> *
</span><span class="cx"> * @since 3.9.0
</span><del>- * @static
</del><span class="cx"> * @access public
</span><span class="cx"> *
</span><span class="cx"> * @param array $sidebars_widgets Array of
</span><span class="cx"> * @return array
</span><span class="cx"> */
</span><del>- static function prepreview_added_sidebars_widgets( $sidebars_widgets ) {
- foreach ( self::$_customized as $setting_id => $value ) {
</del><ins>+ public function prepreview_added_sidebars_widgets( $sidebars_widgets ) {
+ foreach ( $this->_customized as $setting_id => $value ) {
</ins><span class="cx"> if ( preg_match( '/^sidebars_widgets\[(.+?)\]$/', $setting_id, $matches ) ) {
</span><span class="cx"> $sidebar_id = $matches[1];
</span><span class="cx"> $sidebars_widgets[$sidebar_id] = $value;
</span><span class="lines">@@ -237,16 +242,15 @@
</span><span class="cx"> * which is too late for the widgets to be set up properly.
</span><span class="cx"> *
</span><span class="cx"> * @since 3.9.0
</span><del>- * @static
</del><span class="cx"> * @access public
</span><span class="cx"> *
</span><span class="cx"> * @param array $instance Widget instance.
</span><span class="cx"> * @param string $setting_id Widget setting ID.
</span><span class="cx"> * @return array Parsed widget instance.
</span><span class="cx"> */
</span><del>- static function prepreview_added_widget_instance( $instance, $setting_id ) {
- if ( isset( self::$_customized[$setting_id] ) ) {
- $parsed_setting_id = self::parse_widget_setting_id( $setting_id );
</del><ins>+ public function prepreview_added_widget_instance( $instance, $setting_id ) {
+ if ( isset( $this->_customized[$setting_id] ) ) {
+ $parsed_setting_id = $this->parse_widget_setting_id( $setting_id );
</ins><span class="cx"> $widget_number = $parsed_setting_id['number'];
</span><span class="cx">
</span><span class="cx"> // Single widget
</span><span class="lines">@@ -273,24 +277,22 @@
</span><span class="cx"> * widgets are populating the options during widgets_init
</span><span class="cx"> *
</span><span class="cx"> * @since 3.9.0
</span><del>- * @static
</del><span class="cx"> * @access public
</span><span class="cx"> */
</span><del>- static function remove_prepreview_filters() {
- foreach ( self::$_prepreview_added_filters as $prepreview_added_filter ) {
</del><ins>+ public function remove_prepreview_filters() {
+ foreach ( $this->_prepreview_added_filters as $prepreview_added_filter ) {
</ins><span class="cx"> remove_filter( $prepreview_added_filter['hook'], $prepreview_added_filter['function'] );
</span><span class="cx"> }
</span><del>- self::$_prepreview_added_filters = array();
</del><ins>+ $this->_prepreview_added_filters = array();
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Make sure that all widgets get loaded into customizer; these actions are also done in the wp_ajax_save_widget()
</span><span class="cx"> *
</span><span class="cx"> * @since 3.9.0
</span><del>- * @static
</del><span class="cx"> * @access public
</span><span class="cx"> */
</span><del>- static function customize_controls_init() {
</del><ins>+ public function customize_controls_init() {
</ins><span class="cx"> do_action( 'load-widgets.php' );
</span><span class="cx"> do_action( 'widgets.php' );
</span><span class="cx"> do_action( 'sidebar_admin_setup' );
</span><span class="lines">@@ -301,16 +303,13 @@
</span><span class="cx"> * loaded so that all filters have been initialized (e.g. Widget Visibility)
</span><span class="cx"> *
</span><span class="cx"> * @since 3.9.0
</span><del>- * @static
</del><span class="cx"> * @access public
</span><del>- *
- * @param WP_Customize_Manager $wp_customize Customizer instance.
</del><span class="cx"> */
</span><del>- static function schedule_customize_register( $wp_customize ) {
</del><ins>+ public function schedule_customize_register() {
</ins><span class="cx"> if ( is_admin() ) { // @todo for some reason, $wp_customize->is_preview() is true here?
</span><del>- self::customize_register( $wp_customize );
</del><ins>+ $this->customize_register();
</ins><span class="cx"> } else {
</span><del>- add_action( 'wp', array( __CLASS__, 'customize_register' ) );
</del><ins>+ add_action( 'wp', array( $this, 'customize_register' ) );
</ins><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -318,16 +317,10 @@
</span><span class="cx"> * Register customizer settings and controls for all sidebars and widgets
</span><span class="cx"> *
</span><span class="cx"> * @since 3.9.0
</span><del>- * @static
</del><span class="cx"> * @access public
</span><del>- *
- * @param WP_Customize_Manager $wp_customize Customizer instance.
</del><span class="cx"> */
</span><del>- static function customize_register( $wp_customize = null ) {
</del><ins>+ public function customize_register() {
</ins><span class="cx"> global $wp_registered_widgets, $wp_registered_widget_controls, $wp_registered_sidebars;
</span><del>- if ( ! ( $wp_customize instanceof WP_Customize_Manager ) ) {
- $wp_customize = $GLOBALS['wp_customize'];
- }
</del><span class="cx">
</span><span class="cx"> $sidebars_widgets = array_merge(
</span><span class="cx"> array( 'wp_inactive_widgets' => array() ),
</span><span class="lines">@@ -342,11 +335,11 @@
</span><span class="cx"> * since a widget may get suppressed from a sidebar via a plugin (like Widget Visibility).
</span><span class="cx"> */
</span><span class="cx"> foreach ( array_keys( $wp_registered_widgets ) as $widget_id ) {
</span><del>- $setting_id = self::get_setting_id( $widget_id );
- $setting_args = self::get_setting_args( $setting_id );
- $setting_args['sanitize_callback'] = array( __CLASS__, 'sanitize_widget_instance' );
- $setting_args['sanitize_js_callback'] = array( __CLASS__, 'sanitize_widget_js_instance' );
- $wp_customize->add_setting( $setting_id, $setting_args );
</del><ins>+ $setting_id = $this->get_setting_id( $widget_id );
+ $setting_args = $this->get_setting_args( $setting_id );
+ $setting_args['sanitize_callback'] = array( $this, 'sanitize_widget_instance' );
+ $setting_args['sanitize_js_callback'] = array( $this, 'sanitize_widget_js_instance' );
+ $this->manager->add_setting( $setting_id, $setting_args );
</ins><span class="cx"> $new_setting_ids[] = $setting_id;
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -363,10 +356,10 @@
</span><span class="cx"> */
</span><span class="cx"> if ( $is_registered_sidebar || $is_inactive_widgets ) {
</span><span class="cx"> $setting_id = sprintf( 'sidebars_widgets[%s]', $sidebar_id );
</span><del>- $setting_args = self::get_setting_args( $setting_id );
- $setting_args['sanitize_callback'] = array( __CLASS__, 'sanitize_sidebar_widgets' );
- $setting_args['sanitize_js_callback'] = array( __CLASS__, 'sanitize_sidebar_widgets_js_instance' );
- $wp_customize->add_setting( $setting_id, $setting_args );
</del><ins>+ $setting_args = $this->get_setting_args( $setting_id );
+ $setting_args['sanitize_callback'] = array( $this, 'sanitize_sidebar_widgets' );
+ $setting_args['sanitize_js_callback'] = array( $this, 'sanitize_sidebar_widgets_js_instance' );
+ $this->manager->add_setting( $setting_id, $setting_args );
</ins><span class="cx"> $new_setting_ids[] = $setting_id;
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="lines">@@ -381,10 +374,10 @@
</span><span class="cx"> 'priority' => 1000 + array_search( $sidebar_id, array_keys( $wp_registered_sidebars ) ),
</span><span class="cx"> );
</span><span class="cx"> $section_args = apply_filters( 'customizer_widgets_section_args', $section_args, $section_id, $sidebar_id );
</span><del>- $wp_customize->add_section( $section_id, $section_args );
</del><ins>+ $this->manager->add_section( $section_id, $section_args );
</ins><span class="cx">
</span><span class="cx"> $control = new WP_Widget_Area_Customize_Control(
</span><del>- $wp_customize,
</del><ins>+ $this->manager,
</ins><span class="cx"> $setting_id,
</span><span class="cx"> array(
</span><span class="cx"> 'section' => $section_id,
</span><span class="lines">@@ -393,7 +386,7 @@
</span><span class="cx"> )
</span><span class="cx"> );
</span><span class="cx"> $new_setting_ids[] = $setting_id;
</span><del>- $wp_customize->add_control( $control );
</del><ins>+ $this->manager->add_control( $control );
</ins><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -405,11 +398,11 @@
</span><span class="cx"> continue;
</span><span class="cx"> }
</span><span class="cx"> $registered_widget = $GLOBALS['wp_registered_widgets'][$widget_id];
</span><del>- $setting_id = self::get_setting_id( $widget_id );
</del><ins>+ $setting_id = $this->get_setting_id( $widget_id );
</ins><span class="cx"> $id_base = $GLOBALS['wp_registered_widget_controls'][$widget_id]['id_base'];
</span><span class="cx"> assert( false !== is_active_widget( $registered_widget['callback'], $registered_widget['id'], false, false ) );
</span><span class="cx"> $control = new WP_Widget_Form_Customize_Control(
</span><del>- $wp_customize,
</del><ins>+ $this->manager,
</ins><span class="cx"> $setting_id,
</span><span class="cx"> array(
</span><span class="cx"> 'label' => $registered_widget['name'],
</span><span class="lines">@@ -420,10 +413,10 @@
</span><span class="cx"> 'priority' => $i,
</span><span class="cx"> 'width' => $wp_registered_widget_controls[$widget_id]['width'],
</span><span class="cx"> 'height' => $wp_registered_widget_controls[$widget_id]['height'],
</span><del>- 'is_wide' => self::is_wide_widget( $widget_id ),
</del><ins>+ 'is_wide' => $this->is_wide_widget( $widget_id ),
</ins><span class="cx"> )
</span><span class="cx"> );
</span><del>- $wp_customize->add_control( $control );
</del><ins>+ $this->manager->add_control( $control );
</ins><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -433,25 +426,24 @@
</span><span class="cx"> */
</span><span class="cx"> if ( did_action( 'customize_preview_init' ) ) {
</span><span class="cx"> foreach ( $new_setting_ids as $new_setting_id ) {
</span><del>- $wp_customize->get_setting( $new_setting_id )->preview();
</del><ins>+ $this->manager->get_setting( $new_setting_id )->preview();
</ins><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx">
</span><del>- self::remove_prepreview_filters();
</del><ins>+ $this->remove_prepreview_filters();
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Covert a widget_id into its corresponding customizer setting id (option name)
</span><span class="cx"> *
</span><span class="cx"> * @since 3.9.0
</span><del>- * @static
</del><span class="cx"> * @access public
</span><span class="cx"> *
</span><span class="cx"> * @param string $widget_id Widget ID.
</span><span class="cx"> * @return string Maybe-parsed widget ID.
</span><span class="cx"> */
</span><del>- static function get_setting_id( $widget_id ) {
- $parsed_widget_id = self::parse_widget_id( $widget_id );
</del><ins>+ public function get_setting_id( $widget_id ) {
+ $parsed_widget_id = $this->parse_widget_id( $widget_id );
</ins><span class="cx"> $setting_id = sprintf( 'widget_%s', $parsed_widget_id['id_base'] );
</span><span class="cx"> if ( ! is_null( $parsed_widget_id['number'] ) ) {
</span><span class="cx"> $setting_id .= sprintf( '[%d]', $parsed_widget_id['number'] );
</span><span class="lines">@@ -468,17 +460,16 @@
</span><span class="cx"> * filter.
</span><span class="cx"> *
</span><span class="cx"> * @since 3.9.0
</span><del>- * @static
</del><span class="cx"> * @access public
</span><span class="cx"> *
</span><span class="cx"> * @param string $widget_id Widget ID.
</span><span class="cx"> * @return bool Whether or not the widget is a "wide" widget.
</span><span class="cx"> */
</span><del>- static function is_wide_widget( $widget_id ) {
</del><ins>+ public function is_wide_widget( $widget_id ) {
</ins><span class="cx"> global $wp_registered_widget_controls;
</span><del>- $parsed_widget_id = self::parse_widget_id( $widget_id );
</del><ins>+ $parsed_widget_id = $this->parse_widget_id( $widget_id );
</ins><span class="cx"> $width = $wp_registered_widget_controls[$widget_id]['width'];
</span><del>- $is_core = in_array( $parsed_widget_id['id_base'], self::$core_widget_id_bases );
</del><ins>+ $is_core = in_array( $parsed_widget_id['id_base'], $this->core_widget_id_bases );
</ins><span class="cx"> $is_wide = ( $width > 250 && ! $is_core );
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="lines">@@ -497,13 +488,12 @@
</span><span class="cx"> * Covert a widget ID into its id_base and number components.
</span><span class="cx"> *
</span><span class="cx"> * @since 3.9.0
</span><del>- * @static
</del><span class="cx"> * @access public
</span><span class="cx"> *
</span><span class="cx"> * @param string $widget_id Widget ID.
</span><span class="cx"> * @return array Array containing a widget's id_base and number components.
</span><span class="cx"> */
</span><del>- static function parse_widget_id( $widget_id ) {
</del><ins>+ public function parse_widget_id( $widget_id ) {
</ins><span class="cx"> $parsed = array(
</span><span class="cx"> 'number' => null,
</span><span class="cx"> 'id_base' => null,
</span><span class="lines">@@ -522,14 +512,13 @@
</span><span class="cx"> * Convert a widget setting ID (option path) to its id_base and number components.
</span><span class="cx"> *
</span><span class="cx"> * @since 3.9.0
</span><del>- * @static
</del><span class="cx"> * @access public
</span><span class="cx"> *
</span><span class="cx"> * @param string $setting_id Widget setting ID.
</span><span class="cx"> * @return WP_Error|array Array contain a widget's id_base and number components,
</span><span class="cx"> * or a WP_Error object.
</span><span class="cx"> */
</span><del>- static function parse_widget_setting_id( $setting_id ) {
</del><ins>+ public function parse_widget_setting_id( $setting_id ) {
</ins><span class="cx"> if ( ! preg_match( '/^(widget_(.+?))(?:\[(\d+)\])?$/', $setting_id, $matches ) ) {
</span><span class="cx"> return new WP_Error( 'invalid_setting_id', 'Invalid widget setting ID' );
</span><span class="cx"> }
</span><span class="lines">@@ -543,17 +532,16 @@
</span><span class="cx"> * Enqueue scripts and styles for customizer panel and export data to JS.
</span><span class="cx"> *
</span><span class="cx"> * @since 3.9.0
</span><del>- * @static
</del><span class="cx"> * @access public
</span><span class="cx"> */
</span><del>- static function customize_controls_enqueue_deps() {
</del><ins>+ public function customize_controls_enqueue_deps() {
</ins><span class="cx"> wp_enqueue_style( 'customize-widgets' );
</span><span class="cx"> wp_enqueue_script( 'customize-widgets' );
</span><span class="cx">
</span><span class="cx"> // Export available widgets with control_tpl removed from model
</span><span class="cx"> // since plugins need templates to be in the DOM
</span><span class="cx"> $available_widgets = array();
</span><del>- foreach ( self::get_available_widgets() as $available_widget ) {
</del><ins>+ foreach ( $this->get_available_widgets() as $available_widget ) {
</ins><span class="cx"> unset( $available_widget['control_tpl'] );
</span><span class="cx"> $available_widgets[] = $available_widget;
</span><span class="cx"> }
</span><span class="lines">@@ -601,7 +589,7 @@
</span><span class="cx"> 'save_btn_tooltip' => ( 'Save and preview changes before publishing them.' ),
</span><span class="cx"> 'remove_btn_label' => __( 'Remove' ),
</span><span class="cx"> 'remove_btn_tooltip' => ( 'Trash widget by moving it to the inactive widgets sidebar.' ),
</span><del>- 'error' => __('An error has occurred. Please reload the page and try again.'),
</del><ins>+ 'error' => __( 'An error has occurred. Please reload the page and try again.' ),
</ins><span class="cx"> ),
</span><span class="cx"> 'tpl' => array(
</span><span class="cx"> 'widget_reorder_nav' => $widget_reorder_nav_tpl,
</span><span class="lines">@@ -623,17 +611,16 @@
</span><span class="cx"> * Render the widget form control templates into the DOM so that plugin scripts can manipulate them
</span><span class="cx"> *
</span><span class="cx"> * @since 3.9.0
</span><del>- * @static
</del><span class="cx"> * @access public
</span><span class="cx"> */
</span><del>- static function output_widget_control_templates() {
</del><ins>+ public function output_widget_control_templates() {
</ins><span class="cx"> ?>
</span><span class="cx"> <div id="widgets-left"><!-- compatibility with JS which looks for widget templates here -->
</span><span class="cx"> <div id="available-widgets">
</span><span class="cx"> <div id="available-widgets-filter">
</span><span class="cx"> <input type="search" placeholder="<?php esc_attr_e( 'Find widgets…' ) ?>">
</span><span class="cx"> </div>
</span><del>- <?php foreach ( self::get_available_widgets() as $available_widget ): ?>
</del><ins>+ <?php foreach ( $this->get_available_widgets() as $available_widget ): ?>
</ins><span class="cx"> <div id="widget-tpl-<?php echo esc_attr( $available_widget['id'] ) ?>" data-widget-id="<?php echo esc_attr( $available_widget['id'] ) ?>" class="widget-tpl <?php echo esc_attr( $available_widget['id'] ) ?>" tabindex="0">
</span><span class="cx"> <?php echo $available_widget['control_tpl']; // xss ok ?>
</span><span class="cx"> </div>
</span><span class="lines">@@ -647,14 +634,13 @@
</span><span class="cx"> * Get common arguments to supply when constructing a customizer setting
</span><span class="cx"> *
</span><span class="cx"> * @since 3.9.0
</span><del>- * @static
</del><span class="cx"> * @access public
</span><span class="cx"> *
</span><span class="cx"> * @param string $id Widget setting ID.
</span><span class="cx"> * @param array $overrides Array of setting overrides.
</span><span class="cx"> * @return array Possibly modified setting arguments.
</span><span class="cx"> */
</span><del>- static function get_setting_args( $id, $overrides = array() ) {
</del><ins>+ public function get_setting_args( $id, $overrides = array() ) {
</ins><span class="cx"> $args = array(
</span><span class="cx"> 'type' => 'option',
</span><span class="cx"> 'capability' => 'edit_theme_options',
</span><span class="lines">@@ -671,13 +657,12 @@
</span><span class="cx"> * Used as sanitize_callback for each sidebars_widgets setting.
</span><span class="cx"> *
</span><span class="cx"> * @since 3.9.0
</span><del>- * @static
</del><span class="cx"> * @access public
</span><span class="cx"> *
</span><span class="cx"> * @param array $widget_ids Array of widget IDs.
</span><span class="cx"> * @return array Array of sanitized widget IDs.
</span><span class="cx"> */
</span><del>- static function sanitize_sidebar_widgets( $widget_ids ) {
</del><ins>+ public function sanitize_sidebar_widgets( $widget_ids ) {
</ins><span class="cx"> global $wp_registered_widgets;
</span><span class="cx"> $widget_ids = array_map( 'strval', (array) $widget_ids );
</span><span class="cx"> $sanitized_widget_ids = array();
</span><span class="lines">@@ -693,13 +678,12 @@
</span><span class="cx"> * Build up an index of all available widgets for use in Backbone models.
</span><span class="cx"> *
</span><span class="cx"> * @since 3.9.0
</span><del>- * @static
</del><span class="cx"> * @access public
</span><span class="cx"> *
</span><span class="cx"> * @see wp_list_widgets()
</span><span class="cx"> * @return array
</span><span class="cx"> */
</span><del>- static function get_available_widgets() {
</del><ins>+ public function get_available_widgets() {
</ins><span class="cx"> static $available_widgets = array();
</span><span class="cx"> if ( ! empty( $available_widgets ) ) {
</span><span class="cx"> return $available_widgets;
</span><span class="lines">@@ -709,7 +693,7 @@
</span><span class="cx"> require_once ABSPATH . '/wp-admin/includes/widgets.php'; // for next_widget_id_number()
</span><span class="cx">
</span><span class="cx"> $sort = $wp_registered_widgets;
</span><del>- usort( $sort, array( __CLASS__, '_sort_name_callback' ) );
</del><ins>+ usort( $sort, array( $this, '_sort_name_callback' ) );
</ins><span class="cx"> $done = array();
</span><span class="cx">
</span><span class="cx"> foreach ( $sort as $widget ) {
</span><span class="lines">@@ -753,7 +737,7 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> $list_widget_controls_args = wp_list_widget_controls_dynamic_sidebar( array( 0 => $args, 1 => $widget['params'][0] ) );
</span><del>- $control_tpl = self::get_widget_control( $list_widget_controls_args );
</del><ins>+ $control_tpl = $this->get_widget_control( $list_widget_controls_args );
</ins><span class="cx">
</span><span class="cx"> // The properties here are mapped to the Backbone Widget model
</span><span class="cx"> $available_widget = array_merge(
</span><span class="lines">@@ -768,7 +752,7 @@
</span><span class="cx"> 'transport' => 'refresh',
</span><span class="cx"> 'width' => $wp_registered_widget_controls[$widget['id']]['width'],
</span><span class="cx"> 'height' => $wp_registered_widget_controls[$widget['id']]['height'],
</span><del>- 'is_wide' => self::is_wide_widget( $widget['id'] ),
</del><ins>+ 'is_wide' => $this->is_wide_widget( $widget['id'] ),
</ins><span class="cx"> )
</span><span class="cx"> );
</span><span class="cx">
</span><span class="lines">@@ -782,13 +766,13 @@
</span><span class="cx"> *
</span><span class="cx"> * @since 3.9.0
</span><span class="cx"> * @static
</span><del>- * @access public
</del><ins>+ * @access protected
</ins><span class="cx"> *
</span><span class="cx"> * @param array $widget_a The first widget to compare.
</span><span class="cx"> * @param array $widget_b The second widget to compare.
</span><span class="cx"> * @return int Reorder position for the current widget comparison.
</span><span class="cx"> */
</span><del>- static function _sort_name_callback( $widget_a, $widget_b ) {
</del><ins>+ protected function _sort_name_callback( $widget_a, $widget_b ) {
</ins><span class="cx"> return strnatcasecmp( $widget_a['name'], $widget_b['name'] );
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -797,13 +781,12 @@
</span><span class="cx"> * so that it can be used in the customizer.
</span><span class="cx"> *
</span><span class="cx"> * @since 3.9.0
</span><del>- * @static
</del><span class="cx"> * @access public
</span><span class="cx"> *
</span><span class="cx"> * @param array $args Widget control arguments.
</span><span class="cx"> * @return string Widget control form HTML markup.
</span><span class="cx"> */
</span><del>- static function get_widget_control( $args ) {
</del><ins>+ public function get_widget_control( $args ) {
</ins><span class="cx"> ob_start();
</span><span class="cx"> call_user_func_array( 'wp_widget_control', $args );
</span><span class="cx"> $replacements = array(
</span><span class="lines">@@ -819,14 +802,13 @@
</span><span class="cx"> * Add hooks for the customizer preview
</span><span class="cx"> *
</span><span class="cx"> * @since 3.9.0
</span><del>- * @static
</del><span class="cx"> * @access public
</span><span class="cx"> */
</span><del>- static function customize_preview_init() {
- add_filter( 'sidebars_widgets', array( __CLASS__, 'preview_sidebars_widgets' ), 1 );
- add_action( 'wp_enqueue_scripts', array( __CLASS__, 'customize_preview_enqueue' ) );
- add_action( 'wp_print_styles', array( __CLASS__, 'inject_preview_css' ), 1 );
- add_action( 'wp_footer', array( __CLASS__, 'export_preview_data' ), 20 );
</del><ins>+ public function customize_preview_init() {
+ add_filter( 'sidebars_widgets', array( $this, 'preview_sidebars_widgets' ), 1 );
+ add_action( 'wp_enqueue_scripts', array( $this, 'customize_preview_enqueue' ) );
+ add_action( 'wp_print_styles', array( $this, 'inject_preview_css' ), 1 );
+ add_action( 'wp_footer', array( $this, 'export_preview_data' ), 20 );
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="lines">@@ -838,12 +820,11 @@
</span><span class="cx"> * preview filter is added, we have to reset it after the filter has been added.
</span><span class="cx"> *
</span><span class="cx"> * @since 3.9.0
</span><del>- * @static
</del><span class="cx"> * @access public
</span><span class="cx"> *
</span><span class="cx"> * @param array $sidebars_widgets List of widgets for the current sidebar.
</span><span class="cx"> */
</span><del>- static function preview_sidebars_widgets( $sidebars_widgets ) {
</del><ins>+ public function preview_sidebars_widgets( $sidebars_widgets ) {
</ins><span class="cx"> $sidebars_widgets = get_option( 'sidebars_widgets' );
</span><span class="cx"> unset( $sidebars_widgets['array_version'] );
</span><span class="cx"> return $sidebars_widgets;
</span><span class="lines">@@ -853,24 +834,22 @@
</span><span class="cx"> * Enqueue scripts for the customizer preview
</span><span class="cx"> *
</span><span class="cx"> * @since 3.9.0
</span><del>- * @static
</del><span class="cx"> * @access public
</span><span class="cx"> */
</span><del>- static function customize_preview_enqueue() {
</del><ins>+ public function customize_preview_enqueue() {
</ins><span class="cx"> wp_enqueue_script( 'customize-preview-widgets' );
</span><del>- }
</del><ins>+ }
</ins><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Insert default style for highlighted widget at early point so theme
</span><span class="cx"> * stylesheet can override.
</span><span class="cx"> *
</span><span class="cx"> * @since 3.9.0
</span><del>- * @static
</del><span class="cx"> * @access public
</span><span class="cx"> *
</span><span class="cx"> * @action wp_print_styles
</span><span class="cx"> */
</span><del>- static function inject_preview_css() {
</del><ins>+ public function inject_preview_css() {
</ins><span class="cx"> ?>
</span><span class="cx"> <style>
</span><span class="cx"> .widget-customizer-highlighted-widget {
</span><span class="lines">@@ -888,14 +867,13 @@
</span><span class="cx"> * At the very end of the page, at the very end of the wp_footer, communicate the sidebars that appeared on the page.
</span><span class="cx"> *
</span><span class="cx"> * @since 3.9.0
</span><del>- * @static
</del><span class="cx"> * @access public
</span><span class="cx"> */
</span><del>- static function export_preview_data() {
</del><ins>+ public function export_preview_data() {
</ins><span class="cx"> // Prepare customizer settings to pass to Javascript.
</span><span class="cx"> $settings = array(
</span><del>- 'renderedSidebars' => array_fill_keys( array_unique( self::$rendered_sidebars ), true ),
- 'renderedWidgets' => array_fill_keys( array_keys( self::$rendered_widgets ), true ),
</del><ins>+ 'renderedSidebars' => array_fill_keys( array_unique( $this->rendered_sidebars ), true ),
+ 'renderedWidgets' => array_fill_keys( array_keys( $this->rendered_widgets ), true ),
</ins><span class="cx"> 'registeredSidebars' => array_values( $GLOBALS['wp_registered_sidebars'] ),
</span><span class="cx"> 'registeredWidgets' => $GLOBALS['wp_registered_widgets'],
</span><span class="cx"> 'l10n' => array(
</span><span class="lines">@@ -917,13 +895,12 @@
</span><span class="cx"> * Keep track of the widgets that were rendered
</span><span class="cx"> *
</span><span class="cx"> * @since 3.9.0
</span><del>- * @static
</del><span class="cx"> * @access public
</span><span class="cx"> *
</span><span class="cx"> * @param array $widget Rendered widget to tally.
</span><span class="cx"> */
</span><del>- static function tally_rendered_widgets( $widget ) {
- self::$rendered_widgets[$widget['id']] = true;
</del><ins>+ public function tally_rendered_widgets( $widget ) {
+ $this->rendered_widgets[$widget['id']] = true;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="lines">@@ -931,15 +908,14 @@
</span><span class="cx"> * means that the sidebar would be rendered on the template if there were widgets populating it.
</span><span class="cx"> *
</span><span class="cx"> * @since 3.9.0
</span><del>- * @static
</del><span class="cx"> * @access public
</span><span class="cx"> *
</span><span class="cx"> * @param bool $is_active Whether the sidebar is active.
</span><span class="cx"> * @pasram string $sidebar_id Sidebar ID.
</span><span class="cx"> */
</span><del>- static function tally_sidebars_via_is_active_sidebar_calls( $is_active, $sidebar_id ) {
</del><ins>+ public function tally_sidebars_via_is_active_sidebar_calls( $is_active, $sidebar_id ) {
</ins><span class="cx"> if ( isset( $GLOBALS['wp_registered_sidebars'][$sidebar_id] ) ) {
</span><del>- self::$rendered_sidebars[] = $sidebar_id;
</del><ins>+ $this->rendered_sidebars[] = $sidebar_id;
</ins><span class="cx"> }
</span><span class="cx"> // We may need to force this to true, and also force-true the value for dynamic_sidebar_has_widgets
</span><span class="cx"> // if we want to ensure that there is an area to drop widgets into, if the sidebar is empty.
</span><span class="lines">@@ -951,15 +927,14 @@
</span><span class="cx"> * means that the sidebar would be rendered on the template if there were widgets populating it.
</span><span class="cx"> *
</span><span class="cx"> * @since 3.9.0
</span><del>- * @static
</del><span class="cx"> * @access public
</span><span class="cx"> *
</span><span class="cx"> * @param bool $has_widgets Whether the current sidebar has widgets.
</span><span class="cx"> * @param string $sidebar_id Sidebar ID.
</span><span class="cx"> */
</span><del>- static function tally_sidebars_via_dynamic_sidebar_calls( $has_widgets, $sidebar_id ) {
</del><ins>+ public function tally_sidebars_via_dynamic_sidebar_calls( $has_widgets, $sidebar_id ) {
</ins><span class="cx"> if ( isset( $GLOBALS['wp_registered_sidebars'][$sidebar_id] ) ) {
</span><del>- self::$rendered_sidebars[] = $sidebar_id;
</del><ins>+ $this->rendered_sidebars[] = $sidebar_id;
</ins><span class="cx"> }
</span><span class="cx"> /*
</span><span class="cx"> * We may need to force this to true, and also force-true the value for is_active_sidebar
</span><span class="lines">@@ -977,13 +952,12 @@
</span><span class="cx"> * from WordPress and so is sanitized.
</span><span class="cx"> *
</span><span class="cx"> * @since 3.9.0
</span><del>- * @static
</del><span class="cx"> * @access protected
</span><span class="cx"> *
</span><span class="cx"> * @param array $instance Widget instance.
</span><span class="cx"> * @return string Widget instance's hash key.
</span><span class="cx"> */
</span><del>- protected static function get_instance_hash_key( $instance ) {
</del><ins>+ protected function get_instance_hash_key( $instance ) {
</ins><span class="cx"> $hash = md5( AUTH_KEY . serialize( $instance ) );
</span><span class="cx"> return $hash;
</span><span class="cx"> }
</span><span class="lines">@@ -995,7 +969,6 @@
</span><span class="cx"> * that this filter only get applied to an instance once.
</span><span class="cx"> *
</span><span class="cx"> * @since 3.9.0
</span><del>- * @static
</del><span class="cx"> * @access public
</span><span class="cx"> *
</span><span class="cx"> * @see Widget_Customizer::sanitize_widget_js_instance()
</span><span class="lines">@@ -1003,7 +976,7 @@
</span><span class="cx"> * @param array $value Widget instance to sanitize.
</span><span class="cx"> * @return array Sanitized widget instance.
</span><span class="cx"> */
</span><del>- static function sanitize_widget_instance( $value ) {
</del><ins>+ public function sanitize_widget_instance( $value ) {
</ins><span class="cx"> if ( $value === array() ) {
</span><span class="cx"> return $value;
</span><span class="cx"> }
</span><span class="lines">@@ -1025,7 +998,7 @@
</span><span class="cx"> if ( false === $instance ) {
</span><span class="cx"> return null;
</span><span class="cx"> }
</span><del>- if ( self::get_instance_hash_key( $instance ) !== $value['instance_hash_key'] ) {
</del><ins>+ if ( $this->get_instance_hash_key( $instance ) !== $value['instance_hash_key'] ) {
</ins><span class="cx"> return null;
</span><span class="cx"> }
</span><span class="cx"> return $instance;
</span><span class="lines">@@ -1035,7 +1008,6 @@
</span><span class="cx"> * Convert widget instance into JSON-representable format.
</span><span class="cx"> *
</span><span class="cx"> * @since 3.9.0
</span><del>- * @static
</del><span class="cx"> * @access public
</span><span class="cx"> *
</span><span class="cx"> * @see Widget_Customizer::sanitize_widget_instance()
</span><span class="lines">@@ -1043,14 +1015,14 @@
</span><span class="cx"> * @param array $value Widget instance to convert to JSON.
</span><span class="cx"> * @return array JSON-converted widget instance.
</span><span class="cx"> */
</span><del>- static function sanitize_widget_js_instance( $value ) {
</del><ins>+ public function sanitize_widget_js_instance( $value ) {
</ins><span class="cx"> if ( empty( $value['is_widget_customizer_js_value'] ) ) {
</span><span class="cx"> $serialized = serialize( $value );
</span><span class="cx"> $value = array(
</span><span class="cx"> 'encoded_serialized_instance' => base64_encode( $serialized ),
</span><span class="cx"> 'title' => empty( $value['title'] ) ? '' : $value['title'],
</span><span class="cx"> 'is_widget_customizer_js_value' => true,
</span><del>- 'instance_hash_key' => self::get_instance_hash_key( $value ),
</del><ins>+ 'instance_hash_key' => $this->get_instance_hash_key( $value ),
</ins><span class="cx"> );
</span><span class="cx"> }
</span><span class="cx"> return $value;
</span><span class="lines">@@ -1061,13 +1033,12 @@
</span><span class="cx"> * as the case when a plugin orphans a widget in a sidebar when it is deactivated.
</span><span class="cx"> *
</span><span class="cx"> * @since 3.9.0
</span><del>- * @static
</del><span class="cx"> * @access public
</span><span class="cx"> *
</span><span class="cx"> * @param array $widget_ids List of widget IDs.
</span><span class="cx"> * @return array Parsed list of widget IDs.
</span><span class="cx"> */
</span><del>- static function sanitize_sidebar_widgets_js_instance( $widget_ids ) {
</del><ins>+ public function sanitize_sidebar_widgets_js_instance( $widget_ids ) {
</ins><span class="cx"> global $wp_registered_widgets;
</span><span class="cx"> $widget_ids = array_values( array_intersect( $widget_ids, array_keys( $wp_registered_widgets ) ) );
</span><span class="cx"> return $widget_ids;
</span><span class="lines">@@ -1079,19 +1050,16 @@
</span><span class="cx"> * Requires that $_POST be populated with the instance data.
</span><span class="cx"> *
</span><span class="cx"> * @since 3.9.0
</span><del>- * @static
</del><span class="cx"> * @access public
</span><span class="cx"> *
</span><span class="cx"> * @param string $widget_id Widget ID.
</span><span class="cx"> * @return WP_Error|array Array containing the updated widget information. WP_Error, otherwise.
</span><span class="cx"> */
</span><del>- static function call_widget_update( $widget_id ) {
</del><ins>+ public function call_widget_update( $widget_id ) {
</ins><span class="cx"> global $wp_registered_widget_updates, $wp_registered_widget_controls;
</span><span class="cx">
</span><del>- $options_transaction = new Options_Transaction();
-
- $options_transaction->start();
- $parsed_id = self::parse_widget_id( $widget_id );
</del><ins>+ $this->start_capturing_option_updates();
+ $parsed_id = $this->parse_widget_id( $widget_id );
</ins><span class="cx"> $option_name = 'widget_' . $parsed_id['id_base'];
</span><span class="cx">
</span><span class="cx"> /*
</span><span class="lines">@@ -1100,15 +1068,15 @@
</span><span class="cx"> */
</span><span class="cx"> $added_input_vars = array();
</span><span class="cx"> if ( ! empty( $_POST['sanitized_widget_setting'] ) ) {
</span><del>- $sanitized_widget_setting = json_decode( self::get_post_value( 'sanitized_widget_setting' ), true );
</del><ins>+ $sanitized_widget_setting = json_decode( $this->get_post_value( 'sanitized_widget_setting' ), true );
</ins><span class="cx"> if ( empty( $sanitized_widget_setting ) ) {
</span><del>- $options_transaction->rollback();
</del><ins>+ $this->stop_capturing_option_updates();
</ins><span class="cx"> return new WP_Error( 'malformed_data', 'Malformed sanitized_widget_setting' );
</span><span class="cx"> }
</span><span class="cx">
</span><del>- $instance = self::sanitize_widget_instance( $sanitized_widget_setting );
</del><ins>+ $instance = $this->sanitize_widget_instance( $sanitized_widget_setting );
</ins><span class="cx"> if ( is_null( $instance ) ) {
</span><del>- $options_transaction->rollback();
</del><ins>+ $this->stop_capturing_option_updates();
</ins><span class="cx"> return new WP_Error( 'unsanitary_data', 'Unsanitary sanitized_widget_setting' );
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -1143,15 +1111,15 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> // Make sure the expected option was updated.
</span><del>- if ( 0 !== $options_transaction->count() ) {
- if ( count( $options_transaction->options ) > 1 ) {
- $options_transaction->rollback();
</del><ins>+ if ( 0 !== $this->count_captured_options() ) {
+ if ( $this->count_captured_options() > 1 ) {
+ $this->stop_capturing_option_updates();
</ins><span class="cx"> return new WP_Error( 'unexpected_update', 'Widget unexpectedly updated more than one option.' );
</span><span class="cx"> }
</span><span class="cx">
</span><del>- $updated_option_name = key( $options_transaction->options );
</del><ins>+ $updated_option_name = key( $this->get_captured_options() );
</ins><span class="cx"> if ( $updated_option_name !== $option_name ) {
</span><del>- $options_transaction->rollback();
</del><ins>+ $this->stop_capturing_option_updates();
</ins><span class="cx"> return new WP_Error( 'wrong_option', sprintf( 'Widget updated option "%1$s", but expected "%2$s".', $updated_option_name, $option_name ) );
</span><span class="cx"> }
</span><span class="cx"> }
</span><span class="lines">@@ -1172,7 +1140,7 @@
</span><span class="cx"> $instance = $option;
</span><span class="cx"> }
</span><span class="cx">
</span><del>- $options_transaction->rollback();
</del><ins>+ $this->stop_capturing_option_updates();
</ins><span class="cx"> return compact( 'instance', 'form' );
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -1182,14 +1150,13 @@
</span><span class="cx"> * Most code here copied from wp_ajax_save_widget()
</span><span class="cx"> *
</span><span class="cx"> * @since 3.9.0
</span><del>- * @static
</del><span class="cx"> * @access public
</span><span class="cx"> *
</span><span class="cx"> * @see wp_ajax_save_widget
</span><span class="cx"> * @todo Reuse wp_ajax_save_widget now that we have option transactions?
</span><span class="cx"> * @action wp_ajax_update_widget
</span><span class="cx"> */
</span><del>- static function wp_ajax_update_widget() {
</del><ins>+ public function wp_ajax_update_widget() {
</ins><span class="cx">
</span><span class="cx"> if ( ! is_user_logged_in() ) {
</span><span class="cx"> wp_die( 0 );
</span><span class="lines">@@ -1211,158 +1178,125 @@
</span><span class="cx"> do_action( 'widgets.php' );
</span><span class="cx"> do_action( 'sidebar_admin_setup' );
</span><span class="cx">
</span><del>- $widget_id = self::get_post_value( 'widget-id' );
- $parsed_id = self::parse_widget_id( $widget_id );
</del><ins>+ $widget_id = $this->get_post_value( 'widget-id' );
+ $parsed_id = $this->parse_widget_id( $widget_id );
</ins><span class="cx"> $id_base = $parsed_id['id_base'];
</span><span class="cx">
</span><span class="cx"> if ( isset( $_POST['widget-' . $id_base] ) && is_array( $_POST['widget-' . $id_base] ) && preg_match( '/__i__|%i%/', key( $_POST['widget-' . $id_base] ) ) ) {
</span><span class="cx"> wp_send_json_error();
</span><span class="cx"> }
</span><span class="cx">
</span><del>- $updated_widget = self::call_widget_update( $widget_id ); // => {instance,form}
</del><ins>+ $updated_widget = $this->call_widget_update( $widget_id ); // => {instance,form}
</ins><span class="cx"> if ( is_wp_error( $updated_widget ) ) {
</span><span class="cx"> wp_send_json_error();
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> $form = $updated_widget['form'];
</span><del>- $instance = self::sanitize_widget_js_instance( $updated_widget['instance'] );
</del><ins>+ $instance = $this->sanitize_widget_js_instance( $updated_widget['instance'] );
</ins><span class="cx">
</span><span class="cx"> wp_send_json_success( compact( 'form', 'instance' ) );
</span><span class="cx"> }
</span><del>-}
</del><span class="cx">
</span><del>-class Options_Transaction {
</del><ins>+ /***************************************************************************
+ * Option Update Capturing
+ ***************************************************************************/
</ins><span class="cx">
</span><span class="cx"> /**
</span><del>- * @var array $options values updated while transaction is open
</del><ins>+ * @var array $_captured_options values updated while capturing is happening
</ins><span class="cx"> */
</span><del>- public $options = array();
</del><ins>+ protected $_captured_options = array();
</ins><span class="cx">
</span><del>- protected $_ignore_transients = true;
- protected $_is_current = false;
- protected $_operations = array();
-
- function __construct( $ignore_transients = true ) {
- $this->_ignore_transients = $ignore_transients;
- }
-
</del><span class="cx"> /**
</span><del>- * Determine whether or not the transaction is open
- * @return bool
</del><ins>+ * @var bool $_is_current whether capturing is currently happening or not
</ins><span class="cx"> */
</span><del>- function is_current() {
- return $this->_is_current;
- }
</del><ins>+ protected $_is_capturing_option_updates = false;
</ins><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * @param $option_name
</span><span class="cx"> * @return boolean
</span><span class="cx"> */
</span><del>- function is_option_ignored( $option_name ) {
- return ( $this->_ignore_transients && 0 === strpos( $option_name, '_transient_' ) );
</del><ins>+ protected function is_option_capture_ignored( $option_name ) {
+ return ( 0 === strpos( $option_name, '_transient_' ) );
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><del>- * Get the number of operations performed in the transaction
- * @return bool
</del><ins>+ * Get options updated
+ * @return array
</ins><span class="cx"> */
</span><del>- function count() {
- return count( $this->_operations );
</del><ins>+ protected function get_captured_options() {
+ return $this->_captured_options;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><del>- * Start keeping track of changes to options, and cache their new values
</del><ins>+ * Get the number of options updated
+ * @return bool
</ins><span class="cx"> */
</span><del>- function start() {
- $this->_is_current = true;
- add_action( 'added_option', array( $this, '_capture_added_option' ), 10, 2 );
- add_action( 'updated_option', array( $this, '_capture_updated_option' ), 10, 3 );
- add_action( 'delete_option', array( $this, '_capture_pre_deleted_option' ), 10, 1 );
- add_action( 'deleted_option', array( $this, '_capture_deleted_option' ), 10, 1 );
</del><ins>+ protected function count_captured_options() {
+ return count( $this->_captured_options );
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><del>- * @action added_option
- * @param $option_name
- * @param $new_value
</del><ins>+ * Start keeping track of changes to options, and cache their new values
</ins><span class="cx"> */
</span><del>- function _capture_added_option( $option_name, $new_value ) {
- if ( $this->is_option_ignored( $option_name ) ) {
</del><ins>+ protected function start_capturing_option_updates() {
+ if ( $this->_is_capturing_option_updates ) {
</ins><span class="cx"> return;
</span><span class="cx"> }
</span><del>- $this->options[$option_name] = $new_value;
- $operation = 'add';
- $this->_operations[] = compact( 'operation', 'option_name', 'new_value' );
</del><ins>+
+ $this->_is_capturing_option_updates = true;
+ add_filter( 'pre_update_option', array( $this, '_capture_filter_pre_update_option' ), 10, 3 );
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><del>- * @action updated_option
</del><ins>+ * @access private
+ * @param mixed $new_value
</ins><span class="cx"> * @param string $option_name
</span><span class="cx"> * @param mixed $old_value
</span><del>- * @param mixed $new_value
</del><ins>+ * @return mixed
</ins><span class="cx"> */
</span><del>- function _capture_updated_option( $option_name, $old_value, $new_value ) {
- if ( $this->is_option_ignored( $option_name ) ) {
</del><ins>+ public function _capture_filter_pre_update_option( $new_value, $option_name, $old_value ) {
+ if ( $this->is_option_capture_ignored( $option_name ) ) {
</ins><span class="cx"> return;
</span><span class="cx"> }
</span><del>- $this->options[$option_name] = $new_value;
- $operation = 'update';
- $this->_operations[] = compact( 'operation', 'option_name', 'old_value', 'new_value' );
</del><ins>+
+ if ( ! isset( $this->_captured_options[$option_name] ) ) {
+ add_filter( "pre_option_{$option_name}", array( $this, '_capture_filter_pre_get_option' ) );
+ }
+
+ $this->_captured_options[$option_name] = $new_value;
+
+ return $old_value;
</ins><span class="cx"> }
</span><span class="cx">
</span><del>- protected $_pending_delete_option_autoload;
- protected $_pending_delete_option_value;
-
</del><span class="cx"> /**
</span><del>- * It's too bad the old_value and autoload aren't passed into the deleted_option action
- * @action delete_option
- * @param string $option_name
</del><ins>+ * @access private
+ * @param mixed $value
+ * @return mixed
</ins><span class="cx"> */
</span><del>- function _capture_pre_deleted_option( $option_name ) {
- if ( $this->is_option_ignored( $option_name ) ) {
- return;
</del><ins>+ public function _capture_filter_pre_get_option( $value ) {
+ $option_name = preg_replace( '/^pre_option_/', '', current_filter() );
+ if ( isset( $this->_captured_options[$option_name] ) ) {
+ $value = $this->_captured_options[$option_name];
+ $value = apply_filters( 'option_' . $option_name, $value );
</ins><span class="cx"> }
</span><del>- global $wpdb;
- $autoload = $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", $option_name ) ); // db call ok; no-cache ok
- $this->_pending_delete_option_autoload = $autoload;
- $this->_pending_delete_option_value = get_option( $option_name );
</del><ins>+
+ return $value;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><del>- * @action deleted_option
- * @param string $option_name
</del><ins>+ * Undo any changes to the options since start_capturing_option_updates() was called
</ins><span class="cx"> */
</span><del>- function _capture_deleted_option( $option_name ) {
- if ( $this->is_option_ignored( $option_name ) ) {
</del><ins>+ protected function stop_capturing_option_updates() {
+ if ( ! $this->_is_capturing_option_updates ) {
</ins><span class="cx"> return;
</span><span class="cx"> }
</span><del>- unset( $this->options[$option_name] );
- $operation = 'delete';
- $old_value = $this->_pending_delete_option_value;
- $autoload = $this->_pending_delete_option_autoload;
- $this->_operations[] = compact( 'operation', 'option_name', 'old_value', 'autoload' );
- }
</del><span class="cx">
</span><del>- /**
- * Undo any changes to the options since start() was called
- */
- function rollback() {
- remove_action( 'updated_option', array( $this, '_capture_updated_option' ), 10, 3 );
- remove_action( 'added_option', array( $this, '_capture_added_option' ), 10, 2 );
- remove_action( 'delete_option', array( $this, '_capture_pre_deleted_option' ), 10, 1 );
- remove_action( 'deleted_option', array( $this, '_capture_deleted_option' ), 10, 1 );
- while ( 0 !== count( $this->_operations ) ) {
- $option_operation = array_pop( $this->_operations );
- if ( 'add' === $option_operation['operation'] ) {
- delete_option( $option_operation['option_name'] );
- }
- else if ( 'delete' === $option_operation['operation'] ) {
- add_option( $option_operation['option_name'], $option_operation['old_value'], null, $option_operation['autoload'] );
- }
- else if ( 'update' === $option_operation['operation'] ) {
- update_option( $option_operation['option_name'], $option_operation['old_value'] );
- }
</del><ins>+ remove_filter( '_capture_filter_pre_update_option', array( $this, '_capture_filter_pre_update_option' ), 10, 3 );
+ foreach ( array_keys( $this->_captured_options ) as $option_name ) {
+ remove_filter( "pre_option_{$option_name}", array( $this, '_capture_filter_pre_get_option' ) );
</ins><span class="cx"> }
</span><del>- $this->_is_current = false;
</del><ins>+
+ $this->_captured_options = array();
+ $this->_is_capturing_option_updates = false;
</ins><span class="cx"> }
</span><span class="cx"> }
</span></span></pre>
</div>
</div>
</body>
</html>