WordPress.org

Make WordPress Core

Changeset 42034


Ignore:
Timestamp:
10/28/2017 05:47:06 AM (21 months ago)
Author:
westonruter
Message:

Customize: Deprecate nav menu classes that are no longer used, instead of removing them immediately.

  • Deprecate PHP classes WP_Customize_New_Menu_Section and WP_Customize_New_Menu_Control.
  • Deprecate JS class wp.customize.Menus.NewMenuControl.
  • Also introduce wp.customize.Menus.createNavMenu() for logic to create nav menus separately from the logic for handling UI interactions.

Amends [41768].
See #40104, #42364.
Fixes #42357.

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/js/customize-nav-menus.js

    r41930 r42034  
    11631163
    11641164    /**
     1165     * Create a nav menu setting and section.
     1166     *
     1167     * @since 4.9.0
     1168     *
     1169     * @param {string} [name=''] Nav menu name.
     1170     * @returns {wp.customize.Menus.MenuSection} Added nav menu.
     1171     */
     1172    api.Menus.createNavMenu = function createNavMenu( name ) {
     1173        var customizeId, placeholderId, setting;
     1174        placeholderId = api.Menus.generatePlaceholderAutoIncrementId();
     1175
     1176        customizeId = 'nav_menu[' + String( placeholderId ) + ']';
     1177
     1178        // Register the menu control setting.
     1179        setting = api.create( customizeId, customizeId, {}, {
     1180            type: 'nav_menu',
     1181            transport: api.Menus.data.settingTransport,
     1182            previewer: api.previewer
     1183        } );
     1184        setting.set( $.extend(
     1185            {},
     1186            api.Menus.data.defaultSettingValues.nav_menu,
     1187            {
     1188                name: name || ''
     1189            }
     1190        ) );
     1191
     1192        /*
     1193         * Add the menu section (and its controls).
     1194         * Note that this will automatically create the required controls
     1195         * inside via the Section's ready method.
     1196         */
     1197        return api.section.add( new api.Menus.MenuSection( customizeId, {
     1198            panel: 'nav_menus',
     1199            title: displayNavMenuName( name ),
     1200            customizeAction: api.Menus.data.l10n.customizingMenus,
     1201            priority: 10,
     1202            menu_id: placeholderId
     1203        } ) );
     1204    };
     1205
     1206    /**
    11651207     * wp.customize.Menus.NewMenuSection
    11661208     *
     
    13401382                nameInput = contentContainer.find( '.menu-name-field' ).first(),
    13411383                name = nameInput.val(),
    1342                 menuSection,
    1343                 customizeId,
    1344                 editMenuSection,
    1345                 placeholderId = api.Menus.generatePlaceholderAutoIncrementId();
     1384                menuSection;
    13461385
    13471386            if ( ! name ) {
     
    13511390            }
    13521391
    1353             customizeId = 'nav_menu[' + String( placeholderId ) + ']';
    1354 
    1355             // Register the menu control setting.
    1356             api.create( customizeId, customizeId, {}, {
    1357                 type: 'nav_menu',
    1358                 transport: api.Menus.data.settingTransport,
    1359                 previewer: api.previewer
    1360             } );
    1361             api( customizeId ).set( $.extend(
    1362                 {},
    1363                 api.Menus.data.defaultSettingValues.nav_menu,
    1364                 {
    1365                     name: name
    1366                 }
    1367             ) );
    1368 
    1369             /*
    1370              * Add the menu section (and its controls).
    1371              * Note that this will automatically create the required controls
    1372              * inside via the Section's ready method.
    1373              */
    1374             menuSection = new api.Menus.MenuSection( customizeId, {
    1375                 panel: 'nav_menus',
    1376                 title: displayNavMenuName( name ),
    1377                 customizeAction: api.Menus.data.l10n.customizingMenus,
    1378                 priority: 10,
    1379                 menu_id: placeholderId
    1380             } );
    1381             api.section.add( customizeId, menuSection );
     1392            menuSection = api.Menus.createNavMenu( name );
    13821393
    13831394            // Clear name field.
     
    13911402                if ( checkbox.prop( 'checked' ) ) {
    13921403                    navMenuLocationSetting = api( 'nav_menu_locations[' + checkbox.data( 'location-id' ) + ']' );
    1393                     navMenuLocationSetting.set( placeholderId );
     1404                    navMenuLocationSetting.set( menuSection.params.menu_id );
    13941405
    13951406                    // Reset state for next new menu
     
    14011412
    14021413            // Focus on the new menu section.
    1403             editMenuSection = api.section( customizeId );
    1404             editMenuSection.focus( {
     1414            menuSection.focus( {
    14051415                completeCallback: function() {
    1406                     editMenuSection.highlightNewItemButton();
    1407                 }
    1408             } ); // @todo should we focus on the new menu's control and open the add-items panel? Thinking user flow...
     1416                    menuSection.highlightNewItemButton();
     1417                }
     1418            } );
    14091419        },
    14101420
     
    30093019
    30103020    /**
     3021     * wp.customize.Menus.NewMenuControl
     3022     *
     3023     * Customizer control for creating new menus and handling deletion of existing menus.
     3024     * Note that 'new_menu' must match the WP_Customize_New_Menu_Control::$type.
     3025     *
     3026     * @constructor
     3027     * @augments wp.customize.Control
     3028     * @deprecated 4.9.0 This class is no longer used due to new menu creation UX.
     3029     */
     3030    api.Menus.NewMenuControl = api.Control.extend({
     3031
     3032        /**
     3033         * Initialize.
     3034         *
     3035         * @deprecated 4.9.0
     3036         */
     3037        initialize: function() {
     3038            if ( 'undefined' !== typeof console && console.warn ) {
     3039                console.warn( '[DEPRECATED] wp.customize.NewMenuControl will be removed. Please use wp.customize.Menus.createNavMenu() instead.' );
     3040            }
     3041            api.Control.prototype.initialize.apply( this, arguments );
     3042        },
     3043
     3044        /**
     3045         * Set up the control.
     3046         *
     3047         * @deprecated 4.9.0
     3048         */
     3049        ready: function() {
     3050            this._bindHandlers();
     3051        },
     3052
     3053        _bindHandlers: function() {
     3054            var self = this,
     3055                name = $( '#customize-control-new_menu_name input' ),
     3056                submit = $( '#create-new-menu-submit' );
     3057            name.on( 'keydown', function( event ) {
     3058                if ( 13 === event.which ) { // Enter.
     3059                    self.submit();
     3060                }
     3061            } );
     3062            submit.on( 'click', function( event ) {
     3063                self.submit();
     3064                event.stopPropagation();
     3065                event.preventDefault();
     3066            } );
     3067        },
     3068
     3069        /**
     3070         * Create the new menu with the name supplied.
     3071         *
     3072         * @deprecated 4.9.0
     3073         */
     3074        submit: function() {
     3075
     3076            var control = this,
     3077                container = control.container.closest( '.accordion-section-new-menu' ),
     3078                nameInput = container.find( '.menu-name-field' ).first(),
     3079                name = nameInput.val(),
     3080                menuSection;
     3081
     3082            if ( ! name ) {
     3083                nameInput.addClass( 'invalid' );
     3084                nameInput.focus();
     3085                return;
     3086            }
     3087
     3088            menuSection = api.Menus.createNavMenu( name );
     3089
     3090            // Clear name field.
     3091            nameInput.val( '' );
     3092            nameInput.removeClass( 'invalid' );
     3093
     3094            wp.a11y.speak( api.Menus.data.l10n.menuAdded );
     3095
     3096            // Focus on the new menu section.
     3097            menuSection.focus();
     3098        }
     3099    });
     3100
     3101    /**
    30113102     * Extends wp.customize.controlConstructor with control constructor for
    30123103     * menu_location, menu_item, nav_menu, and new_menu.
     
    30173108        nav_menu: api.Menus.MenuControl,
    30183109        nav_menu_name: api.Menus.MenuNameControl,
     3110        new_menu: api.Menus.NewMenuControl, // @todo Remove in 5.0. See #42364.
    30193111        nav_menu_locations: api.Menus.MenuLocationsControl,
    30203112        nav_menu_auto_add: api.Menus.MenuAutoAddControl
  • trunk/src/wp-includes/class-wp-customize-control.php

    r41935 r42034  
    770770/**
    771771 * WP_Customize_Nav_Menu_Name_Control class.
     772 *
     773 * As this file is deprecated, it will trigger a deprecation notice if instantiated. In a subsequent
     774 * release, the require_once() here will be removed and _deprecated_file() will be called if file is
     775 * required at all.
     776 *
     777 * @deprecated 4.9.0 This file is no longer used due to new menu creation UX.
    772778 */
    773779require_once( ABSPATH . WPINC . '/customize/class-wp-customize-nav-menu-name-control.php' );
  • trunk/src/wp-includes/class-wp-customize-manager.php

    r42025 r42034  
    318318        require_once( ABSPATH . WPINC . '/customize/class-wp-customize-nav-menu-locations-control.php' );
    319319        require_once( ABSPATH . WPINC . '/customize/class-wp-customize-nav-menu-auto-add-control.php' );
     320        require_once( ABSPATH . WPINC . '/customize/class-wp-customize-new-menu-control.php' ); // @todo Remove in 5.0. See #42364.
    320321
    321322        require_once( ABSPATH . WPINC . '/customize/class-wp-customize-nav-menus-panel.php' );
     
    325326        require_once( ABSPATH . WPINC . '/customize/class-wp-customize-sidebar-section.php' );
    326327        require_once( ABSPATH . WPINC . '/customize/class-wp-customize-nav-menu-section.php' );
     328        require_once( ABSPATH . WPINC . '/customize/class-wp-customize-new-menu-section.php' ); // @todo Remove in 5.0. See #42364.
    327329
    328330        require_once( ABSPATH . WPINC . '/customize/class-wp-customize-custom-css-setting.php' );
  • trunk/src/wp-includes/class-wp-customize-section.php

    r41768 r42034  
    386386/** WP_Customize_Nav_Menu_Section class */
    387387require_once( ABSPATH . WPINC . '/customize/class-wp-customize-nav-menu-section.php' );
     388
     389/**
     390 * WP_Customize_New_Menu_Section class
     391 *
     392 * As this file is deprecated, it will trigger a deprecation notice if instantiated. In a subsequent
     393 * release, the require_once() here will be removed and _deprecated_file() will be called if file is
     394 * required at all.
     395 *
     396 * @deprecated 4.9.0 This file is no longer used due to new menu creation UX.
     397 */
     398require_once( ABSPATH . WPINC . '/customize/class-wp-customize-new-menu-section.php' );
  • trunk/src/wp-includes/customize/class-wp-customize-new-menu-control.php

    r41162 r42034  
    66 * @subpackage Customize
    77 * @since 4.4.0
     8 * @deprecated 4.9.0 This file is no longer used as of the menu creation UX introduced in #40104.
    89 */
    910
     
    1213 *
    1314 * @since 4.3.0
     15 * @deprecated 4.9.0 This class is no longer used as of the menu creation UX introduced in #40104.
    1416 *
    1517 * @see WP_Customize_Control
     
    2628
    2729    /**
     30     * Constructor.
     31     *
     32     * @since 4.9.0
     33     *
     34     * @param WP_Customize_Manager $manager Manager.
     35     * @param string               $id      ID.
     36     * @param array                $args    Args.
     37     */
     38    public function __construct( WP_Customize_Manager $manager, $id, array $args = array() ) {
     39        _deprecated_file( basename( __FILE__ ), '4.9.0' ); // @todo Move this outside of class in 5.0, and remove its require_once() from class-wp-customize-control.php. See #42364.
     40        parent::__construct( $manager, $id, $args );
     41    }
     42
     43    /**
    2844     * Render the control's content.
    2945     *
  • trunk/src/wp-includes/customize/class-wp-customize-new-menu-section.php

    r41162 r42034  
    66 * @subpackage Customize
    77 * @since 4.4.0
     8 * @deprecated 4.9.0 This file is no longer used as of the menu creation UX introduced in #40104.
    89 */
    910
     
    1112 * Customize Menu Section Class
    1213 *
    13  * Implements the new-menu-ui toggle button instead of a regular section.
    14  *
    1514 * @since 4.3.0
     15 * @deprecated 4.9.0 This class is no longer used as of the menu creation UX introduced in #40104.
    1616 *
    1717 * @see WP_Customize_Section
     
    2626     */
    2727    public $type = 'new_menu';
     28
     29    /**
     30     * Constructor.
     31     *
     32     * Any supplied $args override class property defaults.
     33     *
     34     * @since 4.9.0
     35     *
     36     * @param WP_Customize_Manager $manager Customizer bootstrap instance.
     37     * @param string               $id      An specific ID of the section.
     38     * @param array                $args    Section arguments.
     39     */
     40    public function __construct( WP_Customize_Manager $manager, $id, array $args = array() ) {
     41        _deprecated_file( basename( __FILE__ ), '4.9.0' ); // @todo Move this outside of class in 5.0, and remove its require_once() from class-wp-customize-section.php. See #42364.
     42        parent::__construct( $manager, $id, $args );
     43    }
    2844
    2945    /**
  • trunk/tests/qunit/wp-admin/js/customize-nav-menus.js

    r41899 r42034  
    114114    // @todo Add tests for api.Menus.MenuAutoAddControl
    115115    // @todo Add tests for api.Menus.MenuControl
    116     // @todo Add tests for api.Menus.NewMenuControl
    117116    // @todo Add tests for api.Menus.applySavedData
    118117    // @todo Add tests for api.Menus.focusMenuItemControl
     118    // @todo Add tests for api.Menus.createNavMenu
    119119
    120120    test( 'api.Menus.getMenuControl() should return the expected control', function() {
Note: See TracChangeset for help on using the changeset viewer.