WordPress.org

Make WordPress Core


Ignore:
Timestamp:
11/15/2016 09:02:38 AM (3 years ago)
Author:
westonruter
Message:

Customize: Allow starter content to apply in a new theme when switching from another theme containing changes.

  • Ensure that starter content can apply from theme B after previewing starter content in theme A.
  • Introduce new starter_content flag in changeset setting params which is used to capture whether a value is starter content and thus can be overridden.
  • Create changeset up-front with starter_content flags instead of waiting for AUTOSAVE_INTERVAL.
  • Eliminate instantiation of settings for widget instances in favor of directly calling sanitize_widget_js_instance. This eliminates issues with looking for widgets before they are registered.
  • Ensure that non-placeholders (inline arrays instead of string references) can be supplied in starter content.
  • Re-use auto-draft posts as starter content across theme switches.
  • Introduce starter_content param for WP_Customize_Manager::save_changeset_post() which is false except when starter content is being loaded on a fresh_site.

See #38114.
Fixes #38541.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/theme.php

    r39240 r39241  
    18251825    }
    18261826
    1827     $core_content = array (
     1827    $core_content = array(
    18281828        'widgets' => array(
    1829             'text_business_info' => array ( 'text', array (
     1829            'text_business_info' => array( 'text', array(
    18301830                'title' => _x( 'Find Us', 'Theme starter content' ),
    1831                 'text' => join( '', array (
     1831                'text' => join( '', array(
    18321832                    '<p><strong>' . _x( 'Address', 'Theme starter content' ) . '</strong><br />',
    18331833                    _x( '123 Main Street', 'Theme starter content' ) . '<br />' . _x( 'New York, NY 10001', 'Theme starter content' ) . '</p>',
     
    18361836                ) ),
    18371837            ) ),
    1838             'search' => array ( 'search', array (
     1838            'search' => array( 'search', array(
    18391839                'title' => _x( 'Site Search', 'Theme starter content' ),
    18401840            ) ),
    1841             'text_credits' => array ( 'text', array (
     1841            'text_credits' => array( 'text', array(
    18421842                'title' => _x( 'Site Credits', 'Theme starter content' ),
    18431843                'text' => sprintf( _x( 'This site was created on %s', 'Theme starter content' ), get_date_from_gmt( current_time( 'mysql', 1 ), 'c' ) ),
    18441844            ) ),
    18451845        ),
    1846         'nav_menus' => array (
     1846        'nav_menus' => array(
    18471847            'page_home' => array(
    18481848                'type' => 'post_type',
     
    19201920    foreach ( $config as $type => $args ) {
    19211921        switch( $type ) {
    1922             // Use options and theme_mods as-is
     1922            // Use options and theme_mods as-is.
    19231923            case 'options' :
    19241924            case 'theme_mods' :
     
    19261926                break;
    19271927
    1928             // Widgets are an extra level down due to groupings
     1928            // Widgets are grouped into sidebars.
    19291929            case 'widgets' :
    1930                 foreach ( $config[ $type ] as $group => $items ) {
    1931                     foreach ( $items as $id ) {
    1932                         if ( ! empty( $core_content[ $type ] ) && ! empty( $core_content[ $type ][ $id ] ) ) {
    1933                             $content[ $type ][ $group ][ $id ] = $core_content[ $type ][ $id ];
     1930                foreach ( $config[ $type ] as $sidebar_id => $widgets ) {
     1931                    foreach ( $widgets as $widget ) {
     1932                        if ( is_array( $widget ) ) {
     1933                            $content[ $type ][ $sidebar_id ][] = $widget;
     1934                        } elseif ( is_string( $widget ) && ! empty( $core_content[ $type ] ) && ! empty( $core_content[ $type ][ $widget ] ) ) {
     1935                            $content[ $type ][ $sidebar_id ][] = $core_content[ $type ][ $widget ];
    19341936                        }
    19351937                    }
     
    19371939                break;
    19381940
    1939             // And nav menus are yet another level down
     1941            // And nav menu items are grouped into nav menus.
    19401942            case 'nav_menus' :
    1941                 foreach ( $config[ $type ] as $group => $args2 ) {
    1942                     // Menu groups need a name
    1943                     if ( empty( $args['name'] ) ) {
    1944                         $args2['name'] = $group;
     1943                foreach ( $config[ $type ] as $nav_menu_location => $nav_menu ) {
     1944
     1945                    // Ensure nav menus get a name.
     1946                    if ( empty( $nav_menu['name'] ) ) {
     1947                        $nav_menu['name'] = $nav_menu_location;
    19451948                    }
    19461949
    1947                     $content[ $type ][ $group ]['name'] = $args2['name'];
    1948 
    1949                     // Do we need to check if this is empty?
    1950                     foreach ( $args2['items'] as $id ) {
    1951                         if ( ! empty( $core_content[ $type ] ) && ! empty( $core_content[ $type ][ $id ] ) ) {
    1952                             $content[ $type ][ $group ]['items'][ $id ] = $core_content[ $type ][ $id ];
     1950                    $content[ $type ][ $nav_menu_location ]['name'] = $nav_menu['name'];
     1951
     1952                    foreach ( $nav_menu['items'] as $nav_menu_item ) {
     1953                        if ( is_array( $nav_menu_item ) ) {
     1954                            $content[ $type ][ $nav_menu_location ]['items'][] = $nav_menu_item;
     1955                        } elseif ( is_string( $nav_menu_item ) && ! empty( $core_content[ $type ] ) && ! empty( $core_content[ $type ][ $nav_menu_item ] ) ) {
     1956                            $content[ $type ][ $nav_menu_location ]['items'][] = $core_content[ $type ][ $nav_menu_item ];
    19531957                        }
    19541958                    }
     
    19561960                break;
    19571961
    1958 
    1959             // Everything else should map at the next level
     1962            // Everything else should map at the next level.
    19601963            default :
    1961                 foreach( $config[ $type ] as $id ) {
    1962                     if ( ! empty( $core_content[ $type ] ) && ! empty( $core_content[ $type ][ $id ] ) ) {
    1963                         $content[ $type ][ $id ] = $core_content[ $type ][ $id ];
     1964                foreach( $config[ $type ] as $i => $item ) {
     1965                    if ( is_array( $item ) ) {
     1966                        $content[ $type ][ $i ] = $item;
     1967                    } elseif ( is_string( $item ) && ! empty( $core_content[ $type ] ) && ! empty( $core_content[ $type ][ $item ] ) ) {
     1968                        $content[ $type ][ $item ] = $core_content[ $type ][ $item ];
    19641969                    }
    19651970                }
Note: See TracChangeset for help on using the changeset viewer.