WordPress 4.7
[autoinstalls/wordpress.git] / wp-includes / widgets / class-wp-nav-menu-widget.php
index 22ec8610763ad05a8bcb0f9552c8edf9e32382a7..d7ad82b7e82d0d28a37830b36dfdf6274c1e6c07 100644 (file)
@@ -14,7 +14,7 @@
  *
  * @see WP_Widget
  */
- class WP_Nav_Menu_Widget extends WP_Widget {
+class WP_Nav_Menu_Widget extends WP_Widget {
 
        /**
         * Sets up a new Custom Menu widget instance.
         * @access public
         */
        public function __construct() {
-               $widget_ops = array( 'description' => __('Add a custom menu to your sidebar.') );
+               $widget_ops = array(
+                       'description' => __( 'Add a custom menu to your sidebar.' ),
+                       'customize_selective_refresh' => true,
+               );
                parent::__construct( 'nav_menu', __('Custom Menu'), $widget_ops );
        }
 
@@ -58,7 +61,7 @@
                );
 
                /**
-                * Filter the arguments for the Custom Menu widget.
+                * Filters the arguments for the Custom Menu widget.
                 *
                 * @since 4.2.0
                 * @since 4.4.0 Added the `$instance` parameter.
@@ -69,7 +72,7 @@
                 *     @type callable|bool $fallback_cb Callback to fire if the menu doesn't exist. Default empty.
                 *     @type mixed         $menu        Menu ID, slug, or name.
                 * }
-                * @param stdClass $nav_menu      Nav menu object for the current menu.
+                * @param WP_Term  $nav_menu      Nav menu object for the current menu.
                 * @param array    $args          Display arguments for the current widget.
                 * @param array    $instance      Array of settings for the current widget.
                 */
@@ -92,7 +95,7 @@
        public function update( $new_instance, $old_instance ) {
                $instance = array();
                if ( ! empty( $new_instance['title'] ) ) {
-                       $instance['title'] = sanitize_text_field( stripslashes( $new_instance['title'] ) );
+                       $instance['title'] = sanitize_text_field( $new_instance['title'] );
                }
                if ( ! empty( $new_instance['nav_menu'] ) ) {
                        $instance['nav_menu'] = (int) $new_instance['nav_menu'];
         * @access public
         *
         * @param array $instance Current settings.
+        * @global WP_Customize_Manager $wp_customize
         */
        public function form( $instance ) {
+               global $wp_customize;
                $title = isset( $instance['title'] ) ? $instance['title'] : '';
                $nav_menu = isset( $instance['nav_menu'] ) ? $instance['nav_menu'] : '';
 
                ?>
                <p class="nav-menu-widget-no-menus-message" <?php if ( ! empty( $menus ) ) { echo ' style="display:none" '; } ?>>
                        <?php
-                       if ( isset( $GLOBALS['wp_customize'] ) && $GLOBALS['wp_customize'] instanceof WP_Customize_Manager ) {
+                       if ( $wp_customize instanceof WP_Customize_Manager ) {
                                $url = 'javascript: wp.customize.panel( "nav_menus" ).focus();';
                        } else {
                                $url = admin_url( 'nav-menus.php' );
                                        <?php endforeach; ?>
                                </select>
                        </p>
+                       <?php if ( $wp_customize instanceof WP_Customize_Manager ) : ?>
+                               <p class="edit-selected-nav-menu" style="<?php if ( ! $nav_menu ) { echo 'display: none;'; } ?>">
+                                       <button type="button" class="button"><?php _e( 'Edit Menu' ) ?></button>
+                               </p>
+                       <?php endif; ?>
                </div>
                <?php
        }