Edit File by line
/home/barbar84/www/wp-admin/includes
File: upgrade.php
[1000] Fix | Delete
// Get the GMT offset, we'll use that later on.
[1001] Fix | Delete
$all_options = get_alloptions_110();
[1002] Fix | Delete
[1003] Fix | Delete
$time_difference = $all_options->time_difference;
[1004] Fix | Delete
[1005] Fix | Delete
$server_time = time() + gmdate( 'Z' );
[1006] Fix | Delete
$weblogger_time = $server_time + $time_difference * HOUR_IN_SECONDS;
[1007] Fix | Delete
$gmt_time = time();
[1008] Fix | Delete
[1009] Fix | Delete
$diff_gmt_server = ( $gmt_time - $server_time ) / HOUR_IN_SECONDS;
[1010] Fix | Delete
$diff_weblogger_server = ( $weblogger_time - $server_time ) / HOUR_IN_SECONDS;
[1011] Fix | Delete
$diff_gmt_weblogger = $diff_gmt_server - $diff_weblogger_server;
[1012] Fix | Delete
$gmt_offset = -$diff_gmt_weblogger;
[1013] Fix | Delete
[1014] Fix | Delete
// Add a gmt_offset option, with value $gmt_offset.
[1015] Fix | Delete
add_option( 'gmt_offset', $gmt_offset );
[1016] Fix | Delete
[1017] Fix | Delete
/*
[1018] Fix | Delete
* Check if we already set the GMT fields. If we did, then
[1019] Fix | Delete
* MAX(post_date_gmt) can't be '0000-00-00 00:00:00'.
[1020] Fix | Delete
* <michel_v> I just slapped myself silly for not thinking about it earlier.
[1021] Fix | Delete
*/
[1022] Fix | Delete
$got_gmt_fields = ( '0000-00-00 00:00:00' !== $wpdb->get_var( "SELECT MAX(post_date_gmt) FROM $wpdb->posts" ) );
[1023] Fix | Delete
[1024] Fix | Delete
if ( ! $got_gmt_fields ) {
[1025] Fix | Delete
[1026] Fix | Delete
// Add or subtract time to all dates, to get GMT dates.
[1027] Fix | Delete
$add_hours = (int) $diff_gmt_weblogger;
[1028] Fix | Delete
$add_minutes = (int) ( 60 * ( $diff_gmt_weblogger - $add_hours ) );
[1029] Fix | Delete
$wpdb->query( "UPDATE $wpdb->posts SET post_date_gmt = DATE_ADD(post_date, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE)" );
[1030] Fix | Delete
$wpdb->query( "UPDATE $wpdb->posts SET post_modified = post_date" );
[1031] Fix | Delete
$wpdb->query( "UPDATE $wpdb->posts SET post_modified_gmt = DATE_ADD(post_modified, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE) WHERE post_modified != '0000-00-00 00:00:00'" );
[1032] Fix | Delete
$wpdb->query( "UPDATE $wpdb->comments SET comment_date_gmt = DATE_ADD(comment_date, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE)" );
[1033] Fix | Delete
$wpdb->query( "UPDATE $wpdb->users SET user_registered = DATE_ADD(user_registered, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE)" );
[1034] Fix | Delete
}
[1035] Fix | Delete
[1036] Fix | Delete
}
[1037] Fix | Delete
[1038] Fix | Delete
/**
[1039] Fix | Delete
* Execute changes made in WordPress 1.5.
[1040] Fix | Delete
*
[1041] Fix | Delete
* @ignore
[1042] Fix | Delete
* @since 1.5.0
[1043] Fix | Delete
*
[1044] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[1045] Fix | Delete
*/
[1046] Fix | Delete
function upgrade_130() {
[1047] Fix | Delete
global $wpdb;
[1048] Fix | Delete
[1049] Fix | Delete
// Remove extraneous backslashes.
[1050] Fix | Delete
$posts = $wpdb->get_results( "SELECT ID, post_title, post_content, post_excerpt, guid, post_date, post_name, post_status, post_author FROM $wpdb->posts" );
[1051] Fix | Delete
if ( $posts ) {
[1052] Fix | Delete
foreach ( $posts as $post ) {
[1053] Fix | Delete
$post_content = addslashes( deslash( $post->post_content ) );
[1054] Fix | Delete
$post_title = addslashes( deslash( $post->post_title ) );
[1055] Fix | Delete
$post_excerpt = addslashes( deslash( $post->post_excerpt ) );
[1056] Fix | Delete
if ( empty( $post->guid ) ) {
[1057] Fix | Delete
$guid = get_permalink( $post->ID );
[1058] Fix | Delete
} else {
[1059] Fix | Delete
$guid = $post->guid;
[1060] Fix | Delete
}
[1061] Fix | Delete
[1062] Fix | Delete
$wpdb->update( $wpdb->posts, compact( 'post_title', 'post_content', 'post_excerpt', 'guid' ), array( 'ID' => $post->ID ) );
[1063] Fix | Delete
[1064] Fix | Delete
}
[1065] Fix | Delete
}
[1066] Fix | Delete
[1067] Fix | Delete
// Remove extraneous backslashes.
[1068] Fix | Delete
$comments = $wpdb->get_results( "SELECT comment_ID, comment_author, comment_content FROM $wpdb->comments" );
[1069] Fix | Delete
if ( $comments ) {
[1070] Fix | Delete
foreach ( $comments as $comment ) {
[1071] Fix | Delete
$comment_content = deslash( $comment->comment_content );
[1072] Fix | Delete
$comment_author = deslash( $comment->comment_author );
[1073] Fix | Delete
[1074] Fix | Delete
$wpdb->update( $wpdb->comments, compact( 'comment_content', 'comment_author' ), array( 'comment_ID' => $comment->comment_ID ) );
[1075] Fix | Delete
}
[1076] Fix | Delete
}
[1077] Fix | Delete
[1078] Fix | Delete
// Remove extraneous backslashes.
[1079] Fix | Delete
$links = $wpdb->get_results( "SELECT link_id, link_name, link_description FROM $wpdb->links" );
[1080] Fix | Delete
if ( $links ) {
[1081] Fix | Delete
foreach ( $links as $link ) {
[1082] Fix | Delete
$link_name = deslash( $link->link_name );
[1083] Fix | Delete
$link_description = deslash( $link->link_description );
[1084] Fix | Delete
[1085] Fix | Delete
$wpdb->update( $wpdb->links, compact( 'link_name', 'link_description' ), array( 'link_id' => $link->link_id ) );
[1086] Fix | Delete
}
[1087] Fix | Delete
}
[1088] Fix | Delete
[1089] Fix | Delete
$active_plugins = __get_option( 'active_plugins' );
[1090] Fix | Delete
[1091] Fix | Delete
/*
[1092] Fix | Delete
* If plugins are not stored in an array, they're stored in the old
[1093] Fix | Delete
* newline separated format. Convert to new format.
[1094] Fix | Delete
*/
[1095] Fix | Delete
if ( ! is_array( $active_plugins ) ) {
[1096] Fix | Delete
$active_plugins = explode( "\n", trim( $active_plugins ) );
[1097] Fix | Delete
update_option( 'active_plugins', $active_plugins );
[1098] Fix | Delete
}
[1099] Fix | Delete
[1100] Fix | Delete
// Obsolete tables.
[1101] Fix | Delete
$wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optionvalues' );
[1102] Fix | Delete
$wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optiontypes' );
[1103] Fix | Delete
$wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optiongroups' );
[1104] Fix | Delete
$wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optiongroup_options' );
[1105] Fix | Delete
[1106] Fix | Delete
// Update comments table to use comment_type.
[1107] Fix | Delete
$wpdb->query( "UPDATE $wpdb->comments SET comment_type='trackback', comment_content = REPLACE(comment_content, '<trackback />', '') WHERE comment_content LIKE '<trackback />%'" );
[1108] Fix | Delete
$wpdb->query( "UPDATE $wpdb->comments SET comment_type='pingback', comment_content = REPLACE(comment_content, '<pingback />', '') WHERE comment_content LIKE '<pingback />%'" );
[1109] Fix | Delete
[1110] Fix | Delete
// Some versions have multiple duplicate option_name rows with the same values.
[1111] Fix | Delete
$options = $wpdb->get_results( "SELECT option_name, COUNT(option_name) AS dupes FROM `$wpdb->options` GROUP BY option_name" );
[1112] Fix | Delete
foreach ( $options as $option ) {
[1113] Fix | Delete
if ( 1 != $option->dupes ) { // Could this be done in the query?
[1114] Fix | Delete
$limit = $option->dupes - 1;
[1115] Fix | Delete
$dupe_ids = $wpdb->get_col( $wpdb->prepare( "SELECT option_id FROM $wpdb->options WHERE option_name = %s LIMIT %d", $option->option_name, $limit ) );
[1116] Fix | Delete
if ( $dupe_ids ) {
[1117] Fix | Delete
$dupe_ids = implode( ',', $dupe_ids );
[1118] Fix | Delete
$wpdb->query( "DELETE FROM $wpdb->options WHERE option_id IN ($dupe_ids)" );
[1119] Fix | Delete
}
[1120] Fix | Delete
}
[1121] Fix | Delete
}
[1122] Fix | Delete
[1123] Fix | Delete
make_site_theme();
[1124] Fix | Delete
}
[1125] Fix | Delete
[1126] Fix | Delete
/**
[1127] Fix | Delete
* Execute changes made in WordPress 2.0.
[1128] Fix | Delete
*
[1129] Fix | Delete
* @ignore
[1130] Fix | Delete
* @since 2.0.0
[1131] Fix | Delete
*
[1132] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[1133] Fix | Delete
* @global int $wp_current_db_version The old (current) database version.
[1134] Fix | Delete
*/
[1135] Fix | Delete
function upgrade_160() {
[1136] Fix | Delete
global $wpdb, $wp_current_db_version;
[1137] Fix | Delete
[1138] Fix | Delete
populate_roles_160();
[1139] Fix | Delete
[1140] Fix | Delete
$users = $wpdb->get_results( "SELECT * FROM $wpdb->users" );
[1141] Fix | Delete
foreach ( $users as $user ) :
[1142] Fix | Delete
if ( ! empty( $user->user_firstname ) ) {
[1143] Fix | Delete
update_user_meta( $user->ID, 'first_name', wp_slash( $user->user_firstname ) );
[1144] Fix | Delete
}
[1145] Fix | Delete
if ( ! empty( $user->user_lastname ) ) {
[1146] Fix | Delete
update_user_meta( $user->ID, 'last_name', wp_slash( $user->user_lastname ) );
[1147] Fix | Delete
}
[1148] Fix | Delete
if ( ! empty( $user->user_nickname ) ) {
[1149] Fix | Delete
update_user_meta( $user->ID, 'nickname', wp_slash( $user->user_nickname ) );
[1150] Fix | Delete
}
[1151] Fix | Delete
if ( ! empty( $user->user_level ) ) {
[1152] Fix | Delete
update_user_meta( $user->ID, $wpdb->prefix . 'user_level', $user->user_level );
[1153] Fix | Delete
}
[1154] Fix | Delete
if ( ! empty( $user->user_icq ) ) {
[1155] Fix | Delete
update_user_meta( $user->ID, 'icq', wp_slash( $user->user_icq ) );
[1156] Fix | Delete
}
[1157] Fix | Delete
if ( ! empty( $user->user_aim ) ) {
[1158] Fix | Delete
update_user_meta( $user->ID, 'aim', wp_slash( $user->user_aim ) );
[1159] Fix | Delete
}
[1160] Fix | Delete
if ( ! empty( $user->user_msn ) ) {
[1161] Fix | Delete
update_user_meta( $user->ID, 'msn', wp_slash( $user->user_msn ) );
[1162] Fix | Delete
}
[1163] Fix | Delete
if ( ! empty( $user->user_yim ) ) {
[1164] Fix | Delete
update_user_meta( $user->ID, 'yim', wp_slash( $user->user_icq ) );
[1165] Fix | Delete
}
[1166] Fix | Delete
if ( ! empty( $user->user_description ) ) {
[1167] Fix | Delete
update_user_meta( $user->ID, 'description', wp_slash( $user->user_description ) );
[1168] Fix | Delete
}
[1169] Fix | Delete
[1170] Fix | Delete
if ( isset( $user->user_idmode ) ) :
[1171] Fix | Delete
$idmode = $user->user_idmode;
[1172] Fix | Delete
if ( 'nickname' === $idmode ) {
[1173] Fix | Delete
$id = $user->user_nickname;
[1174] Fix | Delete
}
[1175] Fix | Delete
if ( 'login' === $idmode ) {
[1176] Fix | Delete
$id = $user->user_login;
[1177] Fix | Delete
}
[1178] Fix | Delete
if ( 'firstname' === $idmode ) {
[1179] Fix | Delete
$id = $user->user_firstname;
[1180] Fix | Delete
}
[1181] Fix | Delete
if ( 'lastname' === $idmode ) {
[1182] Fix | Delete
$id = $user->user_lastname;
[1183] Fix | Delete
}
[1184] Fix | Delete
if ( 'namefl' === $idmode ) {
[1185] Fix | Delete
$id = $user->user_firstname . ' ' . $user->user_lastname;
[1186] Fix | Delete
}
[1187] Fix | Delete
if ( 'namelf' === $idmode ) {
[1188] Fix | Delete
$id = $user->user_lastname . ' ' . $user->user_firstname;
[1189] Fix | Delete
}
[1190] Fix | Delete
if ( ! $idmode ) {
[1191] Fix | Delete
$id = $user->user_nickname;
[1192] Fix | Delete
}
[1193] Fix | Delete
$wpdb->update( $wpdb->users, array( 'display_name' => $id ), array( 'ID' => $user->ID ) );
[1194] Fix | Delete
endif;
[1195] Fix | Delete
[1196] Fix | Delete
// FIXME: RESET_CAPS is temporary code to reset roles and caps if flag is set.
[1197] Fix | Delete
$caps = get_user_meta( $user->ID, $wpdb->prefix . 'capabilities' );
[1198] Fix | Delete
if ( empty( $caps ) || defined( 'RESET_CAPS' ) ) {
[1199] Fix | Delete
$level = get_user_meta( $user->ID, $wpdb->prefix . 'user_level', true );
[1200] Fix | Delete
$role = translate_level_to_role( $level );
[1201] Fix | Delete
update_user_meta( $user->ID, $wpdb->prefix . 'capabilities', array( $role => true ) );
[1202] Fix | Delete
}
[1203] Fix | Delete
[1204] Fix | Delete
endforeach;
[1205] Fix | Delete
$old_user_fields = array( 'user_firstname', 'user_lastname', 'user_icq', 'user_aim', 'user_msn', 'user_yim', 'user_idmode', 'user_ip', 'user_domain', 'user_browser', 'user_description', 'user_nickname', 'user_level' );
[1206] Fix | Delete
$wpdb->hide_errors();
[1207] Fix | Delete
foreach ( $old_user_fields as $old ) {
[1208] Fix | Delete
$wpdb->query( "ALTER TABLE $wpdb->users DROP $old" );
[1209] Fix | Delete
}
[1210] Fix | Delete
$wpdb->show_errors();
[1211] Fix | Delete
[1212] Fix | Delete
// Populate comment_count field of posts table.
[1213] Fix | Delete
$comments = $wpdb->get_results( "SELECT comment_post_ID, COUNT(*) as c FROM $wpdb->comments WHERE comment_approved = '1' GROUP BY comment_post_ID" );
[1214] Fix | Delete
if ( is_array( $comments ) ) {
[1215] Fix | Delete
foreach ( $comments as $comment ) {
[1216] Fix | Delete
$wpdb->update( $wpdb->posts, array( 'comment_count' => $comment->c ), array( 'ID' => $comment->comment_post_ID ) );
[1217] Fix | Delete
}
[1218] Fix | Delete
}
[1219] Fix | Delete
[1220] Fix | Delete
/*
[1221] Fix | Delete
* Some alpha versions used a post status of object instead of attachment
[1222] Fix | Delete
* and put the mime type in post_type instead of post_mime_type.
[1223] Fix | Delete
*/
[1224] Fix | Delete
if ( $wp_current_db_version > 2541 && $wp_current_db_version <= 3091 ) {
[1225] Fix | Delete
$objects = $wpdb->get_results( "SELECT ID, post_type FROM $wpdb->posts WHERE post_status = 'object'" );
[1226] Fix | Delete
foreach ( $objects as $object ) {
[1227] Fix | Delete
$wpdb->update(
[1228] Fix | Delete
$wpdb->posts,
[1229] Fix | Delete
array(
[1230] Fix | Delete
'post_status' => 'attachment',
[1231] Fix | Delete
'post_mime_type' => $object->post_type,
[1232] Fix | Delete
'post_type' => '',
[1233] Fix | Delete
),
[1234] Fix | Delete
array( 'ID' => $object->ID )
[1235] Fix | Delete
);
[1236] Fix | Delete
[1237] Fix | Delete
$meta = get_post_meta( $object->ID, 'imagedata', true );
[1238] Fix | Delete
if ( ! empty( $meta['file'] ) ) {
[1239] Fix | Delete
update_attached_file( $object->ID, $meta['file'] );
[1240] Fix | Delete
}
[1241] Fix | Delete
}
[1242] Fix | Delete
}
[1243] Fix | Delete
}
[1244] Fix | Delete
[1245] Fix | Delete
/**
[1246] Fix | Delete
* Execute changes made in WordPress 2.1.
[1247] Fix | Delete
*
[1248] Fix | Delete
* @ignore
[1249] Fix | Delete
* @since 2.1.0
[1250] Fix | Delete
*
[1251] Fix | Delete
* @global int $wp_current_db_version The old (current) database version.
[1252] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[1253] Fix | Delete
*/
[1254] Fix | Delete
function upgrade_210() {
[1255] Fix | Delete
global $wp_current_db_version, $wpdb;
[1256] Fix | Delete
[1257] Fix | Delete
if ( $wp_current_db_version < 3506 ) {
[1258] Fix | Delete
// Update status and type.
[1259] Fix | Delete
$posts = $wpdb->get_results( "SELECT ID, post_status FROM $wpdb->posts" );
[1260] Fix | Delete
[1261] Fix | Delete
if ( ! empty( $posts ) ) {
[1262] Fix | Delete
foreach ( $posts as $post ) {
[1263] Fix | Delete
$status = $post->post_status;
[1264] Fix | Delete
$type = 'post';
[1265] Fix | Delete
[1266] Fix | Delete
if ( 'static' === $status ) {
[1267] Fix | Delete
$status = 'publish';
[1268] Fix | Delete
$type = 'page';
[1269] Fix | Delete
} elseif ( 'attachment' === $status ) {
[1270] Fix | Delete
$status = 'inherit';
[1271] Fix | Delete
$type = 'attachment';
[1272] Fix | Delete
}
[1273] Fix | Delete
[1274] Fix | Delete
$wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET post_status = %s, post_type = %s WHERE ID = %d", $status, $type, $post->ID ) );
[1275] Fix | Delete
}
[1276] Fix | Delete
}
[1277] Fix | Delete
}
[1278] Fix | Delete
[1279] Fix | Delete
if ( $wp_current_db_version < 3845 ) {
[1280] Fix | Delete
populate_roles_210();
[1281] Fix | Delete
}
[1282] Fix | Delete
[1283] Fix | Delete
if ( $wp_current_db_version < 3531 ) {
[1284] Fix | Delete
// Give future posts a post_status of future.
[1285] Fix | Delete
$now = gmdate( 'Y-m-d H:i:59' );
[1286] Fix | Delete
$wpdb->query( "UPDATE $wpdb->posts SET post_status = 'future' WHERE post_status = 'publish' AND post_date_gmt > '$now'" );
[1287] Fix | Delete
[1288] Fix | Delete
$posts = $wpdb->get_results( "SELECT ID, post_date FROM $wpdb->posts WHERE post_status ='future'" );
[1289] Fix | Delete
if ( ! empty( $posts ) ) {
[1290] Fix | Delete
foreach ( $posts as $post ) {
[1291] Fix | Delete
wp_schedule_single_event( mysql2date( 'U', $post->post_date, false ), 'publish_future_post', array( $post->ID ) );
[1292] Fix | Delete
}
[1293] Fix | Delete
}
[1294] Fix | Delete
}
[1295] Fix | Delete
}
[1296] Fix | Delete
[1297] Fix | Delete
/**
[1298] Fix | Delete
* Execute changes made in WordPress 2.3.
[1299] Fix | Delete
*
[1300] Fix | Delete
* @ignore
[1301] Fix | Delete
* @since 2.3.0
[1302] Fix | Delete
*
[1303] Fix | Delete
* @global int $wp_current_db_version The old (current) database version.
[1304] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[1305] Fix | Delete
*/
[1306] Fix | Delete
function upgrade_230() {
[1307] Fix | Delete
global $wp_current_db_version, $wpdb;
[1308] Fix | Delete
[1309] Fix | Delete
if ( $wp_current_db_version < 5200 ) {
[1310] Fix | Delete
populate_roles_230();
[1311] Fix | Delete
}
[1312] Fix | Delete
[1313] Fix | Delete
// Convert categories to terms.
[1314] Fix | Delete
$tt_ids = array();
[1315] Fix | Delete
$have_tags = false;
[1316] Fix | Delete
$categories = $wpdb->get_results( "SELECT * FROM $wpdb->categories ORDER BY cat_ID" );
[1317] Fix | Delete
foreach ( $categories as $category ) {
[1318] Fix | Delete
$term_id = (int) $category->cat_ID;
[1319] Fix | Delete
$name = $category->cat_name;
[1320] Fix | Delete
$description = $category->category_description;
[1321] Fix | Delete
$slug = $category->category_nicename;
[1322] Fix | Delete
$parent = $category->category_parent;
[1323] Fix | Delete
$term_group = 0;
[1324] Fix | Delete
[1325] Fix | Delete
// Associate terms with the same slug in a term group and make slugs unique.
[1326] Fix | Delete
$exists = $wpdb->get_results( $wpdb->prepare( "SELECT term_id, term_group FROM $wpdb->terms WHERE slug = %s", $slug ) );
[1327] Fix | Delete
if ( $exists ) {
[1328] Fix | Delete
$term_group = $exists[0]->term_group;
[1329] Fix | Delete
$id = $exists[0]->term_id;
[1330] Fix | Delete
$num = 2;
[1331] Fix | Delete
do {
[1332] Fix | Delete
$alt_slug = $slug . "-$num";
[1333] Fix | Delete
$num++;
[1334] Fix | Delete
$slug_check = $wpdb->get_var( $wpdb->prepare( "SELECT slug FROM $wpdb->terms WHERE slug = %s", $alt_slug ) );
[1335] Fix | Delete
} while ( $slug_check );
[1336] Fix | Delete
[1337] Fix | Delete
$slug = $alt_slug;
[1338] Fix | Delete
[1339] Fix | Delete
if ( empty( $term_group ) ) {
[1340] Fix | Delete
$term_group = $wpdb->get_var( "SELECT MAX(term_group) FROM $wpdb->terms GROUP BY term_group" ) + 1;
[1341] Fix | Delete
$wpdb->query( $wpdb->prepare( "UPDATE $wpdb->terms SET term_group = %d WHERE term_id = %d", $term_group, $id ) );
[1342] Fix | Delete
}
[1343] Fix | Delete
}
[1344] Fix | Delete
[1345] Fix | Delete
$wpdb->query(
[1346] Fix | Delete
$wpdb->prepare(
[1347] Fix | Delete
"INSERT INTO $wpdb->terms (term_id, name, slug, term_group) VALUES
[1348] Fix | Delete
(%d, %s, %s, %d)",
[1349] Fix | Delete
$term_id,
[1350] Fix | Delete
$name,
[1351] Fix | Delete
$slug,
[1352] Fix | Delete
$term_group
[1353] Fix | Delete
)
[1354] Fix | Delete
);
[1355] Fix | Delete
[1356] Fix | Delete
$count = 0;
[1357] Fix | Delete
if ( ! empty( $category->category_count ) ) {
[1358] Fix | Delete
$count = (int) $category->category_count;
[1359] Fix | Delete
$taxonomy = 'category';
[1360] Fix | Delete
$wpdb->query( $wpdb->prepare( "INSERT INTO $wpdb->term_taxonomy (term_id, taxonomy, description, parent, count) VALUES ( %d, %s, %s, %d, %d)", $term_id, $taxonomy, $description, $parent, $count ) );
[1361] Fix | Delete
$tt_ids[ $term_id ][ $taxonomy ] = (int) $wpdb->insert_id;
[1362] Fix | Delete
}
[1363] Fix | Delete
[1364] Fix | Delete
if ( ! empty( $category->link_count ) ) {
[1365] Fix | Delete
$count = (int) $category->link_count;
[1366] Fix | Delete
$taxonomy = 'link_category';
[1367] Fix | Delete
$wpdb->query( $wpdb->prepare( "INSERT INTO $wpdb->term_taxonomy (term_id, taxonomy, description, parent, count) VALUES ( %d, %s, %s, %d, %d)", $term_id, $taxonomy, $description, $parent, $count ) );
[1368] Fix | Delete
$tt_ids[ $term_id ][ $taxonomy ] = (int) $wpdb->insert_id;
[1369] Fix | Delete
}
[1370] Fix | Delete
[1371] Fix | Delete
if ( ! empty( $category->tag_count ) ) {
[1372] Fix | Delete
$have_tags = true;
[1373] Fix | Delete
$count = (int) $category->tag_count;
[1374] Fix | Delete
$taxonomy = 'post_tag';
[1375] Fix | Delete
$wpdb->insert( $wpdb->term_taxonomy, compact( 'term_id', 'taxonomy', 'description', 'parent', 'count' ) );
[1376] Fix | Delete
$tt_ids[ $term_id ][ $taxonomy ] = (int) $wpdb->insert_id;
[1377] Fix | Delete
}
[1378] Fix | Delete
[1379] Fix | Delete
if ( empty( $count ) ) {
[1380] Fix | Delete
$count = 0;
[1381] Fix | Delete
$taxonomy = 'category';
[1382] Fix | Delete
$wpdb->insert( $wpdb->term_taxonomy, compact( 'term_id', 'taxonomy', 'description', 'parent', 'count' ) );
[1383] Fix | Delete
$tt_ids[ $term_id ][ $taxonomy ] = (int) $wpdb->insert_id;
[1384] Fix | Delete
}
[1385] Fix | Delete
}
[1386] Fix | Delete
[1387] Fix | Delete
$select = 'post_id, category_id';
[1388] Fix | Delete
if ( $have_tags ) {
[1389] Fix | Delete
$select .= ', rel_type';
[1390] Fix | Delete
}
[1391] Fix | Delete
[1392] Fix | Delete
$posts = $wpdb->get_results( "SELECT $select FROM $wpdb->post2cat GROUP BY post_id, category_id" );
[1393] Fix | Delete
foreach ( $posts as $post ) {
[1394] Fix | Delete
$post_id = (int) $post->post_id;
[1395] Fix | Delete
$term_id = (int) $post->category_id;
[1396] Fix | Delete
$taxonomy = 'category';
[1397] Fix | Delete
if ( ! empty( $post->rel_type ) && 'tag' === $post->rel_type ) {
[1398] Fix | Delete
$taxonomy = 'tag';
[1399] Fix | Delete
}
[1400] Fix | Delete
$tt_id = $tt_ids[ $term_id ][ $taxonomy ];
[1401] Fix | Delete
if ( empty( $tt_id ) ) {
[1402] Fix | Delete
continue;
[1403] Fix | Delete
}
[1404] Fix | Delete
[1405] Fix | Delete
$wpdb->insert(
[1406] Fix | Delete
$wpdb->term_relationships,
[1407] Fix | Delete
array(
[1408] Fix | Delete
'object_id' => $post_id,
[1409] Fix | Delete
'term_taxonomy_id' => $tt_id,
[1410] Fix | Delete
)
[1411] Fix | Delete
);
[1412] Fix | Delete
}
[1413] Fix | Delete
[1414] Fix | Delete
// < 3570 we used linkcategories. >= 3570 we used categories and link2cat.
[1415] Fix | Delete
if ( $wp_current_db_version < 3570 ) {
[1416] Fix | Delete
/*
[1417] Fix | Delete
* Create link_category terms for link categories. Create a map of link
[1418] Fix | Delete
* category IDs to link_category terms.
[1419] Fix | Delete
*/
[1420] Fix | Delete
$link_cat_id_map = array();
[1421] Fix | Delete
$default_link_cat = 0;
[1422] Fix | Delete
$tt_ids = array();
[1423] Fix | Delete
$link_cats = $wpdb->get_results( 'SELECT cat_id, cat_name FROM ' . $wpdb->prefix . 'linkcategories' );
[1424] Fix | Delete
foreach ( $link_cats as $category ) {
[1425] Fix | Delete
$cat_id = (int) $category->cat_id;
[1426] Fix | Delete
$term_id = 0;
[1427] Fix | Delete
$name = wp_slash( $category->cat_name );
[1428] Fix | Delete
$slug = sanitize_title( $name );
[1429] Fix | Delete
$term_group = 0;
[1430] Fix | Delete
[1431] Fix | Delete
// Associate terms with the same slug in a term group and make slugs unique.
[1432] Fix | Delete
$exists = $wpdb->get_results( $wpdb->prepare( "SELECT term_id, term_group FROM $wpdb->terms WHERE slug = %s", $slug ) );
[1433] Fix | Delete
if ( $exists ) {
[1434] Fix | Delete
$term_group = $exists[0]->term_group;
[1435] Fix | Delete
$term_id = $exists[0]->term_id;
[1436] Fix | Delete
}
[1437] Fix | Delete
[1438] Fix | Delete
if ( empty( $term_id ) ) {
[1439] Fix | Delete
$wpdb->insert( $wpdb->terms, compact( 'name', 'slug', 'term_group' ) );
[1440] Fix | Delete
$term_id = (int) $wpdb->insert_id;
[1441] Fix | Delete
}
[1442] Fix | Delete
[1443] Fix | Delete
$link_cat_id_map[ $cat_id ] = $term_id;
[1444] Fix | Delete
$default_link_cat = $term_id;
[1445] Fix | Delete
[1446] Fix | Delete
$wpdb->insert(
[1447] Fix | Delete
$wpdb->term_taxonomy,
[1448] Fix | Delete
array(
[1449] Fix | Delete
'term_id' => $term_id,
[1450] Fix | Delete
'taxonomy' => 'link_category',
[1451] Fix | Delete
'description' => '',
[1452] Fix | Delete
'parent' => 0,
[1453] Fix | Delete
'count' => 0,
[1454] Fix | Delete
)
[1455] Fix | Delete
);
[1456] Fix | Delete
$tt_ids[ $term_id ] = (int) $wpdb->insert_id;
[1457] Fix | Delete
}
[1458] Fix | Delete
[1459] Fix | Delete
// Associate links to categories.
[1460] Fix | Delete
$links = $wpdb->get_results( "SELECT link_id, link_category FROM $wpdb->links" );
[1461] Fix | Delete
if ( ! empty( $links ) ) {
[1462] Fix | Delete
foreach ( $links as $link ) {
[1463] Fix | Delete
if ( 0 == $link->link_category ) {
[1464] Fix | Delete
continue;
[1465] Fix | Delete
}
[1466] Fix | Delete
if ( ! isset( $link_cat_id_map[ $link->link_category ] ) ) {
[1467] Fix | Delete
continue;
[1468] Fix | Delete
}
[1469] Fix | Delete
$term_id = $link_cat_id_map[ $link->link_category ];
[1470] Fix | Delete
$tt_id = $tt_ids[ $term_id ];
[1471] Fix | Delete
if ( empty( $tt_id ) ) {
[1472] Fix | Delete
continue;
[1473] Fix | Delete
}
[1474] Fix | Delete
[1475] Fix | Delete
$wpdb->insert(
[1476] Fix | Delete
$wpdb->term_relationships,
[1477] Fix | Delete
array(
[1478] Fix | Delete
'object_id' => $link->link_id,
[1479] Fix | Delete
'term_taxonomy_id' => $tt_id,
[1480] Fix | Delete
)
[1481] Fix | Delete
);
[1482] Fix | Delete
}
[1483] Fix | Delete
}
[1484] Fix | Delete
[1485] Fix | Delete
// Set default to the last category we grabbed during the upgrade loop.
[1486] Fix | Delete
update_option( 'default_link_category', $default_link_cat );
[1487] Fix | Delete
} else {
[1488] Fix | Delete
$links = $wpdb->get_results( "SELECT link_id, category_id FROM $wpdb->link2cat GROUP BY link_id, category_id" );
[1489] Fix | Delete
foreach ( $links as $link ) {
[1490] Fix | Delete
$link_id = (int) $link->link_id;
[1491] Fix | Delete
$term_id = (int) $link->category_id;
[1492] Fix | Delete
$taxonomy = 'link_category';
[1493] Fix | Delete
$tt_id = $tt_ids[ $term_id ][ $taxonomy ];
[1494] Fix | Delete
if ( empty( $tt_id ) ) {
[1495] Fix | Delete
continue;
[1496] Fix | Delete
}
[1497] Fix | Delete
$wpdb->insert(
[1498] Fix | Delete
$wpdb->term_relationships,
[1499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function