Make WordPress Core

Ticket #28436: 28436.2.diff

File 28436.2.diff, 2.8 KB (added by lamosty, 10 years ago)

Pass $blog_id parameter into the filter and create unit test.

  • src/wp-includes/class-wp-theme.php

    diff --git src/wp-includes/class-wp-theme.php src/wp-includes/class-wp-theme.php
    index 523c733..3b80657 100644
    final class WP_Theme implements ArrayAccess { 
    11041104                /**
    11051105                 * Filter the array of themes allowed on the site or network.
    11061106                 *
    1107                  * @since MU
     1107                 * @since 4.2
    11081108                 *
    11091109                 * @param array $allowed_themes An array of theme stylesheet names.
    11101110                 */
    1111                 $network = (array) apply_filters( 'allowed_themes', self::get_allowed_on_network() );
     1111                $network = (array) apply_filters( 'allowed_themes_combined', self::get_allowed_on_network(), $blog_id );
    11121112                return $network + self::get_allowed_on_site( $blog_id );
    11131113        }
    11141114
    final class WP_Theme implements ArrayAccess { 
    11221122         */
    11231123        public static function get_allowed_on_network() {
    11241124                static $allowed_themes;
    1125                 if ( ! isset( $allowed_themes ) )
    1126                         $allowed_themes = (array) get_site_option( 'allowedthemes' );
     1125                if ( ! isset( $allowed_themes ) ) {
     1126                        /**
     1127                         * Filter the array of themes allowed on the network.
     1128                         *
     1129                         * @since 4.2
     1130                         *
     1131                         * @param array $allowed_themes An array of theme stylesheet names.
     1132                         */
     1133                        $allowed_themes = (array) apply_filters( 'allowed_themes', get_site_option( 'allowedthemes' ) );
     1134                }
    11271135                return $allowed_themes;
    11281136        }
    11291137
    final class WP_Theme implements ArrayAccess { 
    11911199                        }
    11921200                }
    11931201
    1194                 return (array) $allowed_themes[ $blog_id ];
     1202                /**
     1203                 * Filter the array of themes allowed on the site.
     1204                 *
     1205                 * @since 4.2
     1206                 *
     1207                 * @param array $allowed_themes An array of theme stylesheet names.
     1208                 */
     1209                $allowed_themes = (array) apply_filters( 'allowed_themes_site', $allowed_themes[ $blog_id ], $blog_id );
     1210                return $allowed_themes;
    11951211        }
    11961212
    11971213        /**
  • new file tests/phpunit/tests/multisite/theme.php

    diff --git tests/phpunit/tests/multisite/theme.php tests/phpunit/tests/multisite/theme.php
    new file mode 100644
    index 0000000..a8944dd
    - +  
     1<?php
     2
     3if ( is_multisite() ) : /**
     4 * Tests specific to networks in multisite.
     5 *
     6 * @group ms-network
     7 * @group multisite
     8 */ {
     9        class Tests_Multisite_Theme extends WP_UnitTestCase {
     10
     11                function setUp() {
     12                        global $wpdb;
     13                        parent::setUp();
     14                        $this->suppress = $wpdb->suppress_errors();
     15
     16                        $_SERVER['REMOTE_ADDR'] = '';
     17                }
     18
     19                function tearDown() {
     20                        global $wpdb;
     21                        $wpdb->suppress_errors( $this->suppress );
     22                        parent::tearDown();
     23                }
     24
     25                function test_nav_menu_theme_filter_sends_blog_id() {
     26                        $args = [ ];
     27
     28                        add_filter( 'allowed_themes_combined', function () use ( &$args ) {
     29                                $args = func_get_args();
     30                        }, 10, 2 );
     31
     32                        $blog_id = 2;
     33
     34                        WP_Theme::get_allowed( $blog_id );
     35
     36                        $this->assertNotEmpty( $args );
     37                        $this->assertEquals( 2, count( $args ) );
     38                        $this->assertEquals( $blog_id, $args[1] );
     39                }
     40
     41        }
     42}
     43
     44endif;