WordPress.org

Ready to get started?Download WordPress

Forums

How To Check if a User is NOT on a Subdomain and Redirect them (2 posts)

  1. foxymcfox
    Member
    Posted 1 year ago #

    Are there any built in functions in WordPress that would allow me to check if a logged-in users is trying to view the root domain or any of its pages and redirect them to a subdomain for logged in users?

    I'm looking for something similar to "is_page()" but instead of checking the page, it would check whether or not the domain being accessed is the root one. I could then pass it to wp_redirect(), what I'm looking for would look like this, I just need the proper function...

    function root_domain_check() {
    	if ( is_user_logged_in() && !current_user_can('manage_options') && ***FUNCTION ASKING IS THIS THE ROOT DOMAIN***) {
    		wp_redirect(***SUBDOMAIN***);
    		exit;
    	}
    }

    If I have to roll my own solution possibly using the $_SERVER array, that's fine, but I figured I'd see if anyone knew of a built in solution already.

    Thanks!

    -Nick

  2. Hmm. Maybe check the blog ID?

    function root_domain_check() {
    	if ( is_user_logged_in() && !current_user_can('manage_options') && $blog_id == 1 ) {
    		wp_redirect(***SUBDOMAIN***);
    		exit;
    	}
    }

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.