mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-07 09:49:04 +00: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. git-svn-id: https://develop.svn.wordpress.org/trunk@37202 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -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.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user