Make WordPress Core

Ticket #32678: 32678.diff

File 32678.diff, 8.6 KB (added by celloexpressions, 10 years ago)

Replace "appearance" with "admin" menu in admin bar, add top-level Customize link for admin and front-end.

  • src/wp-includes/admin-bar.php

     
    313313                        'href'   => admin_url(),
    314314                ) );
    315315
    316                 // Add the appearance submenu items.
    317                 wp_admin_bar_appearance_menu( $wp_admin_bar );
     316                // Add the admin submenu items.
     317                wp_admin_bar_admin_menu( $wp_admin_bar );
    318318        }
    319319}
    320320
     
    655655}
    656656
    657657/**
    658  * Add appearance submenu items to the "Site Name" menu.
     658 * Add "Customize" menu.
    659659 *
    660  * @since 3.1.0
     660 * @since 4.3.0
    661661 *
    662662 * @param WP_Admin_Bar $wp_admin_bar
    663663 */
    664 function wp_admin_bar_appearance_menu( $wp_admin_bar ) {
    665         $wp_admin_bar->add_group( array( 'parent' => 'site-name', 'id' => 'appearance' ) );
    666 
    667         $current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
    668         $customize_url = add_query_arg( 'url', urlencode( $current_url ), wp_customize_url() );
    669 
    670         if ( current_user_can( 'switch_themes' ) ) {
    671                 $wp_admin_bar->add_menu( array(
    672                         'parent' => 'appearance',
    673                         'id'     => 'themes',
    674                         'title'  => __( 'Themes' ),
    675                         'href'   => admin_url( 'themes.php' ),
    676                         'meta'   => array(
    677                                 'class' => 'hide-if-customize',
    678                         ),
    679                 ) );
    680 
    681                 if ( current_user_can( 'customize' ) ) {
    682                         $wp_admin_bar->add_menu( array(
    683                                 'parent' => 'appearance',
    684                                 'id'     => 'customize-themes',
    685                                 'title'  => __( 'Themes' ),
    686                                 'href'   => add_query_arg( urlencode( 'autofocus[section]' ), 'themes', $customize_url ), // urlencode() needed due to #16859
    687                                 'meta'   => array(
    688                                         'class' => 'hide-if-no-customize',
    689                                 ),
    690                         ) );
    691                 }
    692         }
    693 
     664function wp_admin_bar_customize_menu( $wp_admin_bar ) {
    694665        if ( current_user_can( 'customize' ) ) {
     666                $current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
     667                $customize_url = add_query_arg( 'url', urlencode( $current_url ), wp_customize_url() );
     668                $title = '<span class="ab-icon"></span><span class="ab-label">' . __( 'Customize' ) . '</span>';
    695669                $wp_admin_bar->add_menu( array(
    696                         'parent' => 'appearance',
    697670                        'id'     => 'customize',
    698                         'title'  => __('Customize'),
     671                        'title'  => $title,
    699672                        'href'   => $customize_url,
    700673                        'meta'   => array(
    701674                                'class' => 'hide-if-no-customize',
     
    703676                ) );
    704677                add_action( 'wp_before_admin_bar_render', 'wp_customize_support_script' );
    705678        }
     679}
    706680
    707         if ( ! current_user_can( 'edit_theme_options' ) ) {
    708                 return;
     681/**
     682 * Add admin submenu items to the "Site Name" menu.
     683 *
     684 * @since 4.3.0
     685 *
     686 * @param WP_Admin_Bar $wp_admin_bar
     687 */
     688function wp_admin_bar_admin_menu( $wp_admin_bar ) {
     689        $wp_admin_bar->add_group( array( 'parent' => 'site-name', 'id' => 'admin' ) );
     690
     691        // Post types.
     692        $cpts = (array) get_post_types( array( 'show_in_admin_bar' => true ), 'objects' );
     693
     694        if ( isset( $cpts['post'] ) && current_user_can( $cpts['post']->cap->edit_posts ) ) {
     695                $actions[ 'edit.php' ] = array( $cpts['post']->labels->name, 'edit-posts' );
    709696        }
    710697
    711         if ( current_theme_supports( 'widgets' )  ) {
    712                 $wp_admin_bar->add_menu( array(
    713                         'parent' => 'appearance',
    714                         'id'     => 'widgets',
    715                         'title'  => __( 'Widgets' ),
    716                         'href'   => admin_url( 'widgets.php' ),
    717                         'meta'   => array(
    718                                 'class' => 'hide-if-customize',
    719                         ),
    720                 ) );
     698        if ( isset( $cpts['attachment'] ) && current_user_can( 'edit_posts' ) ) {
     699                $actions[ 'upload.php' ] = array( $cpts['attachment']->labels->name, 'edit-media' );
     700        }
    721701
    722                 if ( current_user_can( 'customize' ) ) {
    723                         $wp_admin_bar->add_menu( array(
    724                                 'parent' => 'appearance',
    725                                 'id'     => 'customize-widgets',
    726                                 'title'  => __( 'Widgets' ),
    727                                 'href'   => add_query_arg( urlencode( 'autofocus[panel]' ), 'widgets', $customize_url ), // urlencode() needed due to #16859
    728                                 'meta'   => array(
    729                                         'class' => 'hide-if-no-customize',
    730                                 ),
    731                         ) );
    732                 }
     702        if ( isset( $cpts['page'] ) && current_user_can( $cpts['page']->cap->edit_posts ) ) {
     703                $actions[ 'edit.php?post_type=page' ] = array( $cpts['page']->labels->name, 'edit-pages' );
    733704        }
    734705
    735         if ( current_theme_supports( 'menus' ) || current_theme_supports( 'widgets' ) )
    736                 $wp_admin_bar->add_menu( array( 'parent' => 'appearance', 'id' => 'menus', 'title' => __('Menus'), 'href' => admin_url('nav-menus.php') ) );
     706        unset( $cpts['post'], $cpts['page'], $cpts['attachment'] );
    737707
    738         if ( current_theme_supports( 'custom-background' ) ) {
    739                 $wp_admin_bar->add_menu( array(
    740                         'parent' => 'appearance',
    741                         'id'     => 'background',
    742                         'title'  => __( 'Background' ),
    743                         'href'   => admin_url( 'themes.php?page=custom-background' ),
    744                         'meta'   => array(
    745                                 'class' => 'hide-if-customize',
    746                         ),
    747                 ) );
     708        // Add any additional custom post types.
     709        foreach ( $cpts as $cpt ) {
     710                if ( ! current_user_can( $cpt->cap->edit_posts ) )
     711                        continue;
    748712
    749                 if ( current_user_can( 'customize' ) ) {
     713                $key = 'edit.php?post_type=' . $cpt->name;
     714                $actions[ $key ] = array( $cpt->labels->name, 'edit-' . $cpt->name );
     715        }
     716
     717        if ( $actions ) {
     718                foreach ( $actions as $link => $action ) {
     719                        list( $title, $id ) = $action;
     720
    750721                        $wp_admin_bar->add_menu( array(
    751                                 'parent' => 'appearance',
    752                                 'id'     => 'customize-background',
    753                                 'title'  => __( 'Background' ),
    754                                 'href'   => add_query_arg( urlencode( 'autofocus[control]' ), 'background_image', $customize_url ), // urlencode() needed due to #16859
    755                                 'meta'   => array(
    756                                         'class' => 'hide-if-no-customize',
    757                                 ),
     722                                'parent'    => 'admin',
     723                                'id'        => $id,
     724                                'title'     => $title,
     725                                'href'      => admin_url( $link )
    758726                        ) );
    759727                }
    760728        }
    761729
    762         if ( current_theme_supports( 'custom-header' ) ) {
     730        // Appearance.
     731        if ( current_user_can( 'switch_themes' ) ) {
    763732                $wp_admin_bar->add_menu( array(
    764                         'parent' => 'appearance',
    765                         'id'     => 'header',
    766                         'title'  => __( 'Header' ),
    767                         'href'   => admin_url( 'themes.php?page=custom-header' ),
    768                         'meta'   => array(
    769                                 'class' => 'hide-if-customize',
    770                         ),
     733                        'parent' => 'admin',
     734                        'id'     => 'themes',
     735                        'title'  => __( 'Appearance' ), // @todo should we just say themes here since there isn't a submenu?
     736                        'href'   => admin_url( 'themes.php' )
    771737                ) );
     738        }
     739       
     740        // Plugins.
     741        if ( current_user_can( 'activate_plugins' ) ) {
     742                $wp_admin_bar->add_menu( array(
     743                        'parent' => 'admin',
     744                        'id'     => 'plugins',
     745                        'title'  => __( 'Plugins' ),
     746                        'href'   => admin_url( 'plugins.php' )
     747                ) );
     748        }
    772749
    773                 if ( current_user_can( 'customize' ) ) {
    774                         $wp_admin_bar->add_menu( array(
    775                                 'parent' => 'appearance',
    776                                 'id'     => 'customize-header',
    777                                 'title'  => __( 'Header' ),
    778                                 'href'   => add_query_arg( urlencode( 'autofocus[control]' ), 'header_image', $customize_url ), // urlencode() needed due to #16859
    779                                 'meta'   => array(
    780                                         'class' => 'hide-if-no-customize',
    781                                 ),
    782                         ) );
    783                 }
     750        // Users.
     751        if ( current_user_can( 'edit_users' ) ) {
     752                $wp_admin_bar->add_menu( array(
     753                        'parent' => 'admin',
     754                        'id'     => 'edit-users',
     755                        'title'  => __( 'Users' ),
     756                        'href'   => admin_url( 'users.php' )
     757                ) );
    784758        }
    785759
     760        // Settings.
     761        if ( current_user_can( 'manage_options' ) ) {
     762                $wp_admin_bar->add_menu( array(
     763                        'parent' => 'admin',
     764                        'id'     => 'settings',
     765                        'title'  => __( 'Settings' ),
     766                        'href'   => admin_url( 'options.php' )
     767                ) );
     768        }
    786769}
    787770
    788771/**
  • src/wp-includes/class-wp-admin-bar.php

     
    557557                add_action( 'admin_bar_menu', 'wp_admin_bar_my_sites_menu', 20 );
    558558                add_action( 'admin_bar_menu', 'wp_admin_bar_site_menu', 30 );
    559559                add_action( 'admin_bar_menu', 'wp_admin_bar_updates_menu', 40 );
     560                add_action( 'admin_bar_menu', 'wp_admin_bar_customize_menu', 75 );
    560561
    561562                // Content related.
    562563                if ( ! is_network_admin() && ! is_user_admin() ) {
  • src/wp-includes/css/admin-bar.css

     
    501501        margin: 6px 8px 0 -2px;
    502502}
    503503
    504 #wpadminbar #wp-admin-bar-appearance {
    505         margin-top: -12px;
     504#wpadminbar #wp-admin-bar-site-name-default {
     505        padding-bottom: 2px;
    506506}
    507507
     508#wpadminbar #wp-admin-bar-themes {
     509        margin-top: 8px;
     510}
     511
    508512#wpadminbar #wp-admin-bar-my-sites > .ab-item:before,
    509513#wpadminbar #wp-admin-bar-site-name > .ab-item:before {
    510514        content: '\f112';
     
    551555}
    552556
    553557/**
     558 * Customize
     559 */
     560#wpadminbar #wp-admin-bar-customize .ab-icon {
     561        margin-right: 6px;
     562}
     563
     564#wpadminbar #wp-admin-bar-customize .ab-icon:before {
     565        content: '\f180';
     566        top: 2px;
     567}
     568
     569/**
    554570 * Updates
    555571 */
    556572#wpadminbar #wp-admin-bar-updates .ab-icon:before {