Support » Themes and Templates » [Theme : suffusion] Add-in WP-members

  • Resolved Nadege78

    (@nadege78)


    Good afternoon,

    I installed the Wp-members plug-in which works perfectly.
    Now, I would need to add the following code :

    add_action( ‘wp_head’, ‘check_page’ );
    function check_page() {
    if( is_page( ‘landing-page’ ) && is_user_logged_in() ) {
    wp_redirect( ‘http:// mysite.com/my-page/’ );
    exit();
    } return;
    }

    as instructed on the author’s website (http://butlerblog.com/2012/02/11/new-filter-and-action-hooks-in-wp-members-2-7-1/) ‘before headers are sent’.

    The question is : where exactly should I insert that code ???
    I am no IT and none of my trials worked out.

    Thank you in advance for your help.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Typically it is safest to do this kind of thing in a child theme. Get the child theme starter pack from here and put in the add_action call in the suffu_scion_theme_setup function of functions.php, then define your check_page function right after that. The functions.php file is commented enough to help you figure out where to put things.

    Chad Butler

    (@cbutlerjr)

    To clarify, you stated “as instructed on the author’s website,” except the code you posted is not what is discussed there, and this is not an example of the hooks internal to the plugin. What you are is using the WordPress wp_head action hook.

    Based on your check_page function, it looks like what you want to do is have a landing page that you are directing users to and if they are already logged in, you want to send them somewhere else.

    You can use the wp_head action here as you have it. This is a WordPress hook for putting things into the <head> of the HTML sent down to the user. You need to make sure that no other plugins are jumping out in front of you at this point, makeing sure that content is not already being sent downstream to the user. So instead of the just the action call & your function, you should set the priority to ‘1’ (as in the example code below).

    Here’s a cleaned up version of your code snippet with some explanation:

    // at wp_head, fire the check_page function priority 1.
    add_action( 'wp_head', 'check_page', 1 );
    function check_page()
    {
    	// compare the slug name and check if user is logged in
    	if( is_page( 'landing-page' ) && is_user_logged_in() ) {
    
    		// if that's true, then redirect the user
    		wp_redirect( 'http://mysite.com/my-page' );
    		exit();
    
    	}
    
    	// otherwise, we are done here
    	return;
    }

    As Sayontan stated, this should go in your functions.php file.

    Thread Starter Nadege78

    (@nadege78)

    Thank you Sayontan, thank you Chad.

    Chad,
    Some of my users do not log out. I’d like them to be re-directed on a specific page when they come back to the blog (those users, as in DJ’s case) checked the box ‘remember me’ and they currently land on the page enabling them to modify their profile/password.
    I’d rather like them to land directly on the blog page…

    (Sorry, my English is awfull !).

    I’ll have a close look to your answers this week-end but I wish to thank you both for your quick answer.

    Nadege

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Theme : suffusion] Add-in WP-members’ is closed to new replies.