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