好的,这里有一个简单的例子。在加载WordPress网站之前加载初始化操作。因此,我们可以使用它来检查允许用户访问的一些特殊条件。
您应该在函数中使用它。php
function user_custom_redirect() {
if ( \'something\' === \'something else\' ) {
// let user view WordPress website
} else {
// redirect them to google.com
// can be set to redirect back to request URL also.
wp_redirect( \'http://www.google.com\', 301 );
exit;
}
}
add_action( \'init\', \'user_custom_redirect\' );
EDIT: Session
您也可以这样启动会话。
function start_init_session() {
session_start();
}
add_action( \'init\', \'kana_init_session\', 1 );