* Edit Site Themes Administration Screen
/** Load WordPress Administration Bootstrap */
require_once __DIR__ . '/admin.php';
if ( ! current_user_can( 'manage_sites' ) ) {
wp_die( __( 'Sorry, you are not allowed to manage themes for this site.' ) );
get_current_screen()->add_help_tab( get_site_screen_help_tab_args() );
get_current_screen()->set_help_sidebar( get_site_screen_help_sidebar_content() );
get_current_screen()->set_screen_reader_content(
'heading_views' => __( 'Filter site themes list' ),
'heading_pagination' => __( 'Site themes list navigation' ),
'heading_list' => __( 'Site themes list' ),
$wp_list_table = _get_list_table( 'WP_MS_Themes_List_Table' );
$action = $wp_list_table->current_action();
$s = isset( $_REQUEST['s'] ) ? $_REQUEST['s'] : '';
// Clean up request URI from temporary args for screen options/paging uri's to work as expected.
$temp_args = array( 'enabled', 'disabled', 'error' );
$_SERVER['REQUEST_URI'] = remove_query_arg( $temp_args, $_SERVER['REQUEST_URI'] );
$referer = remove_query_arg( $temp_args, wp_get_referer() );
if ( ! empty( $_REQUEST['paged'] ) ) {
$referer = add_query_arg( 'paged', (int) $_REQUEST['paged'], $referer );
$id = isset( $_REQUEST['id'] ) ? (int) $_REQUEST['id'] : 0;
wp_die( __( 'Invalid site ID.' ) );
$wp_list_table->prepare_items();
$details = get_site( $id );
wp_die( __( 'The requested site does not exist.' ) );
if ( ! can_edit_network( $details->site_id ) ) {
wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 );
$is_main_site = is_main_site( $id );
$allowed_themes = get_option( 'allowedthemes' );
check_admin_referer( 'enable-theme_' . $_GET['theme'] );
if ( ! $allowed_themes ) {
$allowed_themes = array( $theme => true );
$allowed_themes[ $theme ] = true;
check_admin_referer( 'disable-theme_' . $_GET['theme'] );
if ( ! $allowed_themes ) {
$allowed_themes = array();
unset( $allowed_themes[ $theme ] );
check_admin_referer( 'bulk-themes' );
if ( isset( $_POST['checked'] ) ) {
$themes = (array) $_POST['checked'];
foreach ( (array) $themes as $theme ) {
$allowed_themes[ $theme ] = true;
check_admin_referer( 'bulk-themes' );
if ( isset( $_POST['checked'] ) ) {
$themes = (array) $_POST['checked'];
foreach ( (array) $themes as $theme ) {
unset( $allowed_themes[ $theme ] );
if ( isset( $_POST['checked'] ) ) {
check_admin_referer( 'bulk-themes' );
$themes = (array) $_POST['checked'];
$screen = get_current_screen()->id;
* Fires when a custom bulk action should be handled.
* The redirect link should be modified with success or failure feedback
* from the action to be used to display feedback to the user.
* The dynamic portion of the hook name, `$screen`, refers to the current screen ID.
* @param string $redirect_url The redirect URL.
* @param string $action The action being taken.
* @param array $items The items to take the action on.
* @param int $site_id The site ID.
$referer = apply_filters( "handle_network_bulk_actions-{$screen}", $referer, $action, $themes, $id ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
update_option( 'allowedthemes', $allowed_themes );
if ( isset( $_GET['action'] ) && 'update-site' === $_GET['action'] ) {
wp_safe_redirect( $referer );
add_screen_option( 'per_page' );
/* translators: %s: Site title. */
$title = sprintf( __( 'Edit Site: %s' ), esc_html( $details->blogname ) );
$parent_file = 'sites.php';
$submenu_file = 'sites.php';
require_once ABSPATH . 'wp-admin/admin-header.php'; ?>
<h1 id="edit-site"><?php echo $title; ?></h1>
<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>
'selected' => 'site-themes',
if ( isset( $_GET['enabled'] ) ) {
$enabled = absint( $_GET['enabled'] );
$message = __( 'Theme enabled.' );
/* translators: %s: Number of themes. */
$message = _n( '%s theme enabled.', '%s themes enabled.', $enabled );
echo '<div id="message" class="updated notice is-dismissible"><p>' . sprintf( $message, number_format_i18n( $enabled ) ) . '</p></div>';
} elseif ( isset( $_GET['disabled'] ) ) {
$disabled = absint( $_GET['disabled'] );
$message = __( 'Theme disabled.' );
/* translators: %s: Number of themes. */
$message = _n( '%s theme disabled.', '%s themes disabled.', $disabled );
echo '<div id="message" class="updated notice is-dismissible"><p>' . sprintf( $message, number_format_i18n( $disabled ) ) . '</p></div>';
} elseif ( isset( $_GET['error'] ) && 'none' === $_GET['error'] ) {
echo '<div id="message" class="error notice is-dismissible"><p>' . __( 'No theme selected.' ) . '</p></div>';
<p><?php _e( 'Network enabled themes are not shown on this screen.' ); ?></p>
<?php $wp_list_table->search_box( __( 'Search Installed Themes' ), 'theme' ); ?>
<input type="hidden" name="id" value="<?php echo esc_attr( $id ); ?>" />
<?php $wp_list_table->views(); ?>
<form method="post" action="site-themes.php?action=update-site">
<input type="hidden" name="id" value="<?php echo esc_attr( $id ); ?>" />
<?php $wp_list_table->display(); ?>
<?php require_once ABSPATH . 'wp-admin/admin-footer.php'; ?>