Make WordPress Core

Ticket #30594: enable_themes_function.diff

File enable_themes_function.diff, 3.1 KB (added by igmoweb, 12 years ago)

Enable/Disable themes network widly functions

  • src/wp-admin/network/themes.php

     
    2929$referer = remove_query_arg( $temp_args, wp_get_referer() );
    3030
    3131if ( $action ) {
    32         $allowed_themes = get_site_option( 'allowedthemes' );
    3332        switch ( $action ) {
    3433                case 'enable':
    3534                        check_admin_referer('enable-theme_' . $_GET['theme']);
    36                         $allowed_themes[ $_GET['theme'] ] = true;
    37                         update_site_option( 'allowedthemes', $allowed_themes );
     35                        wp_network_enable_themes( $_GET['theme'] );
    3836                        if ( false === strpos( $referer, '/network/themes.php' ) )
    3937                                wp_redirect( network_admin_url( 'themes.php?enabled=1' ) );
    4038                        else
    … …  
    4240                        exit;
    4341                case 'disable':
    4442                        check_admin_referer('disable-theme_' . $_GET['theme']);
    45                         unset( $allowed_themes[ $_GET['theme'] ] );
    46                         update_site_option( 'allowedthemes', $allowed_themes );
     43                        wp_network_disable_themes( $_GET['theme'] );
    4744                        wp_safe_redirect( add_query_arg( 'disabled', '1', $referer ) );
    4845                        exit;
    4946                case 'enable-selected':
    … …  
    5350                                wp_safe_redirect( add_query_arg( 'error', 'none', $referer ) );
    5451                                exit;
    5552                        }
    56                         foreach( (array) $themes as $theme )
    57                                 $allowed_themes[ $theme ] = true;
    58                         update_site_option( 'allowedthemes', $allowed_themes );
     53                        wp_network_enable_themes( (array) $themes );
    5954                        wp_safe_redirect( add_query_arg( 'enabled', count( $themes ), $referer ) );
    6055                        exit;
    6156                case 'disable-selected':
    … …  
    6560                                wp_safe_redirect( add_query_arg( 'error', 'none', $referer ) );
    6661                                exit;
    6762                        }
    68                         foreach( (array) $themes as $theme )
    69                                 unset( $allowed_themes[ $theme ] );
    70                         update_site_option( 'allowedthemes', $allowed_themes );
     63                        wp_network_disable_themes( (array) $themes );
    7164                        wp_safe_redirect( add_query_arg( 'disabled', count( $themes ), $referer ) );
    7265                        exit;
    7366                case 'update-selected' :
  • src/wp-includes/ms-functions.php

     
    24342434
    24352435        return $site_results;
    24362436}
     2437
     2438/**
     2439 * Enable a theme network widly
     2440 *
     2441 * @param string $stylesheet Stylesheet name
     2442 */
     2443function wp_network_enable_themes( $stylesheets ) {
     2444
     2445        if ( ! is_array( $stylesheets ) )
     2446                $stylesheets = array( $stylesheets );
     2447
     2448        $allowed_themes = get_site_option( 'allowedthemes' );
     2449
     2450        foreach ( $stylesheets as $stylesheet )
     2451                $allowed_themes[ $stylesheet ] = true;
     2452                       
     2453        update_site_option( 'allowedthemes', $allowed_themes );
     2454}
     2455
     2456/**
     2457 * Disable a theme network widly
     2458 *
     2459 * @param string $stylesheet Stylesheet name
     2460 */
     2461function wp_network_disable_themes( $stylesheets ) {
     2462
     2463        if ( ! is_array( $stylesheets ) )
     2464                $stylesheets = array( $stylesheets );
     2465       
     2466        $allowed_themes = get_site_option( 'allowedthemes' );
     2467
     2468        foreach ( $stylesheets as $stylesheet ) {
     2469                if ( isset( $allowed_themes[ $stylesheet ] ) )
     2470                        unset( $allowed_themes[ $stylesheet ] );
     2471        }
     2472
     2473        update_site_option( 'allowedthemes', $allowed_themes );
     2474}