Wednesday 28 December 2016

BbPress links shortcode in WordPress

Below given shortcode for
Profile  => [BUDDYUSER-PROFILE text='Edit Profile']
Friends  => [BUDDYUSER-FRIENDS text='My Friends']
Activity => [BUDDYUSER-ACTIVITY text='My Activity']
Add following code in your theme "functions.php" file.


/** bbpress profile link shortdode "[BUDDYUSER-PROFILE text='Edit Profile']" **/
add_shortcode( 'BUDDYUSER-PROFILE', 'cuser_profile_shortocode_handler' );
function cuser_profile_shortocode_handler( $atts ){
$atts = shortcode_atts( array(
'text' => 'my profile',
), $atts );

if( !is_user_logged_in() )
return '';

$link = home_url( '/members/' . bp_core_get_username( get_current_user_id() ) . '/profile/' );
return "" . $atts['text'] . "";
}


/** bbpress friends link shortdode "[BUDDYUSER-FRIENDS text='My Friends']" **/
add_shortcode( 'BUDDYUSER-FRIENDS', 'cuser_friends_shortocode_handler' );
function cuser_friends_shortocode_handler( $atts_friends ){
$atts_friends = shortcode_atts( array(
'text' => 'my friends',
), $atts_friends );

if( !is_user_logged_in() )
return '';

$link = home_url( '/members/' . bp_core_get_username( get_current_user_id() ) . '/friends/' );
return "" . $atts_friends['text'] . "";
}


/** bbpress activity link shortdode "[BUDDYUSER-ACTIVITY text='My Activity']" **/
add_shortcode( 'BUDDYUSER-ACTIVITY', 'cuser_activity_shortocode_handler' );
function cuser_activity_shortocode_handler( $atts_activity ){
$atts_activity = shortcode_atts( array(
'text' => 'my activity',
), $atts_activity );

if( !is_user_logged_in() )
return '';

$link = home_url( '/members/' . bp_core_get_username( get_current_user_id() ) . '/' );
return "" . $atts_activity['text'] . "";
}

Ankit Shah PHP Expert

IT New Code suggest a solution for your problem related to coding, Specially .PHP, Wordpress, WooCommerce, Magento, HTML and CSS. Visit Our website for Information.

0 comments:

Post a Comment

 

Copyright @ 2016 IT New Code | Developing Code | Designing Code.

Designed by: Ankit Shah