WordPress.org

Make WordPress Core

Ticket #12739: remove_theme_support-ugly.diff

File remove_theme_support-ugly.diff, 2.0 KB (added by nacin, 12 years ago)

Patch blacklists internal theme support registrations. Also, it handles unregistering of post thumbnail support by post type.

  • theme.php

     
    15311531/**
    15321532 * Allows a theme to register its support of a certain feature
    15331533 *
    1534  * Must be called in the themes functions.php file to work.
     1534 * Must be called in the theme's functions.php file to work.
     1535 * If attached to a hook, it must be after_setup_theme.
     1536 * The init hook may be too late for some features.
    15351537 *
    15361538 * @since 2.9.0
    15371539 * @param string $feature the feature being added
     
    15481550/**
    15491551 * Allows a theme to de-register its support of a certain feature
    15501552 *
    1551  * Must be called in the themes functions.php file to work.
     1553 * Should be called in the theme's functions.php file. Generally would
     1554 * be used for child themes to override support from the parent theme.
    15521555 *
    15531556 * @since 3.0.0
     1557 * @see add_theme_support()
    15541558 * @param string $feature the feature being added
    15551559 */
    15561560function remove_theme_support( $feature ) {
     1561        // Blacklist: for internal registrations not used directly by themes.
     1562        if ( in_array( $feature, array( 'custom-background', 'custom-header', 'editor-style', 'widgets' ) ) )
     1563                return false;
     1564
    15571565        global $_wp_theme_features;
    15581566
    1559         unset($_wp_theme_features[$feature]);
     1567        if ( ! isset( $_wp_theme_features[$feature] ) )
     1568                return false;
     1569
     1570        if ( func_num_args() == 1 ) {
     1571                unset( $_wp_theme_features[$feature] );
     1572                return true;
     1573        }
     1574
     1575        // @todo pluggable arg checking. see current_theme_supports()
     1576        $args = array_slice( func_get_args(), 1 );
     1577        switch( $feature ) {
     1578                case 'post-thumbnails' :
     1579                        if ( true === $_wp_theme_features[$feature] ) {
     1580                                global $_wp_post_type_features;
     1581                                $post_types = array();
     1582
     1583                                foreach ( (array) $_wp_post_type_features as $post_type => $features ) {
     1584                                        if ( ! isset( $features['thumbnail'] ) )
     1585                                                continue;
     1586                                        $post_types[] = $post_type;
     1587                                }
     1588                        } else {
     1589                                $post_types = $_wp_theme_features[$feature][0];
     1590                        }
     1591                        $_wp_theme_features[$feature] = array_diff( $post_types, $args[0] );
     1592                        return true;
     1593                break;
     1594        }
    15601595}
    15611596
    15621597/**