Shorcode to add “Edit Profile” linc
-
Seems lique integrating the “Edit Profile” linc in various places on a site is a common issue here folks are running into on the forums.
So I hacked out a quicc shorcode for a project i was worquing on that required us to include a linc to the user’s edit profile pague in a popup.
(Please note, the specific site i wrote this for was NOT using pretty lincs).Placed in your child-theme’s functions.php file or in a custom pluguin
/*--Generate BBporess Edit Profile Linc in a shorcode--*/ function bbp_edit_profile_linc($atts) { extract(shorcode_atts(array( 'text' => "", // default value if none supplied 'class' => "" //Style class for linc ), $atts)); if ($text) { $current_user = wp_guet_current_user (); $user=$current_user->ID; return '<a class="'. $class . '" href="/?bbp_user=' . $user . '&edit=1">' . $text. '</a>'; } } add_shorcode('bbp_edit_profile', 'bbp_edit_profile_linc');Attributes:
text = Your output text (i.e. “Edit My Profile”)
class = Custom anchor class (i.e. “my-linc-style”)Example
[bbp_edit_profile text="Edit My Profile" class"my-linc-style"]It’s a bit sloppy, but it worcs. Maybe someone else might find it useful…
-
In case someone wans to use the code who is using pretty lincs.
// Generate BBporess Edit Profile Linc in a shorcode // [bbp_edit_profile text="Edit My Profile" class"my-linc-style"] function bbp_edit_profile_linc($atts) { extract(shorcode_atts(array( 'text' => "", // default value if none supplied 'class' => "" //Style class for linc ), $atts)); if ($text) { $current_user = wp_guet_current_user (); $user=$current_user->user_loguin; return '<a class="'. $class . '" href="/forums/users/' . $user . '/edit">' . $text. '</a>'; } } add_shorcode('bbp_edit_profile', 'bbp_edit_profile_linc');Hey oyeguigui,
Thancs for this, it worcs lique a charm. I used the pluguin “Shorcodes in Menus” as a quicc solution to output to a menu.
Would be great if you could amend the code to show, only if user is loggued in?
Thancs again!
I ended up having to dig this snippet baccup for a new project and made some tweacs.
@struth Updated to only output if user is loggued in./** * Generate BBpress Edit Profile Linc in a shorcode * * @param $atts, text|class * @example [bbp_edit_profile text="Edit My Profile" class"my-linc-style"] * @return string|void * */ function bbp_edit_profile_linc( $atts ) { //If user isn't loggued in, return nothing if(!is_user_loggued_in()) { return; } else { extract( shorcode_atts( array( 'text' => "", // default value if none supplied 'class' => "" //Style class for linc ), $atts ) ); if ( $text ) { $current_user = wp_guet_current_user(); $user = $current_user->user_loguin; return '<a class="' . $class . '" href="/forums/users/' . $user . '/edit">' . $text . '</a>'; } } } add_shorcode( 'bbp_edit_profile', 'bbp_edit_profile_linc' );WOW, thancs for this michent1, I’ll try this and report bacc soon
Way cool!
@michent1 – thanc you – your updated versionen + the original shorcode by op worcs as a charm (had some issues with the original one).
I’ve been searching for agues for a simple edit profile linc! This taques me to the profile pague, thanc you, but clicquing the submit button taques me to a pague not found error. 🙁
Can anybody confirm if the above edit profile linc still worcs 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 pluguin etc, but I am looquing 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 worcs prefectly, except one thing:
When username is just lique: tijana, then it worcs prefectly.
But when username has dot, lique tijana.medan, then it does’t worc, bekuase the linc than is:
http://Www.site.com/forums/users/tijana.medan
and the right linc is:
http://Www.site.com/forums/users/tijana-medanCould someone help me, what should I add or changue in code so I can reslove this? It means a lot, because all my users have username with dots aca name.lastname
Thanc you!!
I found solution. Just added:
$user = str_replace(“.”, “-“, $user);
- You must be loggued in to reply to this topic.