我不知道你是否还需要答案,但这里有一个有效的例子。
标题。php
/*SAVE $_GET[\'aff\'] TO COOKIE*/
if(!isset($_SESSION[\'aff\']) and $_GET[\'aff\']){
$cookie_expire = time()+60*60*24*30;
$_SESSION[\'aff\'] = $_GET[\'aff\'];
setcookie(\'aff\', $_SESSION[\'aff\'], $cookie_expire, \'/\', \'.\'.$_SERVER[\'HTTP_HOST\']);
}
功能。php-如果需要传递一个参数
/*APPEND \'aff\' PARAMETER IN URL THROUGH WHOLE SITE*/
function wprdcv_param_redirect(){
if(isset($_COOKIE[\'aff\']) and !$_GET[\'aff\']){
$location = esc_url(add_query_arg(\'aff\', $_COOKIE[\'aff\']));
wp_redirect($location);
}
}
add_action(\'template_redirect\', \'wprdcv_param_redirect\');
OR: 功能。php-如果需要传递参数数组
/*APPEND \'aff\' PARAMETER IN URL THROUGH WHOLE SITE*/
function wprdcv_param_redirect(){
if(isset($_COOKIE[\'aff\']) and !$_GET[\'aff\']){
$location = esc_url(add_query_arg(array(\'aff\' => $_COOKIE[\'aff\'], \'parameter_key\' => \'parameter_value\', \'parameter_key_two\' => \'parameter_value_two\')));
wp_redirect($location);
}
}
add_action(\'template_redirect\', \'wprdcv_param_redirect\');