Edit File by line
/home/barbar84/www/wp-inclu...
File: query.php
* @global WP_Query $wp_query WordPress Query object.
[1000] Fix | Delete
*
[1001] Fix | Delete
* @return null
[1002] Fix | Delete
*/
[1003] Fix | Delete
function the_comment() {
[1004] Fix | Delete
global $wp_query;
[1005] Fix | Delete
return $wp_query->the_comment();
[1006] Fix | Delete
}
[1007] Fix | Delete
[1008] Fix | Delete
/**
[1009] Fix | Delete
* Redirect old slugs to the correct permalink.
[1010] Fix | Delete
*
[1011] Fix | Delete
* Attempts to find the current slug from the past slugs.
[1012] Fix | Delete
*
[1013] Fix | Delete
* @since 2.1.0
[1014] Fix | Delete
*/
[1015] Fix | Delete
function wp_old_slug_redirect() {
[1016] Fix | Delete
if ( is_404() && '' !== get_query_var( 'name' ) ) {
[1017] Fix | Delete
// Guess the current post type based on the query vars.
[1018] Fix | Delete
if ( get_query_var( 'post_type' ) ) {
[1019] Fix | Delete
$post_type = get_query_var( 'post_type' );
[1020] Fix | Delete
} elseif ( get_query_var( 'attachment' ) ) {
[1021] Fix | Delete
$post_type = 'attachment';
[1022] Fix | Delete
} elseif ( get_query_var( 'pagename' ) ) {
[1023] Fix | Delete
$post_type = 'page';
[1024] Fix | Delete
} else {
[1025] Fix | Delete
$post_type = 'post';
[1026] Fix | Delete
}
[1027] Fix | Delete
[1028] Fix | Delete
if ( is_array( $post_type ) ) {
[1029] Fix | Delete
if ( count( $post_type ) > 1 ) {
[1030] Fix | Delete
return;
[1031] Fix | Delete
}
[1032] Fix | Delete
$post_type = reset( $post_type );
[1033] Fix | Delete
}
[1034] Fix | Delete
[1035] Fix | Delete
// Do not attempt redirect for hierarchical post types.
[1036] Fix | Delete
if ( is_post_type_hierarchical( $post_type ) ) {
[1037] Fix | Delete
return;
[1038] Fix | Delete
}
[1039] Fix | Delete
[1040] Fix | Delete
$id = _find_post_by_old_slug( $post_type );
[1041] Fix | Delete
[1042] Fix | Delete
if ( ! $id ) {
[1043] Fix | Delete
$id = _find_post_by_old_date( $post_type );
[1044] Fix | Delete
}
[1045] Fix | Delete
[1046] Fix | Delete
/**
[1047] Fix | Delete
* Filters the old slug redirect post ID.
[1048] Fix | Delete
*
[1049] Fix | Delete
* @since 4.9.3
[1050] Fix | Delete
*
[1051] Fix | Delete
* @param int $id The redirect post ID.
[1052] Fix | Delete
*/
[1053] Fix | Delete
$id = apply_filters( 'old_slug_redirect_post_id', $id );
[1054] Fix | Delete
[1055] Fix | Delete
if ( ! $id ) {
[1056] Fix | Delete
return;
[1057] Fix | Delete
}
[1058] Fix | Delete
[1059] Fix | Delete
$link = get_permalink( $id );
[1060] Fix | Delete
[1061] Fix | Delete
if ( get_query_var( 'paged' ) > 1 ) {
[1062] Fix | Delete
$link = user_trailingslashit( trailingslashit( $link ) . 'page/' . get_query_var( 'paged' ) );
[1063] Fix | Delete
} elseif ( is_embed() ) {
[1064] Fix | Delete
$link = user_trailingslashit( trailingslashit( $link ) . 'embed' );
[1065] Fix | Delete
}
[1066] Fix | Delete
[1067] Fix | Delete
/**
[1068] Fix | Delete
* Filters the old slug redirect URL.
[1069] Fix | Delete
*
[1070] Fix | Delete
* @since 4.4.0
[1071] Fix | Delete
*
[1072] Fix | Delete
* @param string $link The redirect URL.
[1073] Fix | Delete
*/
[1074] Fix | Delete
$link = apply_filters( 'old_slug_redirect_url', $link );
[1075] Fix | Delete
[1076] Fix | Delete
if ( ! $link ) {
[1077] Fix | Delete
return;
[1078] Fix | Delete
}
[1079] Fix | Delete
[1080] Fix | Delete
wp_redirect( $link, 301 ); // Permanent redirect.
[1081] Fix | Delete
exit;
[1082] Fix | Delete
}
[1083] Fix | Delete
}
[1084] Fix | Delete
[1085] Fix | Delete
/**
[1086] Fix | Delete
* Find the post ID for redirecting an old slug.
[1087] Fix | Delete
*
[1088] Fix | Delete
* @since 4.9.3
[1089] Fix | Delete
* @access private
[1090] Fix | Delete
*
[1091] Fix | Delete
* @see wp_old_slug_redirect()
[1092] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[1093] Fix | Delete
*
[1094] Fix | Delete
* @param string $post_type The current post type based on the query vars.
[1095] Fix | Delete
* @return int The Post ID.
[1096] Fix | Delete
*/
[1097] Fix | Delete
function _find_post_by_old_slug( $post_type ) {
[1098] Fix | Delete
global $wpdb;
[1099] Fix | Delete
[1100] Fix | Delete
$query = $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta, $wpdb->posts WHERE ID = post_id AND post_type = %s AND meta_key = '_wp_old_slug' AND meta_value = %s", $post_type, get_query_var( 'name' ) );
[1101] Fix | Delete
[1102] Fix | Delete
// If year, monthnum, or day have been specified, make our query more precise
[1103] Fix | Delete
// just in case there are multiple identical _wp_old_slug values.
[1104] Fix | Delete
if ( get_query_var( 'year' ) ) {
[1105] Fix | Delete
$query .= $wpdb->prepare( ' AND YEAR(post_date) = %d', get_query_var( 'year' ) );
[1106] Fix | Delete
}
[1107] Fix | Delete
if ( get_query_var( 'monthnum' ) ) {
[1108] Fix | Delete
$query .= $wpdb->prepare( ' AND MONTH(post_date) = %d', get_query_var( 'monthnum' ) );
[1109] Fix | Delete
}
[1110] Fix | Delete
if ( get_query_var( 'day' ) ) {
[1111] Fix | Delete
$query .= $wpdb->prepare( ' AND DAYOFMONTH(post_date) = %d', get_query_var( 'day' ) );
[1112] Fix | Delete
}
[1113] Fix | Delete
[1114] Fix | Delete
$id = (int) $wpdb->get_var( $query );
[1115] Fix | Delete
[1116] Fix | Delete
return $id;
[1117] Fix | Delete
}
[1118] Fix | Delete
[1119] Fix | Delete
/**
[1120] Fix | Delete
* Find the post ID for redirecting an old date.
[1121] Fix | Delete
*
[1122] Fix | Delete
* @since 4.9.3
[1123] Fix | Delete
* @access private
[1124] Fix | Delete
*
[1125] Fix | Delete
* @see wp_old_slug_redirect()
[1126] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[1127] Fix | Delete
*
[1128] Fix | Delete
* @param string $post_type The current post type based on the query vars.
[1129] Fix | Delete
* @return int The Post ID.
[1130] Fix | Delete
*/
[1131] Fix | Delete
function _find_post_by_old_date( $post_type ) {
[1132] Fix | Delete
global $wpdb;
[1133] Fix | Delete
[1134] Fix | Delete
$date_query = '';
[1135] Fix | Delete
if ( get_query_var( 'year' ) ) {
[1136] Fix | Delete
$date_query .= $wpdb->prepare( ' AND YEAR(pm_date.meta_value) = %d', get_query_var( 'year' ) );
[1137] Fix | Delete
}
[1138] Fix | Delete
if ( get_query_var( 'monthnum' ) ) {
[1139] Fix | Delete
$date_query .= $wpdb->prepare( ' AND MONTH(pm_date.meta_value) = %d', get_query_var( 'monthnum' ) );
[1140] Fix | Delete
}
[1141] Fix | Delete
if ( get_query_var( 'day' ) ) {
[1142] Fix | Delete
$date_query .= $wpdb->prepare( ' AND DAYOFMONTH(pm_date.meta_value) = %d', get_query_var( 'day' ) );
[1143] Fix | Delete
}
[1144] Fix | Delete
[1145] Fix | Delete
$id = 0;
[1146] Fix | Delete
if ( $date_query ) {
[1147] Fix | Delete
$id = (int) $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta AS pm_date, $wpdb->posts WHERE ID = post_id AND post_type = %s AND meta_key = '_wp_old_date' AND post_name = %s" . $date_query, $post_type, get_query_var( 'name' ) ) );
[1148] Fix | Delete
[1149] Fix | Delete
if ( ! $id ) {
[1150] Fix | Delete
// Check to see if an old slug matches the old date.
[1151] Fix | Delete
$id = (int) $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts, $wpdb->postmeta AS pm_slug, $wpdb->postmeta AS pm_date WHERE ID = pm_slug.post_id AND ID = pm_date.post_id AND post_type = %s AND pm_slug.meta_key = '_wp_old_slug' AND pm_slug.meta_value = %s AND pm_date.meta_key = '_wp_old_date'" . $date_query, $post_type, get_query_var( 'name' ) ) );
[1152] Fix | Delete
}
[1153] Fix | Delete
}
[1154] Fix | Delete
[1155] Fix | Delete
return $id;
[1156] Fix | Delete
}
[1157] Fix | Delete
[1158] Fix | Delete
/**
[1159] Fix | Delete
* Set up global post data.
[1160] Fix | Delete
*
[1161] Fix | Delete
* @since 1.5.0
[1162] Fix | Delete
* @since 4.4.0 Added the ability to pass a post ID to `$post`.
[1163] Fix | Delete
*
[1164] Fix | Delete
* @global WP_Query $wp_query WordPress Query object.
[1165] Fix | Delete
*
[1166] Fix | Delete
* @param WP_Post|object|int $post WP_Post instance or Post ID/object.
[1167] Fix | Delete
* @return bool True when finished.
[1168] Fix | Delete
*/
[1169] Fix | Delete
function setup_postdata( $post ) {
[1170] Fix | Delete
global $wp_query;
[1171] Fix | Delete
[1172] Fix | Delete
if ( ! empty( $wp_query ) && $wp_query instanceof WP_Query ) {
[1173] Fix | Delete
return $wp_query->setup_postdata( $post );
[1174] Fix | Delete
}
[1175] Fix | Delete
[1176] Fix | Delete
return false;
[1177] Fix | Delete
}
[1178] Fix | Delete
[1179] Fix | Delete
/**
[1180] Fix | Delete
* Generates post data.
[1181] Fix | Delete
*
[1182] Fix | Delete
* @since 5.2.0
[1183] Fix | Delete
*
[1184] Fix | Delete
* @global WP_Query $wp_query WordPress Query object.
[1185] Fix | Delete
*
[1186] Fix | Delete
* @param WP_Post|object|int $post WP_Post instance or Post ID/object.
[1187] Fix | Delete
* @return array|false Elements of post, or false on failure.
[1188] Fix | Delete
*/
[1189] Fix | Delete
function generate_postdata( $post ) {
[1190] Fix | Delete
global $wp_query;
[1191] Fix | Delete
[1192] Fix | Delete
if ( ! empty( $wp_query ) && $wp_query instanceof WP_Query ) {
[1193] Fix | Delete
return $wp_query->generate_postdata( $post );
[1194] Fix | Delete
}
[1195] Fix | Delete
[1196] Fix | Delete
return false;
[1197] Fix | Delete
}
[1198] Fix | Delete
[1199] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function