WordPress.org

Make WordPress Core

Ticket #14897: 14897.diff

File 14897.diff, 17.5 KB (added by PeteMall, 3 years ago)

First pass at the new network admin themes panel.

  • wp-admin/includes/list-table-ms-themes.php

     
     1<?php 
     2/** 
     3 * MS Themes List Table class. 
     4 * 
     5 * @package WordPress 
     6 * @subpackage List_Table 
     7 * @since 3.1.0 
     8 */ 
     9class WP_MS_Themes_Table extends WP_List_Table { 
     10 
     11        function WP_MS_Themes_Table() { 
     12                global $status, $page; 
     13 
     14                $default_status = get_user_option( 'themes_last_view' ); 
     15                if ( empty( $default_status ) ) 
     16                        $default_status = 'all'; 
     17                $status = isset( $_REQUEST['theme_status'] ) ? $_REQUEST['theme_status'] : $default_status; 
     18                if ( !in_array( $status, array( 'all', 'enabled', 'disabled', 'upgrade', 'search' ) ) ) 
     19                        $status = 'all'; 
     20                if ( $status != $default_status && 'search' != $status ) 
     21                        update_user_meta( get_current_user_id(), 'themes_last_view', $status ); 
     22 
     23                $page = $this->get_pagenum(); 
     24 
     25                parent::WP_List_Table( array( 
     26                        'screen' => 'themes', 
     27                        'plural' => 'plugins', // @todo replace with themes and add css 
     28                ) ); 
     29        } 
     30         
     31        function check_permissions() { 
     32                if ( is_multisite() ) { 
     33                        $menu_perms = get_site_option( 'menu_items', array() ); 
     34 
     35                        if ( empty( $menu_perms['themes'] ) ) { 
     36                                if ( !is_super_admin() ) 
     37                                        wp_die( __( 'Cheatin&#8217; uh?' ) ); 
     38                        } 
     39                } 
     40 
     41                if ( !current_user_can('manage_network_themes') ) 
     42                        wp_die( __( 'You do not have sufficient permissions to manage themes for this site.' ) ); 
     43        } 
     44 
     45        function prepare_items() { 
     46                global $status, $themes, $totals, $page, $orderby, $order, $s; 
     47 
     48                wp_reset_vars( array( 'orderby', 'order', 's' ) ); 
     49 
     50                $themes = array( 
     51                        'all' => apply_filters( 'all_themes', get_themes() ), 
     52                        'search' => array(), 
     53                        'enabled' => array(), 
     54                        'disabled' => array(), 
     55                        'upgrade' => array() 
     56                ); 
     57                 
     58                $allowed_themes = get_site_allowed_themes(); 
     59                $current = get_site_transient( 'update_themes' ); 
     60 
     61                foreach ( (array) $themes['all'] as $key => $theme ) { 
     62                        if ( array_key_exists( $theme['Template'], $allowed_themes ) ) { 
     63                                $themes['all'][$key]['enabled'] = true; 
     64                                $themes['enabled'][$key] = $themes['all'][$key]; 
     65                        } 
     66                        else { 
     67                                $themes['all'][$key]['enabled'] = false; 
     68                                $themes['disabled'][$key] = $themes['all'][$key]; 
     69                        } 
     70                        if ( isset( $current->response[ $theme['Template'] ] ) ) 
     71                                $themes['upgrade'][$key] = $themes['all'][$key]; 
     72                } 
     73 
     74                if ( !current_user_can( 'update_themes' ) ) 
     75                        $themes['upgrade'] = array(); 
     76 
     77                if ( $s ) { 
     78                        $status = 'search'; echo "opopop"; 
     79                        $themes['search'] = array_filter( $themes['all'], array( $this, '_search_callback' ) ); 
     80                } 
     81 
     82                $totals = array(); 
     83                foreach ( $themes as $type => $list ) 
     84                        $totals[ $type ] = count( $list ); 
     85 
     86                if ( empty( $themes[ $status ] ) && !in_array( $status, array( 'all', 'search' ) ) ) 
     87                        $status = 'all'; 
     88 
     89                $this->items = $themes[ $status ]; 
     90                $total_this_page = $totals[ $status ]; 
     91 
     92                if ( $orderby ) { 
     93                        $orderby = ucfirst( $orderby ); 
     94                        $order = strtoupper( $order ); 
     95 
     96                        uasort( $this->items, array( $this, '_order_callback' ) ); 
     97                } 
     98 
     99                $themes_per_page = $this->get_items_per_page( 'themes_per_page', 999 ); 
     100 
     101                $start = ( $page - 1 ) * $themes_per_page; 
     102 
     103                if ( $total_this_page > $themes_per_page ) 
     104                        $this->items = array_slice( $this->items, $start, $themes_per_page ); 
     105 
     106                $this->set_pagination_args( array( 
     107                        'total_items' => $total_this_page, 
     108                        'per_page' => $themes_per_page, 
     109                ) ); 
     110        } 
     111         
     112        function _search_callback( $theme ) { 
     113                static $term; 
     114                if ( is_null( $term ) ) 
     115                        $term = stripslashes( $_REQUEST['s'] ); 
     116                         
     117                foreach ( $theme as $key->$theme ) 
     118                        if ( stripos( $key, $term ) !== false ) 
     119                                return true; 
     120 
     121                return false; 
     122        } 
     123 
     124        function _order_callback( $theme_a, $theme_b ) { 
     125                global $orderby, $order; 
     126 
     127                $a = $theme_a[$orderby]; 
     128                $b = $theme_b[$orderby]; 
     129 
     130                if ( $a == $b ) 
     131                        return 0; 
     132 
     133                if ( 'DESC' == $order ) 
     134                        return ( $a < $b ) ? 1 : -1; 
     135                else 
     136                        return ( $a < $b ) ? -1 : 1; 
     137        } 
     138 
     139        function no_items() { 
     140                global $themes; 
     141 
     142                if ( !empty( $themes['all'] ) ) 
     143                        _e( 'No themes found.' ); 
     144                else 
     145                        _e( 'You do not appear to have any themes available at this time.' ); 
     146        } 
     147 
     148        function get_columns() { 
     149                global $status; 
     150 
     151                return array( 
     152                        'cb'          => '<input type="checkbox" />', 
     153                        'name'        => __( 'Theme' ), 
     154                        'description' => __( 'Description' ), 
     155                ); 
     156        } 
     157 
     158        function get_sortable_columns() { 
     159                return array( 
     160                        'name'         => 'name', 
     161                ); 
     162        } 
     163 
     164        function display_tablenav( $which ) { 
     165                global $status; 
     166 
     167                parent::display_tablenav( $which ); 
     168        } 
     169 
     170        function get_views() { 
     171                global $totals, $status; 
     172 
     173                $status_links = array(); 
     174                foreach ( $totals as $type => $count ) { 
     175                        if ( !$count ) 
     176                                continue; 
     177 
     178                        switch ( $type ) { 
     179                                case 'all': 
     180                                        $text = _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $count, 'themes' ); 
     181                                        break; 
     182                                case 'enabled': 
     183                                        $text = _n( 'Enabled <span class="count">(%s)</span>', 'Enabled <span class="count">(%s)</span>', $count ); 
     184                                        break; 
     185                                case 'disabled': 
     186                                        $text = _n( 'Disabled <span class="count">(%s)</span>', 'Disabled <span class="count">(%s)</span>', $count ); 
     187                                        break; 
     188                                case 'upgrade': 
     189                                        $text = _n( 'Upgrade Available <span class="count">(%s)</span>', 'Upgrade Available <span class="count">(%s)</span>', $count ); 
     190                                        break; 
     191                                case 'search': 
     192                                        $text = _n( 'Search Results <span class="count">(%s)</span>', 'Search Results <span class="count">(%s)</span>', $count ); 
     193                                        break; 
     194                        } 
     195 
     196                        $status_links[$type] = sprintf( "<li><a href='%s' %s>%s</a>", 
     197                                add_query_arg('theme_status', $type, 'themes.php'), 
     198                                ( $type == $status ) ? ' class="current"' : '', 
     199                                sprintf( $text, number_format_i18n( $count ) ) 
     200                        ); 
     201                } 
     202 
     203                return $status_links; 
     204        } 
     205 
     206        function get_bulk_actions() { 
     207                global $status; 
     208 
     209                $actions = array(); 
     210                if ( 'enabled' != $status ) 
     211                        $actions['network-enable-selected'] = __( 'Network Enable' ); 
     212                if ( 'disabled' != $status ) 
     213                        $actions['network-disable-selected'] = __( 'Network Disable' ); 
     214                if ( current_user_can( 'update_themes' ) ) 
     215                        $actions['update-selected'] = __( 'Update' ); 
     216                         
     217                return $actions; 
     218        } 
     219 
     220        function bulk_actions( $which ) { 
     221                global $status; 
     222                parent::bulk_actions( $which ); 
     223        } 
     224 
     225        function current_action() { 
     226                return parent::current_action(); 
     227        } 
     228 
     229        function display_rows() { 
     230                global $status, $page, $s; 
     231 
     232                $context = $status; 
     233 
     234                foreach ( $this->items as $key => $theme ) { 
     235                        // preorder 
     236                        $actions = array( 
     237                                'network_enable' => '', 
     238                                'network_disable' => '', 
     239                                'edit' => '' 
     240                        ); 
     241                         
     242                        $theme_key = esc_html( $theme['Stylesheet'] ); 
     243 
     244                        if ( empty( $theme['enabled'] ) ) { 
     245                                if ( current_user_can( 'manage_network_themes' ) ) 
     246                                        $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">' . __('Network Enable') . '</a>'; 
     247                        } else { 
     248                                if ( current_user_can( 'manage_network_themes' ) ) 
     249                                        $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') . '">' . __('Network Disable') . '</a>'; 
     250                        } 
     251                         
     252                        /* @todo link to theme editor    
     253                        if ( current_user_can('edit_themes') ) 
     254                                $actions['edit'] = '<a href="theme-editor.php?file=' . $theme['Stylesheet Files'][0] . '" title="' . __('Open this theme in the Theme Editor') . '" class="edit">' . __('Edit') . '</a>'; 
     255                        */ 
     256 
     257                        $actions = apply_filters( 'theme_action_links', array_filter( $actions ), $theme_key, $theme, $context ); 
     258                        $actions = apply_filters( "theme_action_links_$theme_key", $actions, $theme_key, $theme, $context ); 
     259 
     260                        $class = empty( $theme['enabled'] ) ? 'inactive' : 'active'; 
     261                        $checkbox = "<input type='checkbox' name='checked[]' value='" . esc_attr( $theme_key ) . "' />"; 
     262 
     263                        $description = '<p>' . $theme['Description'] . '</p>'; 
     264                        $theme_name = $theme['Name']; 
     265 
     266 
     267                        $id = sanitize_title( $theme_name ); 
     268 
     269                        echo " 
     270                <tr id='$id' class='$class'> 
     271                        <th scope='row' class='check-column'>$checkbox</th> 
     272                        <td class='theme-title'><strong>$theme_name</strong></td> 
     273                        <td class='desc'>$description</td> 
     274                </tr> 
     275                <tr class='$class second'> 
     276                        <td></td> 
     277                        <td class='theme-title'>"; 
     278 
     279                        echo $this->row_actions( $actions, true ); 
     280 
     281                        echo "</td> 
     282                        <td class='desc'>"; 
     283                        $theme_meta = array(); 
     284                        if ( !empty( $theme['Version'] ) ) 
     285                                $theme_meta[] = sprintf( __( 'Version %s' ), $theme['Version'] ); 
     286                        if ( !empty( $theme['Author'] ) ) { 
     287                                $author = $theme['Author']; 
     288                                if ( !empty( $theme['Author URI'] ) ) 
     289                                        $author = '<a href="' . $theme['Author URI'] . '" title="' . __( 'Visit author homepage' ) . '">' . $theme['Author'] . '</a>'; 
     290                                $theme_meta[] = sprintf( __( 'By %s' ), $author ); 
     291                        } 
     292                        if ( !empty( $theme['Theme URI'] ) ) 
     293                                $theme_meta[] = '<a href="' . $theme['Theme URI'] . '" title="' . __( 'Visit theme homepage' ) . '">' . __( 'Visit Theme Site' ) . '</a>'; 
     294 
     295                        $theme_meta = apply_filters( 'theme_row_meta', $theme_meta, $theme_key, $theme, $status ); 
     296                        echo implode( ' | ', $theme_meta ); 
     297                        echo "</td> 
     298                </tr>\n"; 
     299 
     300                        do_action( 'after_theme_row', $theme_key, $theme, $status ); 
     301                        do_action( "after_theme_row_$theme_key", $theme_key, $theme, $status ); 
     302                } 
     303        } 
     304} 
     305?> 
     306 No newline at end of file 
  • wp-admin/includes/class-wp-list-table.php

     
    852852                'WP_Users_Table' => 'users', 'WP_Comments_Table' => 'comments', 'WP_Post_Comments_Table' => 'comments', 
    853853                'WP_Links_Table' => 'links', 'WP_Sites_Table' => 'sites', 'WP_MS_Users_Table' => 'ms-users', 
    854854                'WP_Plugins_Table' => 'plugins', 'WP_Plugin_Install_Table' => 'plugin-install', 'WP_Themes_Table' => 'themes', 
    855                 'WP_Theme_Install_Table' => 'theme-install' ); 
     855                'WP_Theme_Install_Table' => 'theme-install', 'WP_MS_Themes_Table' => 'ms-themes' ); 
    856856 
    857857        if ( isset( $core_classes[ $class ] ) ) { 
    858858                require_once( ABSPATH . '/wp-admin/includes/list-table-' . $core_classes[ $class ] . '.php' ); 
  • wp-admin/network/themes.php

     
    44 * 
    55 * @package WordPress 
    66 * @subpackage Multisite 
    7  * @since 3.0.0 
     7 * @since 3.1.0 
    88 */ 
    99 
    1010require_once( './admin.php' ); 
    1111 
    12 if ( ! current_user_can( 'manage_network_themes' ) ) 
    13         wp_die( __( 'You do not have permission to access this page.' ) ); 
     12$wp_list_table = get_list_table('WP_MS_Themes_Table'); 
     13$wp_list_table->check_permissions(); 
    1414 
    15 $title = __( 'Network Themes' ); 
    16 $parent_file = 'themes.php'; 
     15$action = $wp_list_table->current_action(); 
    1716 
    18 add_contextual_help($current_screen, 
    19         '<p>' . __('This screen enables and disables the inclusion of themes available to choose in the Appearance menu for each site. It does not activate or deactivate which theme a site is currently using.') . '</p>' . 
    20         '<p>' . __('If the network admin disables a theme that is in use, it can still remain selected on that site. If another theme is chosen, the disabled theme will not appear in the site&#8217;s Appearance > Themes screen.') . '</p>' . 
    21         '<p>' . __('Themes can be enabled on a site by site basis by the network admin on the Edit Site screen you go to via the Edit action link on the Sites screen.') . '</p>' . 
    22         '<p><strong>' . __('For more information:') . '</strong></p>' . 
    23         '<p>' . __('<a href="http://codex.wordpress.org/Super_Admin_Themes_SubPanel" target="_blank">Documentation on Network Themes</a>') . '</p>' . 
    24         '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>' 
    25 ); 
     17$plugin = isset($_REQUEST['plugin']) ? $_REQUEST['plugin'] : ''; 
     18$s = isset($_REQUEST['s']) ? $_REQUEST['s'] : ''; 
    2619 
    27 require_once( '../admin-header.php' ); 
     20// Clean up request URI from temporary args for screen options/paging uri's to work as expected. 
     21$_SERVER['REQUEST_URI'] = remove_query_arg(array('error', 'deleted', 'activate', 'activate-multi', 'deactivate', 'deactivate-multi', '_error_nonce'), $_SERVER['REQUEST_URI']); 
    2822 
    29 if ( isset( $_GET['updated'] ) ) { 
    30         ?> 
    31         <div id="message" class="updated"><p><?php _e( 'Site themes saved.' ) ?></p></div> 
    32         <?php 
     23if ( $action ) { 
     24        $allowed_themes = get_site_option( 'allowedthemes' );    
     25        switch ( $action ) { 
     26                case 'network-enable': 
     27                        $allowed_themes[ $_GET['theme'] ] = 1; 
     28                        update_site_option( 'allowedthemes', $allowed_themes ); 
     29                        wp_redirect( wp_get_referer() ); // @todo add_query_arg for update message 
     30                        exit;                    
     31                        break; 
     32                case 'network-disable': 
     33                        unset( $allowed_themes[ $_GET['theme'] ] ); 
     34                        update_site_option( 'allowedthemes', $allowed_themes ); 
     35                        wp_redirect( wp_get_referer() ); // @todo add_query_arg for update message 
     36                        exit; 
     37                        break; 
     38                case 'network-enable-selected': 
     39                        check_admin_referer('bulk-plugins'); 
     40 
     41                        $themes = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array(); 
     42                        if ( empty($themes) ) { 
     43                                wp_redirect( wp_get_referer() ); 
     44                                exit; 
     45                        }                                                
     46                        foreach( (array) $themes as $theme ) 
     47                                $allowed_themes[ $theme ] = 1; 
     48                        update_site_option( 'allowedthemes', $allowed_themes ); 
     49                        break; 
     50                        case 'network-disable-selected': 
     51                                check_admin_referer('bulk-plugins'); 
     52 
     53                                $themes = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array(); 
     54                                if ( empty($themes) ) { 
     55                                        wp_redirect( wp_get_referer() ); 
     56                                        exit; 
     57                                }                                                
     58                                foreach( (array) $themes as $theme ) 
     59                                        unset( $allowed_themes[ $theme ] ); 
     60                                update_site_option( 'allowedthemes', $allowed_themes ); 
     61                                break; 
     62 
     63        } 
    3364} 
    3465 
    35 $themes = get_themes(); 
    36 $allowed_themes = get_site_allowed_themes(); 
     66$wp_list_table->prepare_items(); 
     67 
     68add_screen_option( 'per_page', array('label' => _x( 'Themes', 'themes per page (screen options)' ), 'default' => 999) ); 
     69 
     70$title = __('Themes'); 
     71$parent_file = 'themes.php'; 
     72 
     73require_once(ABSPATH . 'wp-admin/admin-header.php'); 
     74 
    3775?> 
     76 
    3877<div class="wrap"> 
    39         <form action="<?php echo esc_url( network_admin_url( 'edit.php?action=updatethemes' ) ); ?>" method="post"> 
    40                 <?php screen_icon(); ?> 
    41                 <h2><?php _e( 'Network Themes' ) ?></h2> 
    42                 <p><?php _e( 'Themes must be enabled for your network before they will be available to individual sites.' ) ?></p> 
    43                 <?php submit_button( __( 'Apply Changes' ), '', '' ); ?> 
    44                 <table class="widefat"> 
    45                         <thead> 
    46                                 <tr> 
    47                                         <th style="width:15%;"><?php _e( 'Enable' ) ?></th> 
    48                                         <th style="width:25%;"><?php _e( 'Theme' ) ?></th> 
    49                                         <th style="width:10%;"><?php _e( 'Version' ) ?></th> 
    50                                         <th style="width:60%;"><?php _e( 'Description' ) ?></th> 
    51                                 </tr> 
    52                         </thead> 
    53                         <tbody id="plugins"> 
    54                         <?php 
    55                         $total_theme_count = $activated_themes_count = 0; 
    56                         $class = ''; 
    57                         foreach ( (array) $themes as $key => $theme ) { 
    58                                 $total_theme_count++; 
    59                                 $theme_key = esc_html( $theme['Stylesheet'] ); 
    60                                 $class = ( 'alt' == $class ) ? '' : 'alt'; 
    61                                 $class1 = $enabled = $disabled = ''; 
    62                                 $enabled = $disabled = false; 
     78<?php screen_icon('themes'); ?> 
     79<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> 
     80<p><?php _e( 'Themes must be enabled for your network before they will be available to individual sites.' ) ?></p> 
    6381 
    64                                 if ( isset( $allowed_themes[$theme_key] ) == true ) { 
    65                                         $enabled = true; 
    66                                         $activated_themes_count++; 
    67                                         $class1 = 'active'; 
    68                                 } else { 
    69                                         $disabled = true; 
    70                                 } 
    71                                 ?> 
    72                                 <tr valign="top" class="<?php echo $class . ' ' . $class1; ?>"> 
    73                                         <td> 
    74                                                 <label><input name="theme[<?php echo $theme_key ?>]" type="radio" id="enabled_<?php echo $theme_key ?>" value="enabled" <?php checked( $enabled ) ?> /> <?php _e( 'Yes' ) ?></label> 
    75                                                 &nbsp;&nbsp;&nbsp; 
    76                                                 <label><input name="theme[<?php echo $theme_key ?>]" type="radio" id="disabled_<?php echo $theme_key ?>" value="disabled" <?php checked( $disabled ) ?> /> <?php _e( 'No' ) ?></label> 
    77                                         </td> 
    78                                         <th scope="row" style="text-align:left;"><?php echo $key ?></th> 
    79                                         <td><?php echo $theme['Version'] ?></td> 
    80                                         <td><?php echo $theme['Description'] ?></td> 
    81                                 </tr> 
    82                         <?php } ?> 
    83                         </tbody> 
    84                 </table> 
    85                  
    86                 <?php submit_button( __( 'Apply Changes' ), '', '' ); ?> 
    87         </form> 
     82<form method="get" action=""> 
     83<p class="search-box"> 
     84        <label class="screen-reader-text" for="theme-search-input"><?php _e( 'Search Themes' ); ?>:</label> 
     85        <input type="text" id="theme-search-input" name="s" value="<?php _admin_search_query(); ?>" /> 
     86        <?php submit_button( __( 'Search Installed Themes' ), 'button', '', false ); ?> 
     87</p> 
     88</form> 
    8889 
    89         <h3><?php _e( 'Total' )?></h3> 
    90         <p> 
    91                 <?php printf( __( 'Themes Installed: %d' ), $total_theme_count); ?> 
    92                 <br /> 
    93                 <?php printf( __( 'Themes Enabled: %d' ), $activated_themes_count); ?> 
    94         </p> 
     90<?php $wp_list_table->views(); ?> 
     91 
     92<form method="post" action=""> 
     93<input type="hidden" name="theme_status" value="<?php echo esc_attr($status) ?>" /> 
     94<input type="hidden" name="paged" value="<?php echo esc_attr($page) ?>" /> 
     95 
     96<?php $wp_list_table->display(); ?> 
     97</form> 
     98 
    9599</div> 
    96100 
    97 <?php include( '../admin-footer.php' ); ?> 
     101<?php 
     102include(ABSPATH . 'wp-admin/admin-footer.php'); 
     103 No newline at end of file