WordPress.org

Make WordPress Core

Changeset 16242


Ignore:
Timestamp:
11/08/10 21:52:54 (3 years ago)
Author:
ryan
Message:

site-themes.php cleanup. Props PeteMall. see #14897

Location:
trunk/wp-admin
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/class-wp-ms-themes-list-table.php

    r16241 r16242  
    88 */ 
    99class WP_MS_Themes_List_Table extends WP_List_Table { 
     10     
     11    var $site_id; 
     12    var $is_site_themes; 
    1013 
    1114    function WP_MS_Themes_List_Table() { 
     
    3841        } 
    3942 
    40         if ( !current_user_can('manage_network_themes') ) 
    41             wp_die( __( 'You do not have sufficient permissions to manage themes for this site.' ) ); 
     43        if ( $this->is_site_themes && !current_user_can('manage_sites') )  
     44            wp_die( __( 'You do not have sufficient permissions to manage themes for this site.' ) );  
     45        else if ( !$this->is_site_themes && !current_user_can('manage_network_themes') )  
     46            wp_die( __( 'You do not have sufficient permissions to manage network themes.' ) ); 
    4247    } 
    4348 
     
    5560        ); 
    5661 
    57         $allowed_themes = get_site_allowed_themes(); 
     62        $site_allowed_themes = get_site_allowed_themes();  
     63        if ( !$this->is_site_themes )  
     64            $allowed_themes = $site_allowed_themes;  
     65        else  
     66            $allowed_themes = wpmu_get_blog_allowedthemes( $this->site_id ); 
     67         
    5868        $current = get_site_transient( 'update_themes' ); 
    5969 
    6070        foreach ( (array) $themes['all'] as $key => $theme ) { 
    6171            $theme_key = esc_html( $theme['Stylesheet'] ); 
     72 
    6273            if ( isset( $allowed_themes [ $theme_key ] ) )  { 
    6374                $themes['all'][$key]['enabled'] = true; 
     
    7081            if ( isset( $current->response[ $theme['Template'] ] ) ) 
    7182                $themes['upgrade'][$key] = $themes['all'][$key]; 
     83 
     84            if ( $this->is_site_themes && isset( $site_allowed_themes[$theme_key] ) ) {  
     85                unset( $themes['all'][$key] );  
     86                unset( $themes['enabled'][$key] );  
     87                unset( $themes['disabled'][$key] );  
     88            } 
    7289        } 
    7390 
     
    189206            } 
    190207 
     208            if ( $this->is_site_themes )  
     209                $url = 'site-themes.php?id=' . $this->site_id;  
     210            else  
     211                $url = 'themes.php'; 
     212 
    191213            $status_links[$type] = sprintf( "<a href='%s' %s>%s</a>", 
    192                 add_query_arg('theme_status', $type, 'themes.php'), 
     214                add_query_arg('theme_status', $type, $url), 
    193215                ( $type == $status ) ? ' class="current"' : '', 
    194216                sprintf( $text, number_format_i18n( $count ) ) 
     
    204226        $actions = array(); 
    205227        if ( 'enabled' != $status ) 
    206             $actions['network-enable-selected'] = __( 'Enable' ); 
     228            $actions['enable-selected'] = __( 'Enable' ); 
    207229        if ( 'disabled' != $status ) 
    208             $actions['network-disable-selected'] = __( 'Disable' ); 
     230            $actions['disable-selected'] = __( 'Disable' ); 
    209231        if ( current_user_can( 'update_themes' ) ) 
    210232            $actions['update-selected'] = __( 'Update' ); 
     
    226248 
    227249        $context = $status; 
     250         
     251        if ( $this->is_site_themes ) 
     252            $url = "site-themes.php?id={$this->site_id}&amp;"; 
     253        else 
     254            $url = 'themes.php?'; 
    228255 
    229256        foreach ( $this->items as $key => $theme ) { 
    230257            // preorder 
    231258            $actions = array( 
    232                 'network_enable' => '', 
    233                 'network_disable' => '', 
     259                'enable' => '', 
     260                'disable' => '', 
    234261                'edit' => '' 
    235262            ); 
     
    237264            $theme_key = esc_html( $theme['Stylesheet'] ); 
    238265 
    239             if ( empty( $theme['enabled'] ) ) { 
    240                 if ( current_user_can( 'manage_network_themes' ) ) 
    241                     $actions['network_enable'] = '<a href="' . wp_nonce_url('themes.php?action=network-enable&amp;theme=' . $theme_key . '&amp;paged=' . $page . '&amp;s=' . $s, 'enable-theme_' . $theme_key) . '" title="' . __('Enable this theme for all sites in this network') . '" class="edit">' . __('Enable') . '</a>'; 
    242             } else { 
    243                 if ( current_user_can( 'manage_network_themes' ) ) 
    244                     $actions['network_disable'] = '<a href="' . wp_nonce_url('themes.php?action=network-disable&amp;theme=' . $theme_key . '&amp;paged=' . $page . '&amp;s=' . $s, 'disable-theme_' . $theme_key) . '" title="' . __('Disable this theme') . '">' . __('Disable') . '</a>'; 
    245             } 
     266            if ( empty( $theme['enabled'] ) ) 
     267                    $actions['enable'] = '<a href="' . wp_nonce_url($url . 'action=enable&amp;theme=' . $theme_key . '&amp;paged=' . $page . '&amp;s=' . $s, 'enable-theme_' . $theme_key) . '" title="' . __('Enable this theme') . '" class="edit">' . __('Enable') . '</a>'; 
     268            else 
     269                    $actions['disable'] = '<a href="' . wp_nonce_url($url . 'action=disable&amp;theme=' . $theme_key . '&amp;paged=' . $page . '&amp;s=' . $s, 'disable-theme_' . $theme_key) . '" title="' . __('Disable this theme') . '">' . __('Disable') . '</a>'; 
    246270             
    247271            if ( current_user_can('edit_themes') ) 
  • trunk/wp-admin/network/site-themes.php

    r15962 r16242  
    11<?php 
    2  
    32/** 
    4  * Edit Site Themes Administration Screen 
     3 * Multisite themes administration panel. 
    54 * 
    65 * @package WordPress 
    7  * @subpackage Administration 
     6 * @subpackage Multisite 
    87 * @since 3.1.0 
    98 */ 
    109 
    11 /** Load WordPress Administration Bootstrap */ 
    12 require_once('./admin.php'); 
     10require_once( './admin.php' ); 
    1311 
    14 if ( ! is_multisite() ) 
    15     wp_die( __( 'Multisite support is not enabled.' ) ); 
     12$wp_list_table = get_list_table('WP_MS_Themes_List_Table'); 
     13$wp_list_table->check_permissions(); 
    1614 
    17 if ( ! current_user_can('manage_sites') ) 
    18     wp_die(__('You do not have sufficient permissions to edit this site.')); 
     15$action = $wp_list_table->current_action(); 
     16 
     17$s = isset($_REQUEST['s']) ? $_REQUEST['s'] : ''; 
     18 
     19// Clean up request URI from temporary args for screen options/paging uri's to work as expected. 
     20$_SERVER['REQUEST_URI'] = remove_query_arg(array('network-enable', 'network-disable', 'network-enable-selected', 'network-disable-selected'), $_SERVER['REQUEST_URI']); 
    1921 
    2022$id = isset( $_REQUEST['id'] ) ? intval( $_REQUEST['id'] ) : 0; 
     
    2224if ( ! $id ) 
    2325    wp_die( __('Invalid site ID.') ); 
     26     
     27$wp_list_table->site_id = $id; 
     28$wp_list_table->is_site_themes = true; 
     29$wp_list_table->prepare_items(); 
    2430 
    2531$details = get_blog_details( $id ); 
     
    2935$is_main_site = is_main_site( $id ); 
    3036 
    31 if ( isset($_REQUEST['action']) && 'update-site' == $_REQUEST['action'] ) { 
    32     check_admin_referer( 'edit-site' ); 
     37if ( $action ) { 
     38    switch_to_blog( $id ); 
     39    $allowed_themes = get_option( 'allowedthemes' ); 
    3340 
    34     switch_to_blog( $id ); 
    35  
    36     $allowedthemes = array(); 
    37     if ( isset($_POST['theme']) && is_array( $_POST['theme'] ) ) { 
    38         foreach ( $_POST['theme'] as $theme => $val ) { 
    39             if ( 'on' == $val ) 
    40                 $allowedthemes[$theme] = true; 
    41         } 
     41    switch ( $action ) { 
     42        case 'enable': 
     43            $theme = $_GET['theme']; 
     44            if ( !$allowed_themes ) 
     45                $allowed_themes = array( $theme => true ); 
     46            else 
     47                $allowed_themes[$theme] = true; 
     48            break; 
     49        case 'disable': 
     50            $theme = $_GET['theme']; 
     51            if ( !$allowed_themes ) 
     52                $allowed_themes = array(); 
     53            else 
     54                unset( $allowed_themes[$theme] ); 
     55            break; 
     56        case 'enable-selected': 
     57            $themes = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array(); 
     58            if ( empty($themes) ) { 
     59                restore_current_blog(); 
     60                wp_redirect( wp_get_referer() ); 
     61                exit; 
     62            }                        
     63            foreach( (array) $themes as $theme ) 
     64                $allowed_themes[ $theme ] = true; 
     65            break; 
     66        case 'disable-selected': 
     67            $themes = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array(); 
     68            if ( empty($themes) ) { 
     69                restore_current_blog(); 
     70                wp_redirect( wp_get_referer() ); 
     71                exit; 
     72            }                        
     73            foreach( (array) $themes as $theme ) 
     74                unset( $allowed_themes[ $theme ] ); 
     75            break; 
    4276    } 
    43     update_option( 'allowedthemes',  $allowedthemes ); 
    44  
     77     
     78    update_option( 'allowedthemes', $allowed_themes ); 
    4579    restore_current_blog(); 
    46     wp_redirect( add_query_arg( array( 'update' => 'updated', 'id' => $id ), 'site-themes.php') ); 
    47 } 
    48  
    49 if ( isset($_GET['update']) ) { 
    50     $messages = array(); 
    51     if ( 'updated' == $_GET['update'] ) 
    52         $messages[] = __('Site users updated.'); 
     80     
     81    wp_redirect( wp_get_referer() ); // @todo add_query_arg for update message 
     82    exit;    
    5383} 
    5484 
     
    5989require('../admin-header.php'); 
    6090 
     91add_thickbox(); 
     92 
     93add_screen_option( 'per_page', array('label' => _x( 'Themes', 'themes per page (screen options)' ), 'default' => 999) ); 
     94 
     95require_once(ABSPATH . 'wp-admin/admin-header.php'); 
    6196?> 
    6297 
     
    74109?> 
    75110</h3> 
     111<p class="description"><?php _e( 'Network enabled themes are not shown on this screen.' ) ?></p> 
    76112<?php 
    77113if ( ! empty( $messages ) ) { 
    78114    foreach ( $messages as $msg ) 
    79115        echo '<div id="message" class="updated"><p>' . $msg . '</p></div>'; 
    80 } ?> 
     116} 
     117 
     118$wp_list_table->views(); ?> 
     119 
    81120<form method="post" action="site-themes.php?action=update-site"> 
    82121    <?php wp_nonce_field( 'edit-site' ); ?> 
    83122    <input type="hidden" name="id" value="<?php echo esc_attr( $id ) ?>" /> 
    84 <?php 
    85 $themes = get_themes(); 
    86 $blog_allowed_themes = wpmu_get_blog_allowedthemes( $id ); 
    87 $allowed_themes = get_site_option( 'allowedthemes' ); 
    88123 
    89 if ( ! $allowed_themes ) 
    90     $allowed_themes = array_keys( $themes ); 
     124<?php $wp_list_table->display(); ?> 
    91125 
    92 $out = ''; 
    93 foreach ( $themes as $key => $theme ) { 
    94     $theme_key = esc_html( $theme['Stylesheet'] ); 
    95     if ( ! isset( $allowed_themes[$theme_key] ) ) { 
    96         $checked = isset( $blog_allowed_themes[ $theme_key ] ) ? 'checked="checked"' : ''; 
    97         $out .= '<tr class="form-field form-required"> 
    98                 <th title="' . esc_attr( $theme["Description"] ).'" scope="row">' . esc_html( $key ) . '</th> 
    99                 <td><label><input name="theme[' . esc_attr( $theme_key ) . ']" type="checkbox" style="width:20px;" value="on" '.$checked.'/> ' . __( 'Active' ) . '</label></td> 
    100             </tr>'; 
    101     } 
    102 } 
    103  
    104 if ( $out != '' ) { 
    105 ?> 
    106 <p class="description"><?php _e( 'Activate the themename of an existing theme and hit "Update Options" to allow the theme for this site.' ) ?></p> 
    107 <table class="form-table"> 
    108 <?php echo $out; ?> 
    109 </table> 
    110 <?php 
    111 submit_button(); 
    112 } else { 
    113     _e('All themes are allowed.'); 
    114 } 
    115 ?> 
    116126</form> 
    117127 
    118128</div> 
    119 <?php 
    120 require('../admin-footer.php'); 
     129<?php include(ABSPATH . 'wp-admin/admin-footer.php'); ?> 
  • trunk/wp-admin/network/themes.php

    r16241 r16242  
    1818 
    1919// Clean up request URI from temporary args for screen options/paging uri's to work as expected. 
    20 $_SERVER['REQUEST_URI'] = remove_query_arg(array('network-enable', 'network-disable', 'network-enable-selected', 'network-disable-selected'), $_SERVER['REQUEST_URI']); 
     20$_SERVER['REQUEST_URI'] = remove_query_arg(array('enable', 'disable', 'enable-selected', 'disable-selected'), $_SERVER['REQUEST_URI']); 
    2121 
    2222if ( $action ) { 
    2323    $allowed_themes = get_site_option( 'allowedthemes' );    
    2424    switch ( $action ) { 
    25         case 'network-enable': 
     25        case 'enable': 
    2626            $allowed_themes[ $_GET['theme'] ] = true; 
    2727            update_site_option( 'allowedthemes', $allowed_themes ); 
     
    2929            exit;            
    3030            break; 
    31         case 'network-disable': 
     31        case 'disable': 
    3232            unset( $allowed_themes[ $_GET['theme'] ] ); 
    3333            update_site_option( 'allowedthemes', $allowed_themes ); 
     
    3535            exit; 
    3636            break; 
    37         case 'network-enable-selected': 
     37        case 'enable-selected': 
    3838            $themes = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array(); 
    3939            if ( empty($themes) ) { 
     
    4545            update_site_option( 'allowedthemes', $allowed_themes ); 
    4646            break; 
    47         case 'network-disable-selected': 
     47        case 'disable-selected': 
    4848            $themes = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array(); 
    4949            if ( empty($themes) ) { 
     
    8282<?php screen_icon('themes'); ?> 
    8383<h2><?php echo esc_html( $title ); if ( current_user_can('install_themes') ) { ?> <a href="theme-install.php" class="button add-new-h2"><?php echo esc_html_x('Add New', 'theme'); ?></a><?php } ?></h2> 
    84 <p><?php _e( 'Themes must be enabled for your network before they will be available to individual sites.' ) ?></p> 
    8584 
    8685<form method="get" action=""> 
Note: See TracChangeset for help on using the changeset viewer.