Support » Plugin: WP Idea Stream » Hide Ideastream from logged out users and redirect

  • I searched the web for quite a while now but I couldnt find the solution for my problem.
    I use the Ideastream-plugin along with Buddypress and I want not-logged-in users to be redirectet to a specific page. So if they click the link in my navigation /ideastream they should be redirected if not logged in.
    I tried this by using this code in my child theme’s function.php:

    function nonreg_visitor_redirect() {
    global $bp;
    if ( bp_is_activity_component() || bp_is_groups_component() || bp_is_group_forum() || bp_is_page( BP_MEMBERS_SLUG ) || is_page('138') || is_page('ideastream') ) {
    if(!is_user_logged_in()) { //just a visitor and not logged in
    wp_redirect( get_option('siteurl') . '/willkommen/' );
    }
    }
    }
    add_filter('get_header','nonreg_visitor_redirect',1);

    This doesnt work – something inside Ideastream seems to override this. I tried lots of different things (eg. the complete url, etc) but by now I didnt managed to redirect not-logged-in users to the page “willkommen” when they click the Ideastream-Link in my navigation.
    It works with all other conditions and with page’138′ but Ideastream refuses to redirect…

    I really dont know how to get it to work.
    Can you help, please?

    Thanks in advance, hage

    https://wordpress.org/plugins/wp-idea-stream/

Viewing 5 replies - 1 through 5 (of 5 total)
  • good idea

    i am interested in this too

    Plugin Author Mathieu Viet

    (@imath)

    Thanks for your feedback @derhage

    WP Idea Stream does not create / require any WordPress page. If you created a page named “ideastream” and the root slug of the plugin is “ideastream”, then if you go on the plugin’s settings page. You should have a slug conflict.

    As a result, doing an is_page( 'ideastream' ) check to restrict the access to loggedin users only will logically have no effects.

    Below, you’ll find some code to restrict the access to BuddyPress and WP Idea Stream to loggedin users. I advise you to use 2 functions, this way if you deactivate BuddyPress or WP Idea Stream, you won’t have a “white screen of death” because one of the function is not available!

    It’s also best to use the bp-custom.php / wp-idea-stream-custom.php file to put your custom code, as these two files won’t be loaded if the corresponding plugins are not activated.

    /**
     * If BuddyPress is activated and you want
     * to restrict BuddyPress front-end access to
     * loggedin users only.
     *
     * Put this in a file named bp-custom.php in
     * your wp-content/plugins directory
     */
    function buddypress_redirect_non_loggedin_user() {
    	if ( is_buddypress() && ! is_user_logged_in() ) {
    		bp_core_redirect( get_home_url() );
    	}
    }
    add_action( 'bp_actions', 'buddypress_redirect_non_loggedin_user', 1 );
    
    /**
     * If WP Idea Stream is activated and you want
     * to restrict WP Idea Stream front-end access to
     * loggedin users only.
     *
     * Put this in a file named wp-idea-stream-custom.php in
     * your wp-content/plugins directory
     */
    function wp_idea_stream_redirect_non_loggedin_user() {
    	if ( wp_idea_stream_is_ideastream() && ! is_user_logged_in() ) {
    		wp_safe_redirect( get_home_url() );
    		exit();
    	}
    }
    add_action( 'wp_idea_stream_actions', 'wp_idea_stream_redirect_non_loggedin_user', 1 );

    I definitely have to dig into this slug-issues, I know.
    Thanks a lot for your reply – it worked perfectly!

    hey guys

    sorry … for the question but … the xxx-custom.php files, do they have to be in the wp-content/plugins/wp-idea-stream (or other plugin) folder itself or in the root wp-content/plugins folder?

    furthermore, do i have to rename the original wp-idea-stream.php file to something else (e.g. …-backup.php)

    thx

    never mind … could figure it out by myself 🙂

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Hide Ideastream from logged out users and redirect’ is closed to new replies.