Make WordPress Core

Ticket #40146: 40146.2.diff

File 40146.2.diff, 10.0 KB (added by dlh, 8 years ago)
  • src/wp-includes/class-wp-customize-manager.php

     
    960960                                $setting_id = sprintf( 'widget_%s[%d]', $id_base, $max_widget_numbers[ $id_base ] );
    961961
    962962                                $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                                ) {
    964969                                        $this->set_post_value( $setting_id, $setting_value );
    965970                                        $this->pending_starter_content_settings_ids[] = $setting_id;
    966971                                }
     
    968973                        }
    969974
    970975                        $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                        ) {
    972982                                $this->set_post_value( $setting_id, $sidebar_widget_ids );
    973983                                $this->pending_starter_content_settings_ids[] = $setting_id;
    974984                        }
     
    11291139                                // Use existing auto-draft post if one already exists with the same type and name.
    11301140                                if ( isset( $existing_starter_content_posts[ $post_type . ':' . $post_name ] ) ) {
    11311141                                        $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() );
    11321143                                        continue;
    11331144                                }
    11341145
     
    11431154                                        $posts[ $post_symbol ]['meta_input']['_wp_page_template'] = $posts[ $post_symbol ]['template'];
    11441155                                }
    11451156
     1157                                $posts[ $post_symbol ]['meta_input']['_starter_content_theme'] = $this->get_stylesheet();
     1158
    11461159                                $r = $this->nav_menus->insert_auto_draft_post( $posts[ $post_symbol ] );
    11471160                                if ( $r instanceof WP_Post ) {
    11481161                                        $posts[ $post_symbol ]['ID'] = $r->ID;
     
    11711184                        // Look for an existing placeholder menu with starter content to re-use.
    11721185                        foreach ( $changeset_data as $setting_id => $setting_params ) {
    11731186                                $can_reuse = (
    1174                                         ! empty( $setting_params['starter_content'] )
     1187                                        ! empty( $setting_params['starter_content'][ $this->get_stylesheet() ] )
    11751188                                        &&
    11761189                                        ! in_array( $setting_id, $reused_nav_menu_setting_ids, true )
    11771190                                        &&
     
    12011214                        // @todo Add support for menu_item_parent.
    12021215                        $position = 0;
    12031216                        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
    12051228                                if ( ! isset( $nav_menu_item['position'] ) ) {
    12061229                                        $nav_menu_item['position'] = $position++;
    12071230                                }
     1231
    12081232                                $nav_menu_item['nav_menu_term_id'] = $nav_menu_term_id;
    12091233
    12101234                                if ( isset( $nav_menu_item['object_id'] ) ) {
     
    12211245                                        $nav_menu_item['object_id'] = 0;
    12221246                                }
    12231247
    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                                ) {
    12251254                                        $this->set_post_value( $nav_menu_item_setting_id, $nav_menu_item );
    12261255                                        $this->pending_starter_content_settings_ids[] = $nav_menu_item_setting_id;
    12271256                                }
     
    12281257                        }
    12291258
    12301259                        $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                        ) {
    12321266                                $this->set_post_value( $setting_id, $nav_menu_term_id );
    12331267                                $this->pending_starter_content_settings_ids[] = $setting_id;
    12341268                        }
     
    12461280                                }
    12471281                        }
    12481282
    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                        ) {
    12501289                                $this->set_post_value( $name, $value );
    12511290                                $this->pending_starter_content_settings_ids[] = $name;
    12521291                        }
     
    12811320                                $value = wp_get_attachment_url( $value );
    12821321                        }
    12831322
    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                        ) {
    12851329                                $this->set_post_value( $name, $value );
    12861330                                $this->pending_starter_content_settings_ids[] = $name;
    12871331                        }
     
    13701414                }
    13711415
    13721416                $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                        ) ),
    13741422                        'starter_content' => true,
    13751423                ) );
    13761424
     
    14291477                                if ( ! array_key_exists( 'value', $setting_params ) ) {
    14301478                                        continue;
    14311479                                }
     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
    14321486                                if ( isset( $setting_params['type'] ) && 'theme_mod' === $setting_params['type'] ) {
    14331487
    14341488                                        // Ensure that theme mods values are only used if they were saved under the current theme.
     
    23932447                                // Remove setting from changeset entirely.
    23942448                                unset( $data[ $changeset_setting_id ] );
    23952449                        } else {
    2396 
    23972450                                if ( ! isset( $data[ $changeset_setting_id ] ) ) {
    23982451                                        $data[ $changeset_setting_id ] = array();
    23992452                                }
    24002453
    24012454                                // 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                                );
    24032465
    24042466                                // Skip updating setting params if unchanged (ensuring the user_id is not overwritten).
    24052467                                if ( $data[ $changeset_setting_id ] === $merged_setting_params ) {
  • src/wp-includes/class-wp-customize-nav-menus.php

     
    173173                        if ( 0 === $page && $this->manager->get_setting( 'nav_menus_created_posts' ) ) {
    174174                                foreach ( $this->manager->get_setting( 'nav_menus_created_posts' )->value() as $post_id ) {
    175175                                        $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;
    178178                                        }
     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;
    179186                                }
    180187                        }
    181188
     
    11681175                $post_ids = $setting->post_value();
    11691176                if ( ! empty( $post_ids ) ) {
    11701177                        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
    11711183                                $target_status = 'attachment' === get_post_type( $post_id ) ? 'inherit' : 'publish';
    11721184                                $args = array(
    11731185                                        'ID' => $post_id,
     
    11821194                                wp_update_post( wp_slash( $args ) );
    11831195
    11841196                                delete_post_meta( $post_id, '_customize_draft_post_name' );
     1197                                delete_post_meta( $post_id, '_starter_content_theme' );
    11851198                        }
    11861199                }
    11871200        }