WordPress.org

Make WordPress Core

Ticket #26516: 26516.3.diff

File 26516.3.diff, 7.4 KB (added by mikeschroder, 6 years ago)

Refreshed.

  • src/wp-includes/theme.php

    diff --git src/wp-includes/theme.php src/wp-includes/theme.php
    index 76aa955..47a1552 100644
    function remove_editor_styles() { 
    13661366 * The init hook may be too late for some features.
    13671367 *
    13681368 * @since 2.9.0
    1369  * @param string $feature the feature being added
     1369 * @global array $_wp_theme_features All supported features.
     1370 * @param string $feature The feature being added.
     1371 * @return bool|void
    13701372 */
    13711373function add_theme_support( $feature ) {
    13721374        global $_wp_theme_features;
    add_action( 'wp_loaded', '_custom_header_background_just_in_time' ); 
    15611563 *
    15621564 * @since 3.1.0
    15631565 *
    1564  * @param string $feature the feature to check
    1565  * @return array The array of extra arguments
     1566 * @global array $_wp_theme_features All supported features.
     1567 * @param string $feature The feature to check.
     1568 * @return array|bool The array of extra arguments, or true if there are none.
    15661569 */
    15671570function get_theme_support( $feature ) {
    15681571        global $_wp_theme_features;
    15691572        if ( ! isset( $_wp_theme_features[ $feature ] ) )
    15701573                return false;
    15711574
    1572         if ( func_num_args() <= 1 )
    1573                 return $_wp_theme_features[ $feature ];
    1574 
    15751575        $args = array_slice( func_get_args(), 1 );
    1576         switch ( $feature ) {
    1577                 case 'custom-header' :
    1578                 case 'custom-background' :
    1579                         if ( isset( $_wp_theme_features[ $feature ][0][ $args[0] ] ) )
    1580                                 return $_wp_theme_features[ $feature ][0][ $args[0] ];
    1581                         return false;
    1582                         break;
    1583                 default :
    1584                         return $_wp_theme_features[ $feature ];
    1585                         break;
     1576        if ( ! empty( $args ) ) {
     1577                switch ( $feature ) {
     1578                        case 'custom-header' :
     1579                        case 'custom-background' :
     1580                                if ( isset( $_wp_theme_features[ $feature ][0][ $args[0] ] ) )
     1581                                        return $_wp_theme_features[ $feature ][0][ $args[0] ];
     1582                                return false;
     1583                                break;
     1584                }
    15861585        }
     1586
     1587        $feature_args = $_wp_theme_features[ $feature ];
     1588        if ( is_array( $feature_args ) ) {
     1589                $feature_args = array_merge( $feature_args, $_wp_theme_features[ $feature ][0] );
     1590        }
     1591
     1592        /**
     1593         * Filter whether the theme support for a specific feature.
     1594         *
     1595         * The dynamic portion of the hook name, $feature, refers to
     1596         * the specific theme feature. Possible values include 'post-formats',
     1597         * 'post-thumbnails', 'menus', 'automatic-feed-links', and 'html5'.
     1598         *
     1599         * @since 3.9.0
     1600         *
     1601         * @param array|bool $feature_args The array of extra arguments, or true if there are none.
     1602         * @param array      $args         Array of arguments for the feature.
     1603         */
     1604        return apply_filters( "get_theme_support-{$feature}", $feature_args, $args );
    15871605}
    15881606
    15891607/**
    function get_theme_support( $feature ) { 
    15941612 *
    15951613 * @since 3.0.0
    15961614 * @see add_theme_support()
    1597  * @param string $feature the feature being added
     1615 * @param string $feature The feature being removed.
    15981616 * @return bool Whether feature was removed.
    15991617 */
    16001618function remove_theme_support( $feature ) {
    function remove_theme_support( $feature ) { 
    16101628 *
    16111629 * @access private
    16121630 * @since 3.1.0
     1631 * @param string $feature The feature being removed.
     1632 * @return bool Whether feature was removed.
    16131633 */
    16141634function _remove_theme_support( $feature ) {
    1615         global $_wp_theme_features;
    1616 
    16171635        switch ( $feature ) {
    16181636                case 'custom-header-uploads' :
    1619                         if ( ! isset( $_wp_theme_features['custom-header'] ) )
     1637                        if ( ! current_theme_supports( 'custom-header' ) )
    16201638                                return false;
    16211639                        add_theme_support( 'custom-header', array( 'uploads' => false ) );
    16221640                        return; // Do not continue - custom-header-uploads no longer exists.
    16231641        }
    16241642
    1625         if ( ! isset( $_wp_theme_features[ $feature ] ) )
     1643        if ( ! current_theme_supports( $feature ) )
    16261644                return false;
    16271645
    16281646        switch ( $feature ) {
    16291647                case 'custom-header' :
    16301648                        if ( ! did_action( 'wp_loaded' ) )
    16311649                                break;
    1632                         $support = get_theme_support( 'custom-header' );
    1633                         if ( $support[0]['wp-head-callback'] )
    1634                                 remove_action( 'wp_head', $support[0]['wp-head-callback'] );
     1650                        remove_action( 'wp_head', get_theme_support( 'custom-header', 'wp-head-callback' ) );
    16351651                        remove_action( 'admin_menu', array( $GLOBALS['custom_image_header'], 'init' ) );
    16361652                        unset( $GLOBALS['custom_image_header'] );
    16371653                        break;
    function _remove_theme_support( $feature ) { 
    16391655                case 'custom-background' :
    16401656                        if ( ! did_action( 'wp_loaded' ) )
    16411657                                break;
    1642                         $support = get_theme_support( 'custom-background' );
    1643                         remove_action( 'wp_head', $support[0]['wp-head-callback'] );
     1658                        remove_action( 'wp_head', get_theme_support( 'custom-background', 'wp-head-callback' ) );
    16441659                        remove_action( 'admin_menu', array( $GLOBALS['custom_background'], 'init' ) );
    16451660                        unset( $GLOBALS['custom_background'] );
    16461661                        break;
    16471662        }
    16481663
    1649         unset( $_wp_theme_features[ $feature ] );
     1664        unset( $GLOBALS['_wp_theme_features'][ $feature ] );
    16501665        return true;
    16511666}
    16521667
    function _remove_theme_support( $feature ) { 
    16541669 * Checks a theme's support for a given feature
    16551670 *
    16561671 * @since 2.9.0
    1657  * @param string $feature the feature being checked
    1658  * @return boolean
     1672 * @param string $feature The feature being checked.
     1673 * @return boolean Whether the current theme supports the given feature.
    16591674 */
    16601675function current_theme_supports( $feature ) {
    1661         global $_wp_theme_features;
    1662 
    16631676        if ( 'custom-header-uploads' == $feature )
    16641677                return current_theme_supports( 'custom-header', 'uploads' );
    16651678
    1666         if ( !isset( $_wp_theme_features[$feature] ) )
     1679        if ( ! get_theme_support( $feature ) )
    16671680                return false;
    16681681
    16691682        // If no args passed then no extra checks need be performed
    function current_theme_supports( $feature ) { 
    16771690                        // post-thumbnails can be registered for only certain content/post types by passing
    16781691                        // an array of types to add_theme_support(). If no array was passed, then
    16791692                        // any type is accepted
    1680                         if ( true === $_wp_theme_features[$feature] )  // Registered for all types
     1693                        if ( true === get_theme_support( $feature ) )  // Registered for all types
    16811694                                return true;
    16821695                        $content_type = $args[0];
    1683                         return in_array( $content_type, $_wp_theme_features[$feature][0] );
     1696                        return in_array( $content_type, get_theme_support( $feature ) );
    16841697                        break;
    16851698
    16861699                case 'html5':
    function current_theme_supports( $feature ) { 
    16911704                        // Specific areas of HTML5 support *must* be passed via an array to add_theme_support()
    16921705
    16931706                        $type = $args[0];
    1694                         return in_array( $type, $_wp_theme_features[$feature][0] );
     1707                        return in_array( $type, get_theme_support( $feature ) );
    16951708                        break;
    16961709
    16971710                case 'custom-header':
    16981711                case 'custom-background' :
    16991712                        // specific custom header and background capabilities can be registered by passing
    17001713                        // an array to add_theme_support()
    1701                         $header_support = $args[0];
    1702                         return ( isset( $_wp_theme_features[$feature][0][$header_support] ) && $_wp_theme_features[$feature][0][$header_support] );
     1714                        $capability = $args[0];
     1715                        return (bool) get_theme_support( $feature, $capability );
    17031716                        break;
    17041717        }
    17051718
    function current_theme_supports( $feature ) { 
    17131726         *
    17141727         * @since 3.4.0
    17151728         *
    1716          * @param bool   true     Whether the current theme supports the given feature. Default true.
    1717          * @param array  $args    Array of arguments for the feature.
    1718          * @param string $feature The theme feature.
     1729         * @param bool  true     Whether the current theme supports the given feature. Default true.
     1730         * @param array $args    Array of arguments for the feature.
     1731         * @param array $support Specific theme support for the feature.
    17191732         */
    1720         return apply_filters( "current_theme_supports-{$feature}", true, $args, $_wp_theme_features[$feature] );
     1733        return apply_filters( "current_theme_supports-{$feature}", true, $args, get_theme_support( $feature ) );
    17211734}
    17221735
    17231736/**