2010-07-30 22:34:54 +02:00
< ? php
/**
* Multisite themes administration panel .
*
* @ package WordPress
* @ subpackage Multisite
2010-10-31 10:37:15 +01:00
* @ since 3.1 . 0
2010-07-30 22:34:54 +02:00
*/
2010-11-10 15:27:15 +01:00
/** Load WordPress Administration Bootstrap */
2013-09-25 02:18:11 +02:00
require_once ( dirname ( __FILE__ ) . '/admin.php' );
2010-07-30 22:34:54 +02:00
2010-11-10 15:27:15 +01:00
if ( ! is_multisite () )
wp_die ( __ ( 'Multisite support is not enabled.' ) );
2010-12-15 20:24:42 +01:00
if ( ! current_user_can ( 'manage_network_themes' ) )
wp_die ( __ ( 'You do not have sufficient permissions to manage network themes.' ) );
2011-01-16 22:47:24 +01:00
$wp_list_table = _get_list_table ( 'WP_MS_Themes_List_Table' );
2011-01-13 01:03:38 +01:00
$pagenum = $wp_list_table -> get_pagenum ();
2010-07-30 22:34:54 +02:00
2010-10-31 10:37:15 +01:00
$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.
2010-12-25 14:44:03 +01:00
$temp_args = array ( 'enabled' , 'disabled' , 'deleted' , 'error' );
2010-12-24 18:41:36 +01:00
$_SERVER [ 'REQUEST_URI' ] = remove_query_arg ( $temp_args , $_SERVER [ 'REQUEST_URI' ] );
$referer = remove_query_arg ( $temp_args , wp_get_referer () );
2010-10-31 10:37:15 +01:00
if ( $action ) {
2015-10-07 19:11:25 +02:00
$allowed_themes = get_site_option ( 'allowedthemes' );
2010-10-31 10:37:15 +01:00
switch ( $action ) {
2010-11-08 22:52:54 +01:00
case 'enable' :
2010-12-23 17:20:36 +01:00
check_admin_referer ( 'enable-theme_' . $_GET [ 'theme' ]);
2010-11-08 20:40:05 +01:00
$allowed_themes [ $_GET [ 'theme' ] ] = true ;
2015-10-07 19:11:25 +02:00
update_site_option ( 'allowedthemes' , $allowed_themes );
2012-06-12 17:31:25 +02:00
if ( false === strpos ( $referer , '/network/themes.php' ) )
wp_redirect ( network_admin_url ( 'themes.php?enabled=1' ) );
else
wp_safe_redirect ( add_query_arg ( 'enabled' , 1 , $referer ) );
2010-12-24 18:41:36 +01:00
exit ;
2010-11-08 22:52:54 +01:00
case 'disable' :
2010-12-23 17:20:36 +01:00
check_admin_referer ( 'disable-theme_' . $_GET [ 'theme' ]);
2010-10-31 10:37:15 +01:00
unset ( $allowed_themes [ $_GET [ 'theme' ] ] );
2015-10-07 19:11:25 +02:00
update_site_option ( 'allowedthemes' , $allowed_themes );
2011-12-10 19:26:48 +01:00
wp_safe_redirect ( add_query_arg ( 'disabled' , '1' , $referer ) );
2010-10-31 10:37:15 +01:00
exit ;
2010-11-08 22:52:54 +01:00
case 'enable-selected' :
2010-12-23 17:20:36 +01:00
check_admin_referer ( 'bulk-themes' );
2010-10-31 10:37:15 +01:00
$themes = isset ( $_POST [ 'checked' ] ) ? ( array ) $_POST [ 'checked' ] : array ();
if ( empty ( $themes ) ) {
2011-12-10 19:26:48 +01:00
wp_safe_redirect ( add_query_arg ( 'error' , 'none' , $referer ) );
2010-10-31 10:37:15 +01:00
exit ;
2010-12-24 18:41:36 +01:00
}
2015-08-25 22:28:22 +02:00
foreach ( ( array ) $themes as $theme )
2010-11-08 20:40:05 +01:00
$allowed_themes [ $theme ] = true ;
2015-10-07 19:11:25 +02:00
update_site_option ( 'allowedthemes' , $allowed_themes );
2011-12-10 19:26:48 +01:00
wp_safe_redirect ( add_query_arg ( 'enabled' , count ( $themes ), $referer ) );
2010-12-24 18:41:36 +01:00
exit ;
2010-11-08 22:52:54 +01:00
case 'disable-selected' :
2010-12-23 17:20:36 +01:00
check_admin_referer ( 'bulk-themes' );
2010-11-04 21:11:08 +01:00
$themes = isset ( $_POST [ 'checked' ] ) ? ( array ) $_POST [ 'checked' ] : array ();
if ( empty ( $themes ) ) {
2011-12-10 19:26:48 +01:00
wp_safe_redirect ( add_query_arg ( 'error' , 'none' , $referer ) );
2010-11-04 21:11:08 +01:00
exit ;
2010-12-24 18:41:36 +01:00
}
2015-08-25 22:28:22 +02:00
foreach ( ( array ) $themes as $theme )
2010-11-04 21:11:08 +01:00
unset ( $allowed_themes [ $theme ] );
2015-10-07 19:11:25 +02:00
update_site_option ( 'allowedthemes' , $allowed_themes );
2011-12-10 19:26:48 +01:00
wp_safe_redirect ( add_query_arg ( 'disabled' , count ( $themes ), $referer ) );
2010-12-24 18:41:36 +01:00
exit ;
2011-10-03 16:35:43 +02:00
case 'update-selected' :
check_admin_referer ( 'bulk-themes' );
if ( isset ( $_GET [ 'themes' ] ) )
$themes = explode ( ',' , $_GET [ 'themes' ] );
elseif ( isset ( $_POST [ 'checked' ] ) )
$themes = ( array ) $_POST [ 'checked' ];
else
$themes = array ();
$title = __ ( 'Update Themes' );
$parent_file = 'themes.php' ;
require_once ( ABSPATH . 'wp-admin/admin-header.php' );
echo '<div class="wrap">' ;
2015-06-27 17:41:25 +02:00
echo '<h1>' . esc_html ( $title ) . '</h1>' ;
2011-10-03 16:35:43 +02:00
$url = self_admin_url ( 'update.php?action=update-selected-themes&themes=' . urlencode ( join ( ',' , $themes ) ));
$url = wp_nonce_url ( $url , 'bulk-update-themes' );
echo " <iframe src=' $url ' style='width: 100%; height:100%; min-height:850px;'></iframe> " ;
echo '</div>' ;
require_once ( ABSPATH . 'wp-admin/admin-footer.php' );
exit ;
2010-12-21 17:50:16 +01:00
case 'delete-selected' :
2014-10-08 21:05:20 +02:00
if ( ! current_user_can ( 'delete_themes' ) ) {
2010-12-21 17:50:16 +01:00
wp_die ( __ ( 'You do not have sufficient permissions to delete themes for this site.' ) );
2014-10-08 21:05:20 +02:00
}
2010-12-23 19:53:44 +01:00
check_admin_referer ( 'bulk-themes' );
2010-12-21 17:50:16 +01:00
$themes = isset ( $_REQUEST [ 'checked' ] ) ? ( array ) $_REQUEST [ 'checked' ] : array ();
2010-12-24 18:41:36 +01:00
2010-12-21 17:50:16 +01:00
if ( empty ( $themes ) ) {
2011-12-10 19:26:48 +01:00
wp_safe_redirect ( add_query_arg ( 'error' , 'none' , $referer ) );
2010-12-21 17:50:16 +01:00
exit ;
}
2014-10-05 22:37:17 +02:00
$themes = array_diff ( $themes , array ( get_option ( 'stylesheet' ), get_option ( 'template' ) ) );
2011-12-09 00:02:33 +01:00
2010-12-21 17:50:16 +01:00
if ( empty ( $themes ) ) {
2011-12-10 19:26:48 +01:00
wp_safe_redirect ( add_query_arg ( 'error' , 'main' , $referer ) );
2010-12-21 17:50:16 +01:00
exit ;
}
2010-12-23 16:56:32 +01:00
2015-12-17 19:35:26 +01:00
$theme_info = array ();
2014-10-05 22:37:17 +02:00
foreach ( $themes as $key => $theme ) {
$theme_info [ $theme ] = wp_get_theme ( $theme );
}
2010-12-21 17:50:16 +01:00
include ( ABSPATH . 'wp-admin/update.php' );
$parent_file = 'themes.php' ;
if ( ! isset ( $_REQUEST [ 'verify-delete' ] ) ) {
wp_enqueue_script ( 'jquery' );
require_once ( ABSPATH . 'wp-admin/admin-header.php' );
2015-03-31 20:45:28 +02:00
$themes_to_delete = count ( $themes );
2010-12-21 17:50:16 +01:00
?>
< div class = " wrap " >
2015-03-31 20:45:28 +02:00
< ? php if ( 1 == $themes_to_delete ) : ?>
2015-06-27 17:41:25 +02:00
< h1 >< ? php _e ( 'Delete Theme' ); ?> </h1>
2015-03-31 20:45:28 +02:00
< div class = " error " >< p >< strong >< ? php _e ( 'Caution:' ); ?> </strong> <?php _e( 'This theme may be active on other sites in the network.' ); ?></p></div>
< p >< ? php _e ( 'You are about to remove the following theme:' ); ?> </p>
< ? php else : ?>
2015-06-27 17:41:25 +02:00
< h1 >< ? php _e ( 'Delete Themes' ); ?> </h1>
2015-03-31 20:45:28 +02:00
< div class = " error " >< p >< strong >< ? php _e ( 'Caution:' ); ?> </strong> <?php _e( 'These themes may be active on other sites in the network.' ); ?></p></div>
< p >< ? php _e ( 'You are about to remove the following themes:' ); ?> </p>
< ? php endif ; ?>
2010-12-21 17:50:16 +01:00
< ul class = " ul-disc " >
2014-10-08 21:05:20 +02:00
< ? php
foreach ( $theme_info as $theme ) {
2016-02-29 03:38:26 +01:00
echo '<li>' . sprintf (
/* translators: 1: theme name, 2: theme author */
_x ( '%1$s by %2$s' , 'theme' ),
'<strong>' . $theme -> display ( 'Name' ) . '</strong>' ,
'<em>' . $theme -> display ( 'Author' ) . '</em>'
) . '</li>' ;
2014-10-08 21:05:20 +02:00
}
?>
2010-12-21 17:50:16 +01:00
</ ul >
2015-03-31 20:45:28 +02:00
< ? php if ( 1 == $themes_to_delete ) : ?>
< p >< ? php _e ( 'Are you sure you wish to delete this theme?' ); ?> </p>
< ? php else : ?>
< p >< ? php _e ( 'Are you sure you wish to delete these themes?' ); ?> </p>
< ? php endif ; ?>
2010-12-21 17:50:16 +01:00
< form method = " post " action = " <?php echo esc_url( $_SERVER['REQUEST_URI'] ); ?> " style = " display:inline; " >
< input type = " hidden " name = " verify-delete " value = " 1 " />
< input type = " hidden " name = " action " value = " delete-selected " />
< ? php
2014-10-08 21:05:20 +02:00
foreach ( ( array ) $themes as $theme ) {
2010-12-21 17:50:16 +01:00
echo '<input type="hidden" name="checked[]" value="' . esc_attr ( $theme ) . '" />' ;
2014-10-08 21:05:20 +02:00
}
2015-03-31 20:45:28 +02:00
wp_nonce_field ( 'bulk-themes' );
if ( 1 == $themes_to_delete ) {
2015-07-04 02:50:25 +02:00
submit_button ( __ ( 'Yes, delete this theme' ), 'button' , 'submit' , false );
2015-03-31 20:45:28 +02:00
} else {
2015-07-04 02:50:25 +02:00
submit_button ( __ ( 'Yes, delete these themes' ), 'button' , 'submit' , false );
2015-03-31 20:45:28 +02:00
}
2010-12-21 17:50:16 +01:00
?>
</ form >
2015-03-09 03:11:28 +01:00
< ? php
$referer = wp_get_referer ();
?>
< form method = " post " action = " <?php echo $referer ? esc_url( $referer ) : ''; ?> " style = " display:inline; " >
2015-07-04 02:50:25 +02:00
< ? php submit_button ( __ ( 'No, return me to the theme list' ), 'button' , 'submit' , false ); ?>
2010-12-21 17:50:16 +01:00
</ form >
</ div >
< ? php
require_once ( ABSPATH . 'wp-admin/admin-footer.php' );
exit ;
2010-12-23 16:56:32 +01:00
} // Endif verify-delete
2010-12-23 20:40:32 +01:00
2012-09-29 03:36:14 +02:00
foreach ( $themes as $theme ) {
$delete_result = delete_theme ( $theme , esc_url ( add_query_arg ( array (
'verify-delete' => 1 ,
'action' => 'delete-selected' ,
'checked' => $_REQUEST [ 'checked' ],
'_wpnonce' => $_REQUEST [ '_wpnonce' ]
), network_admin_url ( 'themes.php' ) ) ) );
}
2014-05-06 20:08:14 +02:00
2011-12-09 00:02:33 +01:00
$paged = ( $_REQUEST [ 'paged' ] ) ? $_REQUEST [ 'paged' ] : 1 ;
2012-09-29 03:36:14 +02:00
wp_redirect ( add_query_arg ( array (
'deleted' => count ( $themes ),
'paged' => $paged ,
's' => $s
), network_admin_url ( 'themes.php' ) ) );
2010-12-21 17:50:16 +01:00
exit ;
2010-10-31 10:37:15 +01:00
}
2010-07-30 22:34:54 +02:00
}
2010-10-31 10:37:15 +01:00
$wp_list_table -> prepare_items ();
2011-01-13 01:03:38 +01:00
2010-11-01 21:08:25 +01:00
add_thickbox ();
2010-10-31 10:37:15 +01:00
2015-03-10 16:32:27 +01:00
add_screen_option ( 'per_page' );
2011-10-02 08:59:36 +02:00
2011-12-01 03:22:07 +01:00
get_current_screen () -> add_help_tab ( array (
'id' => 'overview' ,
'title' => __ ( 'Overview' ),
'content' =>
'<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>' .
'<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’s Appearance > Themes screen.' ) . '</p>' .
'<p>' . __ ( 'Themes can be enabled on a site by site basis by the network admin on the Edit Site screen (which has a Themes tab); get there via the Edit action link on the All Sites screen. Only network admins are able to install or edit themes.' ) . '</p>'
) );
2011-11-02 06:33:53 +01:00
2011-11-02 22:32:16 +01:00
get_current_screen () -> set_help_sidebar (
2010-12-18 19:27:12 +01:00
'<p><strong>' . __ ( 'For more information:' ) . '</strong></p>' .
2015-04-12 23:29:32 +02:00
'<p>' . __ ( '<a href="https://codex.wordpress.org/Network_Admin_Themes_Screen" target="_blank">Documentation on Network Themes</a>' ) . '</p>' .
2014-03-08 05:14:15 +01:00
'<p>' . __ ( '<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>' ) . '</p>'
2010-11-01 00:23:32 +01:00
);
2015-10-07 03:28:25 +02:00
get_current_screen () -> set_screen_reader_content ( array (
'heading_views' => __ ( 'Filter themes list' ),
'heading_pagination' => __ ( 'Themes list navigation' ),
'heading_list' => __ ( 'Themes list' ),
) );
2010-10-31 10:37:15 +01:00
$title = __ ( 'Themes' );
$parent_file = 'themes.php' ;
No-JavaScript and no-Customizer support for the new Themes screen.
JavaScript is rarely disabled, but graceful degradation is still important. For example, syntax errors can occur, usually with major WP updates that overhaul entire experiences and update external libraries combined with themes or plugins doing weird or old things. If this error is due to their current theme, a user needs to be able to access the themes screen to switch away from the theme. A more subtle issue could make things painful to diagnose.
This commit renders the grid in PHP (the template is duplicated, but it lightweight, fairly mundane, and easy to sync). On Backbone render, the grid is then re-rendered from JavaScript so searches can occur. Customize and Live Preview is disabled if JS fails to kick in. If JS is disabled, old-school "Preview" links are displayed.
No-Customizer support: The customizer is only supported when the browser supports postMessage (IE8+), and if the frontend is a different domain, CORS (IE10+). We use the .hide-if-no-customize class for this. Pre-customize "Preview" links should use .hide-if-customize.
The .load-customize class should be used to declare a link that opens the customizer. This enables customize-loader.js to intercept this link and load the customizer on top of the current window, making for a smoother experience.
fixes #25964.
Built from https://develop.svn.wordpress.org/trunk@26726
git-svn-id: http://core.svn.wordpress.org/trunk@26615 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-12-06 17:11:10 +01:00
wp_enqueue_script ( 'theme-preview' );
2013-07-05 17:15:58 +02:00
2010-10-31 10:37:15 +01:00
require_once ( ABSPATH . 'wp-admin/admin-header.php' );
2010-07-30 22:34:54 +02:00
?>
2010-10-31 10:37:15 +01:00
2010-07-30 22:34:54 +02:00
< div class = " wrap " >
2015-07-03 18:42:24 +02:00
< h1 >< ? php echo esc_html ( $title ); if ( current_user_can ( 'install_themes' ) ) { ?> <a href="theme-install.php" class="page-title-action"><?php echo esc_html_x('Add New', 'theme'); ?></a><?php }
2016-01-14 21:06:25 +01:00
if ( isset ( $_REQUEST [ 's' ] ) && strlen ( $_REQUEST [ 's' ] ) ) {
/* translators: %s: search keywords */
printf ( '<span class="subtitle">' . __ ( 'Search results for “%s”' ) . '</span>' , esc_html ( $s ) );
}
?>
2015-06-27 17:41:25 +02:00
</ h1 >
2010-10-31 10:37:15 +01:00
2010-12-24 18:41:36 +01:00
< ? php
if ( isset ( $_GET [ 'enabled' ] ) ) {
2015-03-31 20:45:28 +02:00
$enabled = absint ( $_GET [ 'enabled' ] );
if ( 1 == $enabled ) {
$message = __ ( 'Theme enabled.' );
} else {
$message = _n ( '%s theme enabled.' , '%s themes enabled.' , $enabled );
}
2015-04-02 00:06:28 +02:00
echo '<div id="message" class="updated notice is-dismissible"><p>' . sprintf ( $message , number_format_i18n ( $enabled ) ) . '</p></div>' ;
2010-12-24 18:41:36 +01:00
} elseif ( isset ( $_GET [ 'disabled' ] ) ) {
2015-03-31 20:45:28 +02:00
$disabled = absint ( $_GET [ 'disabled' ] );
if ( 1 == $disabled ) {
$message = __ ( 'Theme disabled.' );
} else {
$message = _n ( '%s theme disabled.' , '%s themes disabled.' , $disabled );
}
2015-04-02 00:06:28 +02:00
echo '<div id="message" class="updated notice is-dismissible"><p>' . sprintf ( $message , number_format_i18n ( $disabled ) ) . '</p></div>' ;
2010-12-24 18:41:36 +01:00
} elseif ( isset ( $_GET [ 'deleted' ] ) ) {
2015-03-31 20:45:28 +02:00
$deleted = absint ( $_GET [ 'deleted' ] );
if ( 1 == $deleted ) {
$message = __ ( 'Theme deleted.' );
} else {
$message = _n ( '%s theme deleted.' , '%s themes deleted.' , $deleted );
}
2015-04-02 00:06:28 +02:00
echo '<div id="message" class="updated notice is-dismissible"><p>' . sprintf ( $message , number_format_i18n ( $deleted ) ) . '</p></div>' ;
2010-12-24 18:41:36 +01:00
} elseif ( isset ( $_GET [ 'error' ] ) && 'none' == $_GET [ 'error' ] ) {
2015-04-02 00:06:28 +02:00
echo '<div id="message" class="error notice is-dismissible"><p>' . __ ( 'No theme selected.' ) . '</p></div>' ;
2010-12-24 18:41:36 +01:00
} elseif ( isset ( $_GET [ 'error' ] ) && 'main' == $_GET [ 'error' ] ) {
2015-04-02 00:06:28 +02:00
echo '<div class="error notice is-dismissible"><p>' . __ ( 'You cannot delete a theme while it is active on the main site.' ) . '</p></div>' ;
2010-12-24 18:41:36 +01:00
}
?>
2015-01-16 05:16:24 +01:00
< form method = " get " >
2010-12-16 21:45:10 +01:00
< ? php $wp_list_table -> search_box ( __ ( 'Search Installed Themes' ), 'theme' ); ?>
2010-10-31 10:37:15 +01:00
</ form >
2012-03-08 08:32:42 +01:00
< ? php
$wp_list_table -> views ();
if ( 'broken' == $status )
2016-02-23 18:20:27 +01:00
echo '<p class="clear">' . __ ( 'The following themes are installed but incomplete.' ) . '</p>' ;
2012-03-08 08:32:42 +01:00
?>
2010-10-31 10:37:15 +01:00
2015-01-16 05:16:24 +01:00
< form method = " post " >
2010-10-31 10:37:15 +01:00
< input type = " hidden " name = " theme_status " value = " <?php echo esc_attr( $status ) ?> " />
< input type = " hidden " name = " paged " value = " <?php echo esc_attr( $page ) ?> " />
< ? php $wp_list_table -> display (); ?>
</ form >
2010-07-30 22:34:54 +02:00
</ div >
2010-10-31 10:37:15 +01:00
< ? php
2010-12-16 21:45:10 +01:00
include ( ABSPATH . 'wp-admin/admin-footer.php' );