WordPress.org

Make WordPress Core


Ignore:
Timestamp:
11/23/2016 09:52:27 AM (5 years ago)
Author:
helen
Message:

Theme starter content: Add support for featured images and page templates.

Featured image support means that attachments can now be imported. Media can be sideloaded from within theme or plugin directories. Like other posts, attachments are auto-drafts until customizer changes are published, and are not duplicated when they already exist in the customized state. Attachment IDs can be used for any number of purposes, much like post IDs. Twenty Seventeen now includes 3 images used as featured images to best showcase the multi-section homepage setup.

As featured image IDs are stored in post meta, it also made sense to add support for page templates. Twenty Seventeen does not include any such templates, but the functionality can be quite important for displaying themes to their best effect.

props westonruter, helen, flixos90.
fixes #38615.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/theme/getThemeStarterContent.php

    r39276 r39346  
    4242                'sidebar-1' => array(
    4343                    'text_business_info',
    44                     'text_about',
     44                    'text_about' => array(
     45                        'title' => 'Our Story',
     46                    ),
    4547                    'archives',
    4648                    'calendar',
     
    6466                        'page_blog',
    6567                        'page_news',
    66                         'page_contact',
     68                        'page_contact' => array(
     69                            'title' => 'Email Us',
     70                        ),
    6771                        'link_email',
    6872                        'link_facebook',
     
    8791                'about',
    8892                'contact',
    89                 'blog',
     93                'blog' => array(
     94                    'template' => 'blog.php',
     95                    'post_excerpt' => 'Extended',
     96                ),
    9097                'news',
    9198                'homepage-section',
     
    94101                    'post_type' => 'post',
    95102                    'post_title' => 'Custom',
     103                    'thumbnail' => '{{featured-image-logo}}',
     104                ),
     105            ),
     106            'attachments' => array(
     107                'featured-image-logo' => array(
     108                    'post_title' => 'Title',
     109                    'post_content' => 'Description',
     110                    'post_excerpt' => 'Caption',
     111                    'file' => DIR_TESTDATA . '/images/waffles.jpg',
     112                ),
     113                'featured-image-skipped' => array(
     114                    'post_title' => 'Skipped',
    96115                ),
    97116            ),
     
    116135        $this->assertCount( 16, $hydrated_starter_content['nav_menus']['top']['items'], 'Unknown should be dropped, custom should be present.' );
    117136        $this->assertCount( 10, $hydrated_starter_content['widgets']['sidebar-1'], 'Unknown should be dropped.' );
     137        $this->assertCount( 1, $hydrated_starter_content['attachments'], 'Attachment with missing file is filtered out.' );
     138        $this->assertArrayHasKey( 'featured-image-logo', $hydrated_starter_content['attachments'] );
     139        $this->assertSame( $dehydrated_starter_content['attachments']['featured-image-logo'], $hydrated_starter_content['attachments']['featured-image-logo'] );
    118140
    119141        foreach ( $hydrated_starter_content['widgets']['sidebar-1'] as $widget ) {
     
    124146            $this->assertArrayHasKey( 'title', $widget[1] );
    125147        }
     148        $this->assertEquals( 'text', $hydrated_starter_content['widgets']['sidebar-1'][1][0], 'Core content extended' );
     149        $this->assertEquals( 'Our Story', $hydrated_starter_content['widgets']['sidebar-1'][1][1]['title'], 'Core content extended' );
    126150
    127151        foreach ( $hydrated_starter_content['nav_menus']['top']['items'] as $nav_menu_item ) {
     
    129153            $this->assertTrue( ! empty( $nav_menu_item['object_id'] ) || ! empty( $nav_menu_item['url'] ) );
    130154        }
     155        $this->assertEquals( 'Email Us', $hydrated_starter_content['nav_menus']['top']['items'][4]['title'], 'Core content extended' );
    131156
    132157        foreach ( $hydrated_starter_content['posts'] as $key => $post ) {
     
    137162            $this->assertArrayHasKey( 'post_title', $post );
    138163        }
     164        $this->assertEquals( 'Extended', $hydrated_starter_content['posts']['blog']['post_excerpt'], 'Core content extended' );
     165        $this->assertEquals( 'blog.php', $hydrated_starter_content['posts']['blog']['template'], 'Core content extended' );
     166        $this->assertEquals( '{{featured-image-logo}}', $hydrated_starter_content['posts']['custom']['thumbnail'], 'Core content extended' );
    139167    }
    140168
Note: See TracChangeset for help on using the changeset viewer.