Make WordPress Core

Ticket #13273: 13273.diff

File 13273.diff, 7.1 KB (added by celloexpressions, 9 years ago)

Introduce support for placeholder menu items, which function as custom items without urls.

  • src/wp-admin/css/nav-menus.css

     
    399399        float: left;
    400400}
    401401
     402#menu-item-placeholder-wrap {
     403        margin-left: 72px;
     404}
     405
    402406/* Menu item types */
    403407.quick-search {
    404408        width: 190px;
     
    643647        text-align: center;
    644648}
    645649
     650.menu-item-placeholder .field-link-target,
     651.menu-item-placeholder .field-xfn {
     652        display: none;
     653}
     654
    646655.link-to-original {
    647656        display: block;
    648657        margin: 0 0 10px;
  • src/wp-admin/includes/ajax-actions.php

     
    10511051                if (
    10521052                        ! empty( $menu_item_data['menu-item-type'] ) &&
    10531053                        'custom' != $menu_item_data['menu-item-type'] &&
     1054                        'placeholder' != $menu_item_data['menu-item-type'] &&
    10541055                        ! empty( $menu_item_data['menu-item-object-id'] )
    10551056                ) {
    10561057                        switch( $menu_item_data['menu-item-type'] ) {
  • src/wp-admin/includes/nav-menu.php

     
    195195                                </p>
    196196
    197197                                <div class="menu-item-actions description-wide submitbox">
    198                                         <?php if( 'custom' != $item->type && $original_title !== false ) : ?>
     198                                        <?php if( 'custom' != $item->type && 'placeholder' != $item->type && $original_title !== false ) : ?>
    199199                                                <p class="link-to-original">
    200200                                                        <?php printf( __('Original: %s'), '<a href="' . esc_attr( $item->url ) . '">' . esc_html( $original_title ) . '</a>' ); ?>
    201201                                                </p>
     
    576576
    577577        ?>
    578578        <div class="customlinkdiv" id="customlinkdiv">
    579                 <input type="hidden" value="custom" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-type]" />
     579                <input type="hidden" value="custom" id="custom-menu-item-type" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-type]" />
     580                <p id="menu-item-placeholder-wrap">
     581                        <label for="custom-menu-item-placeholder">
     582                                <input id="custom-menu-item-placeholder" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-placeholder]" type="checkbox" value="1" > <?php _e( 'Placeholder' ); ?>
     583                        </label>
     584                </p>
     585
    580586                <p id="menu-item-url-wrap">
    581587                        <label class="howto" for="custom-menu-item-url">
    582588                                <span><?php _e('URL'); ?></span>
     
    10471053
    10481054                // Loop through all the menu items' POST values
    10491055                foreach( (array) $menu_data as $_possible_db_id => $_item_object_data ) {
     1056                        if ( isset( $_item_object_data['menu-item-placeholder'] ) ) {
     1057                                $_item_object_data['menu-item-type'] = 'placeholder';
     1058                        }
    10501059                        if (
    10511060                                empty( $_item_object_data['menu-item-object-id'] ) && // checkbox is not checked
    10521061                                (
    10531062                                        ! isset( $_item_object_data['menu-item-type'] ) || // and item type either isn't set
    1054                                         in_array( $_item_object_data['menu-item-url'], array( 'http://', '' ) ) || // or URL is the default
    1055                                         ! ( 'custom' == $_item_object_data['menu-item-type'] && ! isset( $_item_object_data['menu-item-db-id'] ) ) || // or it's not a custom menu item (but not the custom home page)
     1063                                        ( 'placeholder' != $_item_object_data['menu-item-type'] && in_array( $_item_object_data['menu-item-url'], array( 'http://', '' ) ) ) || // Or URL is the default (and it isn't a placeholder).
     1064                                        ! ( in_array( $_item_object_data['menu-item-type'], array( 'custom', 'placeholder' ) ) && ! isset( $_item_object_data['menu-item-db-id'] ) ) || // Or it's not a custom or placeholder menu item (but not the custom home page).
    10561065                                        ! empty( $_item_object_data['menu-item-db-id'] ) // or it *is* a custom menu item that already exists
    10571066                                )
    10581067                        ) {
  • src/wp-admin/js/nav-menu.js

     
    791791                                        $( '#submit-customlinkdiv' ).click();
    792792                                }
    793793                        });
     794                        $( '#custom-menu-item-placeholder').change( function() {
     795                                if ( this.checked ) {
     796                                        $( '#menu-item-url-wrap' ).slideUp( 'fast' );
     797                                        $( '#custom-menu-item-type' ).val( 'placeholder' );
     798                                } else {
     799                                        $( '#menu-item-url-wrap' ).slideDown( 'fast' );
     800                                        $( '#custom-menu-item-type' ).val( 'custom' );
     801                                }
     802                        } );
    794803                },
    795804
    796805                /**
     
    883892                },
    884893
    885894                addCustomLink : function( processMethod ) {
    886                         var url = $('#custom-menu-item-url').val(),
     895                        var type = $('#custom-menu-item-type').val(),
     896                                url = $('#custom-menu-item-url').val(),
    887897                                label = $('#custom-menu-item-name').val();
    888898
    889899                        processMethod = processMethod || api.addMenuItemToBottom;
    890900
    891                         if ( '' === url || 'http://' == url )
     901                        if ( 'placeholder' == type ) {
     902                                url = '';
     903                        } else if ( 'custom' != type ) {
    892904                                return false;
     905                        } else if ( '' === url || 'http://' == url ) {
     906                                return false;
     907                        }
    893908
    894909                        // Show the ajax spinner
    895910                        $('.customlinkdiv .spinner').show();
    896                         this.addLinkToMenu( url, label, processMethod, function() {
     911                        this.addLinkToMenu( type, url, label, processMethod, function() {
    897912                                // Remove the ajax spinner
    898913                                $('.customlinkdiv .spinner').hide();
    899914                                // Set custom link form back to defaults
     
    902917                        });
    903918                },
    904919
    905                 addLinkToMenu : function(url, label, processMethod, callback) {
     920                addLinkToMenu : function( type, url, label, processMethod, callback ) {
    906921                        processMethod = processMethod || api.addMenuItemToBottom;
    907922                        callback = callback || function(){};
    908923
    909924                        api.addItemToMenu({
    910925                                '-1': {
    911                                         'menu-item-type': 'custom',
     926                                        'menu-item-type': type,
    912927                                        'menu-item-url': url,
    913928                                        'menu-item-title': label
    914929                                }
  • src/wp-includes/nav-menu.php

     
    349349
    350350        $original_parent = 0 < $menu_item_db_id ? get_post_field( 'post_parent', $menu_item_db_id ) : 0;
    351351
    352         if ( 'custom' != $args['menu-item-type'] ) {
     352        if ( 'custom' != $args['menu-item-type'] && 'placeholder' != $args['menu-item-type'] ) {
    353353                /* if non-custom menu item, then:
    354354                        * use original object's URL
    355355                        * blank default title to sync with original object's
     
    407407        if ( 'custom' == $args['menu-item-type'] ) {
    408408                $args['menu-item-object-id'] = $menu_item_db_id;
    409409                $args['menu-item-object'] = 'custom';
     410        } elseif ( 'placeholder' == $args['menu-item-type'] ) {
     411                $args['menu-item-object-id'] = $menu_item_db_id;
     412                $args['menu-item-object'] = 'placeholder';
     413                $args['menu-item-url'] = '';
    410414        }
    411415
    412416        $menu_item_db_id = (int) $menu_item_db_id;
     
    680684                                $menu_item->title = '' == $menu_item->post_title ? $original_title : $menu_item->post_title;
    681685
    682686                        } else {
    683                                 $menu_item->type_label = __('Custom');
     687                                $menu_item->type_label = ( 'placeholder' == $menu_item->type ) ? __( 'Placeholder' ) : __( 'Custom' );
    684688                                $menu_item->title = $menu_item->post_title;
    685689                                $menu_item->url = empty( $menu_item->url ) ? get_post_meta( $menu_item->ID, '_menu_item_url', true ) : $menu_item->url;
    686690                        }