10 require_once( dirname( __FILE__ ) . '/admin.php' ); |
10 require_once( dirname( __FILE__ ) . '/admin.php' ); |
11 |
11 |
12 /** WordPress Administration Widgets API */ |
12 /** WordPress Administration Widgets API */ |
13 require_once(ABSPATH . 'wp-admin/includes/widgets.php'); |
13 require_once(ABSPATH . 'wp-admin/includes/widgets.php'); |
14 |
14 |
15 if ( ! current_user_can('edit_theme_options') ) |
15 if ( ! current_user_can( 'edit_theme_options' ) ) { |
16 wp_die( __( 'Cheatin’ uh?' ), 403 ); |
16 wp_die( |
|
17 '<h1>' . __( 'You need a higher level of permission.' ) . '</h1>' . |
|
18 '<p>' . __( 'Sorry, you are not allowed to edit theme options on this site.' ) . '</p>', |
|
19 403 |
|
20 ); |
|
21 } |
17 |
22 |
18 $widgets_access = get_user_setting( 'widgets_access' ); |
23 $widgets_access = get_user_setting( 'widgets_access' ); |
19 if ( isset($_GET['widgets-access']) ) { |
24 if ( isset($_GET['widgets-access']) ) { |
|
25 check_admin_referer( 'widgets-access' ); |
|
26 |
20 $widgets_access = 'on' == $_GET['widgets-access'] ? 'on' : 'off'; |
27 $widgets_access = 'on' == $_GET['widgets-access'] ? 'on' : 'off'; |
21 set_user_setting( 'widgets_access', $widgets_access ); |
28 set_user_setting( 'widgets_access', $widgets_access ); |
22 } |
|
23 |
|
24 function wp_widgets_access_body_class($classes) { |
|
25 return "$classes widgets_access "; |
|
26 } |
29 } |
27 |
30 |
28 if ( 'on' == $widgets_access ) { |
31 if ( 'on' == $widgets_access ) { |
29 add_filter( 'admin_body_class', 'wp_widgets_access_body_class' ); |
32 add_filter( 'admin_body_class', 'wp_widgets_access_body_class' ); |
30 } else { |
33 } else { |
68 '<p>' . __('When changing themes, there is often some variation in the number and setup of widget areas/sidebars and sometimes these conflicts make the transition a bit less smooth. If you changed themes and seem to be missing widgets, scroll down on this screen to the Inactive Widgets area, where all of your widgets and their settings will have been saved.') . '</p>' |
71 '<p>' . __('When changing themes, there is often some variation in the number and setup of widget areas/sidebars and sometimes these conflicts make the transition a bit less smooth. If you changed themes and seem to be missing widgets, scroll down on this screen to the Inactive Widgets area, where all of your widgets and their settings will have been saved.') . '</p>' |
69 ) ); |
72 ) ); |
70 |
73 |
71 get_current_screen()->set_help_sidebar( |
74 get_current_screen()->set_help_sidebar( |
72 '<p><strong>' . __('For more information:') . '</strong></p>' . |
75 '<p><strong>' . __('For more information:') . '</strong></p>' . |
73 '<p>' . __('<a href="https://codex.wordpress.org/Appearance_Widgets_Screen" target="_blank">Documentation on Widgets</a>') . '</p>' . |
76 '<p>' . __('<a href="https://codex.wordpress.org/Appearance_Widgets_Screen">Documentation on Widgets</a>') . '</p>' . |
74 '<p>' . __('<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>' |
77 '<p>' . __('<a href="https://wordpress.org/support/">Support Forums</a>') . '</p>' |
75 ); |
78 ); |
76 |
79 |
77 if ( ! current_theme_supports( 'widgets' ) ) { |
80 if ( ! current_theme_supports( 'widgets' ) ) { |
78 wp_die( __( 'The theme you are currently using isn’t widget-aware, meaning that it has no sidebars that you are able to change. For information on making your theme widget-aware, please <a href="https://codex.wordpress.org/Widgetizing_Themes">follow these instructions</a>.' ) ); |
81 wp_die( __( 'The theme you are currently using isn’t widget-aware, meaning that it has no sidebars that you are able to change. For information on making your theme widget-aware, please <a href="https://codex.wordpress.org/Widgetizing_Themes">follow these instructions</a>.' ) ); |
79 } |
82 } |
86 |
89 |
87 foreach ( $sidebars_widgets as $sidebar_id => $widgets ) { |
90 foreach ( $sidebars_widgets as $sidebar_id => $widgets ) { |
88 if ( 'wp_inactive_widgets' == $sidebar_id ) |
91 if ( 'wp_inactive_widgets' == $sidebar_id ) |
89 continue; |
92 continue; |
90 |
93 |
91 if ( !isset( $wp_registered_sidebars[ $sidebar_id ] ) ) { |
94 if ( ! is_registered_sidebar( $sidebar_id ) ) { |
92 if ( ! empty( $widgets ) ) { // register the inactive_widgets area as sidebar |
95 if ( ! empty( $widgets ) ) { // register the inactive_widgets area as sidebar |
93 register_sidebar(array( |
96 register_sidebar(array( |
94 'name' => __( 'Inactive Sidebar (not used)' ), |
97 'name' => __( 'Inactive Sidebar (not used)' ), |
95 'id' => $sidebar_id, |
98 'id' => $sidebar_id, |
96 'class' => 'inactive-sidebar orphan-sidebar', |
99 'class' => 'inactive-sidebar orphan-sidebar', |
149 exit; |
152 exit; |
150 } |
153 } |
151 |
154 |
152 $sidebar = array_diff( $sidebar, array($widget_id) ); |
155 $sidebar = array_diff( $sidebar, array($widget_id) ); |
153 $_POST = array('sidebar' => $sidebar_id, 'widget-' . $id_base => array(), 'the-widget-id' => $widget_id, 'delete_widget' => '1'); |
156 $_POST = array('sidebar' => $sidebar_id, 'widget-' . $id_base => array(), 'the-widget-id' => $widget_id, 'delete_widget' => '1'); |
|
157 |
|
158 /** |
|
159 * Fires immediately after a widget has been marked for deletion. |
|
160 * |
|
161 * @since 4.4.0 |
|
162 * |
|
163 * @param string $widget_id ID of the widget marked for deletion. |
|
164 * @param string $sidebar_id ID of the sidebar the widget was deleted from. |
|
165 * @param string $id_base ID base for the widget. |
|
166 */ |
|
167 do_action( 'delete_widget', $widget_id, $sidebar_id, $id_base ); |
154 } |
168 } |
155 |
169 |
156 $_POST['widget-id'] = $sidebar; |
170 $_POST['widget-id'] = $sidebar; |
157 |
171 |
158 foreach ( (array) $wp_registered_widget_updates as $name => $control ) { |
172 foreach ( (array) $wp_registered_widget_updates as $name => $control ) { |
177 array_splice( $sidebars_widgets[$sidebar_id], $position, 0, $widget_id ); |
191 array_splice( $sidebars_widgets[$sidebar_id], $position, 0, $widget_id ); |
178 } |
192 } |
179 |
193 |
180 wp_set_sidebars_widgets($sidebars_widgets); |
194 wp_set_sidebars_widgets($sidebars_widgets); |
181 wp_redirect( admin_url('widgets.php?message=0') ); |
195 wp_redirect( admin_url('widgets.php?message=0') ); |
|
196 exit; |
|
197 } |
|
198 |
|
199 // Remove inactive widgets without js |
|
200 if ( isset( $_POST['removeinactivewidgets'] ) ) { |
|
201 check_admin_referer( 'remove-inactive-widgets', '_wpnonce_remove_inactive_widgets' ); |
|
202 |
|
203 if ( $_POST['removeinactivewidgets'] ) { |
|
204 foreach ( $sidebars_widgets['wp_inactive_widgets'] as $key => $widget_id ) { |
|
205 $pieces = explode( '-', $widget_id ); |
|
206 $multi_number = array_pop( $pieces ); |
|
207 $id_base = implode( '-', $pieces ); |
|
208 $widget = get_option( 'widget_' . $id_base ); |
|
209 unset( $widget[$multi_number] ); |
|
210 update_option( 'widget_' . $id_base, $widget ); |
|
211 unset( $sidebars_widgets['wp_inactive_widgets'][$key] ); |
|
212 } |
|
213 |
|
214 wp_set_sidebars_widgets( $sidebars_widgets ); |
|
215 } |
|
216 |
|
217 wp_redirect( admin_url( 'widgets.php?message=0' ) ); |
182 exit; |
218 exit; |
183 } |
219 } |
184 |
220 |
185 // Output the widget form without js |
221 // Output the widget form without js |
186 if ( isset($_GET['editwidget']) && $_GET['editwidget'] ) { |
222 if ( isset($_GET['editwidget']) && $_GET['editwidget'] ) { |
228 $width = ' style="width:' . max($control['width'], 350) . 'px"'; |
264 $width = ' style="width:' . max($control['width'], 350) . 'px"'; |
229 $key = isset($_GET['key']) ? (int) $_GET['key'] : 0; |
265 $key = isset($_GET['key']) ? (int) $_GET['key'] : 0; |
230 |
266 |
231 require_once( ABSPATH . 'wp-admin/admin-header.php' ); ?> |
267 require_once( ABSPATH . 'wp-admin/admin-header.php' ); ?> |
232 <div class="wrap"> |
268 <div class="wrap"> |
233 <h2><?php echo esc_html( $title ); ?></h2> |
269 <h1><?php echo esc_html( $title ); ?></h1> |
234 <div class="editwidget"<?php echo $width; ?>> |
270 <div class="editwidget"<?php echo $width; ?>> |
235 <h3><?php printf( __( 'Widget %s' ), $name ); ?></h3> |
271 <h2><?php printf( __( 'Widget %s' ), $name ); ?></h2> |
236 |
272 |
237 <form action="widgets.php" method="post"> |
273 <form action="widgets.php" method="post"> |
238 <div class="widget-inside"> |
274 <div class="widget-inside"> |
239 <?php |
275 <?php |
240 if ( is_callable( $control_callback ) ) |
276 if ( is_callable( $control_callback ) ) |
279 <?php |
315 <?php |
280 if ( isset($_GET['addnew']) ) { ?> |
316 if ( isset($_GET['addnew']) ) { ?> |
281 <a href="widgets.php" class="button alignleft"><?php _e('Cancel'); ?></a> |
317 <a href="widgets.php" class="button alignleft"><?php _e('Cancel'); ?></a> |
282 <?php |
318 <?php |
283 } else { |
319 } else { |
284 submit_button( __( 'Delete' ), 'button alignleft', 'removewidget', false ); |
320 submit_button( __( 'Delete' ), 'alignleft', 'removewidget', false ); |
285 } |
321 } |
286 submit_button( __( 'Save Widget' ), 'button-primary alignright', 'savewidget', false ); ?> |
322 submit_button( __( 'Save Widget' ), 'primary alignright', 'savewidget', false ); ?> |
287 <input type="hidden" name="widget-id" class="widget-id" value="<?php echo esc_attr($widget_id); ?>" /> |
323 <input type="hidden" name="widget-id" class="widget-id" value="<?php echo esc_attr($widget_id); ?>" /> |
288 <input type="hidden" name="id_base" class="id_base" value="<?php echo esc_attr($id_base); ?>" /> |
324 <input type="hidden" name="id_base" class="id_base" value="<?php echo esc_attr($id_base); ?>" /> |
289 <input type="hidden" name="multi_number" class="multi_number" value="<?php echo esc_attr($multi_number); ?>" /> |
325 <input type="hidden" name="multi_number" class="multi_number" value="<?php echo esc_attr($multi_number); ?>" /> |
290 <?php wp_nonce_field("save-delete-widget-$widget_id"); ?> |
326 <?php wp_nonce_field("save-delete-widget-$widget_id"); ?> |
291 <br class="clear" /> |
327 <br class="clear" /> |
308 ); |
344 ); |
309 |
345 |
310 require_once( ABSPATH . 'wp-admin/admin-header.php' ); ?> |
346 require_once( ABSPATH . 'wp-admin/admin-header.php' ); ?> |
311 |
347 |
312 <div class="wrap"> |
348 <div class="wrap"> |
313 <h2> |
349 <h1 class="wp-heading-inline"><?php |
314 <?php |
350 echo esc_html( $title ); |
315 echo esc_html( $title ); |
351 ?></h1> |
316 if ( current_user_can( 'customize' ) ) { |
352 |
317 printf( |
353 <?php |
318 ' <a class="add-new-h2 hide-if-no-customize" href="%1$s">%2$s</a>', |
354 if ( current_user_can( 'customize' ) ) { |
319 esc_url( add_query_arg( |
355 printf( |
320 array( |
356 ' <a class="page-title-action hide-if-no-customize" href="%1$s">%2$s</a>', |
321 array( 'autofocus' => array( 'panel' => 'widgets' ) ), |
357 esc_url( add_query_arg( |
322 'return' => urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ) |
358 array( |
323 ), |
359 array( 'autofocus' => array( 'panel' => 'widgets' ) ), |
324 admin_url( 'customize.php' ) |
360 'return' => urlencode( remove_query_arg( wp_removable_query_args(), wp_unslash( $_SERVER['REQUEST_URI'] ) ) ) |
325 ) ), |
361 ), |
326 __( 'Manage in Customizer' ) |
362 admin_url( 'customize.php' ) |
327 ); |
363 ) ), |
328 } |
364 __( 'Manage with Live Preview' ) |
|
365 ); |
|
366 } |
329 ?> |
367 ?> |
330 </h2> |
368 |
|
369 <hr class="wp-header-end"> |
331 |
370 |
332 <?php if ( isset($_GET['message']) && isset($messages[$_GET['message']]) ) { ?> |
371 <?php if ( isset($_GET['message']) && isset($messages[$_GET['message']]) ) { ?> |
333 <div id="message" class="updated notice is-dismissible"><p><?php echo $messages[$_GET['message']]; ?></p></div> |
372 <div id="message" class="updated notice is-dismissible"><p><?php echo $messages[$_GET['message']]; ?></p></div> |
334 <?php } ?> |
373 <?php } ?> |
335 <?php if ( isset($_GET['error']) && isset($errors[$_GET['error']]) ) { ?> |
374 <?php if ( isset($_GET['error']) && isset($errors[$_GET['error']]) ) { ?> |
346 |
385 |
347 <div class="widget-liquid-left"> |
386 <div class="widget-liquid-left"> |
348 <div id="widgets-left"> |
387 <div id="widgets-left"> |
349 <div id="available-widgets" class="widgets-holder-wrap"> |
388 <div id="available-widgets" class="widgets-holder-wrap"> |
350 <div class="sidebar-name"> |
389 <div class="sidebar-name"> |
351 <div class="sidebar-name-arrow"><br /></div> |
390 <button type="button" class="handlediv hide-if-no-js" aria-expanded="true"> |
352 <h3><?php _e('Available Widgets'); ?> <span id="removing-widget"><?php _ex('Deactivate', 'removing-widget'); ?> <span></span></span></h3> |
391 <span class="screen-reader-text"><?php _e( 'Available Widgets' ); ?></span> |
|
392 <span class="toggle-indicator" aria-hidden="true"></span> |
|
393 </button> |
|
394 <h2><?php _e( 'Available Widgets' ); ?> <span id="removing-widget"><?php _ex( 'Deactivate', 'removing-widget' ); ?> <span></span></span></h2> |
353 </div> |
395 </div> |
354 <div class="widget-holder"> |
396 <div class="widget-holder"> |
355 <div class="sidebar-description"> |
397 <div class="sidebar-description"> |
356 <p class="description"><?php _e('To activate a widget drag it to a sidebar or click on it. To deactivate a widget and delete its settings, drag it back.'); ?></p> |
398 <p class="description"><?php _e('To activate a widget drag it to a sidebar or click on it. To deactivate a widget and delete its settings, drag it back.'); ?></p> |
357 </div> |
399 </div> |
370 if ( false !== strpos( $registered_sidebar['class'], 'inactive-sidebar' ) || 'orphaned_widgets' == substr( $sidebar, 0, 16 ) ) { |
412 if ( false !== strpos( $registered_sidebar['class'], 'inactive-sidebar' ) || 'orphaned_widgets' == substr( $sidebar, 0, 16 ) ) { |
371 $wrap_class = 'widgets-holder-wrap'; |
413 $wrap_class = 'widgets-holder-wrap'; |
372 if ( !empty( $registered_sidebar['class'] ) ) |
414 if ( !empty( $registered_sidebar['class'] ) ) |
373 $wrap_class .= ' ' . $registered_sidebar['class']; |
415 $wrap_class .= ' ' . $registered_sidebar['class']; |
374 |
416 |
|
417 $is_inactive_widgets = 'wp_inactive_widgets' == $registered_sidebar['id']; |
375 ?> |
418 ?> |
376 <div class="<?php echo esc_attr( $wrap_class ); ?>"> |
419 <div class="<?php echo esc_attr( $wrap_class ); ?>"> |
377 <div class="widget-holder inactive"> |
420 <div class="widget-holder inactive"> |
378 <?php wp_list_widget_controls( $registered_sidebar['id'], $registered_sidebar['name'] ); ?> |
421 <?php wp_list_widget_controls( $registered_sidebar['id'], $registered_sidebar['name'] ); ?> |
379 <div class="clear"></div> |
422 |
|
423 <?php if ( $is_inactive_widgets ) { ?> |
|
424 <div class="remove-inactive-widgets"> |
|
425 <form action="" method="post"> |
|
426 <p> |
|
427 <?php |
|
428 $attributes = array( 'id' => 'inactive-widgets-control-remove' ); |
|
429 |
|
430 if ( empty($sidebars_widgets['wp_inactive_widgets']) ) { |
|
431 $attributes['disabled'] = ''; |
|
432 } |
|
433 |
|
434 submit_button( __( 'Clear Inactive Widgets' ), 'delete', 'removeinactivewidgets', false, $attributes ); |
|
435 ?> |
|
436 <span class="spinner"></span> |
|
437 </p> |
|
438 <?php wp_nonce_field( 'remove-inactive-widgets', '_wpnonce_remove_inactive_widgets' ); ?> |
|
439 </form> |
|
440 </div> |
|
441 <?php } ?> |
380 </div> |
442 </div> |
|
443 <?php if ( $is_inactive_widgets ) { ?> |
|
444 <p class="description"><?php _e( 'This will clear all items from the inactive widgets list. You will not be able to restore any customizations.' ); ?></p> |
|
445 <?php } ?> |
381 </div> |
446 </div> |
382 <?php |
447 <?php |
383 |
448 |
384 } else { |
449 } else { |
385 $theme_sidebars[$sidebar] = $registered_sidebar; |
450 $theme_sidebars[$sidebar] = $registered_sidebar; |
396 $sidebars_count = count( $theme_sidebars ); |
461 $sidebars_count = count( $theme_sidebars ); |
397 |
462 |
398 if ( $sidebars_count > 1 ) { |
463 if ( $sidebars_count > 1 ) { |
399 $split = ceil( $sidebars_count / 2 ); |
464 $split = ceil( $sidebars_count / 2 ); |
400 } else { |
465 } else { |
401 $single_sidebar_class = ' class="single-sidebar"'; |
466 $single_sidebar_class = ' single-sidebar'; |
402 } |
467 } |
403 |
468 |
404 ?> |
469 ?> |
405 <div class="widget-liquid-right"> |
470 <div class="widget-liquid-right"> |
406 <div id="widgets-right"<?php echo $single_sidebar_class; ?>> |
471 <div id="widgets-right" class="wp-clearfix<?php echo $single_sidebar_class; ?>"> |
407 <div class="sidebars-column-1"> |
472 <div class="sidebars-column-1"> |
408 <?php |
473 <?php |
409 |
474 |
410 foreach ( $theme_sidebars as $sidebar => $registered_sidebar ) { |
475 foreach ( $theme_sidebars as $sidebar => $registered_sidebar ) { |
411 $wrap_class = 'widgets-holder-wrap'; |
476 $wrap_class = 'widgets-holder-wrap'; |
441 </div> |
506 </div> |
442 |
507 |
443 <div class="widgets-chooser"> |
508 <div class="widgets-chooser"> |
444 <ul class="widgets-chooser-sidebars"></ul> |
509 <ul class="widgets-chooser-sidebars"></ul> |
445 <div class="widgets-chooser-actions"> |
510 <div class="widgets-chooser-actions"> |
446 <button class="button-secondary"><?php _e( 'Cancel' ); ?></button> |
511 <button class="button widgets-chooser-cancel"><?php _e( 'Cancel' ); ?></button> |
447 <button class="button-primary"><?php _e( 'Add Widget' ); ?></button> |
512 <button class="button button-primary widgets-chooser-add"><?php _e( 'Add Widget' ); ?></button> |
448 </div> |
513 </div> |
449 </div> |
514 </div> |
450 |
515 |
451 <?php |
516 <?php |
452 |
517 |