Ticket #26516: 26516.2.diff
| File 26516.2.diff, 7.1 KB (added by , 12 years ago) |
|---|
-
wp-includes/theme.php
1366 1366 * The init hook may be too late for some features. 1367 1367 * 1368 1368 * @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 1370 1372 */ 1371 1373 function add_theme_support( $feature ) { 1372 1374 global $_wp_theme_features; … … 1560 1562 * Gets the theme support arguments passed when registering that support 1561 1563 * 1562 1564 * @since 3.1 1563 * @param string $feature the feature to check 1564 * @return array The array of extra arguments 1565 * @global array $_wp_theme_features All supported features. 1566 * @param string $feature The feature to check. 1567 * @return array|bool The array of extra arguments, or true if there are none. 1565 1568 */ 1566 1569 function get_theme_support( $feature ) { 1567 1570 global $_wp_theme_features; 1568 1571 if ( ! isset( $_wp_theme_features[ $feature ] ) ) 1569 1572 return false; 1570 1573 1571 if ( func_num_args() <= 1 )1572 return $_wp_theme_features[ $feature ];1573 1574 1574 $args = array_slice( func_get_args(), 1 ); 1575 switch ( $feature ) { 1576 case 'custom-header' : 1577 case 'custom-background' : 1578 if ( isset( $_wp_theme_features[ $feature ][0][ $args[0] ] ) ) 1579 return $_wp_theme_features[ $feature ][0][ $args[0] ]; 1580 return false; 1581 break; 1582 default : 1583 return $_wp_theme_features[ $feature ]; 1584 break; 1575 if ( ! empty( $args ) ) { 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 } 1585 1584 } 1585 1586 $feature_args = $_wp_theme_features[ $feature ]; 1587 if ( is_array( $feature_args ) ) { 1588 $feature_args = array_merge( $feature_args, $_wp_theme_features[ $feature ][0] ); 1589 } 1590 1591 /** 1592 * Filter whether the theme support for a specific feature. 1593 * 1594 * The dynamic portion of the hook name, $feature, refers to 1595 * the specific theme feature. Possible values include 'post-formats', 1596 * 'post-thumbnails', 'menus', 'automatic-feed-links', and 'html5'. 1597 * 1598 * @since 3.9.0 1599 * 1600 * @param array|bool $feature_args The array of extra arguments, or true if there are none. 1601 * @param array $args Array of arguments for the feature. 1602 */ 1603 return apply_filters( "get_theme_support-{$feature}", $feature_args, $args ); 1586 1604 } 1587 1605 1588 1606 /** … … 1593 1611 * 1594 1612 * @since 3.0.0 1595 1613 * @see add_theme_support() 1596 * @param string $feature the feature being added1614 * @param string $feature The feature being removed. 1597 1615 * @return bool Whether feature was removed. 1598 1616 */ 1599 1617 function remove_theme_support( $feature ) { … … 1609 1627 * 1610 1628 * @access private 1611 1629 * @since 3.1.0 1630 * @param string $feature The feature being removed. 1631 * @return bool Whether feature was removed. 1612 1632 */ 1613 1633 function _remove_theme_support( $feature ) { 1614 global $_wp_theme_features;1615 1616 1634 switch ( $feature ) { 1617 1635 case 'custom-header-uploads' : 1618 if ( ! isset( $_wp_theme_features['custom-header']) )1636 if ( ! current_theme_supports( 'custom-header' ) ) 1619 1637 return false; 1620 1638 add_theme_support( 'custom-header', array( 'uploads' => false ) ); 1621 1639 return; // Do not continue - custom-header-uploads no longer exists. 1622 1640 } 1623 1641 1624 if ( ! isset( $_wp_theme_features[ $feature ]) )1642 if ( ! current_theme_supports( $feature ) ) 1625 1643 return false; 1626 1644 1627 1645 switch ( $feature ) { 1628 1646 case 'custom-header' : 1629 1647 if ( ! did_action( 'wp_loaded' ) ) 1630 1648 break; 1631 $support = get_theme_support( 'custom-header' ); 1632 if ( $support[0]['wp-head-callback'] ) 1633 remove_action( 'wp_head', $support[0]['wp-head-callback'] ); 1649 remove_action( 'wp_head', get_theme_support( 'custom-header', 'wp-head-callback' ) ); 1634 1650 remove_action( 'admin_menu', array( $GLOBALS['custom_image_header'], 'init' ) ); 1635 1651 unset( $GLOBALS['custom_image_header'] ); 1636 1652 break; … … 1638 1654 case 'custom-background' : 1639 1655 if ( ! did_action( 'wp_loaded' ) ) 1640 1656 break; 1641 $support = get_theme_support( 'custom-background' ); 1642 remove_action( 'wp_head', $support[0]['wp-head-callback'] ); 1657 remove_action( 'wp_head', get_theme_support( 'custom-background', 'wp-head-callback' ) ); 1643 1658 remove_action( 'admin_menu', array( $GLOBALS['custom_background'], 'init' ) ); 1644 1659 unset( $GLOBALS['custom_background'] ); 1645 1660 break; 1646 1661 } 1647 1662 1648 unset( $ _wp_theme_features[ $feature ] );1663 unset( $GLOBALS['_wp_theme_features'][ $feature ] ); 1649 1664 return true; 1650 1665 } 1651 1666 … … 1653 1668 * Checks a theme's support for a given feature 1654 1669 * 1655 1670 * @since 2.9.0 1656 * @param string $feature the feature being checked1657 * @return boolean 1671 * @param string $feature The feature being checked. 1672 * @return boolean Whether the current theme supports the given feature. 1658 1673 */ 1659 1674 function current_theme_supports( $feature ) { 1660 global $_wp_theme_features;1661 1662 1675 if ( 'custom-header-uploads' == $feature ) 1663 1676 return current_theme_supports( 'custom-header', 'uploads' ); 1664 1677 1665 if ( ! isset( $_wp_theme_features[$feature]) )1678 if ( ! get_theme_support( $feature ) ) 1666 1679 return false; 1667 1680 1668 1681 // If no args passed then no extra checks need be performed … … 1676 1689 // post-thumbnails can be registered for only certain content/post types by passing 1677 1690 // an array of types to add_theme_support(). If no array was passed, then 1678 1691 // any type is accepted 1679 if ( true === $_wp_theme_features[$feature]) // Registered for all types1692 if ( true === get_theme_support( $feature ) ) // Registered for all types 1680 1693 return true; 1681 1694 $content_type = $args[0]; 1682 return in_array( $content_type, $_wp_theme_features[$feature][0]);1695 return in_array( $content_type, get_theme_support( $feature ) ); 1683 1696 break; 1684 1697 1685 1698 case 'html5': … … 1690 1703 // Specific areas of HTML5 support *must* be passed via an array to add_theme_support() 1691 1704 1692 1705 $type = $args[0]; 1693 return in_array( $type, $_wp_theme_features[$feature][0]);1706 return in_array( $type, get_theme_support( $feature ) ); 1694 1707 break; 1695 1708 1696 1709 case 'custom-header': 1697 1710 case 'custom-background' : 1698 1711 // specific custom header and background capabilities can be registered by passing 1699 1712 // an array to add_theme_support() 1700 $ header_support= $args[0];1701 return ( isset( $_wp_theme_features[$feature][0][$header_support] ) && $_wp_theme_features[$feature][0][$header_support]);1713 $capability = $args[0]; 1714 return (bool) get_theme_support( $feature, $capability ); 1702 1715 break; 1703 1716 } 1704 1717 … … 1712 1725 * 1713 1726 * @since 3.4.0 1714 1727 * 1715 * @param bool true Whether the current theme supports the given feature. Default true.1716 * @param array $args Array of arguments for the feature.1717 * @param string $feature The theme feature.1728 * @param bool true Whether the current theme supports the given feature. Default true. 1729 * @param array $args Array of arguments for the feature. 1730 * @param array $support Specific theme support for the feature. 1718 1731 */ 1719 return apply_filters( "current_theme_supports-{$feature}", true, $args, $_wp_theme_features[$feature]);1732 return apply_filters( "current_theme_supports-{$feature}", true, $args, get_theme_support( $feature ) ); 1720 1733 } 1721 1734 1722 1735 /**