Edit File by line
/home/barbar84/www/wp-inclu...
File: pluggable.php
[1000] Fix | Delete
if ( ! function_exists( 'wp_clear_auth_cookie' ) ) :
[1001] Fix | Delete
/**
[1002] Fix | Delete
* Removes all of the cookies associated with authentication.
[1003] Fix | Delete
*
[1004] Fix | Delete
* @since 2.5.0
[1005] Fix | Delete
*/
[1006] Fix | Delete
function wp_clear_auth_cookie() {
[1007] Fix | Delete
/**
[1008] Fix | Delete
* Fires just before the authentication cookies are cleared.
[1009] Fix | Delete
*
[1010] Fix | Delete
* @since 2.7.0
[1011] Fix | Delete
*/
[1012] Fix | Delete
do_action( 'clear_auth_cookie' );
[1013] Fix | Delete
[1014] Fix | Delete
/** This filter is documented in wp-includes/pluggable.php */
[1015] Fix | Delete
if ( ! apply_filters( 'send_auth_cookies', true ) ) {
[1016] Fix | Delete
return;
[1017] Fix | Delete
}
[1018] Fix | Delete
[1019] Fix | Delete
// Auth cookies.
[1020] Fix | Delete
setcookie( AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, ADMIN_COOKIE_PATH, COOKIE_DOMAIN );
[1021] Fix | Delete
setcookie( SECURE_AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, ADMIN_COOKIE_PATH, COOKIE_DOMAIN );
[1022] Fix | Delete
setcookie( AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, PLUGINS_COOKIE_PATH, COOKIE_DOMAIN );
[1023] Fix | Delete
setcookie( SECURE_AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, PLUGINS_COOKIE_PATH, COOKIE_DOMAIN );
[1024] Fix | Delete
setcookie( LOGGED_IN_COOKIE, ' ', time() - YEAR_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN );
[1025] Fix | Delete
setcookie( LOGGED_IN_COOKIE, ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH, COOKIE_DOMAIN );
[1026] Fix | Delete
[1027] Fix | Delete
// Settings cookies.
[1028] Fix | Delete
setcookie( 'wp-settings-' . get_current_user_id(), ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH );
[1029] Fix | Delete
setcookie( 'wp-settings-time-' . get_current_user_id(), ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH );
[1030] Fix | Delete
[1031] Fix | Delete
// Old cookies.
[1032] Fix | Delete
setcookie( AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN );
[1033] Fix | Delete
setcookie( AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH, COOKIE_DOMAIN );
[1034] Fix | Delete
setcookie( SECURE_AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN );
[1035] Fix | Delete
setcookie( SECURE_AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH, COOKIE_DOMAIN );
[1036] Fix | Delete
[1037] Fix | Delete
// Even older cookies.
[1038] Fix | Delete
setcookie( USER_COOKIE, ' ', time() - YEAR_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN );
[1039] Fix | Delete
setcookie( PASS_COOKIE, ' ', time() - YEAR_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN );
[1040] Fix | Delete
setcookie( USER_COOKIE, ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH, COOKIE_DOMAIN );
[1041] Fix | Delete
setcookie( PASS_COOKIE, ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH, COOKIE_DOMAIN );
[1042] Fix | Delete
[1043] Fix | Delete
// Post password cookie.
[1044] Fix | Delete
setcookie( 'wp-postpass_' . COOKIEHASH, ' ', time() - YEAR_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN );
[1045] Fix | Delete
}
[1046] Fix | Delete
endif;
[1047] Fix | Delete
[1048] Fix | Delete
if ( ! function_exists( 'is_user_logged_in' ) ) :
[1049] Fix | Delete
/**
[1050] Fix | Delete
* Determines whether the current visitor is a logged in user.
[1051] Fix | Delete
*
[1052] Fix | Delete
* For more information on this and similar theme functions, check out
[1053] Fix | Delete
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
[1054] Fix | Delete
* Conditional Tags} article in the Theme Developer Handbook.
[1055] Fix | Delete
*
[1056] Fix | Delete
* @since 2.0.0
[1057] Fix | Delete
*
[1058] Fix | Delete
* @return bool True if user is logged in, false if not logged in.
[1059] Fix | Delete
*/
[1060] Fix | Delete
function is_user_logged_in() {
[1061] Fix | Delete
$user = wp_get_current_user();
[1062] Fix | Delete
[1063] Fix | Delete
return $user->exists();
[1064] Fix | Delete
}
[1065] Fix | Delete
endif;
[1066] Fix | Delete
[1067] Fix | Delete
if ( ! function_exists( 'auth_redirect' ) ) :
[1068] Fix | Delete
/**
[1069] Fix | Delete
* Checks if a user is logged in, if not it redirects them to the login page.
[1070] Fix | Delete
*
[1071] Fix | Delete
* When this code is called from a page, it checks to see if the user viewing the page is logged in.
[1072] Fix | Delete
* If the user is not logged in, they are redirected to the login page. The user is redirected
[1073] Fix | Delete
* in such a way that, upon logging in, they will be sent directly to the page they were originally
[1074] Fix | Delete
* trying to access.
[1075] Fix | Delete
*
[1076] Fix | Delete
* @since 1.5.0
[1077] Fix | Delete
*/
[1078] Fix | Delete
function auth_redirect() {
[1079] Fix | Delete
$secure = ( is_ssl() || force_ssl_admin() );
[1080] Fix | Delete
[1081] Fix | Delete
/**
[1082] Fix | Delete
* Filters whether to use a secure authentication redirect.
[1083] Fix | Delete
*
[1084] Fix | Delete
* @since 3.1.0
[1085] Fix | Delete
*
[1086] Fix | Delete
* @param bool $secure Whether to use a secure authentication redirect. Default false.
[1087] Fix | Delete
*/
[1088] Fix | Delete
$secure = apply_filters( 'secure_auth_redirect', $secure );
[1089] Fix | Delete
[1090] Fix | Delete
// If https is required and request is http, redirect.
[1091] Fix | Delete
if ( $secure && ! is_ssl() && false !== strpos( $_SERVER['REQUEST_URI'], 'wp-admin' ) ) {
[1092] Fix | Delete
if ( 0 === strpos( $_SERVER['REQUEST_URI'], 'http' ) ) {
[1093] Fix | Delete
wp_redirect( set_url_scheme( $_SERVER['REQUEST_URI'], 'https' ) );
[1094] Fix | Delete
exit;
[1095] Fix | Delete
} else {
[1096] Fix | Delete
wp_redirect( 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
[1097] Fix | Delete
exit;
[1098] Fix | Delete
}
[1099] Fix | Delete
}
[1100] Fix | Delete
[1101] Fix | Delete
/**
[1102] Fix | Delete
* Filters the authentication redirect scheme.
[1103] Fix | Delete
*
[1104] Fix | Delete
* @since 2.9.0
[1105] Fix | Delete
*
[1106] Fix | Delete
* @param string $scheme Authentication redirect scheme. Default empty.
[1107] Fix | Delete
*/
[1108] Fix | Delete
$scheme = apply_filters( 'auth_redirect_scheme', '' );
[1109] Fix | Delete
[1110] Fix | Delete
$user_id = wp_validate_auth_cookie( '', $scheme );
[1111] Fix | Delete
if ( $user_id ) {
[1112] Fix | Delete
/**
[1113] Fix | Delete
* Fires before the authentication redirect.
[1114] Fix | Delete
*
[1115] Fix | Delete
* @since 2.8.0
[1116] Fix | Delete
*
[1117] Fix | Delete
* @param int $user_id User ID.
[1118] Fix | Delete
*/
[1119] Fix | Delete
do_action( 'auth_redirect', $user_id );
[1120] Fix | Delete
[1121] Fix | Delete
// If the user wants ssl but the session is not ssl, redirect.
[1122] Fix | Delete
if ( ! $secure && get_user_option( 'use_ssl', $user_id ) && false !== strpos( $_SERVER['REQUEST_URI'], 'wp-admin' ) ) {
[1123] Fix | Delete
if ( 0 === strpos( $_SERVER['REQUEST_URI'], 'http' ) ) {
[1124] Fix | Delete
wp_redirect( set_url_scheme( $_SERVER['REQUEST_URI'], 'https' ) );
[1125] Fix | Delete
exit;
[1126] Fix | Delete
} else {
[1127] Fix | Delete
wp_redirect( 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
[1128] Fix | Delete
exit;
[1129] Fix | Delete
}
[1130] Fix | Delete
}
[1131] Fix | Delete
[1132] Fix | Delete
return; // The cookie is good, so we're done.
[1133] Fix | Delete
}
[1134] Fix | Delete
[1135] Fix | Delete
// The cookie is no good, so force login.
[1136] Fix | Delete
nocache_headers();
[1137] Fix | Delete
[1138] Fix | Delete
$redirect = ( strpos( $_SERVER['REQUEST_URI'], '/options.php' ) && wp_get_referer() ) ? wp_get_referer() : set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
[1139] Fix | Delete
[1140] Fix | Delete
$login_url = wp_login_url( $redirect, true );
[1141] Fix | Delete
[1142] Fix | Delete
wp_redirect( $login_url );
[1143] Fix | Delete
exit;
[1144] Fix | Delete
}
[1145] Fix | Delete
endif;
[1146] Fix | Delete
[1147] Fix | Delete
if ( ! function_exists( 'check_admin_referer' ) ) :
[1148] Fix | Delete
/**
[1149] Fix | Delete
* Ensures intent by verifying that a user was referred from another admin page with the correct security nonce.
[1150] Fix | Delete
*
[1151] Fix | Delete
* This function ensures the user intends to perform a given action, which helps protect against clickjacking style
[1152] Fix | Delete
* attacks. It verifies intent, not authorisation, therefore it does not verify the user's capabilities. This should
[1153] Fix | Delete
* be performed with `current_user_can()` or similar.
[1154] Fix | Delete
*
[1155] Fix | Delete
* If the nonce value is invalid, the function will exit with an "Are You Sure?" style message.
[1156] Fix | Delete
*
[1157] Fix | Delete
* @since 1.2.0
[1158] Fix | Delete
* @since 2.5.0 The `$query_arg` parameter was added.
[1159] Fix | Delete
*
[1160] Fix | Delete
* @param int|string $action The nonce action.
[1161] Fix | Delete
* @param string $query_arg Optional. Key to check for nonce in `$_REQUEST`. Default '_wpnonce'.
[1162] Fix | Delete
* @return int|false 1 if the nonce is valid and generated between 0-12 hours ago,
[1163] Fix | Delete
* 2 if the nonce is valid and generated between 12-24 hours ago.
[1164] Fix | Delete
* False if the nonce is invalid.
[1165] Fix | Delete
*/
[1166] Fix | Delete
function check_admin_referer( $action = -1, $query_arg = '_wpnonce' ) {
[1167] Fix | Delete
if ( -1 === $action ) {
[1168] Fix | Delete
_doing_it_wrong( __FUNCTION__, __( 'You should specify a nonce action to be verified by using the first parameter.' ), '3.2.0' );
[1169] Fix | Delete
}
[1170] Fix | Delete
[1171] Fix | Delete
$adminurl = strtolower( admin_url() );
[1172] Fix | Delete
$referer = strtolower( wp_get_referer() );
[1173] Fix | Delete
$result = isset( $_REQUEST[ $query_arg ] ) ? wp_verify_nonce( $_REQUEST[ $query_arg ], $action ) : false;
[1174] Fix | Delete
[1175] Fix | Delete
/**
[1176] Fix | Delete
* Fires once the admin request has been validated or not.
[1177] Fix | Delete
*
[1178] Fix | Delete
* @since 1.5.1
[1179] Fix | Delete
*
[1180] Fix | Delete
* @param string $action The nonce action.
[1181] Fix | Delete
* @param false|int $result False if the nonce is invalid, 1 if the nonce is valid and generated between
[1182] Fix | Delete
* 0-12 hours ago, 2 if the nonce is valid and generated between 12-24 hours ago.
[1183] Fix | Delete
*/
[1184] Fix | Delete
do_action( 'check_admin_referer', $action, $result );
[1185] Fix | Delete
[1186] Fix | Delete
if ( ! $result && ! ( -1 === $action && strpos( $referer, $adminurl ) === 0 ) ) {
[1187] Fix | Delete
wp_nonce_ays( $action );
[1188] Fix | Delete
die();
[1189] Fix | Delete
}
[1190] Fix | Delete
[1191] Fix | Delete
return $result;
[1192] Fix | Delete
}
[1193] Fix | Delete
endif;
[1194] Fix | Delete
[1195] Fix | Delete
if ( ! function_exists( 'check_ajax_referer' ) ) :
[1196] Fix | Delete
/**
[1197] Fix | Delete
* Verifies the Ajax request to prevent processing requests external of the blog.
[1198] Fix | Delete
*
[1199] Fix | Delete
* @since 2.0.3
[1200] Fix | Delete
*
[1201] Fix | Delete
* @param int|string $action Action nonce.
[1202] Fix | Delete
* @param false|string $query_arg Optional. Key to check for the nonce in `$_REQUEST` (since 2.5). If false,
[1203] Fix | Delete
* `$_REQUEST` values will be evaluated for '_ajax_nonce', and '_wpnonce'
[1204] Fix | Delete
* (in that order). Default false.
[1205] Fix | Delete
* @param bool $die Optional. Whether to die early when the nonce cannot be verified.
[1206] Fix | Delete
* Default true.
[1207] Fix | Delete
* @return int|false 1 if the nonce is valid and generated between 0-12 hours ago,
[1208] Fix | Delete
* 2 if the nonce is valid and generated between 12-24 hours ago.
[1209] Fix | Delete
* False if the nonce is invalid.
[1210] Fix | Delete
*/
[1211] Fix | Delete
function check_ajax_referer( $action = -1, $query_arg = false, $die = true ) {
[1212] Fix | Delete
if ( -1 == $action ) {
[1213] Fix | Delete
_doing_it_wrong( __FUNCTION__, __( 'You should specify a nonce action to be verified by using the first parameter.' ), '4.7' );
[1214] Fix | Delete
}
[1215] Fix | Delete
[1216] Fix | Delete
$nonce = '';
[1217] Fix | Delete
[1218] Fix | Delete
if ( $query_arg && isset( $_REQUEST[ $query_arg ] ) ) {
[1219] Fix | Delete
$nonce = $_REQUEST[ $query_arg ];
[1220] Fix | Delete
} elseif ( isset( $_REQUEST['_ajax_nonce'] ) ) {
[1221] Fix | Delete
$nonce = $_REQUEST['_ajax_nonce'];
[1222] Fix | Delete
} elseif ( isset( $_REQUEST['_wpnonce'] ) ) {
[1223] Fix | Delete
$nonce = $_REQUEST['_wpnonce'];
[1224] Fix | Delete
}
[1225] Fix | Delete
[1226] Fix | Delete
$result = wp_verify_nonce( $nonce, $action );
[1227] Fix | Delete
[1228] Fix | Delete
/**
[1229] Fix | Delete
* Fires once the Ajax request has been validated or not.
[1230] Fix | Delete
*
[1231] Fix | Delete
* @since 2.1.0
[1232] Fix | Delete
*
[1233] Fix | Delete
* @param string $action The Ajax nonce action.
[1234] Fix | Delete
* @param false|int $result False if the nonce is invalid, 1 if the nonce is valid and generated between
[1235] Fix | Delete
* 0-12 hours ago, 2 if the nonce is valid and generated between 12-24 hours ago.
[1236] Fix | Delete
*/
[1237] Fix | Delete
do_action( 'check_ajax_referer', $action, $result );
[1238] Fix | Delete
[1239] Fix | Delete
if ( $die && false === $result ) {
[1240] Fix | Delete
if ( wp_doing_ajax() ) {
[1241] Fix | Delete
wp_die( -1, 403 );
[1242] Fix | Delete
} else {
[1243] Fix | Delete
die( '-1' );
[1244] Fix | Delete
}
[1245] Fix | Delete
}
[1246] Fix | Delete
[1247] Fix | Delete
return $result;
[1248] Fix | Delete
}
[1249] Fix | Delete
endif;
[1250] Fix | Delete
[1251] Fix | Delete
if ( ! function_exists( 'wp_redirect' ) ) :
[1252] Fix | Delete
/**
[1253] Fix | Delete
* Redirects to another page.
[1254] Fix | Delete
*
[1255] Fix | Delete
* Note: wp_redirect() does not exit automatically, and should almost always be
[1256] Fix | Delete
* followed by a call to `exit;`:
[1257] Fix | Delete
*
[1258] Fix | Delete
* wp_redirect( $url );
[1259] Fix | Delete
* exit;
[1260] Fix | Delete
*
[1261] Fix | Delete
* Exiting can also be selectively manipulated by using wp_redirect() as a conditional
[1262] Fix | Delete
* in conjunction with the {@see 'wp_redirect'} and {@see 'wp_redirect_location'} filters:
[1263] Fix | Delete
*
[1264] Fix | Delete
* if ( wp_redirect( $url ) ) {
[1265] Fix | Delete
* exit;
[1266] Fix | Delete
* }
[1267] Fix | Delete
*
[1268] Fix | Delete
* @since 1.5.1
[1269] Fix | Delete
* @since 5.1.0 The `$x_redirect_by` parameter was added.
[1270] Fix | Delete
* @since 5.4.0 On invalid status codes, wp_die() is called.
[1271] Fix | Delete
*
[1272] Fix | Delete
* @global bool $is_IIS
[1273] Fix | Delete
*
[1274] Fix | Delete
* @param string $location The path or URL to redirect to.
[1275] Fix | Delete
* @param int $status Optional. HTTP response status code to use. Default '302' (Moved Temporarily).
[1276] Fix | Delete
* @param string $x_redirect_by Optional. The application doing the redirect. Default 'WordPress'.
[1277] Fix | Delete
* @return bool False if the redirect was cancelled, true otherwise.
[1278] Fix | Delete
*/
[1279] Fix | Delete
function wp_redirect( $location, $status = 302, $x_redirect_by = 'WordPress' ) {
[1280] Fix | Delete
global $is_IIS;
[1281] Fix | Delete
[1282] Fix | Delete
/**
[1283] Fix | Delete
* Filters the redirect location.
[1284] Fix | Delete
*
[1285] Fix | Delete
* @since 2.1.0
[1286] Fix | Delete
*
[1287] Fix | Delete
* @param string $location The path or URL to redirect to.
[1288] Fix | Delete
* @param int $status The HTTP response status code to use.
[1289] Fix | Delete
*/
[1290] Fix | Delete
$location = apply_filters( 'wp_redirect', $location, $status );
[1291] Fix | Delete
[1292] Fix | Delete
/**
[1293] Fix | Delete
* Filters the redirect HTTP response status code to use.
[1294] Fix | Delete
*
[1295] Fix | Delete
* @since 2.3.0
[1296] Fix | Delete
*
[1297] Fix | Delete
* @param int $status The HTTP response status code to use.
[1298] Fix | Delete
* @param string $location The path or URL to redirect to.
[1299] Fix | Delete
*/
[1300] Fix | Delete
$status = apply_filters( 'wp_redirect_status', $status, $location );
[1301] Fix | Delete
[1302] Fix | Delete
if ( ! $location ) {
[1303] Fix | Delete
return false;
[1304] Fix | Delete
}
[1305] Fix | Delete
[1306] Fix | Delete
if ( $status < 300 || 399 < $status ) {
[1307] Fix | Delete
wp_die( __( 'HTTP redirect status code must be a redirection code, 3xx.' ) );
[1308] Fix | Delete
}
[1309] Fix | Delete
[1310] Fix | Delete
$location = wp_sanitize_redirect( $location );
[1311] Fix | Delete
[1312] Fix | Delete
if ( ! $is_IIS && 'cgi-fcgi' !== PHP_SAPI ) {
[1313] Fix | Delete
status_header( $status ); // This causes problems on IIS and some FastCGI setups.
[1314] Fix | Delete
}
[1315] Fix | Delete
[1316] Fix | Delete
/**
[1317] Fix | Delete
* Filters the X-Redirect-By header.
[1318] Fix | Delete
*
[1319] Fix | Delete
* Allows applications to identify themselves when they're doing a redirect.
[1320] Fix | Delete
*
[1321] Fix | Delete
* @since 5.1.0
[1322] Fix | Delete
*
[1323] Fix | Delete
* @param string $x_redirect_by The application doing the redirect.
[1324] Fix | Delete
* @param int $status Status code to use.
[1325] Fix | Delete
* @param string $location The path to redirect to.
[1326] Fix | Delete
*/
[1327] Fix | Delete
$x_redirect_by = apply_filters( 'x_redirect_by', $x_redirect_by, $status, $location );
[1328] Fix | Delete
if ( is_string( $x_redirect_by ) ) {
[1329] Fix | Delete
header( "X-Redirect-By: $x_redirect_by" );
[1330] Fix | Delete
}
[1331] Fix | Delete
[1332] Fix | Delete
header( "Location: $location", true, $status );
[1333] Fix | Delete
[1334] Fix | Delete
return true;
[1335] Fix | Delete
}
[1336] Fix | Delete
endif;
[1337] Fix | Delete
[1338] Fix | Delete
if ( ! function_exists( 'wp_sanitize_redirect' ) ) :
[1339] Fix | Delete
/**
[1340] Fix | Delete
* Sanitizes a URL for use in a redirect.
[1341] Fix | Delete
*
[1342] Fix | Delete
* @since 2.3.0
[1343] Fix | Delete
*
[1344] Fix | Delete
* @param string $location The path to redirect to.
[1345] Fix | Delete
* @return string Redirect-sanitized URL.
[1346] Fix | Delete
*/
[1347] Fix | Delete
function wp_sanitize_redirect( $location ) {
[1348] Fix | Delete
// Encode spaces.
[1349] Fix | Delete
$location = str_replace( ' ', '%20', $location );
[1350] Fix | Delete
[1351] Fix | Delete
$regex = '/
[1352] Fix | Delete
(
[1353] Fix | Delete
(?: [\xC2-\xDF][\x80-\xBF] # double-byte sequences 110xxxxx 10xxxxxx
[1354] Fix | Delete
| \xE0[\xA0-\xBF][\x80-\xBF] # triple-byte sequences 1110xxxx 10xxxxxx * 2
[1355] Fix | Delete
| [\xE1-\xEC][\x80-\xBF]{2}
[1356] Fix | Delete
| \xED[\x80-\x9F][\x80-\xBF]
[1357] Fix | Delete
| [\xEE-\xEF][\x80-\xBF]{2}
[1358] Fix | Delete
| \xF0[\x90-\xBF][\x80-\xBF]{2} # four-byte sequences 11110xxx 10xxxxxx * 3
[1359] Fix | Delete
| [\xF1-\xF3][\x80-\xBF]{3}
[1360] Fix | Delete
| \xF4[\x80-\x8F][\x80-\xBF]{2}
[1361] Fix | Delete
){1,40} # ...one or more times
[1362] Fix | Delete
)/x';
[1363] Fix | Delete
$location = preg_replace_callback( $regex, '_wp_sanitize_utf8_in_redirect', $location );
[1364] Fix | Delete
$location = preg_replace( '|[^a-z0-9-~+_.?#=&;,/:%!*\[\]()@]|i', '', $location );
[1365] Fix | Delete
$location = wp_kses_no_null( $location );
[1366] Fix | Delete
[1367] Fix | Delete
// Remove %0D and %0A from location.
[1368] Fix | Delete
$strip = array( '%0d', '%0a', '%0D', '%0A' );
[1369] Fix | Delete
return _deep_replace( $strip, $location );
[1370] Fix | Delete
}
[1371] Fix | Delete
[1372] Fix | Delete
/**
[1373] Fix | Delete
* URL encode UTF-8 characters in a URL.
[1374] Fix | Delete
*
[1375] Fix | Delete
* @ignore
[1376] Fix | Delete
* @since 4.2.0
[1377] Fix | Delete
* @access private
[1378] Fix | Delete
*
[1379] Fix | Delete
* @see wp_sanitize_redirect()
[1380] Fix | Delete
*
[1381] Fix | Delete
* @param array $matches RegEx matches against the redirect location.
[1382] Fix | Delete
* @return string URL-encoded version of the first RegEx match.
[1383] Fix | Delete
*/
[1384] Fix | Delete
function _wp_sanitize_utf8_in_redirect( $matches ) {
[1385] Fix | Delete
return urlencode( $matches[0] );
[1386] Fix | Delete
}
[1387] Fix | Delete
endif;
[1388] Fix | Delete
[1389] Fix | Delete
if ( ! function_exists( 'wp_safe_redirect' ) ) :
[1390] Fix | Delete
/**
[1391] Fix | Delete
* Performs a safe (local) redirect, using wp_redirect().
[1392] Fix | Delete
*
[1393] Fix | Delete
* Checks whether the $location is using an allowed host, if it has an absolute
[1394] Fix | Delete
* path. A plugin can therefore set or remove allowed host(s) to or from the
[1395] Fix | Delete
* list.
[1396] Fix | Delete
*
[1397] Fix | Delete
* If the host is not allowed, then the redirect defaults to wp-admin on the siteurl
[1398] Fix | Delete
* instead. This prevents malicious redirects which redirect to another host,
[1399] Fix | Delete
* but only used in a few places.
[1400] Fix | Delete
*
[1401] Fix | Delete
* Note: wp_safe_redirect() does not exit automatically, and should almost always be
[1402] Fix | Delete
* followed by a call to `exit;`:
[1403] Fix | Delete
*
[1404] Fix | Delete
* wp_safe_redirect( $url );
[1405] Fix | Delete
* exit;
[1406] Fix | Delete
*
[1407] Fix | Delete
* Exiting can also be selectively manipulated by using wp_safe_redirect() as a conditional
[1408] Fix | Delete
* in conjunction with the {@see 'wp_redirect'} and {@see 'wp_redirect_location'} filters:
[1409] Fix | Delete
*
[1410] Fix | Delete
* if ( wp_safe_redirect( $url ) ) {
[1411] Fix | Delete
* exit;
[1412] Fix | Delete
* }
[1413] Fix | Delete
*
[1414] Fix | Delete
* @since 2.3.0
[1415] Fix | Delete
* @since 5.1.0 The return value from wp_redirect() is now passed on, and the `$x_redirect_by` parameter was added.
[1416] Fix | Delete
*
[1417] Fix | Delete
* @param string $location The path or URL to redirect to.
[1418] Fix | Delete
* @param int $status Optional. HTTP response status code to use. Default '302' (Moved Temporarily).
[1419] Fix | Delete
* @param string $x_redirect_by Optional. The application doing the redirect. Default 'WordPress'.
[1420] Fix | Delete
* @return bool False if the redirect was cancelled, true otherwise.
[1421] Fix | Delete
*/
[1422] Fix | Delete
function wp_safe_redirect( $location, $status = 302, $x_redirect_by = 'WordPress' ) {
[1423] Fix | Delete
[1424] Fix | Delete
// Need to look at the URL the way it will end up in wp_redirect().
[1425] Fix | Delete
$location = wp_sanitize_redirect( $location );
[1426] Fix | Delete
[1427] Fix | Delete
/**
[1428] Fix | Delete
* Filters the redirect fallback URL for when the provided redirect is not safe (local).
[1429] Fix | Delete
*
[1430] Fix | Delete
* @since 4.3.0
[1431] Fix | Delete
*
[1432] Fix | Delete
* @param string $fallback_url The fallback URL to use by default.
[1433] Fix | Delete
* @param int $status The HTTP response status code to use.
[1434] Fix | Delete
*/
[1435] Fix | Delete
$location = wp_validate_redirect( $location, apply_filters( 'wp_safe_redirect_fallback', admin_url(), $status ) );
[1436] Fix | Delete
[1437] Fix | Delete
return wp_redirect( $location, $status, $x_redirect_by );
[1438] Fix | Delete
}
[1439] Fix | Delete
endif;
[1440] Fix | Delete
[1441] Fix | Delete
if ( ! function_exists( 'wp_validate_redirect' ) ) :
[1442] Fix | Delete
/**
[1443] Fix | Delete
* Validates a URL for use in a redirect.
[1444] Fix | Delete
*
[1445] Fix | Delete
* Checks whether the $location is using an allowed host, if it has an absolute
[1446] Fix | Delete
* path. A plugin can therefore set or remove allowed host(s) to or from the
[1447] Fix | Delete
* list.
[1448] Fix | Delete
*
[1449] Fix | Delete
* If the host is not allowed, then the redirect is to $default supplied
[1450] Fix | Delete
*
[1451] Fix | Delete
* @since 2.8.1
[1452] Fix | Delete
*
[1453] Fix | Delete
* @param string $location The redirect to validate
[1454] Fix | Delete
* @param string $default The value to return if $location is not allowed
[1455] Fix | Delete
* @return string redirect-sanitized URL
[1456] Fix | Delete
*/
[1457] Fix | Delete
function wp_validate_redirect( $location, $default = '' ) {
[1458] Fix | Delete
$location = wp_sanitize_redirect( trim( $location, " \t\n\r\0\x08\x0B" ) );
[1459] Fix | Delete
// Browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'.
[1460] Fix | Delete
if ( '//' === substr( $location, 0, 2 ) ) {
[1461] Fix | Delete
$location = 'http:' . $location;
[1462] Fix | Delete
}
[1463] Fix | Delete
[1464] Fix | Delete
// In PHP 5 parse_url() may fail if the URL query part contains 'http://'.
[1465] Fix | Delete
// See https://bugs.php.net/bug.php?id=38143
[1466] Fix | Delete
$cut = strpos( $location, '?' );
[1467] Fix | Delete
$test = $cut ? substr( $location, 0, $cut ) : $location;
[1468] Fix | Delete
[1469] Fix | Delete
$lp = parse_url( $test );
[1470] Fix | Delete
[1471] Fix | Delete
// Give up if malformed URL.
[1472] Fix | Delete
if ( false === $lp ) {
[1473] Fix | Delete
return $default;
[1474] Fix | Delete
}
[1475] Fix | Delete
[1476] Fix | Delete
// Allow only 'http' and 'https' schemes. No 'data:', etc.
[1477] Fix | Delete
if ( isset( $lp['scheme'] ) && ! ( 'http' === $lp['scheme'] || 'https' === $lp['scheme'] ) ) {
[1478] Fix | Delete
return $default;
[1479] Fix | Delete
}
[1480] Fix | Delete
[1481] Fix | Delete
if ( ! isset( $lp['host'] ) && ! empty( $lp['path'] ) && '/' !== $lp['path'][0] ) {
[1482] Fix | Delete
$path = '';
[1483] Fix | Delete
if ( ! empty( $_SERVER['REQUEST_URI'] ) ) {
[1484] Fix | Delete
$path = dirname( parse_url( 'http://placeholder' . $_SERVER['REQUEST_URI'], PHP_URL_PATH ) . '?' );
[1485] Fix | Delete
$path = wp_normalize_path( $path );
[1486] Fix | Delete
}
[1487] Fix | Delete
$location = '/' . ltrim( $path . '/', '/' ) . $location;
[1488] Fix | Delete
}
[1489] Fix | Delete
[1490] Fix | Delete
// Reject if certain components are set but host is not.
[1491] Fix | Delete
// This catches URLs like https:host.com for which parse_url() does not set the host field.
[1492] Fix | Delete
if ( ! isset( $lp['host'] ) && ( isset( $lp['scheme'] ) || isset( $lp['user'] ) || isset( $lp['pass'] ) || isset( $lp['port'] ) ) ) {
[1493] Fix | Delete
return $default;
[1494] Fix | Delete
}
[1495] Fix | Delete
[1496] Fix | Delete
// Reject malformed components parse_url() can return on odd inputs.
[1497] Fix | Delete
foreach ( array( 'user', 'pass', 'host' ) as $component ) {
[1498] Fix | Delete
if ( isset( $lp[ $component ] ) && strpbrk( $lp[ $component ], ':/?#@' ) ) {
[1499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function