Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93

Warning: Undefined array key "page_file_edit_line" in /home/sportsfever/public_html/filemanger/edit_text_line.php on line 32
/home/sportsfe.../httpdocs/wp-inclu...
File: class-wp-customize-manager.php
'name' => $uuid,
[1000] Fix | Delete
'posts_per_page' => 1,
[1001] Fix | Delete
'no_found_rows' => true,
[1002] Fix | Delete
'cache_results' => true,
[1003] Fix | Delete
'update_post_meta_cache' => false,
[1004] Fix | Delete
'update_post_term_cache' => false,
[1005] Fix | Delete
'lazy_load_term_meta' => false,
[1006] Fix | Delete
)
[1007] Fix | Delete
);
[1008] Fix | Delete
if ( ! empty( $changeset_post_query->posts ) ) {
[1009] Fix | Delete
// Note: 'fields'=>'ids' is not being used in order to cache the post object as it will be needed.
[1010] Fix | Delete
$changeset_post_id = $changeset_post_query->posts[0]->ID;
[1011] Fix | Delete
wp_cache_set( $uuid, $changeset_post_id, $cache_group );
[1012] Fix | Delete
return $changeset_post_id;
[1013] Fix | Delete
}
[1014] Fix | Delete
[1015] Fix | Delete
return null;
[1016] Fix | Delete
}
[1017] Fix | Delete
[1018] Fix | Delete
/**
[1019] Fix | Delete
* Gets changeset posts.
[1020] Fix | Delete
*
[1021] Fix | Delete
* @since 4.9.0
[1022] Fix | Delete
*
[1023] Fix | Delete
* @param array $args {
[1024] Fix | Delete
* Args to pass into `get_posts()` to query changesets.
[1025] Fix | Delete
*
[1026] Fix | Delete
* @type int $posts_per_page Number of posts to return. Defaults to -1 (all posts).
[1027] Fix | Delete
* @type int $author Post author. Defaults to current user.
[1028] Fix | Delete
* @type string $post_status Status of changeset. Defaults to 'auto-draft'.
[1029] Fix | Delete
* @type bool $exclude_restore_dismissed Whether to exclude changeset auto-drafts that have been dismissed. Defaults to true.
[1030] Fix | Delete
* }
[1031] Fix | Delete
* @return WP_Post[] Auto-draft changesets.
[1032] Fix | Delete
*/
[1033] Fix | Delete
protected function get_changeset_posts( $args = array() ) {
[1034] Fix | Delete
$default_args = array(
[1035] Fix | Delete
'exclude_restore_dismissed' => true,
[1036] Fix | Delete
'posts_per_page' => -1,
[1037] Fix | Delete
'post_type' => 'customize_changeset',
[1038] Fix | Delete
'post_status' => 'auto-draft',
[1039] Fix | Delete
'order' => 'DESC',
[1040] Fix | Delete
'orderby' => 'date',
[1041] Fix | Delete
'no_found_rows' => true,
[1042] Fix | Delete
'cache_results' => true,
[1043] Fix | Delete
'update_post_meta_cache' => false,
[1044] Fix | Delete
'update_post_term_cache' => false,
[1045] Fix | Delete
'lazy_load_term_meta' => false,
[1046] Fix | Delete
);
[1047] Fix | Delete
if ( get_current_user_id() ) {
[1048] Fix | Delete
$default_args['author'] = get_current_user_id();
[1049] Fix | Delete
}
[1050] Fix | Delete
$args = array_merge( $default_args, $args );
[1051] Fix | Delete
[1052] Fix | Delete
if ( ! empty( $args['exclude_restore_dismissed'] ) ) {
[1053] Fix | Delete
unset( $args['exclude_restore_dismissed'] );
[1054] Fix | Delete
$args['meta_query'] = array(
[1055] Fix | Delete
array(
[1056] Fix | Delete
'key' => '_customize_restore_dismissed',
[1057] Fix | Delete
'compare' => 'NOT EXISTS',
[1058] Fix | Delete
),
[1059] Fix | Delete
);
[1060] Fix | Delete
}
[1061] Fix | Delete
[1062] Fix | Delete
return get_posts( $args );
[1063] Fix | Delete
}
[1064] Fix | Delete
[1065] Fix | Delete
/**
[1066] Fix | Delete
* Dismisses all of the current user's auto-drafts (other than the present one).
[1067] Fix | Delete
*
[1068] Fix | Delete
* @since 4.9.0
[1069] Fix | Delete
* @return int The number of auto-drafts that were dismissed.
[1070] Fix | Delete
*/
[1071] Fix | Delete
protected function dismiss_user_auto_draft_changesets() {
[1072] Fix | Delete
$changeset_autodraft_posts = $this->get_changeset_posts(
[1073] Fix | Delete
array(
[1074] Fix | Delete
'post_status' => 'auto-draft',
[1075] Fix | Delete
'exclude_restore_dismissed' => true,
[1076] Fix | Delete
'posts_per_page' => -1,
[1077] Fix | Delete
)
[1078] Fix | Delete
);
[1079] Fix | Delete
$dismissed = 0;
[1080] Fix | Delete
foreach ( $changeset_autodraft_posts as $autosave_autodraft_post ) {
[1081] Fix | Delete
if ( $autosave_autodraft_post->ID === $this->changeset_post_id() ) {
[1082] Fix | Delete
continue;
[1083] Fix | Delete
}
[1084] Fix | Delete
if ( update_post_meta( $autosave_autodraft_post->ID, '_customize_restore_dismissed', true ) ) {
[1085] Fix | Delete
++$dismissed;
[1086] Fix | Delete
}
[1087] Fix | Delete
}
[1088] Fix | Delete
return $dismissed;
[1089] Fix | Delete
}
[1090] Fix | Delete
[1091] Fix | Delete
/**
[1092] Fix | Delete
* Gets the changeset post ID for the loaded changeset.
[1093] Fix | Delete
*
[1094] Fix | Delete
* @since 4.7.0
[1095] Fix | Delete
*
[1096] Fix | Delete
* @return int|null Post ID on success or null if there is no post yet saved.
[1097] Fix | Delete
*/
[1098] Fix | Delete
public function changeset_post_id() {
[1099] Fix | Delete
if ( ! isset( $this->_changeset_post_id ) ) {
[1100] Fix | Delete
$post_id = $this->find_changeset_post_id( $this->changeset_uuid() );
[1101] Fix | Delete
if ( ! $post_id ) {
[1102] Fix | Delete
$post_id = false;
[1103] Fix | Delete
}
[1104] Fix | Delete
$this->_changeset_post_id = $post_id;
[1105] Fix | Delete
}
[1106] Fix | Delete
if ( false === $this->_changeset_post_id ) {
[1107] Fix | Delete
return null;
[1108] Fix | Delete
}
[1109] Fix | Delete
return $this->_changeset_post_id;
[1110] Fix | Delete
}
[1111] Fix | Delete
[1112] Fix | Delete
/**
[1113] Fix | Delete
* Gets the data stored in a changeset post.
[1114] Fix | Delete
*
[1115] Fix | Delete
* @since 4.7.0
[1116] Fix | Delete
*
[1117] Fix | Delete
* @param int $post_id Changeset post ID.
[1118] Fix | Delete
* @return array|WP_Error Changeset data or WP_Error on error.
[1119] Fix | Delete
*/
[1120] Fix | Delete
protected function get_changeset_post_data( $post_id ) {
[1121] Fix | Delete
if ( ! $post_id ) {
[1122] Fix | Delete
return new WP_Error( 'empty_post_id' );
[1123] Fix | Delete
}
[1124] Fix | Delete
$changeset_post = get_post( $post_id );
[1125] Fix | Delete
if ( ! $changeset_post ) {
[1126] Fix | Delete
return new WP_Error( 'missing_post' );
[1127] Fix | Delete
}
[1128] Fix | Delete
if ( 'revision' === $changeset_post->post_type ) {
[1129] Fix | Delete
if ( 'customize_changeset' !== get_post_type( $changeset_post->post_parent ) ) {
[1130] Fix | Delete
return new WP_Error( 'wrong_post_type' );
[1131] Fix | Delete
}
[1132] Fix | Delete
} elseif ( 'customize_changeset' !== $changeset_post->post_type ) {
[1133] Fix | Delete
return new WP_Error( 'wrong_post_type' );
[1134] Fix | Delete
}
[1135] Fix | Delete
$changeset_data = json_decode( $changeset_post->post_content, true );
[1136] Fix | Delete
$last_error = json_last_error();
[1137] Fix | Delete
if ( $last_error ) {
[1138] Fix | Delete
return new WP_Error( 'json_parse_error', '', $last_error );
[1139] Fix | Delete
}
[1140] Fix | Delete
if ( ! is_array( $changeset_data ) ) {
[1141] Fix | Delete
return new WP_Error( 'expected_array' );
[1142] Fix | Delete
}
[1143] Fix | Delete
return $changeset_data;
[1144] Fix | Delete
}
[1145] Fix | Delete
[1146] Fix | Delete
/**
[1147] Fix | Delete
* Gets changeset data.
[1148] Fix | Delete
*
[1149] Fix | Delete
* @since 4.7.0
[1150] Fix | Delete
* @since 4.9.0 This will return the changeset's data with a user's autosave revision merged on top, if one exists and $autosaved is true.
[1151] Fix | Delete
*
[1152] Fix | Delete
* @return array Changeset data.
[1153] Fix | Delete
*/
[1154] Fix | Delete
public function changeset_data() {
[1155] Fix | Delete
if ( isset( $this->_changeset_data ) ) {
[1156] Fix | Delete
return $this->_changeset_data;
[1157] Fix | Delete
}
[1158] Fix | Delete
$changeset_post_id = $this->changeset_post_id();
[1159] Fix | Delete
if ( ! $changeset_post_id ) {
[1160] Fix | Delete
$this->_changeset_data = array();
[1161] Fix | Delete
} else {
[1162] Fix | Delete
if ( $this->autosaved() && is_user_logged_in() ) {
[1163] Fix | Delete
$autosave_post = wp_get_post_autosave( $changeset_post_id, get_current_user_id() );
[1164] Fix | Delete
if ( $autosave_post ) {
[1165] Fix | Delete
$data = $this->get_changeset_post_data( $autosave_post->ID );
[1166] Fix | Delete
if ( ! is_wp_error( $data ) ) {
[1167] Fix | Delete
$this->_changeset_data = $data;
[1168] Fix | Delete
}
[1169] Fix | Delete
}
[1170] Fix | Delete
}
[1171] Fix | Delete
[1172] Fix | Delete
// Load data from the changeset if it was not loaded from an autosave.
[1173] Fix | Delete
if ( ! isset( $this->_changeset_data ) ) {
[1174] Fix | Delete
$data = $this->get_changeset_post_data( $changeset_post_id );
[1175] Fix | Delete
if ( ! is_wp_error( $data ) ) {
[1176] Fix | Delete
$this->_changeset_data = $data;
[1177] Fix | Delete
} else {
[1178] Fix | Delete
$this->_changeset_data = array();
[1179] Fix | Delete
}
[1180] Fix | Delete
}
[1181] Fix | Delete
}
[1182] Fix | Delete
return $this->_changeset_data;
[1183] Fix | Delete
}
[1184] Fix | Delete
[1185] Fix | Delete
/**
[1186] Fix | Delete
* Starter content setting IDs.
[1187] Fix | Delete
*
[1188] Fix | Delete
* @since 4.7.0
[1189] Fix | Delete
* @var array
[1190] Fix | Delete
*/
[1191] Fix | Delete
protected $pending_starter_content_settings_ids = array();
[1192] Fix | Delete
[1193] Fix | Delete
/**
[1194] Fix | Delete
* Imports theme starter content into the customized state.
[1195] Fix | Delete
*
[1196] Fix | Delete
* @since 4.7.0
[1197] Fix | Delete
*
[1198] Fix | Delete
* @param array $starter_content Starter content. Defaults to `get_theme_starter_content()`.
[1199] Fix | Delete
*/
[1200] Fix | Delete
public function import_theme_starter_content( $starter_content = array() ) {
[1201] Fix | Delete
if ( empty( $starter_content ) ) {
[1202] Fix | Delete
$starter_content = get_theme_starter_content();
[1203] Fix | Delete
}
[1204] Fix | Delete
[1205] Fix | Delete
$changeset_data = array();
[1206] Fix | Delete
if ( $this->changeset_post_id() ) {
[1207] Fix | Delete
/*
[1208] Fix | Delete
* Don't re-import starter content into a changeset saved persistently.
[1209] Fix | Delete
* This will need to be revisited in the future once theme switching
[1210] Fix | Delete
* is allowed with drafted/scheduled changesets, since switching to
[1211] Fix | Delete
* another theme could result in more starter content being applied.
[1212] Fix | Delete
* However, when doing an explicit save it is currently possible for
[1213] Fix | Delete
* nav menus and nav menu items specifically to lose their starter_content
[1214] Fix | Delete
* flags, thus resulting in duplicates being created since they fail
[1215] Fix | Delete
* to get re-used. See #40146.
[1216] Fix | Delete
*/
[1217] Fix | Delete
if ( 'auto-draft' !== get_post_status( $this->changeset_post_id() ) ) {
[1218] Fix | Delete
return;
[1219] Fix | Delete
}
[1220] Fix | Delete
[1221] Fix | Delete
$changeset_data = $this->get_changeset_post_data( $this->changeset_post_id() );
[1222] Fix | Delete
}
[1223] Fix | Delete
[1224] Fix | Delete
$sidebars_widgets = isset( $starter_content['widgets'] ) && ! empty( $this->widgets ) ? $starter_content['widgets'] : array();
[1225] Fix | Delete
$attachments = isset( $starter_content['attachments'] ) && ! empty( $this->nav_menus ) ? $starter_content['attachments'] : array();
[1226] Fix | Delete
$posts = isset( $starter_content['posts'] ) && ! empty( $this->nav_menus ) ? $starter_content['posts'] : array();
[1227] Fix | Delete
$options = isset( $starter_content['options'] ) ? $starter_content['options'] : array();
[1228] Fix | Delete
$nav_menus = isset( $starter_content['nav_menus'] ) && ! empty( $this->nav_menus ) ? $starter_content['nav_menus'] : array();
[1229] Fix | Delete
$theme_mods = isset( $starter_content['theme_mods'] ) ? $starter_content['theme_mods'] : array();
[1230] Fix | Delete
[1231] Fix | Delete
// Widgets.
[1232] Fix | Delete
$max_widget_numbers = array();
[1233] Fix | Delete
foreach ( $sidebars_widgets as $sidebar_id => $widgets ) {
[1234] Fix | Delete
$sidebar_widget_ids = array();
[1235] Fix | Delete
foreach ( $widgets as $widget ) {
[1236] Fix | Delete
list( $id_base, $instance ) = $widget;
[1237] Fix | Delete
[1238] Fix | Delete
if ( ! isset( $max_widget_numbers[ $id_base ] ) ) {
[1239] Fix | Delete
[1240] Fix | Delete
// When $settings is an array-like object, get an intrinsic array for use with array_keys().
[1241] Fix | Delete
$settings = get_option( "widget_{$id_base}", array() );
[1242] Fix | Delete
if ( $settings instanceof ArrayObject || $settings instanceof ArrayIterator ) {
[1243] Fix | Delete
$settings = $settings->getArrayCopy();
[1244] Fix | Delete
}
[1245] Fix | Delete
[1246] Fix | Delete
unset( $settings['_multiwidget'] );
[1247] Fix | Delete
[1248] Fix | Delete
// Find the max widget number for this type.
[1249] Fix | Delete
$widget_numbers = array_keys( $settings );
[1250] Fix | Delete
if ( count( $widget_numbers ) > 0 ) {
[1251] Fix | Delete
$widget_numbers[] = 1;
[1252] Fix | Delete
$max_widget_numbers[ $id_base ] = max( ...$widget_numbers );
[1253] Fix | Delete
} else {
[1254] Fix | Delete
$max_widget_numbers[ $id_base ] = 1;
[1255] Fix | Delete
}
[1256] Fix | Delete
}
[1257] Fix | Delete
$max_widget_numbers[ $id_base ] += 1;
[1258] Fix | Delete
[1259] Fix | Delete
$widget_id = sprintf( '%s-%d', $id_base, $max_widget_numbers[ $id_base ] );
[1260] Fix | Delete
$setting_id = sprintf( 'widget_%s[%d]', $id_base, $max_widget_numbers[ $id_base ] );
[1261] Fix | Delete
[1262] Fix | Delete
$setting_value = $this->widgets->sanitize_widget_js_instance( $instance );
[1263] Fix | Delete
if ( empty( $changeset_data[ $setting_id ] ) || ! empty( $changeset_data[ $setting_id ]['starter_content'] ) ) {
[1264] Fix | Delete
$this->set_post_value( $setting_id, $setting_value );
[1265] Fix | Delete
$this->pending_starter_content_settings_ids[] = $setting_id;
[1266] Fix | Delete
}
[1267] Fix | Delete
$sidebar_widget_ids[] = $widget_id;
[1268] Fix | Delete
}
[1269] Fix | Delete
[1270] Fix | Delete
$setting_id = sprintf( 'sidebars_widgets[%s]', $sidebar_id );
[1271] Fix | Delete
if ( empty( $changeset_data[ $setting_id ] ) || ! empty( $changeset_data[ $setting_id ]['starter_content'] ) ) {
[1272] Fix | Delete
$this->set_post_value( $setting_id, $sidebar_widget_ids );
[1273] Fix | Delete
$this->pending_starter_content_settings_ids[] = $setting_id;
[1274] Fix | Delete
}
[1275] Fix | Delete
}
[1276] Fix | Delete
[1277] Fix | Delete
$starter_content_auto_draft_post_ids = array();
[1278] Fix | Delete
if ( ! empty( $changeset_data['nav_menus_created_posts']['value'] ) ) {
[1279] Fix | Delete
$starter_content_auto_draft_post_ids = array_merge( $starter_content_auto_draft_post_ids, $changeset_data['nav_menus_created_posts']['value'] );
[1280] Fix | Delete
}
[1281] Fix | Delete
[1282] Fix | Delete
// Make an index of all the posts needed and what their slugs are.
[1283] Fix | Delete
$needed_posts = array();
[1284] Fix | Delete
$attachments = $this->prepare_starter_content_attachments( $attachments );
[1285] Fix | Delete
foreach ( $attachments as $attachment ) {
[1286] Fix | Delete
$key = 'attachment:' . $attachment['post_name'];
[1287] Fix | Delete
$needed_posts[ $key ] = true;
[1288] Fix | Delete
}
[1289] Fix | Delete
foreach ( array_keys( $posts ) as $post_symbol ) {
[1290] Fix | Delete
if ( empty( $posts[ $post_symbol ]['post_name'] ) && empty( $posts[ $post_symbol ]['post_title'] ) ) {
[1291] Fix | Delete
unset( $posts[ $post_symbol ] );
[1292] Fix | Delete
continue;
[1293] Fix | Delete
}
[1294] Fix | Delete
if ( empty( $posts[ $post_symbol ]['post_name'] ) ) {
[1295] Fix | Delete
$posts[ $post_symbol ]['post_name'] = sanitize_title( $posts[ $post_symbol ]['post_title'] );
[1296] Fix | Delete
}
[1297] Fix | Delete
if ( empty( $posts[ $post_symbol ]['post_type'] ) ) {
[1298] Fix | Delete
$posts[ $post_symbol ]['post_type'] = 'post';
[1299] Fix | Delete
}
[1300] Fix | Delete
$needed_posts[ $posts[ $post_symbol ]['post_type'] . ':' . $posts[ $post_symbol ]['post_name'] ] = true;
[1301] Fix | Delete
}
[1302] Fix | Delete
$all_post_slugs = array_merge(
[1303] Fix | Delete
wp_list_pluck( $attachments, 'post_name' ),
[1304] Fix | Delete
wp_list_pluck( $posts, 'post_name' )
[1305] Fix | Delete
);
[1306] Fix | Delete
[1307] Fix | Delete
/*
[1308] Fix | Delete
* Obtain all post types referenced in starter content to use in query.
[1309] Fix | Delete
* This is needed because 'any' will not account for post types not yet registered.
[1310] Fix | Delete
*/
[1311] Fix | Delete
$post_types = array_filter( array_merge( array( 'attachment' ), wp_list_pluck( $posts, 'post_type' ) ) );
[1312] Fix | Delete
[1313] Fix | Delete
// Re-use auto-draft starter content posts referenced in the current customized state.
[1314] Fix | Delete
$existing_starter_content_posts = array();
[1315] Fix | Delete
if ( ! empty( $starter_content_auto_draft_post_ids ) ) {
[1316] Fix | Delete
$existing_posts_query = new WP_Query(
[1317] Fix | Delete
array(
[1318] Fix | Delete
'post__in' => $starter_content_auto_draft_post_ids,
[1319] Fix | Delete
'post_status' => 'auto-draft',
[1320] Fix | Delete
'post_type' => $post_types,
[1321] Fix | Delete
'posts_per_page' => -1,
[1322] Fix | Delete
)
[1323] Fix | Delete
);
[1324] Fix | Delete
foreach ( $existing_posts_query->posts as $existing_post ) {
[1325] Fix | Delete
$post_name = $existing_post->post_name;
[1326] Fix | Delete
if ( empty( $post_name ) ) {
[1327] Fix | Delete
$post_name = get_post_meta( $existing_post->ID, '_customize_draft_post_name', true );
[1328] Fix | Delete
}
[1329] Fix | Delete
$existing_starter_content_posts[ $existing_post->post_type . ':' . $post_name ] = $existing_post;
[1330] Fix | Delete
}
[1331] Fix | Delete
}
[1332] Fix | Delete
[1333] Fix | Delete
// Re-use non-auto-draft posts.
[1334] Fix | Delete
if ( ! empty( $all_post_slugs ) ) {
[1335] Fix | Delete
$existing_posts_query = new WP_Query(
[1336] Fix | Delete
array(
[1337] Fix | Delete
'post_name__in' => $all_post_slugs,
[1338] Fix | Delete
'post_status' => array_diff( get_post_stati(), array( 'auto-draft' ) ),
[1339] Fix | Delete
'post_type' => 'any',
[1340] Fix | Delete
'posts_per_page' => -1,
[1341] Fix | Delete
)
[1342] Fix | Delete
);
[1343] Fix | Delete
foreach ( $existing_posts_query->posts as $existing_post ) {
[1344] Fix | Delete
$key = $existing_post->post_type . ':' . $existing_post->post_name;
[1345] Fix | Delete
if ( isset( $needed_posts[ $key ] ) && ! isset( $existing_starter_content_posts[ $key ] ) ) {
[1346] Fix | Delete
$existing_starter_content_posts[ $key ] = $existing_post;
[1347] Fix | Delete
}
[1348] Fix | Delete
}
[1349] Fix | Delete
}
[1350] Fix | Delete
[1351] Fix | Delete
// Attachments are technically posts but handled differently.
[1352] Fix | Delete
if ( ! empty( $attachments ) ) {
[1353] Fix | Delete
[1354] Fix | Delete
$attachment_ids = array();
[1355] Fix | Delete
[1356] Fix | Delete
foreach ( $attachments as $symbol => $attachment ) {
[1357] Fix | Delete
$file_array = array(
[1358] Fix | Delete
'name' => $attachment['file_name'],
[1359] Fix | Delete
);
[1360] Fix | Delete
$file_path = $attachment['file_path'];
[1361] Fix | Delete
$attachment_id = null;
[1362] Fix | Delete
$attached_file = null;
[1363] Fix | Delete
if ( isset( $existing_starter_content_posts[ 'attachment:' . $attachment['post_name'] ] ) ) {
[1364] Fix | Delete
$attachment_post = $existing_starter_content_posts[ 'attachment:' . $attachment['post_name'] ];
[1365] Fix | Delete
$attachment_id = $attachment_post->ID;
[1366] Fix | Delete
$attached_file = get_attached_file( $attachment_id );
[1367] Fix | Delete
if ( empty( $attached_file ) || ! file_exists( $attached_file ) ) {
[1368] Fix | Delete
$attachment_id = null;
[1369] Fix | Delete
$attached_file = null;
[1370] Fix | Delete
} elseif ( $this->get_stylesheet() !== get_post_meta( $attachment_post->ID, '_starter_content_theme', true ) ) {
[1371] Fix | Delete
[1372] Fix | Delete
// Re-generate attachment metadata since it was previously generated for a different theme.
[1373] Fix | Delete
$metadata = wp_generate_attachment_metadata( $attachment_post->ID, $attached_file );
[1374] Fix | Delete
wp_update_attachment_metadata( $attachment_id, $metadata );
[1375] Fix | Delete
update_post_meta( $attachment_id, '_starter_content_theme', $this->get_stylesheet() );
[1376] Fix | Delete
}
[1377] Fix | Delete
}
[1378] Fix | Delete
[1379] Fix | Delete
// Insert the attachment auto-draft because it doesn't yet exist or the attached file is gone.
[1380] Fix | Delete
if ( ! $attachment_id ) {
[1381] Fix | Delete
[1382] Fix | Delete
// Copy file to temp location so that original file won't get deleted from theme after sideloading.
[1383] Fix | Delete
$temp_file_name = wp_tempnam( wp_basename( $file_path ) );
[1384] Fix | Delete
if ( $temp_file_name && copy( $file_path, $temp_file_name ) ) {
[1385] Fix | Delete
$file_array['tmp_name'] = $temp_file_name;
[1386] Fix | Delete
}
[1387] Fix | Delete
if ( empty( $file_array['tmp_name'] ) ) {
[1388] Fix | Delete
continue;
[1389] Fix | Delete
}
[1390] Fix | Delete
[1391] Fix | Delete
$attachment_post_data = array_merge(
[1392] Fix | Delete
wp_array_slice_assoc( $attachment, array( 'post_title', 'post_content', 'post_excerpt' ) ),
[1393] Fix | Delete
array(
[1394] Fix | Delete
'post_status' => 'auto-draft', // So attachment will be garbage collected in a week if changeset is never published.
[1395] Fix | Delete
)
[1396] Fix | Delete
);
[1397] Fix | Delete
[1398] Fix | Delete
$attachment_id = media_handle_sideload( $file_array, 0, null, $attachment_post_data );
[1399] Fix | Delete
if ( is_wp_error( $attachment_id ) ) {
[1400] Fix | Delete
continue;
[1401] Fix | Delete
}
[1402] Fix | Delete
update_post_meta( $attachment_id, '_starter_content_theme', $this->get_stylesheet() );
[1403] Fix | Delete
update_post_meta( $attachment_id, '_customize_draft_post_name', $attachment['post_name'] );
[1404] Fix | Delete
}
[1405] Fix | Delete
[1406] Fix | Delete
$attachment_ids[ $symbol ] = $attachment_id;
[1407] Fix | Delete
}
[1408] Fix | Delete
$starter_content_auto_draft_post_ids = array_merge( $starter_content_auto_draft_post_ids, array_values( $attachment_ids ) );
[1409] Fix | Delete
}
[1410] Fix | Delete
[1411] Fix | Delete
// Posts & pages.
[1412] Fix | Delete
if ( ! empty( $posts ) ) {
[1413] Fix | Delete
foreach ( array_keys( $posts ) as $post_symbol ) {
[1414] Fix | Delete
if ( empty( $posts[ $post_symbol ]['post_type'] ) || empty( $posts[ $post_symbol ]['post_name'] ) ) {
[1415] Fix | Delete
continue;
[1416] Fix | Delete
}
[1417] Fix | Delete
$post_type = $posts[ $post_symbol ]['post_type'];
[1418] Fix | Delete
if ( ! empty( $posts[ $post_symbol ]['post_name'] ) ) {
[1419] Fix | Delete
$post_name = $posts[ $post_symbol ]['post_name'];
[1420] Fix | Delete
} elseif ( ! empty( $posts[ $post_symbol ]['post_title'] ) ) {
[1421] Fix | Delete
$post_name = sanitize_title( $posts[ $post_symbol ]['post_title'] );
[1422] Fix | Delete
} else {
[1423] Fix | Delete
continue;
[1424] Fix | Delete
}
[1425] Fix | Delete
[1426] Fix | Delete
// Use existing auto-draft post if one already exists with the same type and name.
[1427] Fix | Delete
if ( isset( $existing_starter_content_posts[ $post_type . ':' . $post_name ] ) ) {
[1428] Fix | Delete
$posts[ $post_symbol ]['ID'] = $existing_starter_content_posts[ $post_type . ':' . $post_name ]->ID;
[1429] Fix | Delete
continue;
[1430] Fix | Delete
}
[1431] Fix | Delete
[1432] Fix | Delete
// Translate the featured image symbol.
[1433] Fix | Delete
if ( ! empty( $posts[ $post_symbol ]['thumbnail'] )
[1434] Fix | Delete
&& preg_match( '/^{{(?P<symbol>.+)}}$/', $posts[ $post_symbol ]['thumbnail'], $matches )
[1435] Fix | Delete
&& isset( $attachment_ids[ $matches['symbol'] ] ) ) {
[1436] Fix | Delete
$posts[ $post_symbol ]['meta_input']['_thumbnail_id'] = $attachment_ids[ $matches['symbol'] ];
[1437] Fix | Delete
}
[1438] Fix | Delete
[1439] Fix | Delete
if ( ! empty( $posts[ $post_symbol ]['template'] ) ) {
[1440] Fix | Delete
$posts[ $post_symbol ]['meta_input']['_wp_page_template'] = $posts[ $post_symbol ]['template'];
[1441] Fix | Delete
}
[1442] Fix | Delete
[1443] Fix | Delete
$r = $this->nav_menus->insert_auto_draft_post( $posts[ $post_symbol ] );
[1444] Fix | Delete
if ( $r instanceof WP_Post ) {
[1445] Fix | Delete
$posts[ $post_symbol ]['ID'] = $r->ID;
[1446] Fix | Delete
}
[1447] Fix | Delete
}
[1448] Fix | Delete
[1449] Fix | Delete
$starter_content_auto_draft_post_ids = array_merge( $starter_content_auto_draft_post_ids, wp_list_pluck( $posts, 'ID' ) );
[1450] Fix | Delete
}
[1451] Fix | Delete
[1452] Fix | Delete
// The nav_menus_created_posts setting is why nav_menus component is dependency for adding posts.
[1453] Fix | Delete
if ( ! empty( $this->nav_menus ) && ! empty( $starter_content_auto_draft_post_ids ) ) {
[1454] Fix | Delete
$setting_id = 'nav_menus_created_posts';
[1455] Fix | Delete
$this->set_post_value( $setting_id, array_unique( array_values( $starter_content_auto_draft_post_ids ) ) );
[1456] Fix | Delete
$this->pending_starter_content_settings_ids[] = $setting_id;
[1457] Fix | Delete
}
[1458] Fix | Delete
[1459] Fix | Delete
// Nav menus.
[1460] Fix | Delete
$placeholder_id = -1;
[1461] Fix | Delete
$reused_nav_menu_setting_ids = array();
[1462] Fix | Delete
foreach ( $nav_menus as $nav_menu_location => $nav_menu ) {
[1463] Fix | Delete
[1464] Fix | Delete
$nav_menu_term_id = null;
[1465] Fix | Delete
$nav_menu_setting_id = null;
[1466] Fix | Delete
$matches = array();
[1467] Fix | Delete
[1468] Fix | Delete
// Look for an existing placeholder menu with starter content to re-use.
[1469] Fix | Delete
foreach ( $changeset_data as $setting_id => $setting_params ) {
[1470] Fix | Delete
$can_reuse = (
[1471] Fix | Delete
! empty( $setting_params['starter_content'] )
[1472] Fix | Delete
&&
[1473] Fix | Delete
! in_array( $setting_id, $reused_nav_menu_setting_ids, true )
[1474] Fix | Delete
&&
[1475] Fix | Delete
preg_match( '#^nav_menu\[(?P<nav_menu_id>-?\d+)\]$#', $setting_id, $matches )
[1476] Fix | Delete
);
[1477] Fix | Delete
if ( $can_reuse ) {
[1478] Fix | Delete
$nav_menu_term_id = (int) $matches['nav_menu_id'];
[1479] Fix | Delete
$nav_menu_setting_id = $setting_id;
[1480] Fix | Delete
$reused_nav_menu_setting_ids[] = $setting_id;
[1481] Fix | Delete
break;
[1482] Fix | Delete
}
[1483] Fix | Delete
}
[1484] Fix | Delete
[1485] Fix | Delete
if ( ! $nav_menu_term_id ) {
[1486] Fix | Delete
while ( isset( $changeset_data[ sprintf( 'nav_menu[%d]', $placeholder_id ) ] ) ) {
[1487] Fix | Delete
--$placeholder_id;
[1488] Fix | Delete
}
[1489] Fix | Delete
$nav_menu_term_id = $placeholder_id;
[1490] Fix | Delete
$nav_menu_setting_id = sprintf( 'nav_menu[%d]', $placeholder_id );
[1491] Fix | Delete
}
[1492] Fix | Delete
[1493] Fix | Delete
$this->set_post_value(
[1494] Fix | Delete
$nav_menu_setting_id,
[1495] Fix | Delete
array(
[1496] Fix | Delete
'name' => isset( $nav_menu['name'] ) ? $nav_menu['name'] : $nav_menu_location,
[1497] Fix | Delete
)
[1498] Fix | Delete
);
[1499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function