Skip to:
Content
Pages
Categories
Search
Top
Bottom

Shortcode to add “Edit Profile” link

Viewing 10 replies - 1 through 10 (of 10 total)
  • @oyegigi

    Participant

    In case someone wants to use the code who is using pretty links.

    
    // Generate BBporess Edit Profile Link in a shortcode
    // [bbp_edit_profile text="Edit My Profile" class"my-link-style"]
    
    function bbp_edit_profile_link($atts) {
    	extract(shortcode_atts(array(
    		'text' => "",  // default value if none supplied
    		'class' => "" //Style class for link
        ), $atts));
        
        if ($text) {
    		$current_user = wp_get_current_user (); 
    		$user=$current_user->user_login;
            return '<a class="'. $class . '" href="/forums/users/' . $user . '/edit">' . $text. '</a>';
            
        } 
    }
    add_shortcode('bbp_edit_profile', 'bbp_edit_profile_link');
    

    @struth

    Participant

    Hey oyegigi,

    Thanks for this, it works like a charm. I used the plugin “Shortcodes in Menus” as a quick solution to output to a menu.

    Would be great if you could amend the code to show, only if user is logged in?

    Thanks again!

    @michent1

    Participant

    I ended up having to dig this snippet backup for a new project and made some tweaks.


    @struth
    Updated to only output if user is logged in.

    
    	/**
    	 * Generate BBpress Edit Profile Link in a shortcode
    	 *
    	 * @param $atts, text|class
    	 * @example [bbp_edit_profile text="Edit My Profile" class"my-link-style"]
    	 * @return string|void
    	 *
    	 */
    	function bbp_edit_profile_link( $atts ) {
    		
    		//If user isn't logged in, return nothing
    		if(!is_user_logged_in()) {
    			return;
    		} else {
    			
    			extract( shortcode_atts( array(
    				                         'text'  => "",  // default value if none supplied
    				                         'class' => "" //Style class for link
    			                         ), $atts ) );
    			
    			if ( $text ) {
    				$current_user = wp_get_current_user();
    				$user         = $current_user->user_login;
    				
    				return '<a class="' . $class . '" href="/forums/users/' . $user . '/edit">' . $text . '</a>';
    				
    			}
    		}
    	}
    	
    	add_shortcode( 'bbp_edit_profile', 'bbp_edit_profile_link' );
    

    @struth

    Participant

    WOW, thanks for this michent1, I’ll try this and report back soon

    Way cool!

    @hmprivate

    Participant

    @michent1 – thank you – your updated version + the original shortcode by op works as a charm (had some issues with the original one).

    @angeljs

    Participant

    I’ve been searching for ages for a simple edit profile link! This takes me to the profile page, thank you, but clicking the submit button takes me to a page not found error. πŸ™

    @uksentinel

    Participant

    Can anybody confirm if the above edit profile link still works as this is exactly what I am struggling with at the moment to provide a way for BBPRESS members to access their profile ?

    There are options via paid plugin etc, but I am looking to achieve this at no financial cost if at all possible πŸ˜‰

    Home

    @tijana1234

    Participant

    Hey,

    I hope someone could help me. I used this code from @michent and it works prefectly, except one thing:

    When username is just like: tijana, then it works prefectly.

    But when username has dot, like tijana.medan, then it does’t work, becuase the link than is:
    http://Www.site.com/forums/users/tijana.medan
    and the right link is:
    http://Www.site.com/forums/users/tijana-medan

    Could someone help me, what should I add or change in code so I can reslove this? It means a lot, because all my users have username with dots aka name.lastname

    Thank you!!

    @tijana1234

    Participant

    I found solution. Just added:
    $user = str_replace(β€œ.”, β€œ-β€œ, $user);

    @robin-w

    Moderator

    πŸ™‚

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