Shortcode to add “Edit Profile” link
-
Seems like integrating the “Edit Profile” link in various places on a site is a common issue here folks are running into on the forums.
So I hacked out a quick shortcode for a project i was working on that required us to include a link to the user’s edit profile page in a popup.
(Please note, the specific site i wrote this for was NOT using pretty links).Placed in your child-theme’s functions.php file or in a custom plugin
/*--Generate BBporess Edit Profile Link in a shortcode--*/ 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->ID; return '<a class="'. $class . '" href="/?bbp_user=' . $user . '&edit=1">' . $text. '</a>'; } } add_shortcode('bbp_edit_profile', 'bbp_edit_profile_link');
Attributes:
text = Your output text (i.e. “Edit My Profile”)
class = Custom anchor class (i.e. “my-link-style”)Example
[bbp_edit_profile text="Edit My Profile" class"my-link-style"]
It’s a bit sloppy, but it works. Maybe someone else might find it useful…
-
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');
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!
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' );
WOW, thanks for this michent1, I’ll try this and report back soon
Way cool!
@michent1 – thank you – your updated version + the original shortcode by op works as a charm (had some issues with the original one).
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. π
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 π
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-medanCould 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!!
I found solution. Just added:
$user = str_replace(β.β, β-β, $user);π
- You must be logged in to reply to this topic.