Make WordPress Core

Ticket #39334: 39334.1.patch

File 39334.1.patch, 16.1 KB (added by Mista-Flo, 8 years ago)

First patch

  • wp-admin/includes/theme.php

    diff --git wp-admin/includes/theme.php wp-admin/includes/theme.php
    index 822fb5b..0e738c4 100644
    function wp_prepare_themes_for_js( $themes = null ) { 
    564564
    565565        $parents = array();
    566566
     567        /** @var WP_Theme $theme */
    567568        foreach ( $themes as $theme ) {
    568569                $slug = $theme->get_stylesheet();
    569570                $encoded_slug = urlencode( $slug );
    function wp_prepare_themes_for_js( $themes = null ) { 
    602603                                'activate' => current_user_can( 'switch_themes' ) ? wp_nonce_url( admin_url( 'themes.php?action=activate&stylesheet=' . $encoded_slug ), 'switch-theme_' . $slug ) : null,
    603604                                'customize' => $customize_action,
    604605                                'delete'   => current_user_can( 'delete_themes' ) ? wp_nonce_url( admin_url( 'themes.php?action=delete&stylesheet=' . $encoded_slug ), 'delete-theme_' . $slug ) : null,
     606                                'network_activate' => ( current_user_can( 'manage_network_themes' ) && ! $theme->is_allowed() ) ? wp_nonce_url( admin_url( 'themes.php?action=network_activate&stylesheet=' . $encoded_slug ), 'network-activate_' . $slug ) : null,
    605607                        ),
    606608                );
    607609        }
  • wp-admin/themes.php

    diff --git wp-admin/themes.php wp-admin/themes.php
    index c02c17a..ced36f9 100644
    if ( ! current_user_can( 'switch_themes' ) && ! current_user_can( 'edit_theme_op 
    1717        );
    1818}
    1919
     20if ( current_user_can( 'manage_network_themes' ) && isset($_GET['action'] ) ) {
     21        if ( 'network_activate' === $_GET['action'] ) {
     22                check_admin_referer( 'network-activate_' . $_GET['stylesheet'] );
     23                WP_Theme::network_enable_theme( $_GET['stylesheet'] );
     24                wp_redirect( admin_url('themes.php?network_activated=true') );
     25                exit;
     26        }
     27}
     28
    2029if ( current_user_can( 'switch_themes' ) && isset($_GET['action'] ) ) {
    2130        if ( 'activate' == $_GET['action'] ) {
    2231                check_admin_referer('switch-theme_' . $_GET['stylesheet']);
    get_current_screen()->set_help_sidebar( 
    119128        '<p>' . __( '<a href="https://wordpress.org/support/">Support Forums</a>' ) . '</p>'
    120129);
    121130
    122 if ( current_user_can( 'switch_themes' ) ) {
     131if ( current_user_can( 'manage_network_themes' ) ) {
     132        // Display all themes to allow network administrator who can manage themes to network activate it
     133        $themes = wp_prepare_themes_for_js( wp_get_themes() );
     134} else if ( current_user_can( 'switch_themes' ) ) {
     135        // Display only allowed themes
    123136        $themes = wp_prepare_themes_for_js();
    124137} else {
    125138        $themes = wp_prepare_themes_for_js( array( wp_get_theme() ) );
    require_once( ABSPATH . 'wp-admin/admin-header.php' ); 
    165178        <hr class="wp-header-end">
    166179<?php
    167180if ( ! validate_current_theme() || isset( $_GET['broken'] ) ) : ?>
    168 <div id="message1" class="updated notice is-dismissible"><p><?php _e('The active theme is broken. Reverting to the default theme.'); ?></p></div>
     181        <div id="message1" class="updated notice is-dismissible"><p><?php _e('The active theme is broken. Reverting to the default theme.'); ?></p></div>
    169182<?php elseif ( isset($_GET['activated']) ) :
    170                 if ( isset( $_GET['previewed'] ) ) { ?>
     183        if ( isset( $_GET['previewed'] ) ) : ?>
    171184                <div id="message2" class="updated notice is-dismissible"><p><?php _e( 'Settings saved and theme activated.' ); ?> <a href="<?php echo home_url( '/' ); ?>"><?php _e( 'Visit site' ); ?></a></p></div>
    172                 <?php } else { ?>
    173 <div id="message2" class="updated notice is-dismissible"><p><?php _e( 'New theme activated.' ); ?> <a href="<?php echo home_url( '/' ); ?>"><?php _e( 'Visit site' ); ?></a></p></div><?php
    174                 }
    175         elseif ( isset($_GET['deleted']) ) : ?>
    176 <div id="message3" class="updated notice is-dismissible"><p><?php _e('Theme deleted.') ?></p></div>
     185        <?php else : ?>
     186                <div id="message2" class="updated notice is-dismissible"><p><?php _e( 'New theme activated.' ); ?> <a href="<?php echo home_url( '/' ); ?>"><?php _e( 'Visit site' ); ?></a></p></div>
     187        <?php endif;
     188elseif ( isset( $_GET['deleted'] ) ) : ?>
     189        <div id="message3" class="updated notice is-dismissible"><p><?php _e('Theme deleted.') ?></p></div>
    177190<?php elseif ( isset( $_GET['delete-active-child'] ) ) : ?>
    178191        <div id="message4" class="error"><p><?php _e( 'You cannot delete a theme while it has an active child theme.' ); ?></p></div>
    179 <?php
    180 endif;
     192<?php elseif ( isset( $_GET['network_activated'] ) ) : ?>
     193        <div id="message5" class="updated notice is-dismissible"><p><?php _e( 'New theme activated on the network, you can now active it on your site.' ); ?></p></div>
     194<?php endif;
    181195
    182196$ct = wp_get_theme();
    183197
    foreach ( $themes as $theme ) : 
    281295
    282296        <div class="theme-actions">
    283297
    284         <?php if ( $theme['active'] ) { ?>
     298        <?php if ( $theme['active'] ) : ?>
    285299                <?php if ( $theme['actions']['customize'] && current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) { ?>
    286300                        <a class="button button-primary customize load-customize hide-if-no-customize" href="<?php echo $theme['actions']['customize']; ?>"><?php _e( 'Customize' ); ?></a>
    287301                <?php } ?>
    288         <?php } else { ?>
     302        <?php else : ?>
    289303                <?php
    290                 /* translators: %s: Theme name */
    291                 $aria_label = sprintf( _x( 'Activate %s', 'theme' ), '{{ data.name }}' );
    292                 ?>
    293                 <a class="button activate" href="<?php echo $theme['actions']['activate']; ?>" aria-label="<?php echo esc_attr( $aria_label ); ?>"><?php _e( 'Activate' ); ?></a>
    294                 <?php if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) { ?>
    295                         <a class="button button-primary load-customize hide-if-no-customize" href="<?php echo $theme['actions']['customize']; ?>"><?php _e( 'Live Preview' ); ?></a>
    296                 <?php } ?>
    297         <?php } ?>
     304                if ( $theme['actions']['network_activate'] ) :
     305                        /* translators: %s: Theme name */
     306                        $aria_label = sprintf( _x( 'Network Activate %s', 'theme' ), '{{ data.name }}' );
     307                        ?>
     308                        <a class="button activate" href="<?php echo $theme['actions']['network_activate']; ?>" aria-label="<?php echo esc_attr( $aria_label ); ?>"><?php _e( 'Network Activate' ); ?></a>
     309                <?php else :
     310                        /* translators: %s: Theme name */
     311                        $aria_label = sprintf( _x( 'Activate %s', 'theme' ), '{{ data.name }}' );
     312                        ?>
     313                        <a class="button activate" href="<?php echo $theme['actions']['activate']; ?>" aria-label="<?php echo esc_attr( $aria_label ); ?>"><?php _e( 'Activate' ); ?></a>
     314                        <?php if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) { ?>
     315                                <a class="button button-primary load-customize hide-if-no-customize" href="<?php echo $theme['actions']['customize']; ?>"><?php _e( 'Live Preview' ); ?></a>
     316                        <?php } ?>
     317                <?php endif; ?>
     318        <?php endif; ?>
    298319
    299320        </div>
    300321</div>
    $can_install = current_user_can( 'install_themes' ); 
    419440                                <a class="button button-primary customize load-customize hide-if-no-customize" href="{{{ data.actions.customize }}}"><?php _e( 'Customize' ); ?></a>
    420441                        <# } #>
    421442                <# } else { #>
    422                         <?php
    423                         /* translators: %s: Theme name */
    424                         $aria_label = sprintf( _x( 'Activate %s', 'theme' ), '{{ data.name }}' );
    425                         ?>
    426                         <a class="button activate" href="{{{ data.actions.activate }}}" aria-label="<?php echo $aria_label; ?>"><?php _e( 'Activate' ); ?></a>
    427                         <a class="button button-primary load-customize hide-if-no-customize" href="{{{ data.actions.customize }}}"><?php _e( 'Live Preview' ); ?></a>
     443                        <# if ( data.actions.network_activate ) { #>
     444                                <?php
     445                                /* translators: %s: Theme name */
     446                                $aria_label = sprintf( _x( 'Network Activate %s', 'theme' ), '{{ data.name }}' );
     447                                ?>
     448                                <a class="button activate" href="{{{ data.actions.network_activate }}}" aria-label="<?php echo esc_attr( $aria_label ); ?>"><?php _e( 'Network Activate' ); ?></a>
     449                        <# } else { #>
     450                                <?php
     451                                /* translators: %s: Theme name */
     452                                $aria_label = sprintf( _x( 'Activate %s', 'theme' ), '{{ data.name }}' );
     453                                ?>
     454                                <a class="button activate" href="{{{ data.actions.activate }}}" aria-label="<?php echo $aria_label; ?>"><?php _e( 'Activate' ); ?></a>
     455                                <a class="button button-primary load-customize hide-if-no-customize" href="{{{ data.actions.customize }}}"><?php _e( 'Live Preview' ); ?></a>
     456                        <# } #>
    428457                <# } #>
    429458        </div>
    430459</script>