Skip to:
Content
Pages
Categories
Search
Top
Bottom

User name as a variable

  • @rayray23

    Participant

    I am creating a button so the user can click on it to update their profile. I use to know this information but have since forgotten it.

    The example is: https://thornbladehills.com/members/????????/profile/edit/group/1/

    I need to know the variable to replace the ????? marks. The question marks would represent the user name.

    Any help would be much appreciated.

    Thanks
    Raymond

Viewing 7 replies - 1 through 7 (of 7 total)
  • @thinlizzie

    Participant

    Hi,

    Try “me”

    @rayray23

    Participant

    sorry, did not work.

    @thinlizzie

    Participant

    It’s likely the stuff after the /???????/ which is the issue then.

    Try /members/me/ to see if that gets you to the profile.
    If yes, then you can experiment with removing /profile/ and other combinations.

    @mike80222

    Participant

    Hi @rayray23,

    Since nobody seems to be replying to this … I’m definitely no expert, but I think it’s possible you might want something like:

    if (is_user_logged_in()) {
            $user = wp_get_current_user();
            $username = $user->user_login;

    I personally find it hard to search the WP documentation, but there should be information in:

    https://developer.wordpress.org/reference/functions

    Hope that’s helpful,

    Mike

    @rayray23

    Participant

    Mike,
    Thank you for responding. I appreciate the effort!! I am trying to create a button that redirects the user to a specific part of their profile. I do not necessarily want a function but a variable that inserts the user’s name into the link.

    In the past I have used this:

    
    https://thornbladehills.com/members/[variable]username[/variable]/profile/
    

    I added the ending: edit/group/1/
    and at one time it worked great.

    Combined it use to look like this:

    
    https://thornbladehills.com/members/[variable]username[/variable]/profile/edit/group/1/
    

    The code replaced the variable text with the user’s username and looked like this:

    
    https://thornbladehills.com/members/ppp5555/profile/edit/group/1/
    

    which would take the user to their profile page and also to the section to edit group 1
    Group 1 is the user’s base information they filled out at registration.

    The code works with the user not being logged in. I just have to manually replace the username and then it goes directly to the section I want it to go to.
    Possibly because of security reasons, buddypress may have taken the variable text out of use, but like I said it still works if I manually enter the user’s username.

    Thanks
    Raymond

    @alex409

    Participant

    Does it work?

    @thinlizzie

    Participant

    rayray,

    What happens when you are logged in to your site and you put this in the address bar …

    yoursite/members/me

    Nothing?
    What happens?

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