I'm writing my first WordPress theme from scratch. I need to redirect not logged in users to a virtual login page, when I do wp_safe_redirect( get_site_url() . '/login' )
I would show a virtual page based on a template.
I wrote:
add_action('template_redirect', 'include_theme_template');
add_action('generate_rewrite_rules', 'virtual_pages_rewrite_rules');
and the callbacks:
public function include_theme_template() {
$page_id = intval( get_query_var( 'page_id' ) );
if ( $page_id = 255) {
include get_template_directory() . '/templates/template-login.php';
die;
}
}
public function virtual_pages_rewrite_rules( $wp_rewrite ) {
$wp_rewrite->rules = array_merge(
['login/' => 'index.php?page_id=255'],
$wp_rewrite->rules
);
}
What's wrong? How must I write the rewrite rules?
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745296945a4621200.html
评论列表(0条)