我正在编写一个简单的附属插件,它可以执行以下操作:
我的问题是,它只在永久链接设置为普通时有效,这是什么?page\\u id=342当我将其设置为post name时,我得到404错误,并且没有设置cookie。代码有什么问题?
<?php
add_action(\'init\', \'affiliate_redirect\');
function affiliate_redirect() {
$varname = \'affid\';
$weeks = \'4\';
if( isset($_GET[$varname]) && \'\' != $_GET[$varname] ) {
setcookie(\'wp_affiliate\', $_GET[$varname], time()+648000*$weeks, \'/\');
$pageURL = \'http\';
if ( isset( $_SERVER["HTTPS"] ) && strtolower( $_SERVER["HTTPS"] ) == "on" ) {
$pageURL .= "s";
}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"] ;
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
$url = preg_replace(\'/([?&])\'.$varname.\'=[^&]+(&|$)/\',\'$1\',$pageURL);
$last = $url[strlen($url)-1];
if ($last == \'?\') {
$url = substr_replace($url ,"",-1);
}
wp_redirect($url);
exit;
}
}
?>