Make WordPress Core


Ignore:
Timestamp:
04/14/2016 03:39:45 AM (9 years ago)
Author:
jeremyfelt
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-theme.php

    r36739 r37202  
    13171317
    13181318    /**
     1319     * Enable a theme for all sites on the current network.
     1320     *
     1321     * @since 4.6.0
     1322     *
     1323     * @static
     1324     * @access public
     1325     *
     1326     * @param string|array $stylesheets Stylesheet name or array of stylesheet names.
     1327     */
     1328    public static function network_enable_theme( $stylesheets ) {
     1329        if ( ! is_multisite() ) {
     1330            return;
     1331        }
     1332
     1333        if ( ! is_array( $stylesheets ) ) {
     1334            $stylesheets = array( $stylesheets );
     1335        }
     1336
     1337        $allowed_themes = get_site_option( 'allowedthemes' );
     1338        foreach ( $stylesheets as $stylesheet ) {
     1339            $allowed_themes[ $stylesheet ] = true;
     1340        }
     1341
     1342        update_site_option( 'allowedthemes', $allowed_themes );
     1343    }
     1344
     1345    /**
     1346     * Disable a theme for all sites on the current network.
     1347     *
     1348     * @since 4.6.0
     1349     *
     1350     * @static
     1351     * @access public
     1352     *
     1353     * @param string|array $stylesheets Stylesheet name or array of stylesheet names.
     1354     */
     1355    public static function network_disable_theme( $stylesheets ) {
     1356        if ( ! is_multisite() ) {
     1357            return;
     1358        }
     1359
     1360        if ( ! is_array( $stylesheets ) ) {
     1361            $stylesheets = array( $stylesheets );
     1362        }
     1363
     1364        $allowed_themes = get_site_option( 'allowedthemes' );
     1365        foreach ( $stylesheets as $stylesheet ) {
     1366            if ( isset( $allowed_themes[ $stylesheet ] ) ) {
     1367                unset( $allowed_themes[ $stylesheet ] );
     1368            }
     1369        }
     1370
     1371        update_site_option( 'allowedthemes', $allowed_themes );
     1372    }
     1373
     1374    /**
    13191375     * Sorts themes by name.
    13201376     *
Note: See TracChangeset for help on using the changeset viewer.