wp/wp-admin/network/site-themes.php
changeset 9 177826044cd9
parent 7 cf61fcea0001
child 16 a86126ab1dd4
equal deleted inserted replaced
8:c7c34916027a 9:177826044cd9
     8  */
     8  */
     9 
     9 
    10 /** Load WordPress Administration Bootstrap */
    10 /** Load WordPress Administration Bootstrap */
    11 require_once( dirname( __FILE__ ) . '/admin.php' );
    11 require_once( dirname( __FILE__ ) . '/admin.php' );
    12 
    12 
    13 if ( ! current_user_can( 'manage_sites' ) )
    13 if ( ! current_user_can( 'manage_sites' ) ) {
    14 	wp_die( __( 'Sorry, you are not allowed to manage themes for this site.' ) );
    14 	wp_die( __( 'Sorry, you are not allowed to manage themes for this site.' ) );
       
    15 }
    15 
    16 
    16 get_current_screen()->add_help_tab( get_site_screen_help_tab_args() );
    17 get_current_screen()->add_help_tab( get_site_screen_help_tab_args() );
    17 get_current_screen()->set_help_sidebar( get_site_screen_help_sidebar_content() );
    18 get_current_screen()->set_help_sidebar( get_site_screen_help_sidebar_content() );
    18 
    19 
    19 get_current_screen()->set_screen_reader_content( array(
    20 get_current_screen()->set_screen_reader_content(
    20 	'heading_views'      => __( 'Filter site themes list' ),
    21 	array(
    21 	'heading_pagination' => __( 'Site themes list navigation' ),
    22 		'heading_views'      => __( 'Filter site themes list' ),
    22 	'heading_list'       => __( 'Site themes list' ),
    23 		'heading_pagination' => __( 'Site themes list navigation' ),
    23 ) );
    24 		'heading_list'       => __( 'Site themes list' ),
    24 
    25 	)
    25 $wp_list_table = _get_list_table('WP_MS_Themes_List_Table');
    26 );
       
    27 
       
    28 $wp_list_table = _get_list_table( 'WP_MS_Themes_List_Table' );
    26 
    29 
    27 $action = $wp_list_table->current_action();
    30 $action = $wp_list_table->current_action();
    28 
    31 
    29 $s = isset($_REQUEST['s']) ? $_REQUEST['s'] : '';
    32 $s = isset( $_REQUEST['s'] ) ? $_REQUEST['s'] : '';
    30 
    33 
    31 // Clean up request URI from temporary args for screen options/paging uri's to work as expected.
    34 // Clean up request URI from temporary args for screen options/paging uri's to work as expected.
    32 $temp_args = array( 'enabled', 'disabled', 'error' );
    35 $temp_args              = array( 'enabled', 'disabled', 'error' );
    33 $_SERVER['REQUEST_URI'] = remove_query_arg( $temp_args, $_SERVER['REQUEST_URI'] );
    36 $_SERVER['REQUEST_URI'] = remove_query_arg( $temp_args, $_SERVER['REQUEST_URI'] );
    34 $referer = remove_query_arg( $temp_args, wp_get_referer() );
    37 $referer                = remove_query_arg( $temp_args, wp_get_referer() );
    35 
    38 
    36 if ( ! empty( $_REQUEST['paged'] ) ) {
    39 if ( ! empty( $_REQUEST['paged'] ) ) {
    37 	$referer = add_query_arg( 'paged', (int) $_REQUEST['paged'], $referer );
    40 	$referer = add_query_arg( 'paged', (int) $_REQUEST['paged'], $referer );
    38 }
    41 }
    39 
    42 
    40 $id = isset( $_REQUEST['id'] ) ? intval( $_REQUEST['id'] ) : 0;
    43 $id = isset( $_REQUEST['id'] ) ? intval( $_REQUEST['id'] ) : 0;
    41 
    44 
    42 if ( ! $id )
    45 if ( ! $id ) {
    43 	wp_die( __('Invalid site ID.') );
    46 	wp_die( __( 'Invalid site ID.' ) );
       
    47 }
    44 
    48 
    45 $wp_list_table->prepare_items();
    49 $wp_list_table->prepare_items();
    46 
    50 
    47 $details = get_site( $id );
    51 $details = get_site( $id );
    48 if ( ! $details ) {
    52 if ( ! $details ) {
    49 	wp_die( __( 'The requested site does not exist.' ) );
    53 	wp_die( __( 'The requested site does not exist.' ) );
    50 }
    54 }
    51 
    55 
    52 if ( !can_edit_network( $details->site_id ) )
    56 if ( ! can_edit_network( $details->site_id ) ) {
    53 	wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 );
    57 	wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 );
       
    58 }
    54 
    59 
    55 $is_main_site = is_main_site( $id );
    60 $is_main_site = is_main_site( $id );
    56 
    61 
    57 if ( $action ) {
    62 if ( $action ) {
    58 	switch_to_blog( $id );
    63 	switch_to_blog( $id );
    59 	$allowed_themes = get_option( 'allowedthemes' );
    64 	$allowed_themes = get_option( 'allowedthemes' );
    60 
    65 
    61 	switch ( $action ) {
    66 	switch ( $action ) {
    62 		case 'enable':
    67 		case 'enable':
    63 			check_admin_referer( 'enable-theme_' . $_GET['theme'] );
    68 			check_admin_referer( 'enable-theme_' . $_GET['theme'] );
    64 			$theme = $_GET['theme'];
    69 			$theme  = $_GET['theme'];
    65 			$action = 'enabled';
    70 			$action = 'enabled';
    66 			$n = 1;
    71 			$n      = 1;
    67 			if ( !$allowed_themes )
    72 			if ( ! $allowed_themes ) {
    68 				$allowed_themes = array( $theme => true );
    73 				$allowed_themes = array( $theme => true );
    69 			else
    74 			} else {
    70 				$allowed_themes[$theme] = true;
    75 				$allowed_themes[ $theme ] = true;
       
    76 			}
    71 			break;
    77 			break;
    72 		case 'disable':
    78 		case 'disable':
    73 			check_admin_referer( 'disable-theme_' . $_GET['theme'] );
    79 			check_admin_referer( 'disable-theme_' . $_GET['theme'] );
    74 			$theme = $_GET['theme'];
    80 			$theme  = $_GET['theme'];
    75 			$action = 'disabled';
    81 			$action = 'disabled';
    76 			$n = 1;
    82 			$n      = 1;
    77 			if ( !$allowed_themes )
    83 			if ( ! $allowed_themes ) {
    78 				$allowed_themes = array();
    84 				$allowed_themes = array();
    79 			else
    85 			} else {
    80 				unset( $allowed_themes[$theme] );
    86 				unset( $allowed_themes[ $theme ] );
       
    87 			}
    81 			break;
    88 			break;
    82 		case 'enable-selected':
    89 		case 'enable-selected':
    83 			check_admin_referer( 'bulk-themes' );
    90 			check_admin_referer( 'bulk-themes' );
    84 			if ( isset( $_POST['checked'] ) ) {
    91 			if ( isset( $_POST['checked'] ) ) {
    85 				$themes = (array) $_POST['checked'];
    92 				$themes = (array) $_POST['checked'];
    86 				$action = 'enabled';
    93 				$action = 'enabled';
    87 				$n = count( $themes );
    94 				$n      = count( $themes );
    88 				foreach ( (array) $themes as $theme )
    95 				foreach ( (array) $themes as $theme ) {
    89 					$allowed_themes[ $theme ] = true;
    96 					$allowed_themes[ $theme ] = true;
       
    97 				}
    90 			} else {
    98 			} else {
    91 				$action = 'error';
    99 				$action = 'error';
    92 				$n = 'none';
   100 				$n      = 'none';
    93 			}
   101 			}
    94 			break;
   102 			break;
    95 		case 'disable-selected':
   103 		case 'disable-selected':
    96 			check_admin_referer( 'bulk-themes' );
   104 			check_admin_referer( 'bulk-themes' );
    97 			if ( isset( $_POST['checked'] ) ) {
   105 			if ( isset( $_POST['checked'] ) ) {
    98 				$themes = (array) $_POST['checked'];
   106 				$themes = (array) $_POST['checked'];
    99 				$action = 'disabled';
   107 				$action = 'disabled';
   100 				$n = count( $themes );
   108 				$n      = count( $themes );
   101 				foreach ( (array) $themes as $theme )
   109 				foreach ( (array) $themes as $theme ) {
   102 					unset( $allowed_themes[ $theme ] );
   110 					unset( $allowed_themes[ $theme ] );
       
   111 				}
   103 			} else {
   112 			} else {
   104 				$action = 'error';
   113 				$action = 'error';
   105 				$n = 'none';
   114 				$n      = 'none';
   106 			}
   115 			}
   107 			break;
   116 			break;
   108 		default:
   117 		default:
   109 			if ( isset( $_POST['checked'] ) ) {
   118 			if ( isset( $_POST['checked'] ) ) {
   110 				check_admin_referer( 'bulk-themes' );
   119 				check_admin_referer( 'bulk-themes' );
   111 				$themes = (array) $_POST['checked'];
   120 				$themes = (array) $_POST['checked'];
   112 				$n = count( $themes );
   121 				$n      = count( $themes );
   113 				$screen = get_current_screen()->id;
   122 				$screen = get_current_screen()->id;
   114 
   123 
   115 				/**
   124 				/**
   116 				 * Fires when a custom bulk action should be handled.
   125 				 * Fires when a custom bulk action should be handled.
   117 				 *
   126 				 *
   128 				 * @param int    $site_id      The site ID.
   137 				 * @param int    $site_id      The site ID.
   129 				 */
   138 				 */
   130 				$referer = apply_filters( "handle_network_bulk_actions-{$screen}", $referer, $action, $themes, $id );
   139 				$referer = apply_filters( "handle_network_bulk_actions-{$screen}", $referer, $action, $themes, $id );
   131 			} else {
   140 			} else {
   132 				$action = 'error';
   141 				$action = 'error';
   133 				$n = 'none';
   142 				$n      = 'none';
   134 			}
   143 			}
   135 	}
   144 	}
   136 
   145 
   137 	update_option( 'allowedthemes', $allowed_themes );
   146 	update_option( 'allowedthemes', $allowed_themes );
   138 	restore_current_blog();
   147 	restore_current_blog();
   139 
   148 
   140 	wp_safe_redirect( add_query_arg( array( 'id' => $id, $action => $n ), $referer ) );
   149 	wp_safe_redirect(
       
   150 		add_query_arg(
       
   151 			array(
       
   152 				'id'    => $id,
       
   153 				$action => $n,
       
   154 			),
       
   155 			$referer
       
   156 		)
       
   157 	);
   141 	exit;
   158 	exit;
   142 }
   159 }
   143 
   160 
   144 if ( isset( $_GET['action'] ) && 'update-site' == $_GET['action'] ) {
   161 if ( isset( $_GET['action'] ) && 'update-site' == $_GET['action'] ) {
   145 	wp_safe_redirect( $referer );
   162 	wp_safe_redirect( $referer );
   150 add_screen_option( 'per_page' );
   167 add_screen_option( 'per_page' );
   151 
   168 
   152 /* translators: %s: site name */
   169 /* translators: %s: site name */
   153 $title = sprintf( __( 'Edit Site: %s' ), esc_html( $details->blogname ) );
   170 $title = sprintf( __( 'Edit Site: %s' ), esc_html( $details->blogname ) );
   154 
   171 
   155 $parent_file = 'sites.php';
   172 $parent_file  = 'sites.php';
   156 $submenu_file = 'sites.php';
   173 $submenu_file = 'sites.php';
   157 
   174 
   158 require( ABSPATH . 'wp-admin/admin-header.php' ); ?>
   175 require( ABSPATH . 'wp-admin/admin-header.php' ); ?>
   159 
   176 
   160 <div class="wrap">
   177 <div class="wrap">
   161 <h1 id="edit-site"><?php echo $title; ?></h1>
   178 <h1 id="edit-site"><?php echo $title; ?></h1>
   162 <p class="edit-site-actions"><a href="<?php echo esc_url( get_home_url( $id, '/' ) ); ?>"><?php _e( 'Visit' ); ?></a> | <a href="<?php echo esc_url( get_admin_url( $id ) ); ?>"><?php _e( 'Dashboard' ); ?></a></p>
   179 <p class="edit-site-actions"><a href="<?php echo esc_url( get_home_url( $id, '/' ) ); ?>"><?php _e( 'Visit' ); ?></a> | <a href="<?php echo esc_url( get_admin_url( $id ) ); ?>"><?php _e( 'Dashboard' ); ?></a></p>
   163 <?php
   180 <?php
   164 
   181 
   165 network_edit_site_nav( array(
   182 network_edit_site_nav(
   166 	'blog_id'  => $id,
   183 	array(
   167 	'selected' => 'site-themes'
   184 		'blog_id'  => $id,
   168 ) );
   185 		'selected' => 'site-themes',
       
   186 	)
       
   187 );
   169 
   188 
   170 if ( isset( $_GET['enabled'] ) ) {
   189 if ( isset( $_GET['enabled'] ) ) {
   171 	$enabled = absint( $_GET['enabled'] );
   190 	$enabled = absint( $_GET['enabled'] );
   172 	if ( 1 == $enabled ) {
   191 	if ( 1 == $enabled ) {
   173 		$message = __( 'Theme enabled.' );
   192 		$message = __( 'Theme enabled.' );
   183 		$message = _n( '%s theme disabled.', '%s themes disabled.', $disabled );
   202 		$message = _n( '%s theme disabled.', '%s themes disabled.', $disabled );
   184 	}
   203 	}
   185 	echo '<div id="message" class="updated notice is-dismissible"><p>' . sprintf( $message, number_format_i18n( $disabled ) ) . '</p></div>';
   204 	echo '<div id="message" class="updated notice is-dismissible"><p>' . sprintf( $message, number_format_i18n( $disabled ) ) . '</p></div>';
   186 } elseif ( isset( $_GET['error'] ) && 'none' == $_GET['error'] ) {
   205 } elseif ( isset( $_GET['error'] ) && 'none' == $_GET['error'] ) {
   187 	echo '<div id="message" class="error notice is-dismissible"><p>' . __( 'No theme selected.' ) . '</p></div>';
   206 	echo '<div id="message" class="error notice is-dismissible"><p>' . __( 'No theme selected.' ) . '</p></div>';
   188 } ?>
   207 }
   189 
   208 ?>
   190 <p><?php _e( 'Network enabled themes are not shown on this screen.' ) ?></p>
   209 
       
   210 <p><?php _e( 'Network enabled themes are not shown on this screen.' ); ?></p>
   191 
   211 
   192 <form method="get">
   212 <form method="get">
   193 <?php $wp_list_table->search_box( __( 'Search Installed Themes' ), 'theme' ); ?>
   213 <?php $wp_list_table->search_box( __( 'Search Installed Themes' ), 'theme' ); ?>
   194 <input type="hidden" name="id" value="<?php echo esc_attr( $id ) ?>" />
   214 <input type="hidden" name="id" value="<?php echo esc_attr( $id ); ?>" />
   195 </form>
   215 </form>
   196 
   216 
   197 <?php $wp_list_table->views(); ?>
   217 <?php $wp_list_table->views(); ?>
   198 
   218 
   199 <form method="post" action="site-themes.php?action=update-site">
   219 <form method="post" action="site-themes.php?action=update-site">
   200 	<input type="hidden" name="id" value="<?php echo esc_attr( $id ) ?>" />
   220 	<input type="hidden" name="id" value="<?php echo esc_attr( $id ); ?>" />
   201 
   221 
   202 <?php $wp_list_table->display(); ?>
   222 <?php $wp_list_table->display(); ?>
   203 
   223 
   204 </form>
   224 </form>
   205 
   225 
   206 </div>
   226 </div>
   207 <?php include(ABSPATH . 'wp-admin/admin-footer.php'); ?>
   227 <?php include( ABSPATH . 'wp-admin/admin-footer.php' ); ?>