Ticket #38615: 38615.9.diff
File 38615.9.diff, 8.7 KB (added by , 8 years ago) |
---|
-
src/wp-content/themes/twentyseventeen/functions.php
123 123 124 124 'posts' => array( 125 125 'home', 126 'about', 127 'contact', 128 'blog', 129 'homepage-section', 126 'about' => array( 127 'thumbnail' => '{{featured-image-2}}', 128 ), 129 'contact' => array( 130 'thumbnail' => '{{featured-image-1}}', 131 ), 132 'blog' => array( 133 'thumbnail' => '{{featured-image-3}}', 134 ), 135 'homepage-section' => array( 136 'thumbnail' => '{{featured-image-1}}', 137 ), 130 138 ), 131 139 140 'attachments' => array( 141 'featured-image-1' => array( 142 'file' => '/assets/images/espresso.jpg', 143 ), 144 'featured-image-2' => array( 145 'file' => '/assets/images/sandwich.jpg', 146 ), 147 'featured-image-3' => array( 148 'file' => '/assets/images/coffee.jpg', 149 ), 150 ), 151 132 152 'options' => array( 133 153 'show_on_front' => 'page', 134 154 '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 // We have to replicate logic from inside media_sideload_image() because WordPress. 982 // See https://core.trac.wordpress.org/ticket/19629 983 $file_array = array(); 984 $file_array['name'] = $attributes['basename']; 985 $file_array['tmp_name'] = download_url( $attributes['file_url'] ); 986 987 if ( is_wp_error( $file_array['tmp_name'] ) ) { 988 continue; 989 } 990 991 $attachment_id = media_handle_sideload( $file_array, 0 ); 992 // End duplicated logic 993 994 if ( is_wp_error( $attachment_id ) ) { 995 continue; 996 } 997 998 // Set this to auto-draft for garbage collection later 999 wp_update_post( array( 'ID' => $attachment_id, 'post_status' => 'auto-draft' ) ); 1000 $attachment_ids[ $symbol ] = $attachment_id; 1001 1002 $nav_menus_created_posts = array_merge( $nav_menus_created_posts, array_values( $attachment_ids ) ); 1003 } 1004 } 1005 968 1006 // Posts & pages. 969 1007 if ( ! empty( $posts ) ) { 970 $nav_menus_created_posts = array();971 1008 if ( ! empty( $changeset_data['nav_menus_created_posts']['value'] ) ) { 972 1009 $nav_menus_created_posts = $changeset_data['nav_menus_created_posts']['value']; 973 1010 } … … 1004 1041 continue; 1005 1042 } 1006 1043 1044 // Translate the featured image symbol 1045 if ( ! empty( $posts[ $post_symbol ]['thumbnail'] ) 1046 && preg_match( '/^{{(?P<symbol>.+)}}$/', $posts[ $post_symbol ]['thumbnail'], $matches ) 1047 && isset( $attachment_ids[ $matches['symbol'] ] ) ) { 1048 $posts[ $post_symbol ][ 'meta_input' ][ '_thumbnail_id' ] = $attachment_ids[ $matches['symbol'] ]; 1049 } 1050 1051 if ( ! empty( $posts[ $post_symbol ]['template'] ) ) { 1052 $posts[ $post_symbol ][ 'meta_input' ][ '_wp_page_template' ] = $posts[ $post_symbol ]['template']; 1053 } 1054 1007 1055 $r = $this->nav_menus->insert_auto_draft_post( $posts[ $post_symbol ] ); 1008 1056 if ( $r instanceof WP_Post ) { 1009 1057 $posts[ $post_symbol ]['ID'] = $r->ID; … … 1010 1058 } 1011 1059 } 1012 1060 1013 // The nav_menus_created_posts setting is why nav_menus component is dependency for adding posts. 1061 $nav_menus_created_posts = array_merge( $nav_menus_created_posts, wp_list_pluck( $posts, 'ID' ) ); 1062 } 1063 1064 // The nav_menus_created_posts setting is why nav_menus component is dependency for adding posts. 1065 if ( ! empty( $this->nav_menus ) && ! empty( $nav_menus_created_posts ) ) { 1014 1066 $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; 1067 if ( ! empty( $changeset_data[ $setting_id ]['value'] ) ) { 1068 $nav_menus_created_posts = array_merge( $nav_menus_created_posts, $changeset_data[ $setting_id ]['value'] ); 1019 1069 } 1070 $this->set_post_value( $setting_id, array_unique( array_values( $nav_menus_created_posts ) ) ); 1071 $this->pending_starter_content_settings_ids[] = $setting_id; 1020 1072 } 1021 1073 1022 1074 // Nav menus. -
src/wp-includes/class-wp-customize-nav-menus.php
1191 1191 $post_ids = $setting->post_value(); 1192 1192 if ( ! empty( $post_ids ) ) { 1193 1193 foreach ( $post_ids as $post_id ) { 1194 $target_status = 'attachment' === get_post_type( $post_id ) ? 'inherit' : 'publish'; 1195 1194 1196 // Note that wp_publish_post() cannot be used because unique slugs need to be assigned. 1195 wp_update_post( array( 'ID' => $post_id, 'post_status' => 'publish') );1197 wp_update_post( array( 'ID' => $post_id, 'post_status' => $target_status ) ); 1196 1198 } 1197 1199 } 1198 1200 } -
src/wp-includes/post.php
3058 3058 } 3059 3059 3060 3060 $post_status = empty( $postarr['post_status'] ) ? 'draft' : $postarr['post_status']; 3061 if ( 'attachment' === $post_type && ! in_array( $post_status, array( 'inherit', 'private', 'trash' ) ) ) {3061 if ( 'attachment' === $post_type && ! in_array( $post_status, array( 'inherit', 'private', 'trash', 'auto-draft' ) ) ) { 3062 3062 $post_status = 'inherit'; 3063 3063 } 3064 3064 -
src/wp-includes/theme.php
2012 2012 } 2013 2013 break; 2014 2014 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; 2015 // Attachments are posts but have special treatment. 2016 case 'attachments' : 2017 foreach( $config[ $type ] as $id => $item ) { 2018 // Only allow items with an explicit image file extension in the name. 2019 // Someday, perhaps A/V or named sources sideloaded from w.org. 2020 preg_match( '/[^\?]+\.(jpe?g|jpe|gif|png)\b/i', $item['file'], $matches ); 2021 if ( ! $matches ) { 2022 continue; 2023 } 2024 2025 $item['basename'] = basename( $matches[0] ); 2026 2027 if ( is_child_theme() && file_exists( get_stylesheet_directory() . $item['file'] ) ) { 2028 $item['file_url'] = get_stylesheet_directory_uri() . $item['file']; 2029 } else { 2030 $item['file_url'] = get_template_directory_uri() . $item['file']; 2031 } 2032 2033 $content[ $type ][ $id ] = $item; 2034 } 2035 break; 2036 2037 // All that's left now are posts (besides attachments). Not a default case for the sake of clarity and future work. 2038 case 'posts' : 2039 foreach( $config[ $type ] as $id => $item ) { 2040 if ( is_array( $item ) && ! empty( $core_content[ $type ] ) && ! empty( $core_content[ $type ][ $id ] ) ) { 2041 $content[ $type ][ $id ] = $core_content[ $type ][ $id ]; 2042 2043 // Extra fields - currently locked down because they require special treatment. 2044 foreach( $item as $key => $value ) { 2045 if ( 'thumbnail' === $key || 'template' === $key ) { 2046 $content[ $type ][ $id ][ $key ] = $value; 2047 } 2048 } 2020 2049 } elseif ( is_string( $item ) && ! empty( $core_content[ $type ] ) && ! empty( $core_content[ $type ][ $item ] ) ) { 2021 2050 $content[ $type ][ $item ] = $core_content[ $type ][ $item ]; 2022 2051 }