Skip to:
Content
Pages
Categories
Search
Top
Bottom

front_page and BuddyPress interception


  • Sergio De Falco
    Participant

    @sgr33n

    Hi people,

    I’m trying to solve an issue between a plugin of mines and BuddyPress, I would be glad if somebody, I wish @boonebgorges, colud give me some advice.

    So here’s the problem. I wrote a function to set an option for an alternative front_page if the user is not logged in. It works pretty good on WordPress, and here is how:

    function sgrwp14theme_guests_homepage( $wp ) {
    	// Special case: when a BuddyPress directory (eg example.com/members)
    	// is set to be the front page, BuddyPress will force the page and this
    	// will not work. We have to add a bp_core_get_directory_page_ids filter.
    	$page = get_post( get_option( 'guests_page_on_front' ) );
    	if ( $page ) {
    		if ( ! is_user_logged_in() && empty( $wp->query_vars ) )
    			$wp->query_vars['pagename'] = $page->post_name;
    	}
    }
    add_action( 'parse_request', 'sgrwp14theme_guests_homepage' );

    As I wrote in the code comment, BuddyPress intercepts this and force the front_page if the original one was a BP Directory, so my previous code doesn’t work anymore in this case.

    So I had a trick to make it work. Intercepting the bp_core_get_directory_page_ids, unsetting the page id for the front_page component, in this way:

    function guests_bp_directory_page_ids( $page_ids ) {
    	if ( ! is_user_logged_in() ) {
    		if ( 'page' == get_option( 'show_on_front' ) && $page_on_front = (int) get_option( 'page_on_front' ) )
    			$front_page_component = array_search( $page_on_front, $page_ids );
    
    		if ( false !== $front_page_component )
    			// Disattivo la pagina in questione.
    			$page_ids[$front_page_component] = 0;
    	}
    	return $page_ids;
    }
    add_filter( 'bp_core_get_directory_page_ids', 'guests_bp_directory_page_ids' );

    Anyway it doesn’t really work, because my original (for logged in users) front page is activity, and the bp_core_get_directory_page_ids filter I wrote made a behavior I don’t really want: the user home page will became the profile one and not the activity if the user is not logged in (www.buddypress.org/users/sgr33n/ -> profile page, http://www.buddypress.org/users/sgr33n/activity/ -> activity page).

    Is there an alternative way to make this work?

    Thanks 🙂

  • The topic ‘front_page and BuddyPress interception’ is closed to new replies.
Skip to toolbar