Make WordPress Core


Ignore:
Timestamp:
11/23/2016 09:52:27 AM (7 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/src/wp-includes/theme.php

    r39338 r39346  
    19871987            case 'widgets' :
    19881988                foreach ( $config[ $type ] as $sidebar_id => $widgets ) {
    1989                     foreach ( $widgets as $widget ) {
     1989                    foreach ( $widgets as $id => $widget ) {
    19901990                        if ( is_array( $widget ) ) {
     1991
     1992                            // Item extends core content.
     1993                            if ( ! empty( $core_content[ $type ][ $id ] ) ) {
     1994                                $widget = array(
     1995                                    $core_content[ $type ][ $id ][0],
     1996                                    array_merge( $core_content[ $type ][ $id ][1], $widget ),
     1997                                );
     1998                            }
     1999
    19912000                            $content[ $type ][ $sidebar_id ][] = $widget;
    19922001                        } elseif ( is_string( $widget ) && ! empty( $core_content[ $type ] ) && ! empty( $core_content[ $type ][ $widget ] ) ) {
     
    20082017                    $content[ $type ][ $nav_menu_location ]['name'] = $nav_menu['name'];
    20092018
    2010                     foreach ( $nav_menu['items'] as $nav_menu_item ) {
     2019                    foreach ( $nav_menu['items'] as $id => $nav_menu_item ) {
    20112020                        if ( is_array( $nav_menu_item ) ) {
     2021
     2022                            // Item extends core content.
     2023                            if ( ! empty( $core_content[ $type ][ $id ] ) ) {
     2024                                $nav_menu_item = array_merge( $core_content[ $type ][ $id ], $nav_menu_item );
     2025                            }
     2026
    20122027                            $content[ $type ][ $nav_menu_location ]['items'][] = $nav_menu_item;
    20132028                        } elseif ( is_string( $nav_menu_item ) && ! empty( $core_content[ $type ] ) && ! empty( $core_content[ $type ][ $nav_menu_item ] ) ) {
     
    20182033                break;
    20192034
    2020             // Everything else should map at the next level.
    2021             default :
    2022                 foreach( $config[ $type ] as $i => $item ) {
     2035            // Attachments are posts but have special treatment.
     2036            case 'attachments' :
     2037                foreach ( $config[ $type ] as $id => $item ) {
     2038                    if ( ! empty( $item['file'] ) ) {
     2039                        $content[ $type ][ $id ] = $item;
     2040                    }
     2041                }
     2042                break;
     2043
     2044            // All that's left now are posts (besides attachments). Not a default case for the sake of clarity and future work.
     2045            case 'posts' :
     2046                foreach ( $config[ $type ] as $id => $item ) {
    20232047                    if ( is_array( $item ) ) {
    2024                         $content[ $type ][ $i ] = $item;
    2025                     } elseif ( is_string( $item ) && ! empty( $core_content[ $type ] ) && ! empty( $core_content[ $type ][ $item ] ) ) {
     2048
     2049                        // Item extends core content.
     2050                        if ( ! empty( $core_content[ $type ][ $id ] ) ) {
     2051                            $item = array_merge( $core_content[ $type ][ $id ], $item );
     2052                        }
     2053
     2054                        // Enforce a subset of fields.
     2055                        $content[ $type ][ $id ] = wp_array_slice_assoc(
     2056                            $item,
     2057                            array(
     2058                                'post_type',
     2059                                'post_title',
     2060                                'post_excerpt',
     2061                                'post_name',
     2062                                'post_content',
     2063                                'menu_order',
     2064                                'comment_status',
     2065                                'thumbnail',
     2066                                'template',
     2067                            )
     2068                        );
     2069                    } elseif ( is_string( $item ) && ! empty( $core_content[ $type ][ $item ] ) ) {
    20262070                        $content[ $type ][ $item ] = $core_content[ $type ][ $item ];
    20272071                    }
Note: See TracChangeset for help on using the changeset viewer.