WordPress.org

Make WordPress Core


Ignore:
Timestamp:
11/08/2010 09:52:54 PM (10 years ago)
Author:
ryan
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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'); ?>
Note: See TracChangeset for help on using the changeset viewer.