Ticket #38615: 38615.3.diff
File 38615.3.diff, 7.2 KB (added by , 9 years ago) |
---|
-
src/wp-content/themes/twentyseventeen/functions.php
123 123 124 124 'posts' => array( 125 125 'home', 126 'about', 126 'about' => array( 127 'thumbnail' => '{{featured-image-1}}', 128 ), 127 129 'contact', 128 130 'blog', 129 131 'homepage-section', 130 132 ), 131 133 134 'attachments' => array( 135 'featured-image-1' => array( 136 'file_url' => '/assets/images/espresso.jpg', 137 ), 138 ), 139 132 140 'options' => array( 133 141 'show_on_front' => 'page', 134 142 'page_on_front' => '{{home}}', -
src/wp-includes/class-wp-customize-manager.php
916 916 } 917 917 918 918 $sidebars_widgets = isset( $starter_content['widgets'] ) && ! empty( $this->widgets ) ? $starter_content['widgets'] : array(); 919 $attachments = isset( $starter_content['attachments'] ) && ! empty( $this->nav_menus ) ? $starter_content['attachments'] : array(); 919 920 $posts = isset( $starter_content['posts'] ) && ! empty( $this->nav_menus ) ? $starter_content['posts'] : array(); 920 921 $options = isset( $starter_content['options'] ) ? $starter_content['options'] : array(); 921 922 $nav_menus = isset( $starter_content['nav_menus'] ) && ! empty( $this->nav_menus ) ? $starter_content['nav_menus'] : array(); … … 965 966 } 966 967 } 967 968 969 $nav_menus_created_posts = array(); 970 971 // Attachments are technically posts but handled differently. 972 if ( ! empty( $attachments ) ) { 973 // Such is The WordPress Way. 974 require_once( ABSPATH . 'wp-admin/includes/file.php' ); 975 require_once( ABSPATH . 'wp-admin/includes/media.php' ); 976 require_once( ABSPATH . 'wp-admin/includes/image.php' ); 977 978 $attachment_ids = array(); 979 980 foreach( $attachments as $symbol => $attributes ) { 981 $file = get_stylesheet_directory_uri() . $attributes['file_url']; 982 983 // We have to replicate logic from inside media_sideload_image() because WordPress. 984 // See https://core.trac.wordpress.org/ticket/19629 985 // Set variables for storage, fix file filename for query strings. 986 preg_match( '/[^\?]+\.(jpe?g|jpe|gif|png)\b/i', $file, $matches ); 987 if ( ! $matches ) { 988 continue; 989 } 990 991 $file_array = array(); 992 $file_array['name'] = basename( $matches[0] ); 993 $file_array['tmp_name'] = download_url( $file ); 994 995 if ( is_wp_error( $file_array['tmp_name'] ) ) { 996 continue; 997 } 998 999 $attachment_id = media_handle_sideload( $file_array, 0 ); 1000 // End duplicated logic 1001 1002 if ( is_wp_error( $attachment_id ) ) { 1003 continue; 1004 } 1005 // Problem: Images are missing the "full" size from metadata. What? 1006 // Set this to auto-draft for garbage collection later 1007 // Is this working? 1008 wp_insert_attachment( array( 'ID' => $attachment_id, 'post_status' => 'auto-draft' ) ); 1009 $attachment_ids[ $symbol ] = $attachment_id; 1010 1011 $nav_menus_created_posts = array_merge( $nav_menus_created_posts, array_values( $attachment_ids ) ); 1012 } 1013 } 1014 968 1015 // Posts & pages. 969 1016 if ( ! empty( $posts ) ) { 970 $nav_menus_created_posts = array();971 1017 if ( ! empty( $changeset_data['nav_menus_created_posts']['value'] ) ) { 972 1018 $nav_menus_created_posts = $changeset_data['nav_menus_created_posts']['value']; 973 1019 } … … 1004 1050 continue; 1005 1051 } 1006 1052 1053 // Translate the featured image symbol 1054 if ( ! empty( $posts[ $post_symbol ]['thumbnail'] ) 1055 && preg_match( '/^{{(?P<symbol>.+)}}$/', $posts[ $post_symbol ]['thumbnail'], $matches ) 1056 && isset( $attachment_ids[ $matches['symbol'] ] ) ) { 1057 $posts[ $post_symbol ][ 'meta_input' ][ '_thumbnail_id' ] = $attachment_ids[ $matches['symbol'] ]; 1058 } 1059 1007 1060 $r = $this->nav_menus->insert_auto_draft_post( $posts[ $post_symbol ] ); 1008 1061 if ( $r instanceof WP_Post ) { 1009 1062 $posts[ $post_symbol ]['ID'] = $r->ID; … … 1010 1063 } 1011 1064 } 1012 1065 1013 // The nav_menus_created_posts setting is why nav_menus component is dependency for adding posts. 1066 $nav_menus_created_posts = array_merge( $nav_menus_created_posts, wp_list_pluck( $posts, 'ID' ) ); 1067 } 1068 1069 // The nav_menus_created_posts setting is why nav_menus component is dependency for adding posts. 1070 if ( ! empty( $this->nav_menus ) && ! empty( $nav_menus_created_posts ) ) { 1014 1071 $setting_id = 'nav_menus_created_posts'; 1015 if ( empty( $changeset_data[ $setting_id ] ) || ! empty( $changeset_data[ $setting_id ]['starter_content'] ) ) { 1016 $nav_menus_created_posts = array_unique( array_merge( $nav_menus_created_posts, wp_list_pluck( $posts, 'ID' ) ) ); 1017 $this->set_post_value( $setting_id, array_values( $nav_menus_created_posts ) ); 1018 $this->pending_starter_content_settings_ids[] = $setting_id; 1072 if ( ! empty( $changeset_data[ $setting_id ] ) ) { 1073 $nav_menus_created_posts = array_merge( $nav_menus_created_posts, $changeset_data[ $setting_id ] ); 1019 1074 } 1075 $this->set_post_value( $setting_id, array_unique( array_values( $nav_menus_created_posts ) ) ); 1076 $this->pending_starter_content_settings_ids[] = $setting_id; 1020 1077 } 1021 1078 1022 1079 // Nav menus. -
src/wp-includes/theme.php
1830 1830 $config = array(); 1831 1831 } 1832 1832 1833 /** 1834 * Filters the allowed extra post args for starter content. 1835 * 1836 * @since 4.7.0 1837 * 1838 * @param array $allowed_post_args Array of allowed post args. 1839 * @param array $config Array of theme-specific starter content configuration. 1840 */ 1841 $allowed_post_args = apply_filters( 'starter_content_allowed_post_args', array( 'thumbnail', 'page_template' ), $config ); 1842 1833 1843 $core_content = array( 1834 1844 'widgets' => array( 1835 1845 'text_business_info' => array( 'text', array( … … 1972 1982 1973 1983 foreach ( $config as $type => $args ) { 1974 1984 switch( $type ) { 1975 // Use options and theme_mods as-is. 1985 // Use options and theme_mods as-is. Also, attachments, for now. 1976 1986 case 'options' : 1977 1987 case 'theme_mods' : 1988 case 'attachments' : 1978 1989 $content[ $type ] = $config[ $type ]; 1979 1990 break; 1980 1991 … … 2012 2023 } 2013 2024 break; 2014 2025 2015 // Everything else should map at the next level. 2016 default : 2017 foreach( $config[ $type ] as $i => $item ) { 2018 if ( is_array( $item ) ) { 2019 $content[ $type ][ $i ] = $item; 2026 // All that's left now are posts (besides attachments). Not a default case for the sake of clarity and future work. 2027 case 'posts' : 2028 foreach( $config[ $type ] as $id => $item ) { 2029 // Posts and pages can be passed certain other args 2030 if ( is_array( $item ) && ! empty( $core_content[ $type ] ) && ! empty( $core_content[ $type ][ $id ] ) ) { 2031 $content[ $type ][ $id ] = $core_content[ $type ][ $id ]; 2032 2033 foreach( $item as $key => $value ) { 2034 if ( in_array( $key, $allowed_post_args ) ) { 2035 $content[ $type ][ $id ][ $key ] = $value; 2036 } 2037 } 2020 2038 } elseif ( is_string( $item ) && ! empty( $core_content[ $type ] ) && ! empty( $core_content[ $type ][ $item ] ) ) { 2021 2039 $content[ $type ][ $item ] = $core_content[ $type ][ $item ]; 2022 2040 }