Ticket #40146: 40146.2.diff
File 40146.2.diff, 10.0 KB (added by , 8 years ago) |
---|
-
src/wp-includes/class-wp-customize-manager.php
960 960 $setting_id = sprintf( 'widget_%s[%d]', $id_base, $max_widget_numbers[ $id_base ] ); 961 961 962 962 $setting_value = $this->widgets->sanitize_widget_js_instance( $instance ); 963 if ( empty( $changeset_data[ $setting_id ] ) || ! empty( $changeset_data[ $setting_id ]['starter_content'] ) ) { 963 if ( 964 // The setting doesn't exist. 965 empty( $changeset_data[ $setting_id ] ) 966 // The setting was created by another theme's starter content, and the flag hasn't been cleared. 967 || ( isset( $changeset_data[ $setting_id ]['starter_content'] ) && empty( $changeset_data[ $setting_id ]['starter_content'][ $this->get_stylesheet() ] ) ) 968 ) { 964 969 $this->set_post_value( $setting_id, $setting_value ); 965 970 $this->pending_starter_content_settings_ids[] = $setting_id; 966 971 } … … 968 973 } 969 974 970 975 $setting_id = sprintf( 'sidebars_widgets[%s]', $sidebar_id ); 971 if ( empty( $changeset_data[ $setting_id ] ) || ! empty( $changeset_data[ $setting_id ]['starter_content'] ) ) { 976 if ( 977 // The setting doesn't exist. 978 empty( $changeset_data[ $setting_id ] ) 979 // The setting was created by another theme's starter content, and the flag hasn't been cleared. 980 || empty( $changeset_data[ $setting_id ]['starter_content'][ $this->get_stylesheet() ] ) 981 ) { 972 982 $this->set_post_value( $setting_id, $sidebar_widget_ids ); 973 983 $this->pending_starter_content_settings_ids[] = $setting_id; 974 984 } … … 1129 1139 // Use existing auto-draft post if one already exists with the same type and name. 1130 1140 if ( isset( $existing_starter_content_posts[ $post_type . ':' . $post_name ] ) ) { 1131 1141 $posts[ $post_symbol ]['ID'] = $existing_starter_content_posts[ $post_type . ':' . $post_name ]->ID; 1142 update_post_meta( $existing_starter_content_posts[ $post_type . ':' . $post_name ]->ID, '_starter_content_theme', $this->get_stylesheet() ); 1132 1143 continue; 1133 1144 } 1134 1145 … … 1143 1154 $posts[ $post_symbol ]['meta_input']['_wp_page_template'] = $posts[ $post_symbol ]['template']; 1144 1155 } 1145 1156 1157 $posts[ $post_symbol ]['meta_input']['_starter_content_theme'] = $this->get_stylesheet(); 1158 1146 1159 $r = $this->nav_menus->insert_auto_draft_post( $posts[ $post_symbol ] ); 1147 1160 if ( $r instanceof WP_Post ) { 1148 1161 $posts[ $post_symbol ]['ID'] = $r->ID; … … 1171 1184 // Look for an existing placeholder menu with starter content to re-use. 1172 1185 foreach ( $changeset_data as $setting_id => $setting_params ) { 1173 1186 $can_reuse = ( 1174 ! empty( $setting_params['starter_content'] )1187 ! empty( $setting_params['starter_content'][ $this->get_stylesheet() ] ) 1175 1188 && 1176 1189 ! in_array( $setting_id, $reused_nav_menu_setting_ids, true ) 1177 1190 && … … 1201 1214 // @todo Add support for menu_item_parent. 1202 1215 $position = 0; 1203 1216 foreach ( $nav_menu['items'] as $nav_menu_item ) { 1204 $nav_menu_item_setting_id = sprintf( 'nav_menu_item[%d]', $placeholder_id-- ); 1217 do { 1218 $nav_menu_item_setting_id = sprintf( 'nav_menu_item[%d]', $placeholder_id-- ); 1219 } while ( 1220 // The setting ID already exists, and it's not starter content or it's another theme's starter menu item. 1221 ! empty( $changeset_data[ $nav_menu_item_setting_id ] ) 1222 && ( 1223 ! isset( $changeset_data[ $nav_menu_item_setting_id ]['starter_content'] ) 1224 || empty( $changeset_data[ $nav_menu_item_setting_id ]['starter_content'][ $this->get_stylesheet() ] ) 1225 ) 1226 ); 1227 1205 1228 if ( ! isset( $nav_menu_item['position'] ) ) { 1206 1229 $nav_menu_item['position'] = $position++; 1207 1230 } 1231 1208 1232 $nav_menu_item['nav_menu_term_id'] = $nav_menu_term_id; 1209 1233 1210 1234 if ( isset( $nav_menu_item['object_id'] ) ) { … … 1221 1245 $nav_menu_item['object_id'] = 0; 1222 1246 } 1223 1247 1224 if ( empty( $changeset_data[ $nav_menu_item_setting_id ] ) || ! empty( $changeset_data[ $nav_menu_item_setting_id ]['starter_content'] ) ) { 1248 if ( 1249 // The nav menu item doesn't exist. 1250 empty( $changeset_data[ $nav_menu_item_setting_id ] ) 1251 // The nav menu item was created by another theme's starter content, and the flag hasn't been cleared. 1252 || ( isset( $changeset_data[ $nav_menu_setting_id ]['starter_content'] ) && empty( $changeset_data[ $nav_menu_item_setting_id ]['starter_content'][ $this->get_stylesheet() ] ) ) 1253 ) { 1225 1254 $this->set_post_value( $nav_menu_item_setting_id, $nav_menu_item ); 1226 1255 $this->pending_starter_content_settings_ids[] = $nav_menu_item_setting_id; 1227 1256 } … … 1228 1257 } 1229 1258 1230 1259 $setting_id = sprintf( 'nav_menu_locations[%s]', $nav_menu_location ); 1231 if ( empty( $changeset_data[ $setting_id ] ) || ! empty( $changeset_data[ $setting_id ]['starter_content'] ) ) { 1260 if ( 1261 // The setting doesn't exist. 1262 empty( $changeset_data[ $setting_id ] ) 1263 // The setting was created by another theme's starter content, and the flag hasn't been cleared. 1264 || ( isset( $changeset_data[ $setting_id ]['starter_content'] ) && empty( $changeset_data[ $setting_id ]['starter_content'][ $this->get_stylesheet() ] ) ) 1265 ) { 1232 1266 $this->set_post_value( $setting_id, $nav_menu_term_id ); 1233 1267 $this->pending_starter_content_settings_ids[] = $setting_id; 1234 1268 } … … 1246 1280 } 1247 1281 } 1248 1282 1249 if ( empty( $changeset_data[ $name ] ) || ! empty( $changeset_data[ $name ]['starter_content'] ) ) { 1283 if ( 1284 // The option doesn't exist. 1285 empty( $changeset_data[ $name ] ) 1286 // The option was created by another theme's starter content, and the flag hasn't been cleared. 1287 || ( isset( $changeset_data[ $name ]['starter_content'] ) && empty( $changeset_data[ $name ]['starter_content'][ $this->get_stylesheet() ] ) ) 1288 ) { 1250 1289 $this->set_post_value( $name, $value ); 1251 1290 $this->pending_starter_content_settings_ids[] = $name; 1252 1291 } … … 1281 1320 $value = wp_get_attachment_url( $value ); 1282 1321 } 1283 1322 1284 if ( empty( $changeset_data[ $name ] ) || ! empty( $changeset_data[ $name ]['starter_content'] ) ) { 1323 if ( 1324 // The setting doesn't exist. 1325 empty( $changeset_data[ $name ] ) 1326 // The setting was created by another theme's starter content, and the flag hasn't been cleared. 1327 || ( isset( $changeset_data[ $name ]['starter_content'] ) && empty( $changeset_data[ $name ]['starter_content'][ $this->get_stylesheet() ] ) ) 1328 ) { 1285 1329 $this->set_post_value( $name, $value ); 1286 1330 $this->pending_starter_content_settings_ids[] = $name; 1287 1331 } … … 1370 1414 } 1371 1415 1372 1416 $this->save_changeset_post( array( 1373 'data' => array_fill_keys( $this->pending_starter_content_settings_ids, array( 'starter_content' => true ) ), 1417 'data' => array_fill_keys( $this->pending_starter_content_settings_ids, array( 1418 'starter_content' => array( 1419 $this->get_stylesheet() => true, 1420 ), 1421 ) ), 1374 1422 'starter_content' => true, 1375 1423 ) ); 1376 1424 … … 1429 1477 if ( ! array_key_exists( 'value', $setting_params ) ) { 1430 1478 continue; 1431 1479 } 1480 1481 // The setting is still starter content, but not for this theme. 1482 if ( isset( $setting_params['starter_content'] ) && empty( $setting_params['starter_content'][ $this->get_stylesheet() ] ) ) { 1483 continue; 1484 } 1485 1432 1486 if ( isset( $setting_params['type'] ) && 'theme_mod' === $setting_params['type'] ) { 1433 1487 1434 1488 // Ensure that theme mods values are only used if they were saved under the current theme. … … 2393 2447 // Remove setting from changeset entirely. 2394 2448 unset( $data[ $changeset_setting_id ] ); 2395 2449 } else { 2396 2397 2450 if ( ! isset( $data[ $changeset_setting_id ] ) ) { 2398 2451 $data[ $changeset_setting_id ] = array(); 2399 2452 } 2400 2453 2401 2454 // Merge any additional setting params that have been supplied with the existing params. 2402 $merged_setting_params = array_merge( $data[ $changeset_setting_id ], $setting_params ); 2455 $merged_setting_params = array_merge( 2456 $data[ $changeset_setting_id ], 2457 $setting_params, 2458 array( 2459 'starter_content' => array_merge( 2460 isset( $data[ $changeset_setting_id ]['starter_content'] ) ? $data[ $changeset_setting_id ]['starter_content'] : array(), 2461 isset( $setting_params['starter_content'] ) ? $setting_params['starter_content'] : array() 2462 ), 2463 ) 2464 ); 2403 2465 2404 2466 // Skip updating setting params if unchanged (ensuring the user_id is not overwritten). 2405 2467 if ( $data[ $changeset_setting_id ] === $merged_setting_params ) { -
src/wp-includes/class-wp-customize-nav-menus.php
173 173 if ( 0 === $page && $this->manager->get_setting( 'nav_menus_created_posts' ) ) { 174 174 foreach ( $this->manager->get_setting( 'nav_menus_created_posts' )->value() as $post_id ) { 175 175 $auto_draft_post = get_post( $post_id ); 176 if ( $post_type->name === $auto_draft_post->post_type ) {177 $posts[] = $auto_draft_post;176 if ( $post_type->name !== $auto_draft_post->post_type ) { 177 continue; 178 178 } 179 180 $starter_content_theme = get_post_meta( $post_id, '_starter_content_theme', true ); 181 if ( $starter_content_theme && ( $starter_content_theme !== $this->manager->get_stylesheet() ) ) { 182 continue; 183 } 184 185 $posts[] = $auto_draft_post; 179 186 } 180 187 } 181 188 … … 1168 1175 $post_ids = $setting->post_value(); 1169 1176 if ( ! empty( $post_ids ) ) { 1170 1177 foreach ( $post_ids as $post_id ) { 1178 $starter_content_theme = get_post_meta( $post_id, '_starter_content_theme', true ); 1179 if ( $starter_content_theme && ( $starter_content_theme !== $this->manager->get_stylesheet() ) ) { 1180 continue; 1181 } 1182 1171 1183 $target_status = 'attachment' === get_post_type( $post_id ) ? 'inherit' : 'publish'; 1172 1184 $args = array( 1173 1185 'ID' => $post_id, … … 1182 1194 wp_update_post( wp_slash( $args ) ); 1183 1195 1184 1196 delete_post_meta( $post_id, '_customize_draft_post_name' ); 1197 delete_post_meta( $post_id, '_starter_content_theme' ); 1185 1198 } 1186 1199 } 1187 1200 }