mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-04-11 08:04:32 +00:00
Customize: Introduce starter content and site freshness state.
A theme can opt-in for tailored starter content to apply to the customizer when previewing the theme on a fresh install, when `fresh_site` is at its initial `1` value. Starter content is staged in the customizer and does not go live unless the changes are published. Initial starter content is added to Twenty Seventeen. * The `fresh_site` flag is cleared when a published post or page is saved, when widgets are modified, or when the customizer state is saved. * Starter content is registered via `starter-content` theme support, where the argument is an array containing `widgets`, `posts`, `nav_menus`, `options`, and `theme_mods`. Posts/pages in starter content are created with the `auto-draft` status, re-using the page/post stubs feature added to nav menus and the static front page controls. * A `get_theme_starter_content` filter allows for plugins to extend a theme's starter content. * Starter content in themes can/should re-use existing starter content items in core by using named placeholders. * Import theme starter content into customized state when fresh site. * Prevent original_title differences from causing refreshes if title is present. * Ensure nav menu item url is set according to object when previewing. * Make sure initial saved state is false if there are dirty settings without an existing changeset. * Ensure dirty settings are cleaned upon changeset publishing. Props helen, westonruter, ocean90. Fixes #38114, #38533. git-svn-id: https://develop.svn.wordpress.org/trunk@38991 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -1755,6 +1755,175 @@ function get_editor_stylesheets() {
|
||||
return apply_filters( 'editor_stylesheets', $stylesheets );
|
||||
}
|
||||
|
||||
/**
|
||||
* Expand a theme's starter content configuration using core-provided data.
|
||||
*
|
||||
* @since 4.7.0
|
||||
*
|
||||
* @return array Array of starter content.
|
||||
*/
|
||||
function get_theme_starter_content() {
|
||||
$theme_support = get_theme_support( 'starter-content' );
|
||||
if ( ! empty( $theme_support ) ) {
|
||||
$config = $theme_support[0];
|
||||
} else {
|
||||
$config = array();
|
||||
}
|
||||
|
||||
$core_content = array (
|
||||
'widgets' => array(
|
||||
'text_business_info' => array ( 'text', array (
|
||||
'title' => __( 'Find Us' ),
|
||||
'text' => join( '', array (
|
||||
'<p><strong>' . __( 'Address' ) . '</strong><br />',
|
||||
__( '123 Main Street' ) . '<br />' . __( 'New York, NY 10001' ) . '</p>',
|
||||
'<p><strong>' . __( 'Hours' ) . '</strong><br />',
|
||||
__( 'Monday—Friday: 9:00AM–5:00PM' ) . '<br />' . __( 'Saturday & Sunday: 11:00AM–3:00PM' ) . '</p>'
|
||||
) ),
|
||||
) ),
|
||||
'search' => array ( 'search', array (
|
||||
'title' => __( 'Site Search' ),
|
||||
) ),
|
||||
'text_credits' => array ( 'text', array (
|
||||
'title' => __( 'Site Credits' ),
|
||||
'text' => sprintf( __( 'This site was created on %s' ), get_date_from_gmt( current_time( 'mysql', 1 ), 'c' ) ),
|
||||
) ),
|
||||
),
|
||||
'nav_menus' => array (
|
||||
'page_home' => array(
|
||||
'type' => 'post_type',
|
||||
'object' => 'page',
|
||||
'object_id' => '{{home}}',
|
||||
),
|
||||
'page_about' => array(
|
||||
'type' => 'post_type',
|
||||
'object' => 'page',
|
||||
'object_id' => '{{about-us}}',
|
||||
),
|
||||
'page_blog' => array(
|
||||
'type' => 'post_type',
|
||||
'object' => 'page',
|
||||
'object_id' => '{{blog}}',
|
||||
),
|
||||
'page_contact' => array(
|
||||
'type' => 'post_type',
|
||||
'object' => 'page',
|
||||
'object_id' => '{{contact-us}}',
|
||||
),
|
||||
|
||||
'link_yelp' => array(
|
||||
'title' => __( 'Yelp' ),
|
||||
'url' => 'https://www.yelp.com',
|
||||
),
|
||||
'link_facebook' => array(
|
||||
'title' => __( 'Facebook' ),
|
||||
'url' => 'https://www.facebook.com/wordpress',
|
||||
),
|
||||
'link_twitter' => array(
|
||||
'title' => __( 'Twitter' ),
|
||||
'url' => 'https://twitter.com/wordpress',
|
||||
),
|
||||
'link_instagram' => array(
|
||||
'title' => __( 'Instagram' ),
|
||||
'url' => 'https://www.instagram.com/explore/tags/wordcamp/',
|
||||
),
|
||||
'link_email' => array(
|
||||
'title' => __( 'Email' ),
|
||||
'url' => 'mailto:wordpress@example.com',
|
||||
),
|
||||
),
|
||||
'posts' => array(
|
||||
'home' => array(
|
||||
'post_type' => 'page',
|
||||
'post_title' => __( 'Homepage' ),
|
||||
'post_content' => __( 'Welcome home.' ),
|
||||
),
|
||||
'about-us' => array(
|
||||
'post_type' => 'page',
|
||||
'post_title' => __( 'About Us' ),
|
||||
'post_content' => __( 'More than you ever wanted to know.' ),
|
||||
),
|
||||
'contact-us' => array(
|
||||
'post_type' => 'page',
|
||||
'post_title' => __( 'Contact Us' ),
|
||||
'post_content' => __( 'Call us at 999-999-9999.' ),
|
||||
),
|
||||
'blog' => array(
|
||||
'post_type' => 'page',
|
||||
'post_title' => __( 'Blog' ),
|
||||
),
|
||||
|
||||
'homepage-section' => array(
|
||||
'post_type' => 'page',
|
||||
'post_title' => __( 'A homepage section' ),
|
||||
'post_content' => __( 'This is an example of a homepage section, which are managed in theme options.' ),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
$content = array();
|
||||
|
||||
foreach ( $config as $type => $args ) {
|
||||
switch( $type ) {
|
||||
// Use options and theme_mods as-is
|
||||
case 'options' :
|
||||
case 'theme_mods' :
|
||||
$content[ $type ] = $config[ $type ];
|
||||
break;
|
||||
|
||||
// Widgets are an extra level down due to groupings
|
||||
case 'widgets' :
|
||||
foreach ( $config[ $type ] as $group => $items ) {
|
||||
foreach ( $items as $id ) {
|
||||
if ( ! empty( $core_content[ $type ] ) && ! empty( $core_content[ $type ][ $id ] ) ) {
|
||||
$content[ $type ][ $group ][ $id ] = $core_content[ $type ][ $id ];
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
// And nav menus are yet another level down
|
||||
case 'nav_menus' :
|
||||
foreach ( $config[ $type ] as $group => $args2 ) {
|
||||
// Menu groups need a name
|
||||
if ( empty( $args['name'] ) ) {
|
||||
$args2['name'] = $group;
|
||||
}
|
||||
|
||||
$content[ $type ][ $group ]['name'] = $args2['name'];
|
||||
|
||||
// Do we need to check if this is empty?
|
||||
foreach ( $args2['items'] as $id ) {
|
||||
if ( ! empty( $core_content[ $type ] ) && ! empty( $core_content[ $type ][ $id ] ) ) {
|
||||
$content[ $type ][ $group ]['items'][ $id ] = $core_content[ $type ][ $id ];
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
// Everything else should map at the next level
|
||||
default :
|
||||
foreach( $config[ $type ] as $id ) {
|
||||
if ( ! empty( $core_content[ $type ] ) && ! empty( $core_content[ $type ][ $id ] ) ) {
|
||||
$content[ $type ][ $id ] = $core_content[ $type ][ $id ];
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters the expanded array of starter content.
|
||||
*
|
||||
* @since 4.7.0
|
||||
*
|
||||
* @param array $content Array of starter content.
|
||||
* @param array $config Array of theme-specific starter content configuration.
|
||||
*/
|
||||
return apply_filters( 'get_theme_starter_content', $content, $config );
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers theme support for a given feature.
|
||||
*
|
||||
@@ -1767,12 +1936,13 @@ function get_editor_stylesheets() {
|
||||
* @since 3.9.0 The `html5` feature now also accepts 'gallery' and 'caption'
|
||||
* @since 4.1.0 The `title-tag` feature was added
|
||||
* @since 4.5.0 The `customize-selective-refresh-widgets` feature was added
|
||||
* @since 4.7.0 The `starter-content` feature was added
|
||||
*
|
||||
* @global array $_wp_theme_features
|
||||
*
|
||||
* @param string $feature The feature being added. Likely core values include 'post-formats',
|
||||
* 'post-thumbnails', 'html5', 'custom-logo', 'custom-header-uploads',
|
||||
* 'custom-header', 'custom-background', 'title-tag', etc.
|
||||
* 'custom-header', 'custom-background', 'title-tag', 'starter-content', etc.
|
||||
* @param mixed $args,... Optional extra arguments to pass along with certain features.
|
||||
* @return void|bool False on failure, void otherwise.
|
||||
*/
|
||||
@@ -2204,7 +2374,8 @@ function current_theme_supports( $feature ) {
|
||||
*
|
||||
* The dynamic portion of the hook name, `$feature`, refers to the specific theme
|
||||
* feature. Possible values include 'post-formats', 'post-thumbnails', 'custom-background',
|
||||
* 'custom-header', 'menus', 'automatic-feed-links', 'html5', and `customize-selective-refresh-widgets`.
|
||||
* 'custom-header', 'menus', 'automatic-feed-links', 'html5',
|
||||
* 'starter-content', and 'customize-selective-refresh-widgets'.
|
||||
*
|
||||
* @since 3.4.0
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user