本文整理汇总了PHP中wp_validate_redirect函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_validate_redirect函数的具体用法?PHP wp_validate_redirect怎么用?PHP wp_validate_redirect使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_validate_redirect函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: add_link_rel
/**
* Add rel="nofollow"
* to the given attribute
* array if the specified
* href is external
*
* @param array $attrs
*
* @return mixed
*/
public static function add_link_rel($attrs)
{
if (isset($attrs['href']) && !empty($attrs['href']) && !wp_validate_redirect($attrs['href'], false)) {
$attrs['rel'] = 'nofollow';
}
return $attrs;
}
示例2: wc_add_to_cart_message
/**
* Add to cart messages.
*
* @access public
* @param int|array $products
* @param bool $show_qty Should qty's be shown? Added in 2.6.0
*/
function wc_add_to_cart_message($products, $show_qty = false)
{
$titles = array();
$count = 0;
if (!is_array($products)) {
$products = array($products);
$show_qty = false;
}
if (!$show_qty && !is_array($products)) {
$products = array_fill_keys(array_values($products), 1);
}
foreach ($products as $product_id => $qty) {
$titles[] = ($qty > 1 ? absint($qty) . ' × ' : '') . sprintf(_x('“%s”', 'Item name in quotes', 'woocommerce'), strip_tags(get_the_title($product_id)));
$count += $qty;
}
$titles = array_filter($titles);
$added_text = sprintf(_n('%s has been added to your cart.', '%s have been added to your cart.', $count, 'woocommerce'), wc_format_list_of_items($titles));
// Output success messages
if ('yes' === get_option('woocommerce_cart_redirect_after_add')) {
$return_to = apply_filters('woocommerce_continue_shopping_redirect', wp_get_raw_referer() ? wp_validate_redirect(wp_get_raw_referer(), false) : wc_get_page_permalink('shop'));
$message = sprintf('<a href="%s" class="button wc-forward">%s</a> %s', esc_url($return_to), esc_html__('Continue Shopping', 'woocommerce'), esc_html($added_text));
} else {
$message = sprintf('<a href="%s" class="button wc-forward">%s</a> %s', esc_url(wc_get_page_permalink('cart')), esc_html__('View Cart', 'woocommerce'), esc_html($added_text));
}
wc_add_notice(apply_filters('wc_add_to_cart_message', $message, $product_id));
}
示例3: json_create_user
public function json_create_user()
{
$error = array("status" => 0, "msg" => __('There has been an error processing your request. Please, reload the page and try again.', Eab_EventsHub::TEXT_DOMAIN));
$data = stripslashes_deep($_POST);
$email = $data['email'];
if (empty($email)) {
$error['msg'] = __('Please, submit an email.', Eab_EventsHub::TEXT_DOMAIN);
die(json_encode($error));
}
if (!is_email($email)) {
$error['msg'] = __('Please, submit a valid email.', Eab_EventsHub::TEXT_DOMAIN);
die(json_encode($error));
}
if (email_exists($email)) {
$current_location = get_permalink();
if (!empty($data['location'])) {
// Let's make this sane first - it's coming from a POST request, so make that sane
$loc = wp_validate_redirect(wp_sanitize_redirect($data['location']));
if (!empty($loc)) {
$current_location = $loc;
}
}
$login_link = wp_login_url($current_location);
$login_message = sprintf(__('The email address already exists. Please <a href="%s">Login</a> and RSVP to the event.', Eab_EventsHub::TEXT_DOMAIN), $login_link);
$error['msg'] = $login_message;
die(json_encode($error));
}
$wordp_user = $this->_create_user($email);
if (is_object($wordp_user) && !empty($wordp_user->ID)) {
$this->_login_user($wordp_user);
} else {
die(json_encode($error));
}
die(json_encode(array("status" => 1)));
}
示例4: client_authorize
/**
* Authorizations
*/
function client_authorize()
{
$data = stripslashes_deep($_GET);
$data['auth_type'] = 'client';
$role = Jetpack::translate_current_user_to_role();
$redirect = isset($data['redirect']) ? esc_url_raw((string) $data['redirect']) : '';
$this->check_admin_referer("jetpack-authorize_{$role}_{$redirect}");
$result = $this->authorize($data);
if (is_wp_error($result)) {
Jetpack::state('error', $result->get_error_code());
}
if (wp_validate_redirect($redirect)) {
$this->wp_safe_redirect($redirect);
} else {
$this->wp_safe_redirect(Jetpack::admin_url());
}
/**
* Fires after the Jetpack client is authorized to communicate with WordPress.com.
*
* @since 4.2.0
*
* @param int Jetpack Blog ID.
*/
do_action('jetpack_client_authorized', Jetpack_Options::get_option('id'));
$this->do_exit();
}
示例5: redirect_quick_link
/**
* catch quicklink submissions and redirect if the URL is valid.
*
* @since 1.0.4
* @return void
*/
protected function redirect_quick_link()
{
if (!isset($_POST['mlp_quicklink_select'])) {
return;
}
add_filter('allowed_redirect_hosts', array($this, 'extend_allowed_hosts'), 10, 2);
$url = wp_validate_redirect($_POST['mlp_quicklink_select'], FALSE);
remove_filter('allowed_redirect_hosts', array($this, 'extend_allowed_hosts'));
if (!$url) {
return;
}
// force GET request
wp_redirect($url, 303);
exit;
}
示例6: track_visit
/**
* Track the page view
*
* @since 0.1.0
* @change 1.4.2
*/
public static function track_visit()
{
/* Init vars */
$use_snippet = self::$_options['snippet'];
$is_snippet = $use_snippet && get_query_var('statify_target');
/* Skip tracking */
if (self::_skip_tracking()) {
return self::_jump_out($is_snippet);
}
/* Set target & referrer */
if ($is_snippet) {
$target = urldecode(get_query_var('statify_target'));
$referrer = urldecode(get_query_var('statify_referrer'));
} else {
if (!$use_snippet) {
$target = isset($_SERVER['REQUEST_URI']) ? wp_unslash($_SERVER['REQUEST_URI']) : '/';
$referrer = isset($_SERVER['HTTP_REFERER']) ? wp_unslash($_SERVER['HTTP_REFERER']) : '';
} else {
return;
}
}
/* Invalid target? */
if (empty($target) or !wp_validate_redirect($target, false)) {
return self::_jump_out($is_snippet);
}
/* Global vars */
global $wpdb, $wp_rewrite;
/* Init rows */
$data = array('created' => '', 'referrer' => '', 'target' => '');
/* Set request timestamp */
$data['created'] = strftime('%Y-%m-%d', current_time('timestamp'));
/* Sanitize referrer url */
if (!empty($referrer) && strpos($referrer, home_url()) === false) {
$data['referrer'] = esc_url_raw($referrer, array('http', 'https'));
}
/* Relative target url */
$data['target'] = home_url($target, 'relative');
/* Trim target url */
if ($wp_rewrite->permalink_structure) {
$data['target'] = parse_url($data['target'], PHP_URL_PATH);
}
/* Sanitize target url */
$data['target'] = esc_url_raw($data['target']);
/* Insert */
$wpdb->insert($wpdb->statify, $data);
/* Jump! */
return self::_jump_out($is_snippet);
}
示例7: client_authorize
/**
* Authorizations
*/
function client_authorize()
{
$data = stripslashes_deep($_GET);
$data['auth_type'] = 'client';
$jetpack = $this->get_jetpack();
$role = $jetpack->translate_current_user_to_role();
$redirect = isset($data['redirect']) ? esc_url_raw((string) $data['redirect']) : '';
$this->check_admin_referer("jetpack-authorize_{$role}_{$redirect}");
$result = $this->authorize($data);
if (is_wp_error($result)) {
Jetpack::state('error', $result->get_error_code());
}
if (wp_validate_redirect($redirect)) {
$this->wp_safe_redirect($redirect);
} else {
$this->wp_safe_redirect(Jetpack::admin_url());
}
$this->do_exit();
}
示例8: safe_redirect
/**
* Safe Redirect
*
* Ensure the redirect is to the same site or pluggable list of allowed domains.
* If invalid will redirect to ...
* Based on the WordPress wp_safe_redirect() function.
*/
function safe_redirect($location, $status = 302)
{
$location = wp_sanitize_redirect($location);
$location = wp_validate_redirect($location, home_url());
wp_redirect($location, $status);
}
示例9: authorize
function authorize()
{
$data = stripslashes_deep($_GET);
$args = array();
$redirect = isset($data['redirect']) ? esc_url_raw((string) $data['redirect']) : '';
do {
$jetpack = Jetpack::init();
$role = $jetpack->translate_current_user_to_role();
if (!$role) {
Jetpack::state('error', 'no_role');
break;
}
$cap = $jetpack->translate_role_to_cap($role);
if (!$cap) {
Jetpack::state('error', 'no_cap');
break;
}
check_admin_referer("jetpack-authorize_{$role}_{$redirect}");
if (!empty($data['error'])) {
Jetpack::state('error', $data['error']);
break;
}
if (empty($data['state'])) {
Jetpack::state('error', 'no_state');
break;
}
if (!ctype_digit($data['state'])) {
Jetpack::state('error', 'invalid_state');
break;
}
$current_user_id = get_current_user_id();
if ($current_user_id != $data['state']) {
Jetpack::state('error', 'wrong_state');
break;
}
if (empty($data['code'])) {
Jetpack::state('error', 'no_code');
break;
}
$token = $this->get_token($data);
if (is_wp_error($token)) {
if ($error = $token->get_error_code()) {
Jetpack::state('error', $error);
} else {
Jetpack::state('error', 'invalid_token');
}
Jetpack::state('error_description', $token->get_error_message());
break;
}
if (!$token) {
Jetpack::state('error', 'no_token');
break;
}
$is_master_user = !Jetpack::is_active();
Jetpack::update_user_token($current_user_id, sprintf('%s.%d', $token, $current_user_id), $is_master_user);
if ($is_master_user) {
Jetpack::state('message', 'authorized');
} else {
Jetpack::state('message', 'linked');
// Don't activate anything since we are just connecting a user.
break;
}
if ($active_modules = Jetpack::get_option('active_modules')) {
Jetpack::delete_option('active_modules');
Jetpack::activate_default_modules(999, 1, $active_modules);
} else {
Jetpack::activate_default_modules();
}
$jetpack->sync->register('noop');
// Spawn a sync to make sure the Jetpack Servers know what modules are active.
// Start nonce cleaner
wp_clear_scheduled_hook('jetpack_clean_nonces');
wp_schedule_event(time(), 'hourly', 'jetpack_clean_nonces');
} while (false);
if (wp_validate_redirect($redirect)) {
wp_safe_redirect($redirect);
} else {
wp_safe_redirect(Jetpack::admin_url());
}
exit;
}
示例10: wp_get_original_referer
/**
* Retrieve original referer that was posted, if it exists.
*
* @since 2.0.4
*
* @return string|false False if no original referer or original referer if set.
*/
function wp_get_original_referer()
{
if (!empty($_REQUEST['_wp_original_http_referer']) && function_exists('wp_validate_redirect')) {
return wp_validate_redirect(wp_unslash($_REQUEST['_wp_original_http_referer']), false);
}
return false;
}
示例11: JsRedirect
static function JsRedirect($url, $unsafe = false)
{
$url = wp_sanitize_redirect($url);
if (!$unsafe) {
$url = wp_validate_redirect($url, apply_filters('wp_safe_redirect_fallback', admin_url(), 302));
}
echo '<script type="text/javascript"> window.location = "', str_replace('"', '\\"', $url), '"; </script><h1><a href="', esc_attr($url), '">', esc_html($url), '</a></h1>';
// NO exit/die here!
}
示例12: redirect_after_save_account_details
/**
* Redirect back to the provided return_url
*
* @since 1.2.0
* @param string $redirect_location
* @param string $redirect_location
*/
public function redirect_after_save_account_details($redirect_location)
{
$safe_redirect_location = get_permalink(wc_get_page_id('myaccount'));
$safe_redirect_location = wp_sanitize_redirect($safe_redirect_location);
$safe_redirect_location = wp_validate_redirect($safe_redirect_location, admin_url());
if ($redirect_location === $safe_redirect_location && ($new_location = get_transient('wcsl_' . md5($_SERVER['REMOTE_ADDR'] . $_SERVER['HTTP_USER_AGENT'])))) {
$redirect_location = $new_location;
delete_transient('wcsl_' . md5($_SERVER['REMOTE_ADDR'] . $_SERVER['HTTP_USER_AGENT']));
}
return $redirect_location;
}
开发者ID:sergioblanco86,项目名称:git-gitlab.com-kinivo-kinivo.com,代码行数:18,代码来源:class-wc-social-login-opauth.php
示例13: redirect_after_login
/**
* Возвращает URL, на который пользователь должен быть перенаправлен после успешной авторизации.
*
* @param string $redirect_to URL-адрес перенаправления.
* @param string $requested_redirect_to The requested redirect destination URL passed as a parameter.
* @param WP_User|WP_Error $user WP_User если Логин прошла успешно, в противном случае объект WP_Error.
*
* @return string Redirect URL
*/
public function redirect_after_login($redirect_to, $requested_redirect_to, $user)
{
$redirect_url = home_url();
if (!isset($user->ID)) {
return $redirect_url;
}
if (user_can($user, 'manage_options')) {
// Используйте параметр redirect_to если он установлен, в противном случае перенаправления администратора приборной панели.
if ($requested_redirect_to == '') {
$redirect_url = admin_url();
} else {
$redirect_url = $requested_redirect_to;
}
} else {
//Простым пользователям всегда идти к своей странице аккаунта после регистрации
$redirect_url = home_url('member-account');
}
return wp_validate_redirect($redirect_url, home_url());
}
示例14: logout
/**
* Method used for the janrain_capture_logout action on admin-ajax.php.
*/
function logout()
{
$s = isset($_SERVER['HTTPS']) ? '; secure' : '';
$n = self::$name;
$r = isset($_GET['source']) ? $_GET['source'] : home_url();
$r = wp_validate_redirect($r, home_url());
// Escaping - applied early due to heredoc
if (function_exists('wp_json_encode')) {
$r = wp_json_encode($r);
} elseif (function_exists('json_encode')) {
$r = json_encode($r);
}
echo <<<LOGOUT
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
\t "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
\t<head>
\t<title>Janrain Capture</title>
\t</head>
\t<body>
\t<script type="text/javascript">
\t\tdocument.cookie = 'backplane-channel=; expires=Thu, 01-Jan-70 00:00:01 GMT; path=/{$s}';
\t\twindow.location.href = {$r};
\t</script>
\t</body>
</html>
LOGOUT;
exit;
}
示例15: build_connect_url
/**
* Builds a URL to the Jetpack connection auth page
*
* @since 3.9.5
*
* @param bool $raw If true, URL will not be escaped.
* @param bool|string $redirect If true, will redirect back to Jetpack wp-admin landing page after connection.
* If string, will be a custom redirect.
* @param bool|string $from If not false, adds 'from=$from' param to the connect URL.
*
* @return string Connect URL
*/
function build_connect_url($raw = false, $redirect = false, $from = false)
{
if (!Jetpack_Options::get_option('blog_token') || !Jetpack_Options::get_option('id')) {
$url = Jetpack::nonce_url_no_esc(Jetpack::admin_url('action=register'), 'jetpack-register');
if (is_network_admin()) {
$url = add_query_arg('is_multisite', network_admin_url('admin.php?page=jetpack-settings'), $url);
}
} else {
require_once JETPACK__GLOTPRESS_LOCALES_PATH;
$role = $this->translate_current_user_to_role();
$signed_role = $this->sign_role($role);
$user = wp_get_current_user();
$jetpack_admin_page = esc_url_raw(admin_url('admin.php?page=jetpack'));
$redirect = $redirect ? wp_validate_redirect(esc_url_raw($redirect), $jetpack_admin_page) : $jetpack_admin_page;
$gp_locale = GP_Locales::by_field('wp_locale', get_locale());
if (isset($_REQUEST['is_multisite'])) {
$redirect = Jetpack_Network::init()->get_url('network_admin_page');
}
$secrets = Jetpack::init()->generate_secrets('authorize');
@(list($secret) = explode(':', $secrets));
$site_icon = function_exists('has_site_icon') && has_site_icon() ? get_site_icon_url() : false;
$args = urlencode_deep(array('response_type' => 'code', 'client_id' => Jetpack_Options::get_option('id'), 'redirect_uri' => add_query_arg(array('action' => 'authorize', '_wpnonce' => wp_create_nonce("jetpack-authorize_{$role}_{$redirect}"), 'redirect' => urlencode($redirect)), esc_url(admin_url('admin.php?page=jetpack'))), 'state' => $user->ID, 'scope' => $signed_role, 'user_email' => $user->user_email, 'user_login' => $user->user_login, 'is_active' => Jetpack::is_active(), 'jp_version' => JETPACK__VERSION, 'auth_type' => 'calypso', 'secret' => $secret, 'locale' => isset($gp_locale->slug) ? $gp_locale->slug : '', 'blogname' => get_option('blogname'), 'site_url' => site_url(), 'home_url' => home_url(), 'site_icon' => $site_icon));
$url = add_query_arg($args, Jetpack::api_url('authorize'));
}
if ($from) {
$url = add_query_arg('from', $from, $url);
}
if (isset($_GET['calypso_env'])) {
$url = add_query_arg('calypso_env', sanitize_key($_GET['calypso_env']), $url);
}
return $raw ? $url : esc_url($url);
}