Make WordPress Core

Ticket #38114: 38114.diff

File 38114.diff, 4.8 KB (added by helen, 8 years ago)
  • src/wp-includes/theme.php

     
    16231623}
    16241624
    16251625/**
     1626 * Expand a theme's starter content configuration using core-provided data.
     1627 *
     1628 * @since 4.7.0
     1629 *
     1630 * @return array Array of starter content.
     1631 */
     1632function get_theme_starter_content() {
     1633        $config = get_theme_support( 'starter-content' );
     1634
     1635        if ( empty( $config ) ) {
     1636                return false;
     1637        }
     1638
     1639        $core_content = array(
     1640                'sidebars_widgets' => array(
     1641                        'text_business_info' => array(
     1642                                'type' => 'WP_Widget_Text',
     1643                                'title' => __( 'Find Us' ),
     1644                                'text' => '<p><strong>' . __( 'Address' ) . '</strong><br />' .
     1645                                        __( '123 Main Street' ) . '<br />' . __( 'New York, NY 10001' ) . '</p>' .
     1646                                        '<p><strong>' . __( 'Hours' ) . '</strong><br />' .
     1647                                        __( 'Monday&mndash;Friday: 9:00AM&ndash;5:00PM' ) . '<br />' . __( 'Saturday &amp; Sunday: 11:00AM&ndash;3:00PM' ) . '</p>',
     1648                        ),
     1649                ),
     1650                'nav_menus' => array(
     1651                        'link_yelp' => 'https://www.yelp.com',
     1652                        'link_facebook' => 'https://www.facebook.com/wordpress',
     1653                        'link_twitter' => 'https://twitter.com/wordpress',
     1654                        'link_instagram' => 'https://www.instagram.com/explore/tags/wordcamp/',
     1655                        'link_email' => 'mailto:wordpress@example.com',
     1656                ),
     1657                'posts' => array(
     1658                        'homepage_section' => array(
     1659                                'post_type' => 'page',
     1660                                'post_title' => __( 'This homepage has sections' ),
     1661                                'post_content' => __( 'Sections of a homepage are managed by doing X thing and appear when Y.' ),
     1662                        ),
     1663                ),
     1664        );
     1665
     1666        $content = array();
     1667
     1668        foreach ( $config as $type => $args ) {
     1669                switch( $type ) {
     1670                        // Use options and theme_mods as-is
     1671                        case 'options' :
     1672                        case 'theme_modes' :
     1673                                $content[ $type ] = $config[ $type ];
     1674                                break;
     1675
     1676                        // Widgets are an extra level down due to groupings
     1677                        case 'sidebars_widgets' :
     1678                                foreach( $config[ $type ] as $group => $items ) {
     1679                                        foreach ( $items as $id ) {
     1680                                                if ( ! empty( $core_content[ $type ] && ! empty( $core_content[ $type ][ $id ] ) ) ) {
     1681                                                        $content[ $type ][ $group ][ $id ] = $core_content[ $type ][ $id ];
     1682                                                }
     1683                                        }
     1684                                }
     1685                                break;
     1686
     1687                        // And nav menus are yet another level down
     1688                        case 'nav_menus' :
     1689                                foreach( $config[ $type ] as $group => $args ) {
     1690                                        // Menu groups need a name
     1691                                        if ( empty( $args['name'] ) ) {
     1692                                                $args['name'] = $group;
     1693                                        }
     1694
     1695                                        $content[ $type ][ $group ]['name'] = $args['name'];
     1696
     1697                                        // Do we need to check if this is empty?
     1698                                        foreach ( $args['items'] as $id ) {
     1699                                                if ( ! empty( $core_content[ $type ] && ! empty( $core_content[ $type ][ $id ] ) ) ) {
     1700                                                        $content[ $type ][ $group ]['items'][ $id ] = $core_content[ $type ][ $id ];
     1701                                                }
     1702                                        }
     1703                                }
     1704                                break;
     1705
     1706
     1707                        // Everything else should map at the next level
     1708                        default :
     1709                                foreach( $config[ $type ] as $id ) {
     1710                                        if ( ! empty( $core_content[ $type ] && ! empty( $core_content[ $type ][ $id ] ) ) ) {
     1711                                                $content[ $type ][ $id ] = $core_content[ $type ][ $id ];
     1712                                        }
     1713                                }
     1714                                break;
     1715                }
     1716        }
     1717
     1718        /**
     1719         * Filters the expanded array of starter content.
     1720         *
     1721         * @since 4.7.0
     1722         *
     1723         * @param array $content Array of starter content.
     1724         * @param array $config  Array of theme-specific starter content configuration.
     1725         */
     1726        return apply_filters( 'get_theme_starter_content', $content, $config );
     1727}
     1728
     1729/**
    16261730 * Registers theme support for a given feature.
    16271731 *
    16281732 * Must be called in the theme's functions.php file to work.
     
    16341738 * @since 3.9.0 The `html5` feature now also accepts 'gallery' and 'caption'
    16351739 * @since 4.1.0 The `title-tag` feature was added
    16361740 * @since 4.5.0 The `customize-selective-refresh-widgets` feature was added
     1741 * @since 4.7.0 The `starter-content` feature was added
    16371742 *
    16381743 * @global array $_wp_theme_features
    16391744 *
    16401745 * @param string $feature  The feature being added. Likely core values include 'post-formats',
    16411746 *                         'post-thumbnails', 'html5', 'custom-logo', 'custom-header-uploads',
    1642  *                         'custom-header', 'custom-background', 'title-tag', etc.
     1747 *                         'custom-header', 'custom-background', 'title-tag', 'starter-content', etc.
    16431748 * @param mixed  $args,... Optional extra arguments to pass along with certain features.
    16441749 * @return void|bool False on failure, void otherwise.
    16451750 */
     
    20702175         *
    20712176         * The dynamic portion of the hook name, `$feature`, refers to the specific theme
    20722177         * feature. Possible values include 'post-formats', 'post-thumbnails', 'custom-background',
    2073          * 'custom-header', 'menus', 'automatic-feed-links', 'html5', and `customize-selective-refresh-widgets`.
     2178         * 'custom-header', 'menus', 'automatic-feed-links', 'html5',
     2179         * 'starter-content', and 'customize-selective-refresh-widgets'.
    20742180         *
    20752181         * @since 3.4.0
    20762182         *