Skip to:
Content
Pages
Categories
Search
Top
Bottom

Shortcode to add “Edit Profile” link

Viewing 5 replies - 1 through 5 (of 5 total)

  • oyegigi
    Participant

    @oyegigi

    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

    @struth

    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

    @michent1

    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

    @struth

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

    Way cool!


    hmprivate
    Participant

    @hmprivate

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

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