Make WordPress Core


Ignore:
Timestamp:
01/20/2016 06:28:33 PM (9 years ago)
Author:
jeremyfelt
Message:

Themes: Enhance filtering options for allowed themes on a network.

  • Move the legacy allowed_themes filter to WP_Theme::get_allowed_on_network(), where it will continue to filter themes allowed on the network.
  • Add network_allowed_themes filter to WP_Theme::get_allowed() and pass $blog_id to provide context.
  • Add site_allowed_themes filter to WP_Theme::get_allowed_on_site() and pass $blog_id to provide context.

Props pauldewouters, lamosty, michalzuber, dmsnell, johnnypea, rob.
Fixes #28436.

File:
1 edited

Legend:

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

    r36250 r36366  
    11781178     * @access public
    11791179     *
    1180      * @param int $blog_id Optional. Defaults to current blog.
     1180     * @param int $blog_id Optional. ID of the site. Defaults to the current site.
    11811181     * @return array Array of stylesheet names.
    11821182     */
    11831183    public static function get_allowed( $blog_id = null ) {
    11841184        /**
    1185          * Filter the array of themes allowed on the site or network.
     1185         * Filter the array of themes allowed on the network.
     1186         *
     1187         * Site is provided as context so that a list of network allowed themes can
     1188         * be filtered further.
     1189         *
     1190         * @since 4.5.0
     1191         *
     1192         * @param array $allowed_themes An array of theme stylesheet names.
     1193         * @param int   $blog_id        ID of the site.
     1194         */
     1195        $network = (array) apply_filters( 'network_allowed_themes', self::get_allowed_on_network(), $blog_id );
     1196        return $network + self::get_allowed_on_site( $blog_id );
     1197    }
     1198
     1199    /**
     1200     * Returns array of stylesheet names of themes allowed on the network.
     1201     *
     1202     * @since 3.4.0
     1203     *
     1204     * @static
     1205     * @access public
     1206     *
     1207     * @staticvar array $allowed_themes
     1208     *
     1209     * @return array Array of stylesheet names.
     1210     */
     1211    public static function get_allowed_on_network() {
     1212        static $allowed_themes;
     1213        if ( ! isset( $allowed_themes ) ) {
     1214            $allowed_themes = (array) get_site_option( 'allowedthemes' );
     1215        }
     1216
     1217        /**
     1218         * Filter the array of themes allowed on the network.
    11861219         *
    11871220         * @since MU
     
    11891222         * @param array $allowed_themes An array of theme stylesheet names.
    11901223         */
    1191         $network = (array) apply_filters( 'allowed_themes', self::get_allowed_on_network() );
    1192         return $network + self::get_allowed_on_site( $blog_id );
    1193     }
    1194 
    1195     /**
    1196      * Returns array of stylesheet names of themes allowed on the network.
     1224        $allowed_themes = apply_filters( 'allowed_themes', $allowed_themes );
     1225
     1226        return $allowed_themes;
     1227    }
     1228
     1229    /**
     1230     * Returns array of stylesheet names of themes allowed on the site.
    11971231     *
    11981232     * @since 3.4.0
     
    12031237     * @staticvar array $allowed_themes
    12041238     *
    1205      * @return array Array of stylesheet names.
    1206      */
    1207     public static function get_allowed_on_network() {
    1208         static $allowed_themes;
    1209         if ( ! isset( $allowed_themes ) )
    1210             $allowed_themes = (array) get_site_option( 'allowedthemes' );
    1211         return $allowed_themes;
    1212     }
    1213 
    1214     /**
    1215      * Returns array of stylesheet names of themes allowed on the site.
    1216      *
    1217      * @since 3.4.0
    1218      *
    1219      * @static
    1220      * @access public
    1221      *
    1222      * @staticvar array $allowed_themes
    1223      *
    1224      * @param int $blog_id Optional. Defaults to current blog.
     1239     * @param int $blog_id Optional. ID of the site. Defaults to the current site.
    12251240     * @return array Array of stylesheet names.
    12261241     */
     
    12311246            $blog_id = get_current_blog_id();
    12321247
    1233         if ( isset( $allowed_themes[ $blog_id ] ) )
    1234             return $allowed_themes[ $blog_id ];
     1248        if ( isset( $allowed_themes[ $blog_id ] ) ) {
     1249            /**
     1250             * Filter the array of themes allowed on the site.
     1251             *
     1252             * @since 4.5.0
     1253             *
     1254             * @param array $allowed_themes An array of theme stylesheet names.
     1255             * @param int   $blog_id        ID of the site. Defaults to current site.
     1256             */
     1257            return (array) apply_filters( 'site_allowed_themes', $allowed_themes[ $blog_id ], $blog_id );
     1258        }
    12351259
    12361260        $current = $blog_id == get_current_blog_id();
     
    12801304        }
    12811305
    1282         return (array) $allowed_themes[ $blog_id ];
     1306        /** This filter is documented in wp-includes/class-wp-theme.php */
     1307        return (array) apply_filters( 'site_allowed_themes', $allowed_themes[ $blog_id ], $blog_id );
    12831308    }
    12841309
Note: See TracChangeset for help on using the changeset viewer.