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-- |
0 | 1 |
<?php |
2 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3 |
* Core Widgets API |
0 | 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 | 11 |
* included it in the core from that point on. |
12 |
* |
|
5 | 13 |
* @link https://codex.wordpress.org/Plugins/WordPress_Widgets WordPress Widgets |
14 |
* @link https://codex.wordpress.org/Plugins/WordPress_Widgets_Api Widgets API |
|
0 | 15 |
* |
16 |
* @package WordPress |
|
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 | 19 |
*/ |
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 | 24 |
|
25 |
/** @ignore */ |
|
26 |
global $wp_registered_sidebars, $wp_registered_widgets, $wp_registered_widget_controls, $wp_registered_widget_updates; |
|
27 |
||
28 |
/** |
|
29 |
* Stores the sidebars, since many themes can have more than one. |
|
30 |
* |
|
31 |
* @global array $wp_registered_sidebars |
|
32 |
* @since 2.2.0 |
|
33 |
*/ |
|
34 |
$wp_registered_sidebars = array(); |
|
35 |
||
36 |
/** |
|
37 |
* Stores the registered widgets. |
|
38 |
* |
|
39 |
* @global array $wp_registered_widgets |
|
40 |
* @since 2.2.0 |
|
41 |
*/ |
|
42 |
$wp_registered_widgets = array(); |
|
43 |
||
44 |
/** |
|
45 |
* Stores the registered widget control (options). |
|
46 |
* |
|
47 |
* @global array $wp_registered_widget_controls |
|
48 |
* @since 2.2.0 |
|
49 |
*/ |
|
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 | 54 |
$wp_registered_widget_updates = array(); |
55 |
||
56 |
/** |
|
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 | 60 |
*/ |
61 |
$_wp_sidebars_widgets = array(); |
|
62 |
||
63 |
/** |
|
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 | 67 |
*/ |
5 | 68 |
$GLOBALS['_wp_deprecated_widgets_callbacks'] = array( |
69 |
'wp_widget_pages', |
|
0 | 70 |
'wp_widget_pages_control', |
71 |
'wp_widget_calendar', |
|
72 |
'wp_widget_calendar_control', |
|
73 |
'wp_widget_archives', |
|
74 |
'wp_widget_archives_control', |
|
75 |
'wp_widget_links', |
|
76 |
'wp_widget_meta', |
|
77 |
'wp_widget_meta_control', |
|
78 |
'wp_widget_search', |
|
79 |
'wp_widget_recent_entries', |
|
80 |
'wp_widget_recent_entries_control', |
|
81 |
'wp_widget_tag_cloud', |
|
82 |
'wp_widget_tag_cloud_control', |
|
83 |
'wp_widget_categories', |
|
84 |
'wp_widget_categories_control', |
|
85 |
'wp_widget_text', |
|
86 |
'wp_widget_text_control', |
|
87 |
'wp_widget_rss', |
|
88 |
'wp_widget_rss_control', |
|
89 |
'wp_widget_recent_comments', |
|
90 |
'wp_widget_recent_comments_control' |
|
5 | 91 |
); |
0 | 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 | 96 |
|
97 |
/** |
|
98 |
* Register a widget |
|
99 |
* |
|
100 |
* Registers a WP_Widget widget |
|
101 |
* |
|
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 | 105 |
* |
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 | 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 | 111 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
112 |
function register_widget( $widget ) { |
0 | 113 |
global $wp_widget_factory; |
114 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
115 |
$wp_widget_factory->register( $widget ); |
0 | 116 |
} |
117 |
||
118 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
119 |
* Unregisters a widget. |
0 | 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 | 123 |
* |
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 | 127 |
* |
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 | 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 | 133 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
134 |
function unregister_widget( $widget ) { |
0 | 135 |
global $wp_widget_factory; |
136 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
137 |
$wp_widget_factory->unregister( $widget ); |
0 | 138 |
} |
139 |
||
140 |
/** |
|
141 |
* Creates multiple sidebars. |
|
142 |
* |
|
143 |
* If you wanted to quickly create multiple sidebars for a theme or internally. |
|
144 |
* This function will allow you to do so. If you don't pass the 'name' and/or |
|
5 | 145 |
* 'id' in `$args`, then they will be built for you. |
0 | 146 |
* |
147 |
* @since 2.2.0 |
|
148 |
* |
|
149 |
* @see register_sidebar() The second parameter is documented by register_sidebar() and is the same here. |
|
5 | 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 | 153 |
* @param int $number Optional. Number of sidebars to create. Default 1. |
154 |
* @param array|string $args { |
|
155 |
* Optional. Array or string of arguments for building a sidebar. |
|
0 | 156 |
* |
5 | 157 |
* @type string $id The base string of the unique identifier for each sidebar. If provided, and multiple |
158 |
* sidebars are being defined, the id will have "-2" appended, and so on. |
|
159 |
* Default 'sidebar-' followed by the number the sidebar creation is currently at. |
|
160 |
* @type string $name The name or title for the sidebars displayed in the admin dashboard. If registering |
|
161 |
* more than one sidebar, include '%d' in the string as a placeholder for the uniquely |
|
162 |
* assigned number for each sidebar. |
|
163 |
* Default 'Sidebar' for the first sidebar, otherwise 'Sidebar %d'. |
|
164 |
* } |
|
0 | 165 |
*/ |
5 | 166 |
function register_sidebars( $number = 1, $args = array() ) { |
0 | 167 |
global $wp_registered_sidebars; |
168 |
$number = (int) $number; |
|
169 |
||
170 |
if ( is_string($args) ) |
|
171 |
parse_str($args, $args); |
|
172 |
||
173 |
for ( $i = 1; $i <= $number; $i++ ) { |
|
174 |
$_args = $args; |
|
175 |
||
176 |
if ( $number > 1 ) |
|
177 |
$_args['name'] = isset($args['name']) ? sprintf($args['name'], $i) : sprintf(__('Sidebar %d'), $i); |
|
178 |
else |
|
179 |
$_args['name'] = isset($args['name']) ? $args['name'] : __('Sidebar'); |
|
180 |
||
181 |
// Custom specified ID's are suffixed if they exist already. |
|
182 |
// Automatically generated sidebar names need to be suffixed regardless starting at -0 |
|
183 |
if ( isset($args['id']) ) { |
|
184 |
$_args['id'] = $args['id']; |
|
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 | 187 |
$_args['id'] = $args['id'] . '-' . $n++; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
188 |
} |
0 | 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 | 191 |
do { |
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 | 194 |
} |
195 |
register_sidebar($_args); |
|
196 |
} |
|
197 |
} |
|
198 |
||
199 |
/** |
|
200 |
* Builds the definition for a single sidebar and returns the ID. |
|
201 |
* |
|
202 |
* Accepts either a string or an array and then parses that against a set |
|
203 |
* of default arguments for the new sidebar. WordPress will automatically |
|
204 |
* generate a sidebar ID and name based on the current number of registered |
|
205 |
* sidebars if those arguments are not included. |
|
206 |
* |
|
207 |
* When allowing for automatic generation of the name and ID parameters, keep |
|
208 |
* in mind that the incrementor for your sidebar can change over time depending |
|
209 |
* on what other plugins and themes are installed. |
|
210 |
* |
|
211 |
* If theme support for 'widgets' has not yet been added when this function is |
|
212 |
* called, it will be automatically enabled through the use of add_theme_support() |
|
213 |
* |
|
5 | 214 |
* @since 2.2.0 |
0 | 215 |
* |
5 | 216 |
* @global array $wp_registered_sidebars Stores the new sidebar in this array by sidebar ID. |
0 | 217 |
* |
5 | 218 |
* @param array|string $args { |
219 |
* Optional. Array or string of arguments for the sidebar being registered. |
|
0 | 220 |
* |
5 | 221 |
* @type string $name The name or title of the sidebar displayed in the Widgets |
222 |
* interface. Default 'Sidebar $instance'. |
|
223 |
* @type string $id The unique identifier by which the sidebar will be called. |
|
224 |
* Default 'sidebar-$instance'. |
|
225 |
* @type string $description Description of the sidebar, displayed in the Widgets interface. |
|
226 |
* Default empty string. |
|
227 |
* @type string $class Extra CSS class to assign to the sidebar in the Widgets interface. |
|
228 |
* Default empty. |
|
229 |
* @type string $before_widget HTML content to prepend to each widget's HTML output when |
|
230 |
* assigned to this sidebar. Default is an opening list item element. |
|
231 |
* @type string $after_widget HTML content to append to each widget's HTML output when |
|
232 |
* assigned to this sidebar. Default is a closing list item element. |
|
233 |
* @type string $before_title HTML content to prepend to the sidebar title when displayed. |
|
234 |
* Default is an opening h2 element. |
|
235 |
* @type string $after_title HTML content to append to the sidebar title when displayed. |
|
236 |
* Default is a closing h2 element. |
|
237 |
* } |
|
0 | 238 |
* @return string Sidebar ID added to $wp_registered_sidebars global. |
239 |
*/ |
|
240 |
function register_sidebar($args = array()) { |
|
241 |
global $wp_registered_sidebars; |
|
242 |
||
243 |
$i = count($wp_registered_sidebars) + 1; |
|
244 |
||
5 | 245 |
$id_is_empty = empty( $args['id'] ); |
246 |
||
0 | 247 |
$defaults = array( |
248 |
'name' => sprintf(__('Sidebar %d'), $i ), |
|
249 |
'id' => "sidebar-$i", |
|
250 |
'description' => '', |
|
251 |
'class' => '', |
|
252 |
'before_widget' => '<li id="%1$s" class="widget %2$s">', |
|
253 |
'after_widget' => "</li>\n", |
|
254 |
'before_title' => '<h2 class="widgettitle">', |
|
255 |
'after_title' => "</h2>\n", |
|
256 |
); |
|
257 |
||
258 |
$sidebar = wp_parse_args( $args, $defaults ); |
|
259 |
||
5 | 260 |
if ( $id_is_empty ) { |
261 |
/* translators: 1: the id argument, 2: sidebar name, 3: recommended id value */ |
|
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' ); |
|
263 |
} |
|
264 |
||
0 | 265 |
$wp_registered_sidebars[$sidebar['id']] = $sidebar; |
266 |
||
267 |
add_theme_support('widgets'); |
|
268 |
||
5 | 269 |
/** |
270 |
* Fires once a sidebar has been registered. |
|
271 |
* |
|
272 |
* @since 3.0.0 |
|
273 |
* |
|
274 |
* @param array $sidebar Parsed arguments for the registered sidebar. |
|
275 |
*/ |
|
0 | 276 |
do_action( 'register_sidebar', $sidebar ); |
277 |
||
278 |
return $sidebar['id']; |
|
279 |
} |
|
280 |
||
281 |
/** |
|
282 |
* Removes a sidebar from the list. |
|
283 |
* |
|
284 |
* @since 2.2.0 |
|
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 | 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 | 289 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
290 |
function unregister_sidebar( $sidebar_id ) { |
0 | 291 |
global $wp_registered_sidebars; |
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 | 310 |
} |
311 |
||
312 |
/** |
|
5 | 313 |
* Register an instance of a widget. |
0 | 314 |
* |
5 | 315 |
* The default widget option is 'classname' that can be overridden. |
0 | 316 |
* |
5 | 317 |
* The function can also be used to un-register widgets when `$output_callback` |
0 | 318 |
* parameter is an empty string. |
319 |
* |
|
320 |
* @since 2.2.0 |
|
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 | 326 |
* |
327 |
* @param int|string $id Widget ID. |
|
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 | 330 |
* @param array $options { |
331 |
* Optional. An array of supplementary widget options for the instance. |
|
0 | 332 |
* |
5 | 333 |
* @type string $classname Class name for the widget's HTML container. Default is a shortened |
334 |
* version of the output callback name. |
|
335 |
* @type string $description Widget description for display in the widget administration |
|
336 |
* panel and/or theme. |
|
337 |
* } |
|
0 | 338 |
*/ |
5 | 339 |
function wp_register_sidebar_widget( $id, $name, $output_callback, $options = array() ) { |
0 | 340 |
global $wp_registered_widgets, $wp_registered_widget_controls, $wp_registered_widget_updates, $_wp_deprecated_widgets_callbacks; |
341 |
||
342 |
$id = strtolower($id); |
|
343 |
||
344 |
if ( empty($output_callback) ) { |
|
345 |
unset($wp_registered_widgets[$id]); |
|
346 |
return; |
|
347 |
} |
|
348 |
||
349 |
$id_base = _get_widget_id_base($id); |
|
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 | 353 |
return; |
354 |
} |
|
355 |
||
356 |
$defaults = array('classname' => $output_callback); |
|
357 |
$options = wp_parse_args($options, $defaults); |
|
358 |
$widget = array( |
|
359 |
'name' => $name, |
|
360 |
'id' => $id, |
|
361 |
'callback' => $output_callback, |
|
362 |
'params' => array_slice(func_get_args(), 4) |
|
363 |
); |
|
364 |
$widget = array_merge($widget, $options); |
|
365 |
||
366 |
if ( is_callable($output_callback) && ( !isset($wp_registered_widgets[$id]) || did_action( 'widgets_init' ) ) ) { |
|
5 | 367 |
|
368 |
/** |
|
369 |
* Fires once for each registered widget. |
|
370 |
* |
|
371 |
* @since 3.0.0 |
|
372 |
* |
|
373 |
* @param array $widget An array of default widget arguments. |
|
374 |
*/ |
|
0 | 375 |
do_action( 'wp_register_sidebar_widget', $widget ); |
376 |
$wp_registered_widgets[$id] = $widget; |
|
377 |
} |
|
378 |
} |
|
379 |
||
380 |
/** |
|
381 |
* Retrieve description for widget. |
|
382 |
* |
|
383 |
* When registering widgets, the options can also include 'description' that |
|
384 |
* describes the widget for display on the widget administration panel or |
|
385 |
* in the theme. |
|
386 |
* |
|
387 |
* @since 2.5.0 |
|
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 | 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 | 393 |
*/ |
394 |
function wp_widget_description( $id ) { |
|
395 |
if ( !is_scalar($id) ) |
|
396 |
return; |
|
397 |
||
398 |
global $wp_registered_widgets; |
|
399 |
||
400 |
if ( isset($wp_registered_widgets[$id]['description']) ) |
|
401 |
return esc_html( $wp_registered_widgets[$id]['description'] ); |
|
402 |
} |
|
403 |
||
404 |
/** |
|
405 |
* Retrieve description for a sidebar. |
|
406 |
* |
|
407 |
* When registering sidebars a 'description' parameter can be included that |
|
408 |
* describes the sidebar for display on the widget administration panel. |
|
409 |
* |
|
410 |
* @since 2.9.0 |
|
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 | 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 | 416 |
*/ |
417 |
function wp_sidebar_description( $id ) { |
|
418 |
if ( !is_scalar($id) ) |
|
419 |
return; |
|
420 |
||
421 |
global $wp_registered_sidebars; |
|
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 | 426 |
} |
427 |
||
428 |
/** |
|
429 |
* Remove widget from sidebar. |
|
430 |
* |
|
431 |
* @since 2.2.0 |
|
432 |
* |
|
433 |
* @param int|string $id Widget ID. |
|
434 |
*/ |
|
435 |
function wp_unregister_sidebar_widget($id) { |
|
5 | 436 |
|
437 |
/** |
|
438 |
* Fires just before a widget is removed from a sidebar. |
|
439 |
* |
|
440 |
* @since 3.0.0 |
|
441 |
* |
|
442 |
* @param int $id The widget ID. |
|
443 |
*/ |
|
0 | 444 |
do_action( 'wp_unregister_sidebar_widget', $id ); |
445 |
||
446 |
wp_register_sidebar_widget($id, '', ''); |
|
447 |
wp_unregister_widget_control($id); |
|
448 |
} |
|
449 |
||
450 |
/** |
|
451 |
* Registers widget control callback for customizing options. |
|
452 |
* |
|
453 |
* @since 2.2.0 |
|
454 |
* |
|
5 | 455 |
* @todo `$params` parameter? |
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 | 462 |
* @param int|string $id Sidebar ID. |
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 | 474 |
*/ |
5 | 475 |
function wp_register_widget_control( $id, $name, $control_callback, $options = array() ) { |
0 | 476 |
global $wp_registered_widget_controls, $wp_registered_widget_updates, $wp_registered_widgets, $_wp_deprecated_widgets_callbacks; |
477 |
||
478 |
$id = strtolower($id); |
|
479 |
$id_base = _get_widget_id_base($id); |
|
480 |
||
481 |
if ( empty($control_callback) ) { |
|
482 |
unset($wp_registered_widget_controls[$id]); |
|
483 |
unset($wp_registered_widget_updates[$id_base]); |
|
484 |
return; |
|
485 |
} |
|
486 |
||
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 | 489 |
return; |
490 |
} |
|
491 |
||
492 |
if ( isset($wp_registered_widget_controls[$id]) && !did_action( 'widgets_init' ) ) |
|
493 |
return; |
|
494 |
||
495 |
$defaults = array('width' => 250, 'height' => 200 ); // height is never used |
|
496 |
$options = wp_parse_args($options, $defaults); |
|
497 |
$options['width'] = (int) $options['width']; |
|
498 |
$options['height'] = (int) $options['height']; |
|
499 |
||
500 |
$widget = array( |
|
501 |
'name' => $name, |
|
502 |
'id' => $id, |
|
503 |
'callback' => $control_callback, |
|
504 |
'params' => array_slice(func_get_args(), 4) |
|
505 |
); |
|
506 |
$widget = array_merge($widget, $options); |
|
507 |
||
508 |
$wp_registered_widget_controls[$id] = $widget; |
|
509 |
||
510 |
if ( isset($wp_registered_widget_updates[$id_base]) ) |
|
511 |
return; |
|
512 |
||
513 |
if ( isset($widget['params'][0]['number']) ) |
|
514 |
$widget['params'][0]['number'] = -1; |
|
515 |
||
516 |
unset($widget['width'], $widget['height'], $widget['name'], $widget['id']); |
|
517 |
$wp_registered_widget_updates[$id_base] = $widget; |
|
518 |
} |
|
519 |
||
5 | 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 | 524 |
* |
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 | 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 | 533 |
global $wp_registered_widget_updates; |
534 |
||
535 |
if ( isset($wp_registered_widget_updates[$id_base]) ) { |
|
536 |
if ( empty($update_callback) ) |
|
537 |
unset($wp_registered_widget_updates[$id_base]); |
|
538 |
return; |
|
539 |
} |
|
540 |
||
541 |
$widget = array( |
|
542 |
'callback' => $update_callback, |
|
543 |
'params' => array_slice(func_get_args(), 3) |
|
544 |
); |
|
545 |
||
546 |
$widget = array_merge($widget, $options); |
|
547 |
$wp_registered_widget_updates[$id_base] = $widget; |
|
548 |
} |
|
549 |
||
5 | 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 | 554 |
* |
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 | 562 |
*/ |
0 | 563 |
function _register_widget_form_callback($id, $name, $form_callback, $options = array()) { |
564 |
global $wp_registered_widget_controls; |
|
565 |
||
566 |
$id = strtolower($id); |
|
567 |
||
568 |
if ( empty($form_callback) ) { |
|
569 |
unset($wp_registered_widget_controls[$id]); |
|
570 |
return; |
|
571 |
} |
|
572 |
||
573 |
if ( isset($wp_registered_widget_controls[$id]) && !did_action( 'widgets_init' ) ) |
|
574 |
return; |
|
575 |
||
576 |
$defaults = array('width' => 250, 'height' => 200 ); |
|
577 |
$options = wp_parse_args($options, $defaults); |
|
578 |
$options['width'] = (int) $options['width']; |
|
579 |
$options['height'] = (int) $options['height']; |
|
580 |
||
581 |
$widget = array( |
|
582 |
'name' => $name, |
|
583 |
'id' => $id, |
|
584 |
'callback' => $form_callback, |
|
585 |
'params' => array_slice(func_get_args(), 4) |
|
586 |
); |
|
587 |
$widget = array_merge($widget, $options); |
|
588 |
||
589 |
$wp_registered_widget_controls[$id] = $widget; |
|
590 |
} |
|
591 |
||
592 |
/** |
|
593 |
* Remove control callback for widget. |
|
594 |
* |
|
595 |
* @since 2.2.0 |
|
596 |
* |
|
597 |
* @param int|string $id Widget ID. |
|
598 |
*/ |
|
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 | 601 |
} |
602 |
||
603 |
/** |
|
604 |
* Display dynamic sidebar. |
|
605 |
* |
|
606 |
* By default this displays the default sidebar or 'sidebar-1'. If your theme specifies the 'id' or |
|
607 |
* 'name' parameter for its registered sidebars you can pass an id or name as the $index parameter. |
|
608 |
* Otherwise, you can pass in a numerical index to display the sidebar at that index. |
|
609 |
* |
|
610 |
* @since 2.2.0 |
|
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 | 615 |
* @param int|string $index Optional, default is 1. Index, name or ID of dynamic sidebar. |
616 |
* @return bool True, if widget sidebar was found and called. False if not found or not called. |
|
617 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
618 |
function dynamic_sidebar( $index = 1 ) { |
0 | 619 |
global $wp_registered_sidebars, $wp_registered_widgets; |
620 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
621 |
if ( is_int( $index ) ) { |
0 | 622 |
$index = "sidebar-$index"; |
623 |
} else { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
624 |
$index = sanitize_title( $index ); |
0 | 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 | 627 |
$index = $key; |
628 |
break; |
|
629 |
} |
|
630 |
} |
|
631 |
} |
|
632 |
||
633 |
$sidebars_widgets = wp_get_sidebars_widgets(); |
|
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 | 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 | 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 | 640 |
return apply_filters( 'dynamic_sidebar_has_widgets', false, $index ); |
0 | 641 |
} |
642 |
||
5 | 643 |
/** |
644 |
* Fires before widgets are rendered in a dynamic sidebar. |
|
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 | 648 |
* |
649 |
* @since 3.9.0 |
|
650 |
* |
|
651 |
* @param int|string $index Index, name, or ID of the dynamic sidebar. |
|
652 |
* @param bool $has_widgets Whether the sidebar is populated with widgets. |
|
653 |
* Default true. |
|
654 |
*/ |
|
655 |
do_action( 'dynamic_sidebar_before', $index, true ); |
|
0 | 656 |
$sidebar = $wp_registered_sidebars[$index]; |
657 |
||
658 |
$did_one = false; |
|
659 |
foreach ( (array) $sidebars_widgets[$index] as $id ) { |
|
660 |
||
661 |
if ( !isset($wp_registered_widgets[$id]) ) continue; |
|
662 |
||
663 |
$params = array_merge( |
|
664 |
array( array_merge( $sidebar, array('widget_id' => $id, 'widget_name' => $wp_registered_widgets[$id]['name']) ) ), |
|
665 |
(array) $wp_registered_widgets[$id]['params'] |
|
666 |
); |
|
667 |
||
668 |
// Substitute HTML id and class attributes into before_widget |
|
669 |
$classname_ = ''; |
|
670 |
foreach ( (array) $wp_registered_widgets[$id]['classname'] as $cn ) { |
|
671 |
if ( is_string($cn) ) |
|
672 |
$classname_ .= '_' . $cn; |
|
673 |
elseif ( is_object($cn) ) |
|
674 |
$classname_ .= '_' . get_class($cn); |
|
675 |
} |
|
676 |
$classname_ = ltrim($classname_, '_'); |
|
677 |
$params[0]['before_widget'] = sprintf($params[0]['before_widget'], $id, $classname_); |
|
678 |
||
5 | 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 | 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 | 683 |
* including for the Inactive Widgets sidebar on the Widgets screen. |
684 |
* |
|
685 |
* @since 2.5.0 |
|
686 |
* |
|
687 |
* @see register_sidebar() |
|
688 |
* |
|
689 |
* @param array $params { |
|
690 |
* @type array $args { |
|
691 |
* An array of widget display arguments. |
|
692 |
* |
|
693 |
* @type string $name Name of the sidebar the widget is assigned to. |
|
694 |
* @type string $id ID of the sidebar the widget is assigned to. |
|
695 |
* @type string $description The sidebar description. |
|
696 |
* @type string $class CSS class applied to the sidebar container. |
|
697 |
* @type string $before_widget HTML markup to prepend to each widget in the sidebar. |
|
698 |
* @type string $after_widget HTML markup to append to each widget in the sidebar. |
|
699 |
* @type string $before_title HTML markup to prepend to the widget title when displayed. |
|
700 |
* @type string $after_title HTML markup to append to the widget title when displayed. |
|
701 |
* @type string $widget_id ID of the widget. |
|
702 |
* @type string $widget_name Name of the widget. |
|
703 |
* } |
|
704 |
* @type array $widget_args { |
|
705 |
* An array of multi-widget arguments. |
|
706 |
* |
|
707 |
* @type int $number Number increment used for multiples of the same widget. |
|
708 |
* } |
|
709 |
* } |
|
710 |
*/ |
|
0 | 711 |
$params = apply_filters( 'dynamic_sidebar_params', $params ); |
712 |
||
713 |
$callback = $wp_registered_widgets[$id]['callback']; |
|
714 |
||
5 | 715 |
/** |
716 |
* Fires before a widget's display callback is called. |
|
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 | 719 |
* for widgets in the Inactive Widgets sidebar on the Widgets screen. |
720 |
* |
|
721 |
* The action is not fired for empty sidebars. |
|
722 |
* |
|
723 |
* @since 3.0.0 |
|
724 |
* |
|
725 |
* @param array $widget_id { |
|
726 |
* An associative array of widget arguments. |
|
727 |
* |
|
728 |
* @type string $name Name of the widget. |
|
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 | 732 |
* is 'wp_widget_control', see $_callback. |
733 |
* @type array $params An associative array of multi-widget arguments. |
|
734 |
* @type string $classname CSS class applied to the widget container. |
|
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 | 737 |
* with an array containing the widget object, see $callback. |
738 |
* } |
|
739 |
*/ |
|
740 |
do_action( 'dynamic_sidebar', $wp_registered_widgets[ $id ] ); |
|
0 | 741 |
|
742 |
if ( is_callable($callback) ) { |
|
743 |
call_user_func_array($callback, $params); |
|
744 |
$did_one = true; |
|
745 |
} |
|
746 |
} |
|
747 |
||
5 | 748 |
/** |
749 |
* Fires after widgets are rendered in a dynamic sidebar. |
|
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 | 753 |
* |
754 |
* @since 3.9.0 |
|
755 |
* |
|
756 |
* @param int|string $index Index, name, or ID of the dynamic sidebar. |
|
757 |
* @param bool $has_widgets Whether the sidebar is populated with widgets. |
|
758 |
* Default true. |
|
759 |
*/ |
|
760 |
do_action( 'dynamic_sidebar_after', $index, true ); |
|
761 |
||
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 | 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 | 767 |
* |
768 |
* @since 3.9.0 |
|
769 |
* |
|
770 |
* @param bool $did_one Whether at least one widget was rendered in the sidebar. |
|
771 |
* Default false. |
|
772 |
* @param int|string $index Index, name, or ID of the dynamic sidebar. |
|
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 | 775 |
} |
776 |
||
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 | 779 |
* |
780 |
* Either $callback or $id_base can be used |
|
781 |
* $id_base is the first argument when extending WP_Widget class |
|
782 |
* Without the optional $widget_id parameter, returns the ID of the first sidebar |
|
783 |
* in which the first instance of the widget with the given callback or $id_base is found. |
|
784 |
* With the $widget_id parameter, returns the ID of the sidebar where |
|
785 |
* the widget with that callback/$id_base AND that ID is found. |
|
786 |
* |
|
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 | 789 |
* |
790 |
* @since 2.2.0 |
|
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 | 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 | 801 |
global $wp_registered_widgets; |
802 |
||
803 |
$sidebars_widgets = wp_get_sidebars_widgets(); |
|
804 |
||
805 |
if ( is_array($sidebars_widgets) ) { |
|
806 |
foreach ( $sidebars_widgets as $sidebar => $widgets ) { |
|
5 | 807 |
if ( $skip_inactive && ( 'wp_inactive_widgets' === $sidebar || 'orphaned_widgets' === substr( $sidebar, 0, 16 ) ) ) { |
0 | 808 |
continue; |
5 | 809 |
} |
0 | 810 |
|
811 |
if ( is_array($widgets) ) { |
|
812 |
foreach ( $widgets as $widget ) { |
|
813 |
if ( ( $callback && isset($wp_registered_widgets[$widget]['callback']) && $wp_registered_widgets[$widget]['callback'] == $callback ) || ( $id_base && _get_widget_id_base($widget) == $id_base ) ) { |
|
814 |
if ( !$widget_id || $widget_id == $wp_registered_widgets[$widget]['id'] ) |
|
815 |
return $sidebar; |
|
816 |
} |
|
817 |
} |
|
818 |
} |
|
819 |
} |
|
820 |
} |
|
821 |
return false; |
|
822 |
} |
|
823 |
||
824 |
/** |
|
825 |
* Whether the dynamic sidebar is enabled and used by theme. |
|
826 |
* |
|
827 |
* @since 2.2.0 |
|
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 | 832 |
* @return bool True, if using widgets. False, if not using widgets. |
833 |
*/ |
|
834 |
function is_dynamic_sidebar() { |
|
835 |
global $wp_registered_widgets, $wp_registered_sidebars; |
|
836 |
$sidebars_widgets = get_option('sidebars_widgets'); |
|
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 | 839 |
foreach ( (array) $sidebars_widgets[$index] as $widget ) |
840 |
if ( array_key_exists($widget, $wp_registered_widgets) ) |
|
841 |
return true; |
|
842 |
} |
|
843 |
} |
|
844 |
return false; |
|
845 |
} |
|
846 |
||
847 |
/** |
|
848 |
* Whether a sidebar is in use. |
|
849 |
* |
|
5 | 850 |
* @since 2.8.0 |
0 | 851 |
* |
5 | 852 |
* @param string|int $index Sidebar name, id or number to check. |
0 | 853 |
* @return bool true if the sidebar is in use, false otherwise. |
854 |
*/ |
|
855 |
function is_active_sidebar( $index ) { |
|
856 |
$index = ( is_int($index) ) ? "sidebar-$index" : sanitize_title($index); |
|
857 |
$sidebars_widgets = wp_get_sidebars_widgets(); |
|
858 |
$is_active_sidebar = ! empty( $sidebars_widgets[$index] ); |
|
5 | 859 |
|
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 | 862 |
* |
863 |
* @since 3.9.0 |
|
864 |
* |
|
865 |
* @param bool $is_active_sidebar Whether or not the sidebar should be considered "active". |
|
866 |
* In other words, whether the sidebar contains any widgets. |
|
867 |
* @param int|string $index Index, name, or ID of the dynamic sidebar. |
|
868 |
*/ |
|
869 |
return apply_filters( 'is_active_sidebar', $is_active_sidebar, $index ); |
|
0 | 870 |
} |
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 | 875 |
|
876 |
/** |
|
5 | 877 |
* Retrieve full list of sidebars and their widget instance IDs. |
0 | 878 |
* |
879 |
* Will upgrade sidebar widget list, if needed. Will also save updated list, if |
|
880 |
* needed. |
|
881 |
* |
|
882 |
* @since 2.2.0 |
|
883 |
* @access private |
|
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 | 888 |
* @param bool $deprecated Not used (argument deprecated). |
0 | 889 |
* @return array Upgraded list of widgets to version 3 array format when called from the admin. |
890 |
*/ |
|
5 | 891 |
function wp_get_sidebars_widgets( $deprecated = true ) { |
0 | 892 |
if ( $deprecated !== true ) |
893 |
_deprecated_argument( __FUNCTION__, '2.8.1' ); |
|
894 |
||
895 |
global $_wp_sidebars_widgets, $sidebars_widgets; |
|
896 |
||
897 |
// If loading from front page, consult $_wp_sidebars_widgets rather than options |
|
898 |
// to see if wp_convert_widget_settings() has made manipulations in memory. |
|
899 |
if ( !is_admin() ) { |
|
900 |
if ( empty($_wp_sidebars_widgets) ) |
|
901 |
$_wp_sidebars_widgets = get_option('sidebars_widgets', array()); |
|
902 |
||
903 |
$sidebars_widgets = $_wp_sidebars_widgets; |
|
904 |
} else { |
|
905 |
$sidebars_widgets = get_option('sidebars_widgets', array()); |
|
906 |
} |
|
907 |
||
908 |
if ( is_array( $sidebars_widgets ) && isset($sidebars_widgets['array_version']) ) |
|
909 |
unset($sidebars_widgets['array_version']); |
|
910 |
||
5 | 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 | 913 |
* |
914 |
* @since 2.7.0 |
|
915 |
* |
|
916 |
* @param array $sidebars_widgets An associative array of sidebars and their widgets. |
|
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 | 919 |
} |
920 |
||
921 |
/** |
|
922 |
* Set the sidebar widget option to update sidebars. |
|
923 |
* |
|
924 |
* @since 2.2.0 |
|
925 |
* @access private |
|
926 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
927 |
* @global array $_wp_sidebars_widgets |
0 | 928 |
* @param array $sidebars_widgets Sidebar widgets and their settings. |
929 |
*/ |
|
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 | 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 | 940 |
update_option( 'sidebars_widgets', $sidebars_widgets ); |
941 |
} |
|
942 |
||
943 |
/** |
|
944 |
* Retrieve default registered sidebars list. |
|
945 |
* |
|
946 |
* @since 2.2.0 |
|
947 |
* @access private |
|
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 | 951 |
* @return array |
952 |
*/ |
|
953 |
function wp_get_widget_defaults() { |
|
954 |
global $wp_registered_sidebars; |
|
955 |
||
956 |
$defaults = array(); |
|
957 |
||
958 |
foreach ( (array) $wp_registered_sidebars as $index => $sidebar ) |
|
959 |
$defaults[$index] = array(); |
|
960 |
||
961 |
return $defaults; |
|
962 |
} |
|
963 |
||
964 |
/** |
|
965 |
* Convert the widget settings from single to multi-widget format. |
|
966 |
* |
|
967 |
* @since 2.8.0 |
|
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 | 971 |
* @param string $base_name |
972 |
* @param string $option_name |
|
973 |
* @param array $settings |
|
0 | 974 |
* @return array |
975 |
*/ |
|
976 |
function wp_convert_widget_settings($base_name, $option_name, $settings) { |
|
977 |
// This test may need expanding. |
|
978 |
$single = $changed = false; |
|
979 |
if ( empty($settings) ) { |
|
980 |
$single = true; |
|
981 |
} else { |
|
982 |
foreach ( array_keys($settings) as $number ) { |
|
983 |
if ( 'number' == $number ) |
|
984 |
continue; |
|
985 |
if ( !is_numeric($number) ) { |
|
986 |
$single = true; |
|
987 |
break; |
|
988 |
} |
|
989 |
} |
|
990 |
} |
|
991 |
||
992 |
if ( $single ) { |
|
993 |
$settings = array( 2 => $settings ); |
|
994 |
||
995 |
// If loading from the front page, update sidebar in memory but don't save to options |
|
996 |
if ( is_admin() ) { |
|
997 |
$sidebars_widgets = get_option('sidebars_widgets'); |
|
998 |
} else { |
|
999 |
if ( empty($GLOBALS['_wp_sidebars_widgets']) ) |
|
1000 |
$GLOBALS['_wp_sidebars_widgets'] = get_option('sidebars_widgets', array()); |
|
1001 |
$sidebars_widgets = &$GLOBALS['_wp_sidebars_widgets']; |
|
1002 |
} |
|
1003 |
||
1004 |
foreach ( (array) $sidebars_widgets as $index => $sidebar ) { |
|
1005 |
if ( is_array($sidebar) ) { |
|
1006 |
foreach ( $sidebar as $i => $name ) { |
|
1007 |
if ( $base_name == $name ) { |
|
1008 |
$sidebars_widgets[$index][$i] = "$name-2"; |
|
1009 |
$changed = true; |
|
1010 |
break 2; |
|
1011 |
} |
|
1012 |
} |
|
1013 |
} |
|
1014 |
} |
|
1015 |
||
1016 |
if ( is_admin() && $changed ) |
|
1017 |
update_option('sidebars_widgets', $sidebars_widgets); |
|
1018 |
} |
|
1019 |
||
1020 |
$settings['_multiwidget'] = 1; |
|
1021 |
if ( is_admin() ) |
|
1022 |
update_option( $option_name, $settings ); |
|
1023 |
||
1024 |
return $settings; |
|
1025 |
} |
|
1026 |
||
1027 |
/** |
|
5 | 1028 |
* Output an arbitrary widget as a template tag. |
1029 |
* |
|
1030 |
* @since 2.8.0 |
|
0 | 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 | 1035 |
* @param array $instance Optional. The widget's instance settings. Default empty array. |
1036 |
* @param array $args { |
|
1037 |
* Optional. Array of arguments to configure the display of the widget. |
|
0 | 1038 |
* |
5 | 1039 |
* @type string $before_widget HTML content that will be prepended to the widget's HTML output. |
1040 |
* Default `<div class="widget %s">`, where `%s` is the widget's class name. |
|
1041 |
* @type string $after_widget HTML content that will be appended to the widget's HTML output. |
|
1042 |
* Default `</div>`. |
|
1043 |
* @type string $before_title HTML content that will be prepended to the widget's title when displayed. |
|
1044 |
* Default `<h2 class="widgettitle">`. |
|
1045 |
* @type string $after_title HTML content that will be appended to the widget's title when displayed. |
|
1046 |
* Default `</h2>`. |
|
1047 |
* } |
|
1048 |
*/ |
|
1049 |
function the_widget( $widget, $instance = array(), $args = array() ) { |
|
0 | 1050 |
global $wp_widget_factory; |
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 | 1058 |
$widget_obj = $wp_widget_factory->widgets[$widget]; |
5 | 1059 |
if ( ! ( $widget_obj instanceof WP_Widget ) ) { |
0 | 1060 |
return; |
5 | 1061 |
} |
0 | 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 | 1071 |
|
1072 |
$instance = wp_parse_args($instance); |
|
1073 |
||
5 | 1074 |
/** |
1075 |
* Fires before rendering the requested widget. |
|
1076 |
* |
|
1077 |
* @since 3.0.0 |
|
1078 |
* |
|
1079 |
* @param string $widget The widget's class name. |
|
1080 |
* @param array $instance The current widget instance's settings. |
|
1081 |
* @param array $args An array of the widget's sidebar arguments. |
|
1082 |
*/ |
|
0 | 1083 |
do_action( 'the_widget', $widget, $instance, $args ); |
1084 |
||
1085 |
$widget_obj->_set(-1); |
|
1086 |
$widget_obj->widget($args, $instance); |
|
1087 |
} |
|
1088 |
||
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 | 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 | 1098 |
return preg_replace( '/-[0-9]+$/', '', $id ); |
1099 |
} |
|
1100 |
||
1101 |
/** |
|
1102 |
* Handle sidebars config after theme change |
|
1103 |
* |
|
1104 |
* @access private |
|
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 | 1108 |
*/ |
1109 |
function _wp_sidebars_changed() { |
|
1110 |
global $sidebars_widgets; |
|
1111 |
||
1112 |
if ( ! is_array( $sidebars_widgets ) ) |
|
1113 |
$sidebars_widgets = wp_get_sidebars_widgets(); |
|
1114 |
||
1115 |
retrieve_widgets(true); |
|
1116 |
} |
|
1117 |
||
5 | 1118 |
/** |
1119 |
* Look for "lost" widgets, this has to run at least on each theme change. |
|
1120 |
* |
|
1121 |
* @since 2.8.0 |
|
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 | 1127 |
* @param string|bool $theme_changed Whether the theme was changed as a boolean. A value |
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 | 1130 |
*/ |
1131 |
function retrieve_widgets( $theme_changed = false ) { |
|
0 | 1132 |
global $wp_registered_sidebars, $sidebars_widgets, $wp_registered_widgets; |
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 | 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 | 1140 |
} |
1141 |
||
1142 |
unset( $sidebars_widgets['array_version'] ); |
|
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 | 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 | 1150 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1151 |
return $sidebars_widgets; |
0 | 1152 |
} |
1153 |
} |
|
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 | 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 | 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 | 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 | 1172 |
|
5 | 1173 |
if ( 'customize' !== $theme_changed ) { |
1174 |
wp_set_sidebars_widgets( $sidebars_widgets ); |
|
1175 |
} |
|
0 | 1176 |
|
1177 |
return $sidebars_widgets; |
|
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, ' […]' ) ); |
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 […]. |
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 ) . '[…]'; |
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 |
} |