Make WordPress Core

Ticket #28605: 28605.2.diff

File 28605.2.diff, 10.5 KB (added by westonruter, 11 years ago)

Refresh patch. PR amended: https://github.com/x-team/wordpress-develop/pull/20

  • src/wp-admin/admin-header.php

    diff --git src/wp-admin/admin-header.php src/wp-admin/admin-header.php
    index 1034975..2a8b8d7 100644
    $admin_body_class .= ' no-customize-support no-svg'; 
    177177
    178178<?php
    179179// Make sure the customize body classes are correct as early as possible.
    180 if ( current_user_can( 'edit_theme_options' ) )
     180if ( current_user_can( 'customize' ) )
    181181        wp_customize_support_script();
    182182?>
    183183
  • src/wp-admin/customize.php

    diff --git src/wp-admin/customize.php src/wp-admin/customize.php
    index 50119cd..0863781 100644
    define( 'IFRAME_REQUEST', true ); 
    1212/** Load WordPress Administration Bootstrap */
    1313require_once( dirname( __FILE__ ) . '/admin.php' );
    1414
    15 if ( ! current_user_can( 'edit_theme_options' ) ) {
     15if ( ! current_user_can( 'customize' ) ) {
    1616        wp_die( __( 'Cheatin&#8217; uh?' ) );
    1717}
    1818
    if ( $return ) { 
    2424        $return = wp_validate_redirect( $return );
    2525}
    2626if ( ! $return ) {
    27         $return = $url;
     27        if ( $url ) {
     28                $return = $url;
     29        } elseif ( current_user_can( 'edit_theme_options' ) ) {
     30                $return = admin_url( 'themes.php' );
     31        } else {
     32                $return = admin_url();
     33        }
    2834}
    2935
    3036global $wp_scripts, $wp_customize;
    do_action( 'customize_controls_print_scripts' ); 
    112118                                submit_button( $save_text, 'primary save', 'save', false );
    113119                        ?>
    114120                        <span class="spinner"></span>
    115                         <a class="customize-controls-close" href="<?php echo esc_url( $return ? $return : admin_url( 'themes.php' ) ); ?>">
     121                        <a class="customize-controls-close" href="<?php echo esc_url( $return ); ?>">
    116122                                <span class="screen-reader-text"><?php _e( 'Cancel' ); ?></span>
    117123                        </a>
    118124                </div>
  • src/wp-admin/includes/class-wp-upgrader-skins.php

    diff --git src/wp-admin/includes/class-wp-upgrader-skins.php src/wp-admin/includes/class-wp-upgrader-skins.php
    index c5d1d3f..cd5c68b 100644
    class Theme_Upgrader_Skin extends WP_Upgrader_Skin { 
    594594                        $activate_link = wp_nonce_url( $activate_link, 'switch-theme_' . $stylesheet );
    595595
    596596                        if ( get_stylesheet() == $stylesheet ) {
    597                                 if ( current_user_can( 'edit_theme_options' ) )
     597                                if ( current_user_can( 'customize' ) )
    598598                                        $update_actions['preview']  = '<a href="' . wp_customize_url( $stylesheet ) . '" class="hide-if-no-customize load-customize" title="' . esc_attr( sprintf( __('Customize &#8220;%s&#8221;'), $name ) ) . '">' . __('Customize') . '</a>';
    599599                        } elseif ( current_user_can( 'switch_themes' ) ) {
    600600                                $update_actions['preview']  = '<a href="' . esc_url( $preview_link ) . '" class="hide-if-customize" title="' . esc_attr( sprintf( __('Preview &#8220;%s&#8221;'), $name ) ) . '">' . __('Preview') . '</a>';
  • src/wp-admin/menu.php

    diff --git src/wp-admin/menu.php src/wp-admin/menu.php
    index d32a133..72105ad 100644
    $menu[59] = array( '', 'read', 'separator2', '', 'wp-menu-separator' ); 
    144144
    145145$appearance_cap = current_user_can( 'switch_themes') ? 'switch_themes' : 'edit_theme_options';
    146146
    147 $menu[60] = array( __('Appearance'), $appearance_cap, 'themes.php', '', 'menu-top menu-icon-appearance', 'menu-appearance', 'dashicons-admin-appearance' );
     147$customize_url = add_query_arg( 'return', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), 'customize.php' );
     148if ( current_user_can( $appearance_cap) ) {
     149        $menu[60] = array( __( 'Appearance' ), $appearance_cap, 'themes.php', '', 'menu-top menu-icon-appearance', 'menu-appearance', 'dashicons-admin-appearance' );
    148150        $submenu['themes.php'][5] = array( __( 'Themes' ), $appearance_cap, 'themes.php' );
    149151
    150152        $customize_url = add_query_arg( 'return', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), 'customize.php' );
    151         $submenu['themes.php'][6] = array( __( 'Customize' ), 'edit_theme_options', $customize_url, '', 'hide-if-no-customize' );
     153        $submenu['themes.php'][6] = array( __( 'Customize' ), 'customize', $customize_url, '', 'hide-if-no-customize' );
    152154        unset( $customize_url );
    153155        if ( current_theme_supports( 'menus' ) || current_theme_supports( 'widgets' ) ) {
    154156                $submenu['themes.php'][10] = array(__( 'Menus' ), 'edit_theme_options', 'nav-menus.php');
    155157        }
    156 
    157 unset( $appearance_cap );
     158} else {
     159        $menu[60] = array( __( 'Customize' ), 'customize', $customize_url, '', 'menu-top menu-icon-appearance hide-if-no-customize', 'menu-appearance', 'dashicons-admin-appearance' );
     160}
     161unset( $customize_url, $appearance_cap );
    158162
    159163// Add 'Editor' to the bottom of the Appearance menu.
    160164if ( ! is_multisite() )
  • src/wp-admin/themes.php

    diff --git src/wp-admin/themes.php src/wp-admin/themes.php
    index ad5896c..814fa24 100644
    foreach ( $themes as $theme ) : 
    212212        <div class="theme-actions">
    213213
    214214        <?php if ( $theme['active'] ) { ?>
    215                 <?php if ( $theme['actions']['customize'] ) { ?>
     215                <?php if ( $theme['actions']['customize'] && current_user_can( 'customize' ) ) { ?>
    216216                        <a class="button button-primary customize load-customize hide-if-no-customize" href="<?php echo $theme['actions']['customize']; ?>"><?php _e( 'Customize' ); ?></a>
    217217                <?php } ?>
    218218        <?php } else { ?>
    219219                <a class="button button-primary activate" href="<?php echo $theme['actions']['activate']; ?>"><?php _e( 'Activate' ); ?></a>
    220                 <a class="button button-secondary load-customize hide-if-no-customize" href="<?php echo $theme['actions']['customize']; ?>"><?php _e( 'Live Preview' ); ?></a>
    221                 <a class="button button-secondary hide-if-customize" href="<?php echo $theme['actions']['preview']; ?>"><?php _e( 'Preview' ); ?></a>
     220                <?php if ( current_user_can( 'customize' ) ) { ?>
     221                        <a class="button button-secondary load-customize hide-if-no-customize" href="<?php echo $theme['actions']['customize']; ?>"><?php _e( 'Live Preview' ); ?></a>
     222                        <a class="button button-secondary hide-if-customize" href="<?php echo $theme['actions']['preview']; ?>"><?php _e( 'Preview' ); ?></a>
     223                <?php } ?>
    222224        <?php } ?>
    223225
    224226        </div>
  • src/wp-includes/admin-bar.php

    diff --git src/wp-includes/admin-bar.php src/wp-includes/admin-bar.php
    index 9e4c115..01681e1 100644
    function wp_admin_bar_appearance_menu( $wp_admin_bar ) { 
    657657        if ( current_user_can( 'switch_themes' ) || current_user_can( 'edit_theme_options' ) )
    658658                $wp_admin_bar->add_menu( array( 'parent' => 'appearance', 'id' => 'themes', 'title' => __('Themes'), 'href' => admin_url('themes.php') ) );
    659659
    660         if ( ! current_user_can( 'edit_theme_options' ) )
    661                 return;
    662 
    663         $current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
    664         $wp_admin_bar->add_menu( array(
    665                 'parent' => 'appearance',
    666                 'id'     => 'customize',
    667                 'title'  => __('Customize'),
    668                 'href'   => add_query_arg( 'url', urlencode( $current_url ), wp_customize_url() ),
    669                 'meta'   => array(
    670                         'class' => 'hide-if-no-customize',
    671                 ),
    672         ) );
    673         add_action( 'wp_before_admin_bar_render', 'wp_customize_support_script' );
     660        if ( current_user_can( 'customize' ) ) {
     661                $current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
     662                $wp_admin_bar->add_menu( array(
     663                        'parent' => 'appearance',
     664                        'id'     => 'customize',
     665                        'title'  => __( 'Customize' ),
     666                        'href'   => add_query_arg( 'url', urlencode( $current_url ), wp_customize_url() ),
     667                        'meta'   => array(
     668                                'class' => 'hide-if-no-customize',
     669                        ),
     670                ) );
     671                add_action( 'wp_before_admin_bar_render', 'wp_customize_support_script' );
     672        }
    674673
    675         if ( current_theme_supports( 'widgets' )  )
    676                 $wp_admin_bar->add_menu( array( 'parent' => 'appearance', 'id' => 'widgets', 'title' => __('Widgets'), 'href' => admin_url('widgets.php') ) );
     674        if ( current_user_can( 'edit_theme_options' ) ) {
     675                if ( current_theme_supports( 'widgets' )  ) {
     676                        $wp_admin_bar->add_menu( array( 'parent' => 'appearance', 'id' => 'widgets', 'title' => __( 'Widgets' ), 'href' => admin_url( 'widgets.php' ) ) );
     677                }
    677678
    678         if ( current_theme_supports( 'menus' ) || current_theme_supports( 'widgets' ) )
    679                 $wp_admin_bar->add_menu( array( 'parent' => 'appearance', 'id' => 'menus', 'title' => __('Menus'), 'href' => admin_url('nav-menus.php') ) );
     679                if ( current_theme_supports( 'menus' ) || current_theme_supports( 'widgets' ) ) {
     680                        $wp_admin_bar->add_menu( array( 'parent' => 'appearance', 'id' => 'menus', 'title' => __( 'Menus' ), 'href' => admin_url( 'nav-menus.php' ) ) );
     681                }
    680682
    681         if ( current_theme_supports( 'custom-background' ) )
    682                 $wp_admin_bar->add_menu( array( 'parent' => 'appearance', 'id' => 'background', 'title' => __('Background'), 'href' => admin_url('themes.php?page=custom-background') ) );
     683                if ( current_theme_supports( 'custom-background' ) ) {
     684                        $wp_admin_bar->add_menu( array( 'parent' => 'appearance', 'id' => 'background', 'title' => __( 'Background' ), 'href' => admin_url( 'themes.php?page=custom-background' ) ) );
     685                }
    683686
    684         if ( current_theme_supports( 'custom-header' ) )
    685                 $wp_admin_bar->add_menu( array( 'parent' => 'appearance', 'id' => 'header', 'title' => __('Header'), 'href' => admin_url('themes.php?page=custom-header') ) );
     687                if ( current_theme_supports( 'custom-header' ) ) {
     688                        $wp_admin_bar->add_menu( array( 'parent' => 'appearance', 'id' => 'header', 'title' => __( 'Header' ), 'href' => admin_url( 'themes.php?page=custom-header' ) ) );
     689                }
     690        }
    686691}
    687692
    688693/**
  • src/wp-includes/capabilities.php

    diff --git src/wp-includes/capabilities.php src/wp-includes/capabilities.php
    index 42ec2f1..7f23159 100644
    function map_meta_cap( $cap, $user_id ) { 
    13041304                else
    13051305                        $caps[] = 'do_not_allow';
    13061306                break;
     1307        case 'customize' :
     1308                $caps[] = 'edit_theme_options';
     1309                break;
    13071310        default:
    13081311                // Handle meta capabilities for custom post types.
    13091312                $post_type_meta_caps = _post_type_meta_capabilities();
  • src/wp-includes/class-wp-customize-manager.php

    diff --git src/wp-includes/class-wp-customize-manager.php src/wp-includes/class-wp-customize-manager.php
    index 4929d15..a91ff0e 100644
    final class WP_Customize_Manager { 
    150150        public function setup_theme() {
    151151                send_origin_headers();
    152152
    153                 if ( is_admin() && ! $this->doing_ajax() )
    154                     auth_redirect();
    155                 elseif ( $this->doing_ajax() && ! is_user_logged_in() )
    156                     $this->wp_die( 0 );
     153                if ( is_admin() && ! $this->doing_ajax() ) {
     154                        auth_redirect();
     155                } elseif ( $this->doing_ajax() && ! is_user_logged_in() ) {
     156                        $this->wp_die( 0 );
     157                }
    157158
    158159                show_admin_bar( false );
    159160
    160                 if ( ! current_user_can( 'edit_theme_options' ) )
     161                if ( ! current_user_can( 'customize' ) ) {
    161162                        $this->wp_die( -1 );
     163                }
    162164
    163165                $this->original_stylesheet = get_stylesheet();
    164166