url rewriting - How to redirect to a login virtual page?

I'm writing my first WordPress theme from scratch. I need to redirect not logged in users to a virtual login page,

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

相关推荐

  • url rewriting - How to redirect to a login virtual page?

    I'm writing my first WordPress theme from scratch. I need to redirect not logged in users to a virtual login page,

    17小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信