X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/5aa86a9053fb0fa15846bb60aac2fb8fdfff524a..0459461f9ea42e0b090759ff6fe5f48360bef750:/wp-admin/widgets.php?ds=sidebyside diff --git a/wp-admin/widgets.php b/wp-admin/widgets.php index 6c05e533..0abd81c2 100644 --- a/wp-admin/widgets.php +++ b/wp-admin/widgets.php @@ -1,19 +1,24 @@ ' . __( 'Cheatin’ uh?' ) . '' . + '

' . __( 'You are not allowed to edit theme options on this site.' ) . '

', + 403 + ); +} $widgets_access = get_user_setting( 'widgets_access' ); if ( isset($_GET['widgets-access']) ) { @@ -21,15 +26,21 @@ if ( isset($_GET['widgets-access']) ) { set_user_setting( 'widgets_access', $widgets_access ); } -function wp_widgets_access_body_class($classes) { - return "$classes widgets_access "; -} - -if ( 'on' == $widgets_access ) +if ( 'on' == $widgets_access ) { add_filter( 'admin_body_class', 'wp_widgets_access_body_class' ); -else +} else { wp_enqueue_script('admin-widgets'); + if ( wp_is_mobile() ) + wp_enqueue_script( 'jquery-touch-punch' ); +} + +/** + * Fires early before the Widgets administration screen loads, + * after scripts are enqueued. + * + * @since 2.2.0 + */ do_action( 'sidebar_admin_setup' ); $title = __( 'Widgets' ); @@ -55,32 +66,17 @@ get_current_screen()->add_help_tab( array( 'title' => __('Missing Widgets'), 'content' => '

' . __('Many themes show some sidebar widgets by default until you edit your sidebars, but they are not automatically displayed in your sidebar management tool. After you make your first widget change, you can re-add the default widgets by adding them from the Available Widgets area.') . '

' . - '

' . __('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 area, where all your widgets and their settings will have been saved.') . '

' + '

' . __('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.') . '

' ) ); get_current_screen()->set_help_sidebar( '

' . __('For more information:') . '

' . - '

' . __('Documentation on Widgets') . '

' . - '

' . __('Support Forums') . '

' + '

' . __('Documentation on Widgets') . '

' . + '

' . __('Support Forums') . '

' ); -if ( empty($wp_registered_sidebars) ) { - // the theme has no sidebars, die. - require_once( './admin-header.php' ); -?> - -
- -

-
-

-
-

follow these instructions.' ); ?>

-
- -follow these instructions.' ) ); } // These are the widgets grouped by sidebar @@ -93,7 +89,7 @@ foreach ( $sidebars_widgets as $sidebar_id => $widgets ) { if ( 'wp_inactive_widgets' == $sidebar_id ) continue; - if ( !isset( $wp_registered_sidebars[ $sidebar_id ] ) ) { + if ( ! is_registered_sidebar( $sidebar_id ) ) { if ( ! empty( $widgets ) ) { // register the inactive_widgets area as sidebar register_sidebar(array( 'name' => __( 'Inactive Sidebar (not used)' ), @@ -146,7 +142,7 @@ if ( isset($_POST['savewidget']) || isset($_POST['removewidget']) ) { $id_base = $_POST['id_base']; $sidebar = isset($sidebars_widgets[$sidebar_id]) ? $sidebars_widgets[$sidebar_id] : array(); - // delete + // Delete. if ( isset($_POST['removewidget']) && $_POST['removewidget'] ) { if ( !in_array($widget_id, $sidebar, true) ) { @@ -156,6 +152,17 @@ if ( isset($_POST['savewidget']) || isset($_POST['removewidget']) ) { $sidebar = array_diff( $sidebar, array($widget_id) ); $_POST = array('sidebar' => $sidebar_id, 'widget-' . $id_base => array(), 'the-widget-id' => $widget_id, 'delete_widget' => '1'); + + /** + * Fires immediately after a widget has been marked for deletion. + * + * @since 4.4.0 + * + * @param string $widget_id ID of the widget marked for deletion. + * @param string $sidebar_id ID of the sidebar the widget was deleted from. + * @param string $id_base ID base for the widget. + */ + do_action( 'delete_widget', $widget_id, $sidebar_id, $id_base ); } $_POST['widget-id'] = $sidebar; @@ -173,7 +180,7 @@ if ( isset($_POST['savewidget']) || isset($_POST['removewidget']) ) { $sidebars_widgets[$sidebar_id] = $sidebar; - // remove old position + // Remove old position. if ( !isset($_POST['delete_widget']) ) { foreach ( $sidebars_widgets as $key => $sb ) { if ( is_array($sb) ) @@ -187,13 +194,36 @@ if ( isset($_POST['savewidget']) || isset($_POST['removewidget']) ) { exit; } +// Remove inactive widgets without js +if ( isset( $_POST['removeinactivewidgets'] ) ) { + check_admin_referer( 'remove-inactive-widgets', '_wpnonce_remove_inactive_widgets' ); + + if ( $_POST['removeinactivewidgets'] ) { + foreach ( $sidebars_widgets['wp_inactive_widgets'] as $key => $widget_id ) { + $pieces = explode( '-', $widget_id ); + $multi_number = array_pop( $pieces ); + $id_base = implode( '-', $pieces ); + $widget = get_option( 'widget_' . $id_base ); + unset( $widget[$multi_number] ); + update_option( 'widget_' . $id_base, $widget ); + unset( $sidebars_widgets['wp_inactive_widgets'][$key] ); + } + + wp_set_sidebars_widgets( $sidebars_widgets ); + } + + wp_redirect( admin_url( 'widgets.php?message=0' ) ); + exit; +} + // Output the widget form without js if ( isset($_GET['editwidget']) && $_GET['editwidget'] ) { $widget_id = $_GET['editwidget']; if ( isset($_GET['addnew']) ) { // Default to the first sidebar - $sidebar = array_shift( $keys = array_keys($wp_registered_sidebars) ); + $keys = array_keys( $wp_registered_sidebars ); + $sidebar = reset( $keys ); if ( isset($_GET['base']) && isset($_GET['num']) ) { // multi-widget // Copy minimal info from an existing instance of this widget to a new instance @@ -228,16 +258,15 @@ if ( isset($_GET['editwidget']) && $_GET['editwidget'] ) { $id_base = isset($control['id_base']) ? $control['id_base'] : $control['id']; - // show the widget form + // Show the widget form. $width = ' style="width:' . max($control['width'], 350) . 'px"'; $key = isset($_GET['key']) ? (int) $_GET['key'] : 0; - require_once( './admin-header.php' ); ?> + require_once( ABSPATH . 'wp-admin/admin-header.php' ); ?>
- -

+

> -

+

@@ -299,7 +328,7 @@ if ( isset($_GET['editwidget']) && $_GET['editwidget'] ) {
+require_once( ABSPATH . 'wp-admin/admin-header.php' ); ?>
- -

+

+%2$s', + esc_url( add_query_arg( + array( + array( 'autofocus' => array( 'panel' => 'widgets' ) ), + 'return' => urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ) + ), + admin_url( 'customize.php' ) + ) ), + __( 'Manage in Customizer' ) + ); + } +?> +

-

+

- +
-
-

-
- + +

-
+
+ +
+ +
+

$registered_sidebar ) { if ( false !== strpos( $registered_sidebar['class'], 'inactive-sidebar' ) || 'orphaned_widgets' == substr( $sidebar, 0, 16 ) ) { $wrap_class = 'widgets-holder-wrap'; if ( !empty( $registered_sidebar['class'] ) ) $wrap_class .= ' ' . $registered_sidebar['class']; -?> - + $is_inactive_widgets = 'wp_inactive_widgets' == $registered_sidebar['id']; + ?>
-
- -
+ + + +
+ +

+ 'inactive-widgets-control-remove' ); + + if ( empty($sidebars_widgets['wp_inactive_widgets']) ) { + $attributes['disabled'] = ''; + } + + submit_button( __( 'Clear Inactive Widgets' ), 'delete', 'removeinactivewidgets', false, $attributes ); + ?> + +

+ + +
+
+ +

+
- +?>
+ 1 ) { + $split = ceil( $sidebars_count / 2 ); +} else { + $single_sidebar_class = ' class="single-sidebar"'; +} + +?>
-
+
> +
-
+
+
+
+
    +
    + + +
    +
    +