Make WordPress Core

Ticket #38114: 38114.2.diff

File 38114.2.diff, 5.7 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 ( 'text', array (
     1642                                'title' => __( 'Find Us' ),
     1643                                'text' => join( '', array (
     1644                                        '<p><strong>' . __( 'Address' ) . '</strong><br />',
     1645                                        __( '123 Main Street' ) . '<br />' . __( 'New York, NY 10001' ) . '</p>',
     1646                                        '<p><strong>' . __( 'Hours' ) . '</strong><br />',
     1647                                        __( 'Monday&mdash;Friday: 9:00AM&ndash;5:00PM' ) . '<br />' . __( 'Saturday &amp; Sunday: 11:00AM&ndash;3:00PM' ) . '</p>'
     1648                                ) ),
     1649                        ) ),
     1650                        'search' => array ( 'search', array (
     1651                                'title' => __( 'Site Search' ),
     1652                        ) ),
     1653                        'text_credits' => array ( 'text', array (
     1654                                'title' => __( 'Site Credits' ),
     1655                                'text' => sprintf( __( 'This site was created on %s' ), get_date_from_gmt( current_time( 'mysql', 1 ), 'c' ) ),
     1656                        ) ),
     1657                ),
     1658                'nav_menus' => array (
     1659                        'link_yelp' => 'https://www.yelp.com',
     1660                        'link_facebook' => 'https://www.facebook.com/wordpress',
     1661                        'link_twitter' => 'https://twitter.com/wordpress',
     1662                        'link_instagram' => 'https://www.instagram.com/explore/tags/wordcamp/',
     1663                        'link_email' => 'mailto:wordpress@example.com',
     1664                ),
     1665                'posts' => array(
     1666                        'home' => array(
     1667                                'post_type' => 'page',
     1668                                'post_title' => __( 'Homepage' ),
     1669                                'post_content' => __( 'Welcome home.' ),
     1670                        ),
     1671                        'about-us' => array(
     1672                                'post_type' => 'page',
     1673                                'post_title' => __( 'About Us' ),
     1674                                'post_content' => __( 'More than you ever wanted to know.' ),
     1675                        ),
     1676                        'contact-us' => array(
     1677                                'post_type' => 'page',
     1678                                'post_title' => __( 'Contact Us' ),
     1679                                'post_content' => __( 'Call us at 999-999-9999.' ),
     1680                        ),
     1681                        'blog' => array(
     1682                                'post_type' => 'page',
     1683                                'post_title' => __( 'Blog' ),
     1684                        ),
     1685
     1686                        'homepage-section' => array(
     1687                                'post_type' => 'page',
     1688                                'post_title' => __( 'A homepage section' ),
     1689                                'post_content' => __( 'This is an example of a homepage section, which are managed in theme options.' ),
     1690                        ),
     1691                ),
     1692        );
     1693
     1694        $content = array();
     1695
     1696        foreach ( $config as $type => $args ) {
     1697                switch( $type ) {
     1698                        // Use options and theme_mods as-is
     1699                        case 'options' :
     1700                        case 'theme_modes' :
     1701                                $content[ $type ] = $config[ $type ];
     1702                                break;
     1703
     1704                        // Widgets are an extra level down due to groupings
     1705                        case 'sidebars_widgets' :
     1706                                foreach( $config[ $type ] as $group => $items ) {
     1707                                        foreach ( $items as $id => $item ) {
     1708                                                $id = $item[1];
     1709                                                if ( ! empty( $core_content[ $type ] && ! empty( $core_content[ $type ][ $id ] ) ) ) {
     1710                                                        $content[ $type ][ $group ][ $id ][] = $item[0];
     1711                                                        $content[ $type ][ $group ][ $id ][] = $core_content[ $type ][ $id ];
     1712                                                }
     1713                                        }
     1714                                }
     1715                                break;
     1716
     1717                        // And nav menus are yet another level down
     1718                        case 'nav_menus' :
     1719                                foreach( $config[ $type ] as $group => $args ) {
     1720                                        // Menu groups need a name
     1721                                        if ( empty( $args['name'] ) ) {
     1722                                                $args['name'] = $group;
     1723                                        }
     1724
     1725                                        $content[ $type ][ $group ]['name'] = $args['name'];
     1726
     1727                                        // Do we need to check if this is empty?
     1728                                        foreach ( $args['items'] as $id ) {
     1729                                                if ( ! empty( $core_content[ $type ] && ! empty( $core_content[ $type ][ $id ] ) ) ) {
     1730                                                        $content[ $type ][ $group ]['items'][ $id ] = $core_content[ $type ][ $id ];
     1731                                                }
     1732                                        }
     1733                                }
     1734                                break;
     1735
     1736
     1737                        // Everything else should map at the next level
     1738                        default :
     1739                                foreach( $config[ $type ] as $id ) {
     1740                                        if ( ! empty( $core_content[ $type ] && ! empty( $core_content[ $type ][ $id ] ) ) ) {
     1741                                                $content[ $type ][ $id ] = $core_content[ $type ][ $id ];
     1742                                        }
     1743                                }
     1744                                break;
     1745                }
     1746        }
     1747
     1748        /**
     1749         * Filters the expanded array of starter content.
     1750         *
     1751         * @since 4.7.0
     1752         *
     1753         * @param array $content Array of starter content.
     1754         * @param array $config  Array of theme-specific starter content configuration.
     1755         */
     1756        return apply_filters( 'get_theme_starter_content', $content, $config );
     1757}
     1758
     1759/**
    16261760 * Registers theme support for a given feature.
    16271761 *
    16281762 * Must be called in the theme's functions.php file to work.
     
    16341768 * @since 3.9.0 The `html5` feature now also accepts 'gallery' and 'caption'
    16351769 * @since 4.1.0 The `title-tag` feature was added
    16361770 * @since 4.5.0 The `customize-selective-refresh-widgets` feature was added
     1771 * @since 4.7.0 The `starter-content` feature was added
    16371772 *
    16381773 * @global array $_wp_theme_features
    16391774 *
    16401775 * @param string $feature  The feature being added. Likely core values include 'post-formats',
    16411776 *                         'post-thumbnails', 'html5', 'custom-logo', 'custom-header-uploads',
    1642  *                         'custom-header', 'custom-background', 'title-tag', etc.
     1777 *                         'custom-header', 'custom-background', 'title-tag', 'starter-content', etc.
    16431778 * @param mixed  $args,... Optional extra arguments to pass along with certain features.
    16441779 * @return void|bool False on failure, void otherwise.
    16451780 */
     
    20702205         *
    20712206         * The dynamic portion of the hook name, `$feature`, refers to the specific theme
    20722207         * feature. Possible values include 'post-formats', 'post-thumbnails', 'custom-background',
    2073          * 'custom-header', 'menus', 'automatic-feed-links', 'html5', and `customize-selective-refresh-widgets`.
     2208         * 'custom-header', 'menus', 'automatic-feed-links', 'html5',
     2209         * 'starter-content', and 'customize-selective-refresh-widgets'.
    20742210         *
    20752211         * @since 3.4.0
    20762212         *