Black Friday Sale! Get up to $40 off GP Premium!Learn more

[Resolved] Tom here's my code for your new rego/profile button

Home Forums Support Tom here's my code for your new rego/profile button

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #205350
    Max

    Tom

    I wrote this as payback for your kind assistance. It is ready to go:

    //GP rego and profile shortcode [gp_rego]
    
    add_shortcode( 'gp_rego', 'gp_rego' );
    function gp_rego() {
    	if ( ! is_user_logged_in() ) {
    		return '<a class="button see-through login-button" href="' . esc_url( wp_registration_url( get_permalink() ) ) . '">Register</a>';
    	} else {
    		$current_user = wp_get_current_user();
    		$user=$current_user->user_login ;
    		return '<a class="button see-through login-button" href="http://localhost/forum/forums/users/' . $user . '/edit">My Profile</a>';
    	}
    }
    

    Kind Regards

    Max

    • This topic was modified 4 years, 4 months ago by Max.
    • This topic was modified 4 years, 4 months ago by Tom.
    #205414
    Tom
    Lead Developer
    Lead Developer
    #205707
    Max

    Hmm

    I just found a small bug in this code.

    Works fine for members,but if you log in as the admin and then click on the link, in stead of taking you to your front end bbpress profile page it will take you to an error page:

    β€”β€”β€”-
    Oops! That page can’t be found.

    It looks like nothing was found at this location. Maybe try searching?
    β€”β€”β€”-

    Any ideas to fix this?

    Thanks for your kind assistance.

    Regards

    Max

    #205777
    Tom
    Lead Developer
    Lead Developer

    When you hover over the link is it showing the registration URL or the URL to bbPress?

    #205784
    Max

    My dev site is called forum:

    On hover I get:

    localhost/forum/forums/users/(my user name)/edit

    #205786
    Tom
    Lead Developer
    Lead Developer

    And that matches the URL you get when you manually go to that page through your profile?

    #205788
    Max

    1. On my profile link hover I get:

    localhost/forum/forums/users/(my user name)/edit (NOTE: I have a two word user name and it appears in this link with just a space between the two words)

    2. If I click on the my profile link I get taken to an oops that page can’t be found and the browser link is:

    localhost/forum/forums/users/(firstwordofusername)%20(secondwordofusername)/edit (NOTE: there is a %20 between the first and second words in my username

    3.If I click on my avatar in a topic I get taken to the right page (my profile) and the browser link is:

    localhost/forum/forums/users/(firstwordofusername)-(secondwordofusername)/ (NOTE: there is a hyphen between the first and second words in my username)

    #205789
    Max

    Ok.

    I have just checked. With another two word non admin user name.

    The problem is not related to whether or not the user is admin.

    It is a problem with the two word username.

    That is, if a non admin user with a two word username click on the link, he is also taken to the oops error page.

    • This reply was modified 4 years, 4 months ago by Max.
    #205794
    Max

    Tom

    I fixed this.

    Here is the final code that is good to go (change from user_login to user_nicename):

    
    /GP rego and profile shortcode [gp_rego]
    
    add_shortcode( 'gp_rego', 'gp_rego' );
    function gp_rego() {
    	if ( ! is_user_logged_in() ) {
    		return '<a class="button see-through login-button" href="' . esc_url( wp_registration_url( get_permalink() ) ) . '">Register</a>';
    	} else {
    		$current_user = wp_get_current_user();
    		$user=$current_user->user_nicename ;
    		return '<a class="button see-through login-button" href="http://localhost/forum/forums/users/' . $user . '/edit">My Profile</a>';
    	}
    }

    Kind Regards

    Max

    #205857
    Tom
    Lead Developer
    Lead Developer

    Awesome, glad you got it working πŸ™‚

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.