WordPress.org

Make WordPress Core


Ignore:
Timestamp:
04/14/2016 03:39:45 AM (4 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/tests/phpunit/tests/theme/WPTheme.php

    r27915 r37202  
    140140        $this->assertFalse( $theme->display( 'Tags' ) );
    141141    }
     142
     143
     144    /**
     145     * Enable a single theme on a network.
     146     *
     147     * @ticket 30594
     148     */
     149    function test_wp_theme_network_enable_single_theme() {
     150        if ( ! is_multisite() ) {
     151            $this->markTestSkipped( 'This test requires multisite' );
     152        }
     153
     154        $theme = 'testtheme-1';
     155        $current_allowed_themes = get_site_option( 'allowedthemes' );
     156        WP_Theme::network_enable_theme( $theme );
     157        $new_allowed_themes = get_site_option( 'allowedthemes' );
     158        update_site_option( 'allowedthemes', $current_allowed_themes ); // reset previous value.
     159        $current_allowed_themes['testtheme-1'] = true; // Add the new theme to the previous set.
     160
     161        $this->assertEqualSetsWithIndex( $current_allowed_themes, $new_allowed_themes );
     162    }
     163
     164    /**
     165     * Enable multiple themes on a network.
     166     *
     167     * @ticket 30594
     168     */
     169    function test_wp_theme_network_enable_multiple_themes() {
     170        if ( ! is_multisite() ) {
     171            $this->markTestSkipped( 'This test requires multisite' );
     172        }
     173
     174        $themes = array( 'testtheme-2', 'testtheme-3' );
     175        $current_allowed_themes = get_site_option( 'allowedthemes' );
     176        WP_Theme::network_enable_theme( $themes );
     177        $new_allowed_themes = get_site_option( 'allowedthemes' );
     178        update_site_option( 'allowedthemes', $current_allowed_themes ); // reset previous value.
     179        $current_allowed_themes = array_merge( $current_allowed_themes, array( 'testtheme-2' => true, 'testtheme-3' => true ) );
     180
     181        $this->assertEqualSetsWithIndex( $current_allowed_themes, $new_allowed_themes );
     182    }
     183
     184    /**
     185     * Disable a single theme on a network.
     186     *
     187     * @ticket 30594
     188     */
     189    function test_network_disable_single_theme() {
     190        if ( ! is_multisite() ) {
     191            $this->markTestSkipped( 'This test requires multisite' );
     192        }
     193
     194        $current_allowed_themes = get_site_option( 'allowedthemes' );
     195
     196        $allowed_themes = array( 'existing-1' => true, 'existing-2' => true, 'existing-3' => true );
     197        update_site_option( 'allowedthemes', $allowed_themes );
     198
     199        $disable_theme = 'existing-2';
     200        WP_Theme::network_disable_theme( $disable_theme );
     201        $new_allowed_themes = get_site_option( 'allowedthemes' );
     202        update_site_option( 'allowedthemes', $current_allowed_themes ); // reset previous value.
     203        unset( $allowed_themes[ $disable_theme ] ); // Remove deleted theme from initial set.
     204
     205        $this->assertEqualSetsWithIndex( $allowed_themes, $new_allowed_themes );
     206    }
     207
     208    /**
     209     * Disable multiple themes on a network.
     210     *
     211     * @ticket 30594
     212     */
     213    function test_network_disable_multiple_themes() {
     214        if ( ! is_multisite() ) {
     215            $this->markTestSkipped( 'This test requires multisite' );
     216        }
     217
     218        $current_allowed_themes = get_site_option( 'allowedthemes' );
     219
     220        $allowed_themes = array( 'existing-4' => true, 'existing-5' => true, 'existing-6' => true );
     221        update_site_option( 'allowedthemes', $allowed_themes );
     222
     223        $disable_themes = array( 'existing-4', 'existing-5' );
     224        WP_Theme::network_disable_theme( $disable_themes );
     225        $new_allowed_themes = get_site_option( 'allowedthemes' );
     226        update_site_option( 'allowedthemes', $current_allowed_themes ); // reset previous value.
     227        unset( $allowed_themes['existing-4'] );
     228        unset( $allowed_themes['existing-5'] );
     229
     230        $this->assertEqualSetsWithIndex( $allowed_themes, $new_allowed_themes );
     231    }
    142232}
Note: See TracChangeset for help on using the changeset viewer.