Make WordPress Core

Ticket #28436: 28436.3.diff

File 28436.3.diff, 3.0 KB (added by lamosty, 10 years ago)

Resolved issues mentioned by @pento.

  • 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..5beaa99 100644
    final class WP_Theme implements ArrayAccess { 
    11071107                 * @since MU
    11081108                 *
    11091109                 * @param array $allowed_themes An array of theme stylesheet names.
     1110                 * @param int $blog_id Id of the site or network. Defaults to current blog.
    11101111                 */
    1111                 $network = (array) apply_filters( 'allowed_themes', self::get_allowed_on_network() );
     1112                $network = (array) apply_filters( 'allowed_themes_combined', self::get_allowed_on_network(), $blog_id );
    11121113                return $network + self::get_allowed_on_site( $blog_id );
    11131114        }
    11141115
    final class WP_Theme implements ArrayAccess { 
    11221123         */
    11231124        public static function get_allowed_on_network() {
    11241125                static $allowed_themes;
    1125                 if ( ! isset( $allowed_themes ) )
    1126                         $allowed_themes = (array) get_site_option( 'allowedthemes' );
     1126                if ( ! isset( $allowed_themes ) ) {
     1127                        /**
     1128                         * Filter the array of themes allowed on the network.
     1129                         *
     1130                         * @since 4.2
     1131                         *
     1132                         * @param array $allowed_themes An array of theme stylesheet names.
     1133                         */
     1134                        $allowed_themes = (array) apply_filters( 'allowed_themes', get_site_option( 'allowedthemes' ) );
     1135                }
    11271136                return $allowed_themes;
    11281137        }
    11291138
    final class WP_Theme implements ArrayAccess { 
    11911200                        }
    11921201                }
    11931202
    1194                 return (array) $allowed_themes[ $blog_id ];
     1203                /**
     1204                 * Filter the array of themes allowed on the site.
     1205                 *
     1206                 * @since 4.2
     1207                 *
     1208                 * @param array $allowed_themes An array of theme stylesheet names.
     1209                 * @param int $blog_id Id of the site. Defaults to current blog.
     1210                 */
     1211                $allowed_themes = (array) apply_filters( 'allowed_themes_site', $allowed_themes[ $blog_id ], $blog_id );
     1212                return $allowed_themes;
    11951213        }
    11961214
    11971215        /**
  • 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..c1c6ad7
    - +  
     1<?php
     2
     3if ( is_multisite() ) :
     4
     5        /**
     6         * Tests specific to networks in multisite.
     7         *
     8         * @group ms-network
     9         * @group multisite
     10         */
     11        class Tests_Multisite_Theme extends WP_UnitTestCase {
     12
     13                protected $filter_allowed_themes_combined_args;
     14
     15                function setUp() {
     16                        parent::setUp();
     17                }
     18
     19                function tearDown() {
     20                        parent::tearDown();
     21                }
     22
     23                function test_nav_menu_theme_filter_sends_blog_id() {
     24                        add_filter( 'allowed_themes_combined', array( $this, 'filter_allowed_themes_combined' ), 10, 2 );
     25
     26                        $blog_id = 1;
     27
     28                        WP_Theme::get_allowed( $blog_id );
     29
     30                        $this->assertNotEmpty( $this->filter_allowed_themes_combined_args );
     31                        $this->assertEquals( 2, count( $this->filter_allowed_themes_combined_args ) );
     32                        $this->assertEquals( $blog_id, $this->filter_allowed_themes_combined_args[1] );
     33                }
     34
     35                function filter_allowed_themes_combined() {
     36                        $this->filter_allowed_themes_combined_args = func_get_args();
     37
     38                }
     39        }
     40
     41endif;
     42 No newline at end of file