wp/wp-includes/widgets.php
author ymh <ymh.work@gmail.com>
Tue, 09 Jun 2015 03:35:32 +0200
changeset 5 5e2f62d02dcd
parent 0 d970ebf37754
child 7 cf61fcea0001
permissions -rw-r--r--
upgrade wordpress + plugins
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
 * API for creating dynamic sidebar without hardcoding functionality into
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
 * themes. Includes both internal WordPress routines and theme use routines.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
 * This functionality was found in a plugin before WordPress 2.2 release which
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
 * included it in the core from that point on.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
     9
 * @link https://codex.wordpress.org/Plugins/WordPress_Widgets WordPress Widgets
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    10
 * @link https://codex.wordpress.org/Plugins/WordPress_Widgets_Api Widgets API
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
 * @package WordPress
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
 * @subpackage Widgets
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
 * This class must be extended for each widget and WP_Widget::widget(), WP_Widget::update()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
 * and WP_Widget::form() need to be over-ridden.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
 * @package WordPress
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
 * @subpackage Widgets
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    22
 * @since 2.8.0
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
class WP_Widget {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    26
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    27
	 * Root ID for all widgets of this type.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    28
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    29
	 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    30
	 * @access public
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    31
	 * @var mixed|string
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    32
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    33
	public $id_base;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    34
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    35
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    36
	 * Name for this widget type.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    37
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    38
	 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    39
	 * @access public
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    40
	 * @var string
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    41
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    42
	public $name;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    43
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    44
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    45
	 * Option array passed to {@see wp_register_sidebar_widget()}.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    46
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    47
	 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    48
	 * @access public
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    49
	 * @var array
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    50
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    51
	public $widget_options;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    53
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    54
	 * Option array passed to {@see wp_register_widget_control()}.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    55
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    56
	 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    57
	 * @access public
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    58
	 * @var array
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    59
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    60
	public $control_options;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    61
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    62
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    63
	 * Unique ID number of the current instance.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    64
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    65
	 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    66
	 * @access public
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    67
	 * @var bool|int
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    68
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    69
	public $number = false;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    70
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    71
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    72
	 * Unique ID string of the current instance (id_base-number).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    73
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    74
	 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    75
	 * @access public
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    76
	 * @var bool|string
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    77
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    78
	public $id = false;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    79
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    80
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    81
	 * Whether the widget data has been updated.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    82
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    83
	 * Set to true when the data is updated after a POST submit - ensures it does
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    84
	 * not happen twice.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    85
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    86
	 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    87
	 * @access public
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    88
	 * @var bool
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    89
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    90
	public $updated = false;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    91
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    92
	// Member functions that you must over-ride.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    93
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    94
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    95
	 * Echo the widget content.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    96
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    97
	 * Subclasses should over-ride this function to generate their widget code.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    98
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    99
	 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   100
	 * @access public
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   101
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   102
	 * @param array $args     Display arguments including before_title, after_title,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   103
	 *                        before_widget, and after_widget.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   104
	 * @param array $instance The settings for the particular instance of the widget.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   105
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   106
	public function widget( $args, $instance ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   107
		die('function WP_Widget::widget() must be over-ridden in a sub-class.');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   108
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   109
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   110
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   111
	 * Update a particular instance.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   112
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   113
	 * This function should check that $new_instance is set correctly. The newly-calculated
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   114
	 * value of `$instance` should be returned. If false is returned, the instance won't be
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   115
	 * saved/updated.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   116
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   117
	 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   118
	 * @access public
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   119
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   120
	 * @param array $new_instance New settings for this instance as input by the user via
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   121
	 *                            {@see WP_Widget::form()}.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   122
	 * @param array $old_instance Old settings for this instance.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   123
	 * @return array Settings to save or bool false to cancel saving.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   124
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   125
	public function update( $new_instance, $old_instance ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   126
		return $new_instance;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   127
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   128
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   129
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   130
	 * Output the settings update form.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   131
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   132
	 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   133
	 * @access public
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   134
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   135
	 * @param array $instance Current settings.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   136
	 * @return string Default return is 'noform'.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   137
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   138
	public function form($instance) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   139
		echo '<p class="no-options-widget">' . __('There are no options for this widget.') . '</p>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   140
		return 'noform';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   141
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   142
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   143
	// Functions you'll need to call.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   144
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   145
	/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   146
	 * PHP5 constructor.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   147
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   148
	 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   149
	 * @access public
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   150
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   151
	 * @param string $id_base         Optional Base ID for the widget, lowercase and unique. If left empty,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   152
	 *                                a portion of the widget's class name will be used Has to be unique.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   153
	 * @param string $name            Name for the widget displayed on the configuration page.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   154
	 * @param array  $widget_options  Optional. Widget options. See {@see wp_register_sidebar_widget()} for
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   155
	 *                                information on accepted arguments. Default empty array.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   156
	 * @param array  $control_options Optional. Widget control options. See {@see wp_register_widget_control()}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   157
	 *                                for information on accepted arguments. Default empty array.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   158
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   159
	public function __construct( $id_base, $name, $widget_options = array(), $control_options = array() ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   160
		$this->id_base = empty($id_base) ? preg_replace( '/(wp_)?widget_/', '', strtolower(get_class($this)) ) : strtolower($id_base);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   161
		$this->name = $name;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   162
		$this->option_name = 'widget_' . $this->id_base;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   163
		$this->widget_options = wp_parse_args( $widget_options, array('classname' => $this->option_name) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   164
		$this->control_options = wp_parse_args( $control_options, array('id_base' => $this->id_base) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   165
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   166
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   167
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   168
	 * PHP4 constructor
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   169
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   170
	 * @param string $id_base
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   171
	 * @param string $name
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   172
	 * @param array  $widget_options
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   173
	 * @param array  $control_options
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   174
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   175
	public function WP_Widget( $id_base, $name, $widget_options = array(), $control_options = array() ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   176
		WP_Widget::__construct( $id_base, $name, $widget_options, $control_options );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   177
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   178
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   179
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   180
	 * Constructs name attributes for use in form() fields
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   181
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   182
	 * This function should be used in form() methods to create name attributes for fields to be saved by update()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   183
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   184
	 * @param string $field_name Field name
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   185
	 * @return string Name attribute for $field_name
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   186
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   187
	public function get_field_name($field_name) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   188
		return 'widget-' . $this->id_base . '[' . $this->number . '][' . $field_name . ']';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   189
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   190
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   191
	/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   192
	 * Constructs id attributes for use in {@see WP_Widget::form()} fields.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   193
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   194
	 * This function should be used in form() methods to create id attributes
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   195
	 * for fields to be saved by {@see WP_Widget::update()}.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   196
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   197
	 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   198
	 * @access public
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   199
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   200
	 * @param string $field_name Field name.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   201
	 * @return string ID attribute for `$field_name`.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   202
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   203
	public function get_field_id( $field_name ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   204
		return 'widget-' . $this->id_base . '-' . $this->number . '-' . $field_name;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   205
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   206
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   207
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   208
	 * Register all widget instances of this widget class.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   209
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   210
	 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   211
	 * @access private
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   212
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   213
	public function _register() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   214
		$settings = $this->get_settings();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   215
		$empty = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   216
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   217
		if ( is_array($settings) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   218
			foreach ( array_keys($settings) as $number ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   219
				if ( is_numeric($number) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   220
					$this->_set($number);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   221
					$this->_register_one($number);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   222
					$empty = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   223
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   224
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   225
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   226
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   227
		if ( $empty ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   228
			// If there are none, we register the widget's existence with a
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   229
			// generic template
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   230
			$this->_set(1);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   231
			$this->_register_one();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   232
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   233
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   234
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   235
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   236
	 * Set the internal order number for the widget instance.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   237
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   238
	 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   239
	 * @access private
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   240
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   241
	 * @param int $number The unique order number of this widget instance compared to other
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   242
	 *                    instances of the same class.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   243
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   244
	public function _set($number) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   245
		$this->number = $number;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   246
		$this->id = $this->id_base . '-' . $number;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   247
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   248
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   249
	public function _get_display_callback() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   250
		return array($this, 'display_callback');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   251
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   252
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   253
	public function _get_update_callback() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   254
		return array($this, 'update_callback');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   255
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   256
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   257
	public function _get_form_callback() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   258
		return array($this, 'form_callback');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   259
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   260
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   261
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   262
	 * Determine whether the current request is inside the Customizer preview.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   263
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   264
	 * If true -- the current request is inside the Customizer preview, then
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   265
	 * the object cache gets suspended and widgets should check this to decide
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   266
	 * whether they should store anything persistently to the object cache,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   267
	 * to transients, or anywhere else.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   268
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   269
	 * @since 3.9.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   270
	 * @access public
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   271
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   272
	 * @return bool True if within the Customizer preview, false if not.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   273
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   274
	public function is_preview() {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   275
		global $wp_customize;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   276
		return ( isset( $wp_customize ) && $wp_customize->is_preview() ) ;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   277
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   278
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   279
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   280
	 * Generate the actual widget content (Do NOT override).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   281
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   282
	 * Finds the instance and calls {@see WP_Widget::widget()}.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   283
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   284
	 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   285
	 * @access public
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   286
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   287
	 * @param array     $args        Display arguments. See {@see WP_Widget::widget()} for information
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   288
	 *                               on accepted arguments.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   289
	 * @param int|array $widget_args {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   290
	 *     Optional. Internal order number of the widget instance, or array of multi-widget arguments.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   291
	 *     Default 1.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   292
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   293
	 *     @type int $number Number increment used for multiples of the same widget.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   294
	 * }
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   295
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   296
	public function display_callback( $args, $widget_args = 1 ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   297
		if ( is_numeric($widget_args) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   298
			$widget_args = array( 'number' => $widget_args );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   299
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   300
		$widget_args = wp_parse_args( $widget_args, array( 'number' => -1 ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   301
		$this->_set( $widget_args['number'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   302
		$instance = $this->get_settings();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   303
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   304
		if ( array_key_exists( $this->number, $instance ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   305
			$instance = $instance[$this->number];
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   306
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   307
			/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   308
			 * Filter the settings for a particular widget instance.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   309
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   310
			 * Returning false will effectively short-circuit display of the widget.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   311
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   312
			 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   313
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   314
			 * @param array     $instance The current widget instance's settings.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   315
			 * @param WP_Widget $this     The current widget instance.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   316
			 * @param array     $args     An array of default widget arguments.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   317
			 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   318
			$instance = apply_filters( 'widget_display_callback', $instance, $this, $args );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   319
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   320
			if ( false === $instance ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   321
				return;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   322
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   323
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   324
			$was_cache_addition_suspended = wp_suspend_cache_addition();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   325
			if ( $this->is_preview() && ! $was_cache_addition_suspended ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   326
				wp_suspend_cache_addition( true );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   327
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   328
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   329
			$this->widget( $args, $instance );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   330
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   331
			if ( $this->is_preview() ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   332
				wp_suspend_cache_addition( $was_cache_addition_suspended );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   333
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   334
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   335
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   336
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   337
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   338
	 * Deal with changed settings (Do NOT override).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   339
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   340
	 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   341
	 * @access public
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   342
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   343
	 * @param int $deprecated Not used.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   344
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   345
	public function update_callback( $deprecated = 1 ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   346
		global $wp_registered_widgets;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   347
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   348
		$all_instances = $this->get_settings();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   349
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   350
		// We need to update the data
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   351
		if ( $this->updated )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   352
			return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   353
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   354
		if ( isset($_POST['delete_widget']) && $_POST['delete_widget'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   355
			// Delete the settings for this instance of the widget
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   356
			if ( isset($_POST['the-widget-id']) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   357
				$del_id = $_POST['the-widget-id'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   358
			else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   359
				return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   360
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   361
			if ( isset($wp_registered_widgets[$del_id]['params'][0]['number']) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   362
				$number = $wp_registered_widgets[$del_id]['params'][0]['number'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   363
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   364
				if ( $this->id_base . '-' . $number == $del_id )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   365
					unset($all_instances[$number]);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   366
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   367
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   368
			if ( isset($_POST['widget-' . $this->id_base]) && is_array($_POST['widget-' . $this->id_base]) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   369
				$settings = $_POST['widget-' . $this->id_base];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   370
			} elseif ( isset($_POST['id_base']) && $_POST['id_base'] == $this->id_base ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   371
				$num = $_POST['multi_number'] ? (int) $_POST['multi_number'] : (int) $_POST['widget_number'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   372
				$settings = array( $num => array() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   373
			} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   374
				return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   375
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   376
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   377
			foreach ( $settings as $number => $new_instance ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   378
				$new_instance = stripslashes_deep($new_instance);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   379
				$this->_set($number);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   380
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   381
				$old_instance = isset($all_instances[$number]) ? $all_instances[$number] : array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   382
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   383
				$was_cache_addition_suspended = wp_suspend_cache_addition();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   384
				if ( $this->is_preview() && ! $was_cache_addition_suspended ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   385
					wp_suspend_cache_addition( true );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   386
				}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   387
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   388
				$instance = $this->update( $new_instance, $old_instance );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   389
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   390
				if ( $this->is_preview() ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   391
					wp_suspend_cache_addition( $was_cache_addition_suspended );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   392
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   393
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   394
				/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   395
				 * Filter a widget's settings before saving.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   396
				 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   397
				 * Returning false will effectively short-circuit the widget's ability
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   398
				 * to update settings.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   399
				 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   400
				 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   401
				 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   402
				 * @param array     $instance     The current widget instance's settings.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   403
				 * @param array     $new_instance Array of new widget settings.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   404
				 * @param array     $old_instance Array of old widget settings.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   405
				 * @param WP_Widget $this         The current widget instance.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   406
				 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   407
				$instance = apply_filters( 'widget_update_callback', $instance, $new_instance, $old_instance, $this );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   408
				if ( false !== $instance ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   409
					$all_instances[$number] = $instance;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   410
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   411
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   412
				break; // run only once
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   413
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   414
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   415
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   416
		$this->save_settings($all_instances);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   417
		$this->updated = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   418
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   419
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   420
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   421
	 * Generate the widget control form (Do NOT override).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   422
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   423
	 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   424
	 * @access public
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   425
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   426
	 * @param int|array $widget_args Widget instance number or array of widget arguments.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   427
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   428
	public function form_callback( $widget_args = 1 ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   429
		if ( is_numeric($widget_args) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   430
			$widget_args = array( 'number' => $widget_args );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   431
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   432
		$widget_args = wp_parse_args( $widget_args, array( 'number' => -1 ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   433
		$all_instances = $this->get_settings();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   434
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   435
		if ( -1 == $widget_args['number'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   436
			// We echo out a form where 'number' can be set later
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   437
			$this->_set('__i__');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   438
			$instance = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   439
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   440
			$this->_set($widget_args['number']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   441
			$instance = $all_instances[ $widget_args['number'] ];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   442
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   443
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   444
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   445
		 * Filter the widget instance's settings before displaying the control form.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   446
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   447
		 * Returning false effectively short-circuits display of the control form.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   448
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   449
		 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   450
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   451
		 * @param array     $instance The current widget instance's settings.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   452
		 * @param WP_Widget $this     The current widget instance.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   453
		 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   454
		$instance = apply_filters( 'widget_form_callback', $instance, $this );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   455
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   456
		$return = null;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   457
		if ( false !== $instance ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   458
			$return = $this->form($instance);
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   459
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   460
			/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   461
			 * Fires at the end of the widget control form.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   462
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   463
			 * Use this hook to add extra fields to the widget form. The hook
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   464
			 * is only fired if the value passed to the 'widget_form_callback'
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   465
			 * hook is not false.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   466
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   467
			 * Note: If the widget has no form, the text echoed from the default
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   468
			 * form method can be hidden using CSS.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   469
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   470
			 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   471
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   472
			 * @param WP_Widget $this     The widget instance, passed by reference.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   473
			 * @param null      $return   Return null if new fields are added.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   474
			 * @param array     $instance An array of the widget's settings.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   475
			 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   476
			do_action_ref_array( 'in_widget_form', array( &$this, &$return, $instance ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   477
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   478
		return $return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   479
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   480
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   481
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   482
	 * Register an instance of the widget class.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   483
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   484
	 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   485
	 * @access private
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   486
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   487
	 * @param integer $number Optional. The unique order number of this widget instance
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   488
	 *                        compared to other instances of the same class. Default -1.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   489
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   490
	public function _register_one( $number = -1 ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   491
		wp_register_sidebar_widget(	$this->id, $this->name,	$this->_get_display_callback(), $this->widget_options, array( 'number' => $number ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   492
		_register_widget_update_callback( $this->id_base, $this->_get_update_callback(), $this->control_options, array( 'number' => -1 ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   493
		_register_widget_form_callback(	$this->id, $this->name,	$this->_get_form_callback(), $this->control_options, array( 'number' => $number ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   494
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   495
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   496
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   497
	 * Save the settings for all instances of the widget class.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   498
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   499
	 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   500
	 * @access public
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   501
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   502
	 * @param array $settings Multi-dimensional array of widget instance settings.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   503
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   504
	public function save_settings( $settings ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   505
		$settings['_multiwidget'] = 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   506
		update_option( $this->option_name, $settings );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   507
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   508
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   509
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   510
	 * Get the settings for all instances of the widget class.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   511
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   512
	 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   513
	 * @access public
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   514
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   515
	 * @return array Multi-dimensional array of widget instance settings.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   516
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   517
	public function get_settings() {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   518
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   519
		$settings = get_option($this->option_name);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   520
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   521
		if ( false === $settings && isset($this->alt_option_name) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   522
			$settings = get_option($this->alt_option_name);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   523
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   524
		if ( !is_array($settings) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   525
			$settings = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   526
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   527
		if ( !empty($settings) && !array_key_exists('_multiwidget', $settings) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   528
			// old format, convert if single widget
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   529
			$settings = wp_convert_widget_settings($this->id_base, $this->option_name, $settings);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   530
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   531
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   532
		unset($settings['_multiwidget'], $settings['__i__']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   533
		return $settings;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   534
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   535
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   536
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   537
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   538
 * Singleton that registers and instantiates WP_Widget classes.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   539
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   540
 * @package WordPress
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   541
 * @subpackage Widgets
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   542
 * @since 2.8.0
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   543
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   544
class WP_Widget_Factory {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   545
	public $widgets = array();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   546
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   547
	public function WP_Widget_Factory() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   548
		add_action( 'widgets_init', array( $this, '_register_widgets' ), 100 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   549
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   550
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   551
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   552
	 * Register a widget subclass.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   553
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   554
	 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   555
	 * @access public
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   556
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   557
	 * @param string $widget_class The name of a {@see WP_Widget} subclass.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   558
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   559
	public function register( $widget_class ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   560
		$this->widgets[$widget_class] = new $widget_class();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   561
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   562
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   563
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   564
	 * Un-register a widget subclass.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   565
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   566
	 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   567
	 * @access public
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   568
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   569
	 * @param string $widget_class The name of a {@see WP_Widget} subclass.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   570
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   571
	public function unregister( $widget_class ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   572
		if ( isset($this->widgets[$widget_class]) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   573
			unset($this->widgets[$widget_class]);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   574
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   575
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   576
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   577
	 * Utility method for adding widgets to the registered widgets global.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   578
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   579
	 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   580
	 * @access public
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   581
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   582
	public function _register_widgets() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   583
		global $wp_registered_widgets;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   584
		$keys = array_keys($this->widgets);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   585
		$registered = array_keys($wp_registered_widgets);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   586
		$registered = array_map('_get_widget_id_base', $registered);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   587
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   588
		foreach ( $keys as $key ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   589
			// don't register new widget if old widget with the same id is already registered
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   590
			if ( in_array($this->widgets[$key]->id_base, $registered, true) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   591
				unset($this->widgets[$key]);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   592
				continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   593
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   594
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   595
			$this->widgets[$key]->_register();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   596
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   597
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   598
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   599
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   600
/* Global Variables */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   601
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   602
/** @ignore */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   603
global $wp_registered_sidebars, $wp_registered_widgets, $wp_registered_widget_controls, $wp_registered_widget_updates;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   604
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   605
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   606
 * Stores the sidebars, since many themes can have more than one.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   607
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   608
 * @global array $wp_registered_sidebars
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   609
 * @since 2.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   610
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   611
$wp_registered_sidebars = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   612
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   613
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   614
 * Stores the registered widgets.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   615
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   616
 * @global array $wp_registered_widgets
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   617
 * @since 2.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   618
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   619
$wp_registered_widgets = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   620
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   621
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   622
 * Stores the registered widget control (options).
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   623
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   624
 * @global array $wp_registered_widget_controls
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   625
 * @since 2.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   626
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   627
$wp_registered_widget_controls = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   628
$wp_registered_widget_updates = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   629
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   630
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   631
 * Private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   632
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   633
$_wp_sidebars_widgets = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   634
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   635
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   636
 * Private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   637
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   638
$GLOBALS['_wp_deprecated_widgets_callbacks'] = array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   639
	'wp_widget_pages',
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   640
	'wp_widget_pages_control',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   641
	'wp_widget_calendar',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   642
	'wp_widget_calendar_control',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   643
	'wp_widget_archives',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   644
	'wp_widget_archives_control',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   645
	'wp_widget_links',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   646
	'wp_widget_meta',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   647
	'wp_widget_meta_control',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   648
	'wp_widget_search',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   649
	'wp_widget_recent_entries',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   650
	'wp_widget_recent_entries_control',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   651
	'wp_widget_tag_cloud',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   652
	'wp_widget_tag_cloud_control',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   653
	'wp_widget_categories',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   654
	'wp_widget_categories_control',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   655
	'wp_widget_text',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   656
	'wp_widget_text_control',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   657
	'wp_widget_rss',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   658
	'wp_widget_rss_control',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   659
	'wp_widget_recent_comments',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   660
	'wp_widget_recent_comments_control'
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   661
);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   662
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   663
/* Template tags & API functions */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   664
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   665
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   666
 * Register a widget
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   667
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   668
 * Registers a WP_Widget widget
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   669
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   670
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   671
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   672
 * @see WP_Widget
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   673
 * @see WP_Widget_Factory
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   674
 * @uses WP_Widget_Factory
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   675
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   676
 * @param string $widget_class The name of a class that extends WP_Widget
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   677
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   678
function register_widget($widget_class) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   679
	global $wp_widget_factory;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   680
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   681
	$wp_widget_factory->register($widget_class);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   682
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   683
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   684
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   685
 * Unregister a widget
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   686
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   687
 * Unregisters a WP_Widget widget. Useful for unregistering default widgets.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   688
 * Run within a function hooked to the widgets_init action.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   689
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   690
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   691
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   692
 * @see WP_Widget
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   693
 * @see WP_Widget_Factory
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   694
 * @uses WP_Widget_Factory
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   695
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   696
 * @param string $widget_class The name of a class that extends WP_Widget
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   697
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   698
function unregister_widget($widget_class) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   699
	global $wp_widget_factory;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   700
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   701
	$wp_widget_factory->unregister($widget_class);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   702
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   703
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   704
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   705
 * Creates multiple sidebars.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   706
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   707
 * If you wanted to quickly create multiple sidebars for a theme or internally.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   708
 * This function will allow you to do so. If you don't pass the 'name' and/or
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   709
 * 'id' in `$args`, then they will be built for you.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   710
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   711
 * @since 2.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   712
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   713
 * @see register_sidebar() The second parameter is documented by register_sidebar() and is the same here.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   714
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   715
 * @param int          $number Optional. Number of sidebars to create. Default 1.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   716
 * @param array|string $args {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   717
 *     Optional. Array or string of arguments for building a sidebar.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   718
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   719
 *     @type string $id   The base string of the unique identifier for each sidebar. If provided, and multiple
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   720
 *                        sidebars are being defined, the id will have "-2" appended, and so on.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   721
 *                        Default 'sidebar-' followed by the number the sidebar creation is currently at.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   722
 *     @type string $name The name or title for the sidebars displayed in the admin dashboard. If registering
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   723
 *                        more than one sidebar, include '%d' in the string as a placeholder for the uniquely
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   724
 *                        assigned number for each sidebar.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   725
 *                        Default 'Sidebar' for the first sidebar, otherwise 'Sidebar %d'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   726
 * }
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   727
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   728
function register_sidebars( $number = 1, $args = array() ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   729
	global $wp_registered_sidebars;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   730
	$number = (int) $number;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   731
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   732
	if ( is_string($args) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   733
		parse_str($args, $args);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   734
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   735
	for ( $i = 1; $i <= $number; $i++ ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   736
		$_args = $args;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   737
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   738
		if ( $number > 1 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   739
			$_args['name'] = isset($args['name']) ? sprintf($args['name'], $i) : sprintf(__('Sidebar %d'), $i);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   740
		else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   741
			$_args['name'] = isset($args['name']) ? $args['name'] : __('Sidebar');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   742
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   743
		// Custom specified ID's are suffixed if they exist already.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   744
		// Automatically generated sidebar names need to be suffixed regardless starting at -0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   745
		if ( isset($args['id']) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   746
			$_args['id'] = $args['id'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   747
			$n = 2; // Start at -2 for conflicting custom ID's
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   748
			while ( isset($wp_registered_sidebars[$_args['id']]) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   749
				$_args['id'] = $args['id'] . '-' . $n++;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   750
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   751
			$n = count($wp_registered_sidebars);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   752
			do {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   753
				$_args['id'] = 'sidebar-' . ++$n;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   754
			} while ( isset($wp_registered_sidebars[$_args['id']]) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   755
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   756
		register_sidebar($_args);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   757
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   758
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   759
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   760
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   761
 * Builds the definition for a single sidebar and returns the ID.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   762
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   763
 * Accepts either a string or an array and then parses that against a set
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   764
 * of default arguments for the new sidebar. WordPress will automatically
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   765
 * generate a sidebar ID and name based on the current number of registered
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   766
 * sidebars if those arguments are not included.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   767
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   768
 * When allowing for automatic generation of the name and ID parameters, keep
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   769
 * in mind that the incrementor for your sidebar can change over time depending
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   770
 * on what other plugins and themes are installed.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   771
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   772
 * If theme support for 'widgets' has not yet been added when this function is
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   773
 * called, it will be automatically enabled through the use of add_theme_support()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   774
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   775
 * @since 2.2.0
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   776
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   777
 * @global array $wp_registered_sidebars Stores the new sidebar in this array by sidebar ID.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   778
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   779
 * @param array|string $args {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   780
 *     Optional. Array or string of arguments for the sidebar being registered.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   781
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   782
 *     @type string $name          The name or title of the sidebar displayed in the Widgets
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   783
 *                                 interface. Default 'Sidebar $instance'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   784
 *     @type string $id            The unique identifier by which the sidebar will be called.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   785
 *                                 Default 'sidebar-$instance'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   786
 *     @type string $description   Description of the sidebar, displayed in the Widgets interface.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   787
 *                                 Default empty string.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   788
 *     @type string $class         Extra CSS class to assign to the sidebar in the Widgets interface.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   789
 *                                 Default empty.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   790
 *     @type string $before_widget HTML content to prepend to each widget's HTML output when
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   791
 *                                 assigned to this sidebar. Default is an opening list item element.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   792
 *     @type string $after_widget  HTML content to append to each widget's HTML output when
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   793
 *                                 assigned to this sidebar. Default is a closing list item element.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   794
 *     @type string $before_title  HTML content to prepend to the sidebar title when displayed.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   795
 *                                 Default is an opening h2 element.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   796
 *     @type string $after_title   HTML content to append to the sidebar title when displayed.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   797
 *                                 Default is a closing h2 element.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   798
 * }
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   799
 * @return string Sidebar ID added to $wp_registered_sidebars global.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   800
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   801
function register_sidebar($args = array()) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   802
	global $wp_registered_sidebars;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   803
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   804
	$i = count($wp_registered_sidebars) + 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   805
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   806
	$id_is_empty = empty( $args['id'] );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   807
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   808
	$defaults = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   809
		'name' => sprintf(__('Sidebar %d'), $i ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   810
		'id' => "sidebar-$i",
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   811
		'description' => '',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   812
		'class' => '',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   813
		'before_widget' => '<li id="%1$s" class="widget %2$s">',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   814
		'after_widget' => "</li>\n",
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   815
		'before_title' => '<h2 class="widgettitle">',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   816
		'after_title' => "</h2>\n",
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   817
	);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   818
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   819
	$sidebar = wp_parse_args( $args, $defaults );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   820
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   821
	if ( $id_is_empty ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   822
		/* translators: 1: the id argument, 2: sidebar name, 3: recommended id value */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   823
		_doing_it_wrong( __FUNCTION__, sprintf( __( 'No %1$s was set in the arguments array for the "%2$s" sidebar. Defaulting to "%3$s". Manually set the %1$s to "%3$s" to silence this notice and keep existing sidebar content.' ), '<code>id</code>', $sidebar['name'], $sidebar['id'] ), '4.2.0' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   824
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   825
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   826
	$wp_registered_sidebars[$sidebar['id']] = $sidebar;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   827
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   828
	add_theme_support('widgets');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   829
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   830
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   831
	 * Fires once a sidebar has been registered.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   832
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   833
	 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   834
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   835
	 * @param array $sidebar Parsed arguments for the registered sidebar.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   836
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   837
	do_action( 'register_sidebar', $sidebar );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   838
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   839
	return $sidebar['id'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   840
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   841
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   842
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   843
 * Removes a sidebar from the list.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   844
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   845
 * @since 2.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   846
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   847
 * @uses $wp_registered_sidebars Stores the new sidebar in this array by sidebar ID.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   848
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   849
 * @param string $name The ID of the sidebar when it was added.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   850
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   851
function unregister_sidebar( $name ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   852
	global $wp_registered_sidebars;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   853
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   854
	if ( isset( $wp_registered_sidebars[$name] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   855
		unset( $wp_registered_sidebars[$name] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   856
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   857
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   858
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   859
 * Register an instance of a widget.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   860
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   861
 * The default widget option is 'classname' that can be overridden.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   862
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   863
 * The function can also be used to un-register widgets when `$output_callback`
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   864
 * parameter is an empty string.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   865
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   866
 * @since 2.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   867
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   868
 * @global array $wp_registered_widgets       Uses stored registered widgets.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   869
 * @global array $wp_register_widget_defaults Retrieves widget defaults.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   870
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   871
 * @param int|string $id              Widget ID.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   872
 * @param string     $name            Widget display title.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   873
 * @param callback   $output_callback Run when widget is called.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   874
 * @param array      $options {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   875
 *     Optional. An array of supplementary widget options for the instance.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   876
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   877
 *     @type string $classname   Class name for the widget's HTML container. Default is a shortened
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   878
 *                               version of the output callback name.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   879
 *     @type string $description Widget description for display in the widget administration
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   880
 *                               panel and/or theme.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   881
 * }
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   882
 * @return null Will return if `$output_callback` is empty after removing widget.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   883
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   884
function wp_register_sidebar_widget( $id, $name, $output_callback, $options = array() ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   885
	global $wp_registered_widgets, $wp_registered_widget_controls, $wp_registered_widget_updates, $_wp_deprecated_widgets_callbacks;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   886
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   887
	$id = strtolower($id);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   888
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   889
	if ( empty($output_callback) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   890
		unset($wp_registered_widgets[$id]);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   891
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   892
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   893
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   894
	$id_base = _get_widget_id_base($id);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   895
	if ( in_array($output_callback, $_wp_deprecated_widgets_callbacks, true) && !is_callable($output_callback) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   896
		if ( isset($wp_registered_widget_controls[$id]) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   897
			unset($wp_registered_widget_controls[$id]);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   898
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   899
		if ( isset($wp_registered_widget_updates[$id_base]) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   900
			unset($wp_registered_widget_updates[$id_base]);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   901
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   902
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   903
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   904
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   905
	$defaults = array('classname' => $output_callback);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   906
	$options = wp_parse_args($options, $defaults);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   907
	$widget = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   908
		'name' => $name,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   909
		'id' => $id,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   910
		'callback' => $output_callback,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   911
		'params' => array_slice(func_get_args(), 4)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   912
	);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   913
	$widget = array_merge($widget, $options);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   914
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   915
	if ( is_callable($output_callback) && ( !isset($wp_registered_widgets[$id]) || did_action( 'widgets_init' ) ) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   916
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   917
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   918
		 * Fires once for each registered widget.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   919
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   920
		 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   921
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   922
		 * @param array $widget An array of default widget arguments.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   923
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   924
		do_action( 'wp_register_sidebar_widget', $widget );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   925
		$wp_registered_widgets[$id] = $widget;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   926
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   927
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   928
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   929
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   930
 * Retrieve description for widget.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   931
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   932
 * When registering widgets, the options can also include 'description' that
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   933
 * describes the widget for display on the widget administration panel or
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   934
 * in the theme.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   935
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   936
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   937
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   938
 * @param int|string $id Widget ID.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   939
 * @return string Widget description, if available. Null on failure to retrieve description.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   940
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   941
function wp_widget_description( $id ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   942
	if ( !is_scalar($id) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   943
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   944
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   945
	global $wp_registered_widgets;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   946
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   947
	if ( isset($wp_registered_widgets[$id]['description']) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   948
		return esc_html( $wp_registered_widgets[$id]['description'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   949
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   950
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   951
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   952
 * Retrieve description for a sidebar.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   953
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   954
 * When registering sidebars a 'description' parameter can be included that
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   955
 * describes the sidebar for display on the widget administration panel.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   956
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   957
 * @since 2.9.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   958
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   959
 * @param string $id sidebar ID.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   960
 * @return string Sidebar description, if available. Null on failure to retrieve description.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   961
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   962
function wp_sidebar_description( $id ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   963
	if ( !is_scalar($id) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   964
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   965
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   966
	global $wp_registered_sidebars;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   967
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   968
	if ( isset($wp_registered_sidebars[$id]['description']) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   969
		return esc_html( $wp_registered_sidebars[$id]['description'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   970
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   971
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   972
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   973
 * Remove widget from sidebar.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   974
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   975
 * @since 2.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   976
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   977
 * @param int|string $id Widget ID.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   978
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   979
function wp_unregister_sidebar_widget($id) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   980
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   981
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   982
	 * Fires just before a widget is removed from a sidebar.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   983
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   984
	 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   985
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   986
	 * @param int $id The widget ID.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   987
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   988
	do_action( 'wp_unregister_sidebar_widget', $id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   989
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   990
	wp_register_sidebar_widget($id, '', '');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   991
	wp_unregister_widget_control($id);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   992
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   993
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   994
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   995
 * Registers widget control callback for customizing options.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   996
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   997
 * The options contains the 'height', 'width', and 'id_base' keys. The 'height'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   998
 * option is never used. The 'width' option is the width of the fully expanded
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   999
 * control form, but try hard to use the default width. The 'id_base' is for
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1000
 * multi-widgets (widgets which allow multiple instances such as the text
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1001
 * widget), an id_base must be provided. The widget id will end up looking like
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1002
 * `{$id_base}-{$unique_number}`.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1003
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1004
 * @since 2.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1005
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1006
 * @todo Document `$options` as a hash notation, re: WP_Widget::__construct() cross-reference.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1007
 * @todo `$params` parameter?
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1008
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1009
 * @param int|string   $id               Sidebar ID.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1010
 * @param string       $name             Sidebar display name.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1011
 * @param callback     $control_callback Run when sidebar is displayed.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1012
 * @param array|string $options          Optional. Widget options. See description above. Default empty array.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1013
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1014
function wp_register_widget_control( $id, $name, $control_callback, $options = array() ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1015
	global $wp_registered_widget_controls, $wp_registered_widget_updates, $wp_registered_widgets, $_wp_deprecated_widgets_callbacks;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1016
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1017
	$id = strtolower($id);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1018
	$id_base = _get_widget_id_base($id);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1019
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1020
	if ( empty($control_callback) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1021
		unset($wp_registered_widget_controls[$id]);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1022
		unset($wp_registered_widget_updates[$id_base]);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1023
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1024
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1025
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1026
	if ( in_array($control_callback, $_wp_deprecated_widgets_callbacks, true) && !is_callable($control_callback) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1027
		if ( isset($wp_registered_widgets[$id]) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1028
			unset($wp_registered_widgets[$id]);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1029
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1030
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1031
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1032
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1033
	if ( isset($wp_registered_widget_controls[$id]) && !did_action( 'widgets_init' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1034
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1035
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1036
	$defaults = array('width' => 250, 'height' => 200 ); // height is never used
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1037
	$options = wp_parse_args($options, $defaults);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1038
	$options['width'] = (int) $options['width'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1039
	$options['height'] = (int) $options['height'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1040
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1041
	$widget = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1042
		'name' => $name,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1043
		'id' => $id,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1044
		'callback' => $control_callback,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1045
		'params' => array_slice(func_get_args(), 4)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1046
	);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1047
	$widget = array_merge($widget, $options);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1048
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1049
	$wp_registered_widget_controls[$id] = $widget;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1050
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1051
	if ( isset($wp_registered_widget_updates[$id_base]) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1052
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1053
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1054
	if ( isset($widget['params'][0]['number']) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1055
		$widget['params'][0]['number'] = -1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1056
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1057
	unset($widget['width'], $widget['height'], $widget['name'], $widget['id']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1058
	$wp_registered_widget_updates[$id_base] = $widget;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1059
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1060
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1061
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1062
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1063
 * @global array $wp_registered_widget_updates
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1064
 * @param string   $id_base
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1065
 * @param callable $update_callback
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1066
 * @param array    $options
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1067
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1068
function _register_widget_update_callback($id_base, $update_callback, $options = array()) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1069
	global $wp_registered_widget_updates;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1070
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1071
	if ( isset($wp_registered_widget_updates[$id_base]) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1072
		if ( empty($update_callback) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1073
			unset($wp_registered_widget_updates[$id_base]);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1074
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1075
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1076
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1077
	$widget = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1078
		'callback' => $update_callback,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1079
		'params' => array_slice(func_get_args(), 3)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1080
	);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1081
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1082
	$widget = array_merge($widget, $options);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1083
	$wp_registered_widget_updates[$id_base] = $widget;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1084
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1085
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1086
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1087
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1088
 * @global array $wp_registered_widget_controls
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1089
 * @param int|string $id
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1090
 * @param string     $name
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1091
 * @param callable   $form_callback
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1092
 * @param array      $options
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1093
 * @return null
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1094
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1095
function _register_widget_form_callback($id, $name, $form_callback, $options = array()) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1096
	global $wp_registered_widget_controls;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1097
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1098
	$id = strtolower($id);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1099
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1100
	if ( empty($form_callback) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1101
		unset($wp_registered_widget_controls[$id]);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1102
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1103
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1104
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1105
	if ( isset($wp_registered_widget_controls[$id]) && !did_action( 'widgets_init' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1106
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1107
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1108
	$defaults = array('width' => 250, 'height' => 200 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1109
	$options = wp_parse_args($options, $defaults);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1110
	$options['width'] = (int) $options['width'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1111
	$options['height'] = (int) $options['height'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1112
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1113
	$widget = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1114
		'name' => $name,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1115
		'id' => $id,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1116
		'callback' => $form_callback,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1117
		'params' => array_slice(func_get_args(), 4)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1118
	);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1119
	$widget = array_merge($widget, $options);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1120
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1121
	$wp_registered_widget_controls[$id] = $widget;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1122
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1123
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1124
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1125
 * Remove control callback for widget.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1126
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1127
 * @since 2.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1128
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1129
 * @param int|string $id Widget ID.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1130
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1131
function wp_unregister_widget_control($id) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1132
	return wp_register_widget_control($id, '', '');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1133
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1134
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1135
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1136
 * Display dynamic sidebar.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1137
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1138
 * By default this displays the default sidebar or 'sidebar-1'. If your theme specifies the 'id' or
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1139
 * 'name' parameter for its registered sidebars you can pass an id or name as the $index parameter.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1140
 * Otherwise, you can pass in a numerical index to display the sidebar at that index.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1141
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1142
 * @since 2.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1143
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1144
 * @param int|string $index Optional, default is 1. Index, name or ID of dynamic sidebar.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1145
 * @return bool True, if widget sidebar was found and called. False if not found or not called.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1146
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1147
function dynamic_sidebar($index = 1) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1148
	global $wp_registered_sidebars, $wp_registered_widgets;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1149
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1150
	if ( is_int($index) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1151
		$index = "sidebar-$index";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1152
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1153
		$index = sanitize_title($index);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1154
		foreach ( (array) $wp_registered_sidebars as $key => $value ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1155
			if ( sanitize_title($value['name']) == $index ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1156
				$index = $key;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1157
				break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1158
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1159
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1160
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1161
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1162
	$sidebars_widgets = wp_get_sidebars_widgets();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1163
	if ( empty( $wp_registered_sidebars[ $index ] ) || empty( $sidebars_widgets[ $index ] ) || ! is_array( $sidebars_widgets[ $index ] ) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1164
		/** This action is documented in wp-includes/widgets.php */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1165
		do_action( 'dynamic_sidebar_before', $index, false );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1166
		/** This action is documented in wp-includes/widgets.php */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1167
		do_action( 'dynamic_sidebar_after',  $index, false );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1168
		/** This filter is documented in wp-includes/widgets.php */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1169
		return apply_filters( 'dynamic_sidebar_has_widgets', false, $index );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1170
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1171
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1172
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1173
	 * Fires before widgets are rendered in a dynamic sidebar.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1174
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1175
	 * Note: The action also fires for empty sidebars, and on both the front-end
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1176
	 * and back-end, including the Inactive Widgets sidebar on the Widgets screen.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1177
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1178
	 * @since 3.9.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1179
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1180
	 * @param int|string $index       Index, name, or ID of the dynamic sidebar.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1181
	 * @param bool       $has_widgets Whether the sidebar is populated with widgets.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1182
	 *                                Default true.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1183
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1184
	do_action( 'dynamic_sidebar_before', $index, true );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1185
	$sidebar = $wp_registered_sidebars[$index];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1186
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1187
	$did_one = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1188
	foreach ( (array) $sidebars_widgets[$index] as $id ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1189
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1190
		if ( !isset($wp_registered_widgets[$id]) ) continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1191
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1192
		$params = array_merge(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1193
			array( array_merge( $sidebar, array('widget_id' => $id, 'widget_name' => $wp_registered_widgets[$id]['name']) ) ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1194
			(array) $wp_registered_widgets[$id]['params']
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1195
		);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1196
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1197
		// Substitute HTML id and class attributes into before_widget
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1198
		$classname_ = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1199
		foreach ( (array) $wp_registered_widgets[$id]['classname'] as $cn ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1200
			if ( is_string($cn) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1201
				$classname_ .= '_' . $cn;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1202
			elseif ( is_object($cn) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1203
				$classname_ .= '_' . get_class($cn);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1204
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1205
		$classname_ = ltrim($classname_, '_');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1206
		$params[0]['before_widget'] = sprintf($params[0]['before_widget'], $id, $classname_);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1207
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1208
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1209
		 * Filter the parameters passed to a widget's display callback.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1210
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1211
		 * Note: The filter is evaluated on both the front-end and back-end,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1212
		 * including for the Inactive Widgets sidebar on the Widgets screen.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1213
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1214
		 * @since 2.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1215
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1216
		 * @see register_sidebar()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1217
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1218
		 * @param array $params {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1219
		 *     @type array $args  {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1220
		 *         An array of widget display arguments.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1221
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1222
		 *         @type string $name          Name of the sidebar the widget is assigned to.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1223
		 *         @type string $id            ID of the sidebar the widget is assigned to.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1224
		 *         @type string $description   The sidebar description.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1225
		 *         @type string $class         CSS class applied to the sidebar container.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1226
		 *         @type string $before_widget HTML markup to prepend to each widget in the sidebar.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1227
		 *         @type string $after_widget  HTML markup to append to each widget in the sidebar.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1228
		 *         @type string $before_title  HTML markup to prepend to the widget title when displayed.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1229
		 *         @type string $after_title   HTML markup to append to the widget title when displayed.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1230
		 *         @type string $widget_id     ID of the widget.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1231
		 *         @type string $widget_name   Name of the widget.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1232
		 *     }
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1233
		 *     @type array $widget_args {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1234
		 *         An array of multi-widget arguments.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1235
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1236
		 *         @type int $number Number increment used for multiples of the same widget.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1237
		 *     }
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1238
		 * }
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1239
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1240
		$params = apply_filters( 'dynamic_sidebar_params', $params );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1241
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1242
		$callback = $wp_registered_widgets[$id]['callback'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1243
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1244
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1245
		 * Fires before a widget's display callback is called.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1246
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1247
		 * Note: The action fires on both the front-end and back-end, including
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1248
		 * for widgets in the Inactive Widgets sidebar on the Widgets screen.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1249
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1250
		 * The action is not fired for empty sidebars.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1251
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1252
		 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1253
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1254
		 * @param array $widget_id {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1255
		 *     An associative array of widget arguments.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1256
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1257
		 *     @type string $name                Name of the widget.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1258
		 *     @type string $id                  Widget ID.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1259
		 *     @type array|callback $callback    When the hook is fired on the front-end, $callback is an array
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1260
		 *                                       containing the widget object. Fired on the back-end, $callback
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1261
		 *                                       is 'wp_widget_control', see $_callback.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1262
		 *     @type array          $params      An associative array of multi-widget arguments.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1263
		 *     @type string         $classname   CSS class applied to the widget container.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1264
		 *     @type string         $description The widget description.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1265
		 *     @type array          $_callback   When the hook is fired on the back-end, $_callback is populated
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1266
		 *                                       with an array containing the widget object, see $callback.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1267
		 * }
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1268
		 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1269
		do_action( 'dynamic_sidebar', $wp_registered_widgets[ $id ] );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1270
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1271
		if ( is_callable($callback) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1272
			call_user_func_array($callback, $params);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1273
			$did_one = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1274
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1275
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1276
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1277
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1278
	 * Fires after widgets are rendered in a dynamic sidebar.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1279
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1280
	 * Note: The action also fires for empty sidebars, and on both the front-end
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1281
	 * and back-end, including the Inactive Widgets sidebar on the Widgets screen.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1282
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1283
	 * @since 3.9.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1284
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1285
	 * @param int|string $index       Index, name, or ID of the dynamic sidebar.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1286
	 * @param bool       $has_widgets Whether the sidebar is populated with widgets.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1287
	 *                                Default true.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1288
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1289
	do_action( 'dynamic_sidebar_after', $index, true );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1290
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1291
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1292
	 * Filter whether a sidebar has widgets.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1293
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1294
	 * Note: The filter is also evaluated for empty sidebars, and on both the front-end
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1295
	 * and back-end, including the Inactive Widgets sidebar on the Widgets screen.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1296
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1297
	 * @since 3.9.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1298
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1299
	 * @param bool       $did_one Whether at least one widget was rendered in the sidebar.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1300
	 *                            Default false.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1301
	 * @param int|string $index   Index, name, or ID of the dynamic sidebar.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1302
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1303
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1304
	$did_one = apply_filters( 'dynamic_sidebar_has_widgets', $did_one, $index );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1305
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1306
	return $did_one;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1307
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1308
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1309
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1310
 * Whether widget is displayed on the front-end.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1311
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1312
 * Either $callback or $id_base can be used
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1313
 * $id_base is the first argument when extending WP_Widget class
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1314
 * Without the optional $widget_id parameter, returns the ID of the first sidebar
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1315
 * in which the first instance of the widget with the given callback or $id_base is found.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1316
 * With the $widget_id parameter, returns the ID of the sidebar where
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1317
 * the widget with that callback/$id_base AND that ID is found.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1318
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1319
 * NOTE: $widget_id and $id_base are the same for single widgets. To be effective
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1320
 * this function has to run after widgets have initialized, at action 'init' or later.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1321
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1322
 * @since 2.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1323
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1324
 * @param string $callback Optional, Widget callback to check.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1325
 * @param int $widget_id Optional, but needed for checking. Widget ID.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1326
 * @param string $id_base Optional, the base ID of a widget created by extending WP_Widget.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1327
 * @param bool $skip_inactive Optional, whether to check in 'wp_inactive_widgets'.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1328
 * @return mixed false if widget is not active or id of sidebar in which the widget is active.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1329
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1330
function is_active_widget($callback = false, $widget_id = false, $id_base = false, $skip_inactive = true) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1331
	global $wp_registered_widgets;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1332
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1333
	$sidebars_widgets = wp_get_sidebars_widgets();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1334
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1335
	if ( is_array($sidebars_widgets) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1336
		foreach ( $sidebars_widgets as $sidebar => $widgets ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1337
			if ( $skip_inactive && ( 'wp_inactive_widgets' === $sidebar || 'orphaned_widgets' === substr( $sidebar, 0, 16 ) ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1338
				continue;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1339
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1340
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1341
			if ( is_array($widgets) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1342
				foreach ( $widgets as $widget ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1343
					if ( ( $callback && isset($wp_registered_widgets[$widget]['callback']) && $wp_registered_widgets[$widget]['callback'] == $callback ) || ( $id_base && _get_widget_id_base($widget) == $id_base ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1344
						if ( !$widget_id || $widget_id == $wp_registered_widgets[$widget]['id'] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1345
							return $sidebar;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1346
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1347
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1348
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1349
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1350
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1351
	return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1352
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1353
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1354
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1355
 * Whether the dynamic sidebar is enabled and used by theme.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1356
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1357
 * @since 2.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1358
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1359
 * @return bool True, if using widgets. False, if not using widgets.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1360
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1361
function is_dynamic_sidebar() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1362
	global $wp_registered_widgets, $wp_registered_sidebars;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1363
	$sidebars_widgets = get_option('sidebars_widgets');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1364
	foreach ( (array) $wp_registered_sidebars as $index => $sidebar ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1365
		if ( count($sidebars_widgets[$index]) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1366
			foreach ( (array) $sidebars_widgets[$index] as $widget )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1367
				if ( array_key_exists($widget, $wp_registered_widgets) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1368
					return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1369
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1370
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1371
	return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1372
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1373
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1374
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1375
 * Whether a sidebar is in use.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1376
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1377
 * @since 2.8.0
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1378
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1379
 * @param string|int $index Sidebar name, id or number to check.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1380
 * @return bool true if the sidebar is in use, false otherwise.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1381
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1382
function is_active_sidebar( $index ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1383
	$index = ( is_int($index) ) ? "sidebar-$index" : sanitize_title($index);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1384
	$sidebars_widgets = wp_get_sidebars_widgets();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1385
	$is_active_sidebar = ! empty( $sidebars_widgets[$index] );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1386
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1387
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1388
	 * Filter whether a dynamic sidebar is considered "active".
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1389
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1390
	 * @since 3.9.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1391
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1392
	 * @param bool       $is_active_sidebar Whether or not the sidebar should be considered "active".
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1393
	 *                                      In other words, whether the sidebar contains any widgets.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1394
	 * @param int|string $index             Index, name, or ID of the dynamic sidebar.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1395
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1396
	return apply_filters( 'is_active_sidebar', $is_active_sidebar, $index );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1397
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1398
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1399
/* Internal Functions */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1400
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1401
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1402
 * Retrieve full list of sidebars and their widget instance IDs.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1403
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1404
 * Will upgrade sidebar widget list, if needed. Will also save updated list, if
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1405
 * needed.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1406
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1407
 * @since 2.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1408
 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1409
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1410
 * @param bool $deprecated Not used (argument deprecated).
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1411
 * @return array Upgraded list of widgets to version 3 array format when called from the admin.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1412
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1413
function wp_get_sidebars_widgets( $deprecated = true ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1414
	if ( $deprecated !== true )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1415
		_deprecated_argument( __FUNCTION__, '2.8.1' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1416
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1417
	global $_wp_sidebars_widgets, $sidebars_widgets;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1418
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1419
	// If loading from front page, consult $_wp_sidebars_widgets rather than options
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1420
	// to see if wp_convert_widget_settings() has made manipulations in memory.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1421
	if ( !is_admin() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1422
		if ( empty($_wp_sidebars_widgets) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1423
			$_wp_sidebars_widgets = get_option('sidebars_widgets', array());
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1424
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1425
		$sidebars_widgets = $_wp_sidebars_widgets;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1426
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1427
		$sidebars_widgets = get_option('sidebars_widgets', array());
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1428
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1429
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1430
	if ( is_array( $sidebars_widgets ) && isset($sidebars_widgets['array_version']) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1431
		unset($sidebars_widgets['array_version']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1432
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1433
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1434
	 * Filter the list of sidebars and their widgets.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1435
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1436
	 * @since 2.7.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1437
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1438
	 * @param array $sidebars_widgets An associative array of sidebars and their widgets.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1439
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1440
	$sidebars_widgets = apply_filters( 'sidebars_widgets', $sidebars_widgets );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1441
	return $sidebars_widgets;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1442
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1443
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1444
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1445
 * Set the sidebar widget option to update sidebars.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1446
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1447
 * @since 2.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1448
 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1449
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1450
 * @param array $sidebars_widgets Sidebar widgets and their settings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1451
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1452
function wp_set_sidebars_widgets( $sidebars_widgets ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1453
	if ( !isset( $sidebars_widgets['array_version'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1454
		$sidebars_widgets['array_version'] = 3;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1455
	update_option( 'sidebars_widgets', $sidebars_widgets );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1456
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1457
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1458
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1459
 * Retrieve default registered sidebars list.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1460
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1461
 * @since 2.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1462
 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1463
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1464
 * @return array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1465
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1466
function wp_get_widget_defaults() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1467
	global $wp_registered_sidebars;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1468
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1469
	$defaults = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1470
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1471
	foreach ( (array) $wp_registered_sidebars as $index => $sidebar )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1472
		$defaults[$index] = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1473
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1474
	return $defaults;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1475
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1476
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1477
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1478
 * Convert the widget settings from single to multi-widget format.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1479
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1480
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1481
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1482
 * @param string $base_name
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1483
 * @param string $option_name
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1484
 * @param array  $settings
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1485
 * @return array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1486
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1487
function wp_convert_widget_settings($base_name, $option_name, $settings) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1488
	// This test may need expanding.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1489
	$single = $changed = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1490
	if ( empty($settings) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1491
		$single = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1492
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1493
		foreach ( array_keys($settings) as $number ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1494
			if ( 'number' == $number )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1495
				continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1496
			if ( !is_numeric($number) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1497
				$single = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1498
				break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1499
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1500
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1501
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1502
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1503
	if ( $single ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1504
		$settings = array( 2 => $settings );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1505
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1506
		// If loading from the front page, update sidebar in memory but don't save to options
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1507
		if ( is_admin() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1508
			$sidebars_widgets = get_option('sidebars_widgets');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1509
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1510
			if ( empty($GLOBALS['_wp_sidebars_widgets']) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1511
				$GLOBALS['_wp_sidebars_widgets'] = get_option('sidebars_widgets', array());
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1512
			$sidebars_widgets = &$GLOBALS['_wp_sidebars_widgets'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1513
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1514
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1515
		foreach ( (array) $sidebars_widgets as $index => $sidebar ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1516
			if ( is_array($sidebar) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1517
				foreach ( $sidebar as $i => $name ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1518
					if ( $base_name == $name ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1519
						$sidebars_widgets[$index][$i] = "$name-2";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1520
						$changed = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1521
						break 2;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1522
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1523
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1524
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1525
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1526
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1527
		if ( is_admin() && $changed )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1528
			update_option('sidebars_widgets', $sidebars_widgets);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1529
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1530
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1531
	$settings['_multiwidget'] = 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1532
	if ( is_admin() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1533
		update_option( $option_name, $settings );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1534
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1535
	return $settings;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1536
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1537
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1538
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1539
 * Output an arbitrary widget as a template tag.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1540
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1541
 * @since 2.8.0
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1542
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1543
 * @param string $widget   The widget's PHP class name (see default-widgets.php).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1544
 * @param array  $instance Optional. The widget's instance settings. Default empty array.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1545
 * @param array  $args {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1546
 *     Optional. Array of arguments to configure the display of the widget.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1547
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1548
 *     @type string $before_widget HTML content that will be prepended to the widget's HTML output.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1549
 *                                 Default `<div class="widget %s">`, where `%s` is the widget's class name.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1550
 *     @type string $after_widget  HTML content that will be appended to the widget's HTML output.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1551
 *                                 Default `</div>`.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1552
 *     @type string $before_title  HTML content that will be prepended to the widget's title when displayed.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1553
 *                                 Default `<h2 class="widgettitle">`.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1554
 *     @type string $after_title   HTML content that will be appended to the widget's title when displayed.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1555
 *                                 Default `</h2>`.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1556
 * }
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1557
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1558
function the_widget( $widget, $instance = array(), $args = array() ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1559
	global $wp_widget_factory;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1560
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1561
	$widget_obj = $wp_widget_factory->widgets[$widget];
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1562
	if ( ! ( $widget_obj instanceof WP_Widget ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1563
		return;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1564
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1565
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1566
	$before_widget = sprintf('<div class="widget %s">', $widget_obj->widget_options['classname'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1567
	$default_args = array( 'before_widget' => $before_widget, 'after_widget' => "</div>", 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1568
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1569
	$args = wp_parse_args($args, $default_args);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1570
	$instance = wp_parse_args($instance);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1571
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1572
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1573
	 * Fires before rendering the requested widget.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1574
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1575
	 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1576
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1577
	 * @param string $widget   The widget's class name.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1578
	 * @param array  $instance The current widget instance's settings.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1579
	 * @param array  $args     An array of the widget's sidebar arguments.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1580
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1581
	do_action( 'the_widget', $widget, $instance, $args );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1582
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1583
	$widget_obj->_set(-1);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1584
	$widget_obj->widget($args, $instance);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1585
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1586
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1587
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1588
 * Private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1589
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1590
function _get_widget_id_base($id) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1591
	return preg_replace( '/-[0-9]+$/', '', $id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1592
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1593
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1594
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1595
 * Handle sidebars config after theme change
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1596
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1597
 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1598
 * @since 3.3.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1599
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1600
function _wp_sidebars_changed() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1601
	global $sidebars_widgets;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1602
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1603
	if ( ! is_array( $sidebars_widgets ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1604
		$sidebars_widgets = wp_get_sidebars_widgets();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1605
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1606
	retrieve_widgets(true);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1607
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1608
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1609
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1610
 * Look for "lost" widgets, this has to run at least on each theme change.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1611
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1612
 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1613
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1614
 * @param string|bool $theme_changed Whether the theme was changed as a boolean. A value
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1615
 *                                   of 'customize' defers updates for the Customizer.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1616
 * @return array
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1617
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1618
function retrieve_widgets( $theme_changed = false ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1619
	global $wp_registered_sidebars, $sidebars_widgets, $wp_registered_widgets;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1620
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1621
	$registered_sidebar_keys = array_keys( $wp_registered_sidebars );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1622
	$orphaned = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1623
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1624
	$old_sidebars_widgets = get_theme_mod( 'sidebars_widgets' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1625
	if ( is_array( $old_sidebars_widgets ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1626
		// time() that sidebars were stored is in $old_sidebars_widgets['time']
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1627
		$_sidebars_widgets = $old_sidebars_widgets['data'];
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1628
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1629
		if ( 'customize' !== $theme_changed ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1630
			remove_theme_mod( 'sidebars_widgets' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1631
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1632
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1633
		foreach ( $_sidebars_widgets as $sidebar => $widgets ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1634
			if ( 'wp_inactive_widgets' === $sidebar || 'orphaned_widgets' === substr( $sidebar, 0, 16 ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1635
				continue;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1636
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1637
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1638
			if ( !in_array( $sidebar, $registered_sidebar_keys ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1639
				$_sidebars_widgets['orphaned_widgets_' . ++$orphaned] = $widgets;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1640
				unset( $_sidebars_widgets[$sidebar] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1641
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1642
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1643
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1644
		if ( empty( $sidebars_widgets ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1645
			return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1646
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1647
		unset( $sidebars_widgets['array_version'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1648
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1649
		$old = array_keys($sidebars_widgets);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1650
		sort($old);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1651
		sort($registered_sidebar_keys);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1652
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1653
		if ( $old == $registered_sidebar_keys )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1654
			return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1655
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1656
		$_sidebars_widgets = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1657
			'wp_inactive_widgets' => !empty( $sidebars_widgets['wp_inactive_widgets'] ) ? $sidebars_widgets['wp_inactive_widgets'] : array()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1658
		);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1659
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1660
		unset( $sidebars_widgets['wp_inactive_widgets'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1661
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1662
		foreach ( $wp_registered_sidebars as $id => $settings ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1663
			if ( $theme_changed ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1664
				$_sidebars_widgets[$id] = array_shift( $sidebars_widgets );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1665
			} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1666
				// no theme change, grab only sidebars that are currently registered
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1667
				if ( isset( $sidebars_widgets[$id] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1668
					$_sidebars_widgets[$id] = $sidebars_widgets[$id];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1669
					unset( $sidebars_widgets[$id] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1670
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1671
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1672
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1673
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1674
		foreach ( $sidebars_widgets as $val ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1675
			if ( is_array($val) && ! empty( $val ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1676
				$_sidebars_widgets['orphaned_widgets_' . ++$orphaned] = $val;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1677
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1678
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1679
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1680
	// discard invalid, theme-specific widgets from sidebars
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1681
	$shown_widgets = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1682
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1683
	foreach ( $_sidebars_widgets as $sidebar => $widgets ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1684
		if ( !is_array($widgets) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1685
			continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1686
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1687
		$_widgets = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1688
		foreach ( $widgets as $widget ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1689
			if ( isset($wp_registered_widgets[$widget]) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1690
				$_widgets[] = $widget;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1691
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1692
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1693
		$_sidebars_widgets[$sidebar] = $_widgets;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1694
		$shown_widgets = array_merge($shown_widgets, $_widgets);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1695
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1696
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1697
	$sidebars_widgets = $_sidebars_widgets;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1698
	unset($_sidebars_widgets, $_widgets);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1699
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1700
	// find hidden/lost multi-widget instances
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1701
	$lost_widgets = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1702
	foreach ( $wp_registered_widgets as $key => $val ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1703
		if ( in_array($key, $shown_widgets, true) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1704
			continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1705
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1706
		$number = preg_replace('/.+?-([0-9]+)$/', '$1', $key);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1707
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1708
		if ( 2 > (int) $number )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1709
			continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1710
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1711
		$lost_widgets[] = $key;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1712
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1713
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1714
	$sidebars_widgets['wp_inactive_widgets'] = array_merge($lost_widgets, (array) $sidebars_widgets['wp_inactive_widgets']);
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1715
	if ( 'customize' !== $theme_changed ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1716
		wp_set_sidebars_widgets( $sidebars_widgets );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1717
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1718
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1719
	return $sidebars_widgets;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1720
}