mirror of
https://github.com/WordPress/WordPress.git
synced 2025-01-03 06:57:35 +01:00
Multisite: Introduce WP_Theme
methods to network enable/disable themes.
* `WP_Theme::network_enable_theme()` can be used to enable a theme or array of themes on a network. * `WP_Theme::network_disable_theme()` can be used to disable a theme or array of themes on a network. * Use these new methods in the network admin vs direct `update_site_option()` calls. * Add tests. Props igmoweb. Fixes #30594. Built from https://develop.svn.wordpress.org/trunk@37202 git-svn-id: http://core.svn.wordpress.org/trunk@37168 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
499763f725
commit
6279ca91de
@ -29,12 +29,10 @@ $_SERVER['REQUEST_URI'] = remove_query_arg( $temp_args, $_SERVER['REQUEST_URI']
|
||||
$referer = remove_query_arg( $temp_args, wp_get_referer() );
|
||||
|
||||
if ( $action ) {
|
||||
$allowed_themes = get_site_option( 'allowedthemes' );
|
||||
switch ( $action ) {
|
||||
case 'enable':
|
||||
check_admin_referer('enable-theme_' . $_GET['theme']);
|
||||
$allowed_themes[ $_GET['theme'] ] = true;
|
||||
update_site_option( 'allowedthemes', $allowed_themes );
|
||||
WP_Theme::network_enable_theme( $_GET['theme'] );
|
||||
if ( false === strpos( $referer, '/network/themes.php' ) )
|
||||
wp_redirect( network_admin_url( 'themes.php?enabled=1' ) );
|
||||
else
|
||||
@ -42,8 +40,7 @@ if ( $action ) {
|
||||
exit;
|
||||
case 'disable':
|
||||
check_admin_referer('disable-theme_' . $_GET['theme']);
|
||||
unset( $allowed_themes[ $_GET['theme'] ] );
|
||||
update_site_option( 'allowedthemes', $allowed_themes );
|
||||
WP_Theme::network_disable_theme( $_GET['theme'] );
|
||||
wp_safe_redirect( add_query_arg( 'disabled', '1', $referer ) );
|
||||
exit;
|
||||
case 'enable-selected':
|
||||
@ -53,9 +50,7 @@ if ( $action ) {
|
||||
wp_safe_redirect( add_query_arg( 'error', 'none', $referer ) );
|
||||
exit;
|
||||
}
|
||||
foreach ( (array) $themes as $theme )
|
||||
$allowed_themes[ $theme ] = true;
|
||||
update_site_option( 'allowedthemes', $allowed_themes );
|
||||
WP_Theme::network_enable_theme( (array) $themes );
|
||||
wp_safe_redirect( add_query_arg( 'enabled', count( $themes ), $referer ) );
|
||||
exit;
|
||||
case 'disable-selected':
|
||||
@ -65,9 +60,7 @@ if ( $action ) {
|
||||
wp_safe_redirect( add_query_arg( 'error', 'none', $referer ) );
|
||||
exit;
|
||||
}
|
||||
foreach ( (array) $themes as $theme )
|
||||
unset( $allowed_themes[ $theme ] );
|
||||
update_site_option( 'allowedthemes', $allowed_themes );
|
||||
WP_Theme::network_disable_theme( (array) $themes );
|
||||
wp_safe_redirect( add_query_arg( 'disabled', count( $themes ), $referer ) );
|
||||
exit;
|
||||
case 'update-selected' :
|
||||
|
@ -1315,6 +1315,62 @@ final class WP_Theme implements ArrayAccess {
|
||||
return (array) apply_filters( 'site_allowed_themes', $allowed_themes[ $blog_id ], $blog_id );
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable a theme for all sites on the current network.
|
||||
*
|
||||
* @since 4.6.0
|
||||
*
|
||||
* @static
|
||||
* @access public
|
||||
*
|
||||
* @param string|array $stylesheets Stylesheet name or array of stylesheet names.
|
||||
*/
|
||||
public static function network_enable_theme( $stylesheets ) {
|
||||
if ( ! is_multisite() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! is_array( $stylesheets ) ) {
|
||||
$stylesheets = array( $stylesheets );
|
||||
}
|
||||
|
||||
$allowed_themes = get_site_option( 'allowedthemes' );
|
||||
foreach ( $stylesheets as $stylesheet ) {
|
||||
$allowed_themes[ $stylesheet ] = true;
|
||||
}
|
||||
|
||||
update_site_option( 'allowedthemes', $allowed_themes );
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable a theme for all sites on the current network.
|
||||
*
|
||||
* @since 4.6.0
|
||||
*
|
||||
* @static
|
||||
* @access public
|
||||
*
|
||||
* @param string|array $stylesheets Stylesheet name or array of stylesheet names.
|
||||
*/
|
||||
public static function network_disable_theme( $stylesheets ) {
|
||||
if ( ! is_multisite() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! is_array( $stylesheets ) ) {
|
||||
$stylesheets = array( $stylesheets );
|
||||
}
|
||||
|
||||
$allowed_themes = get_site_option( 'allowedthemes' );
|
||||
foreach ( $stylesheets as $stylesheet ) {
|
||||
if ( isset( $allowed_themes[ $stylesheet ] ) ) {
|
||||
unset( $allowed_themes[ $stylesheet ] );
|
||||
}
|
||||
}
|
||||
|
||||
update_site_option( 'allowedthemes', $allowed_themes );
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts themes by name.
|
||||
*
|
||||
|
@ -4,7 +4,7 @@
|
||||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '4.6-alpha-37201';
|
||||
$wp_version = '4.6-alpha-37202';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
Loading…
Reference in New Issue
Block a user