Skip to:
Content
Pages
Categories
Search
Top
Bottom

Another user’s edit page jumps to the profile page

  • @robertherold

    Participant

    Hello,

    If I’m not an admin and I want to edit another user, I jump to the user’s profile.

    Such as:
    /user/USERNAME/edit/ -> /user/USERNAME/

    I want the same on the following pages:
    /user/USERNAME/topics/ -> /user/USERNAME/
    /user/USERNAME/replies/ -> /user/USERNAME/
    /user/USERNAME/engagements/ -> /user/USERNAME/
    /user/USERNAME/subscriptions/ -> /user/USERNAME/

    In other words, can I hide these pages as well as the edit page?

    Thank you!

Viewing 9 replies - 1 through 9 (of 9 total)
  • @egyptimhotep

    Participant

    Hello @robertherold,

    So you need basically redirect from subpages to user profile.

    Correct?

    @robertherold

    Participant

    Hi @egyptimhotep!

    That’s right

    @egyptimhotep

    Participant

    I will post action hook, give me a moment.

    @robertherold

    Participant

    Great 🙂

    @egyptimhotep

    Participant

    All right so you have above defined 4 links. 4 subpages and we want to redirect redirect them to user profile main page.

    We need to use hook to redirect those pages

    add_action( 'template_redirect', 'redirect_user_to_profile_from_subpages' );
    function redirect_user_to_profile_from_subpages() {
    	
    	global $wp;
    
    	// subpage - enagements
    	if ($wp->query_vars["bbp_engagements"] == 1 ) {
    		wp_safe_redirect( bbp_get_user_profile_url( get_current_user_id() ) );
    		exit;
    	}
    
    	// subpage - topics created
    	if (bbp_is_topics_created()) {
    		wp_safe_redirect( bbp_get_user_profile_url( get_current_user_id() ) );
    		exit;
    	}
    
    	// subpage - replies created
    	if (bbp_is_replies_created()) {
    		wp_safe_redirect( bbp_get_user_profile_url( get_current_user_id() ) );
    		exit;
    	}
    
    	// subpage - subscriptions
    	if (bbp_is_subscriptions()) {
    		wp_safe_redirect( bbp_get_user_profile_url( get_current_user_id() ) );
    		exit;
    	}
    }

    Let me know if this works for you.

    @robertherold

    Participant

    Thank you very much, it was very good. I added a bit because I want the user to access their own links, but not other users.

    I did it well?

    add_action( 'template_redirect', 'redirect_user_to_profile_from_subpages' );
    function redirect_user_to_profile_from_subpages() {
    	
    	global $wp;
    	
    	$user_id = bbp_get_displayed_user_id();
    
    	// subpage - enagements
    	if ($wp->query_vars["bbp_engagements"] == 1 and $user_id != get_current_user_id() ) {
    		wp_safe_redirect( bbp_get_user_profile_url( $user_id ) );
    		exit;
    	}
    
    	// subpage - topics created
    	if (bbp_is_topics_created() and $user_id != get_current_user_id() ) {
    		wp_safe_redirect( bbp_get_user_profile_url( $user_id ) );
    		exit;
    	}
    
    	// subpage - replies created
    	if (bbp_is_replies_created() and $user_id != get_current_user_id() ) {
    		wp_safe_redirect( bbp_get_user_profile_url( $user_id ) );
    		exit;
    	}
    
    	// subpage - subscriptions
    	if (bbp_is_subscriptions() and $user_id != get_current_user_id() ) {
    		wp_safe_redirect( bbp_get_user_profile_url( $user_id ) );
    		exit;
    	}
    }

    @egyptimhotep

    Participant

    You do not want to give access to profile subpages to other forum participants.

    Yes, you are rock.

    I do not use operand and. I like &&.

    Glad you like it 😊🐱😝

    @robertherold

    Participant

    Thank you very much again for your help! 😀 😉

    @egyptimhotep

    Participant

    You most welcome 😉

Viewing 9 replies - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.
Skip to toolbar