Last active
December 18, 2015 02:49
-
-
Save hnla/5713547 to your computer and use it in GitHub Desktop.
This shortcode allows users to add BP user account links to posts or pages or widgets if widgets enabled for shortcode parsing. You can set the account screen to link to as single top level screen or child 'activity', 'activity/mentions' add text required to display for link, add text to display for the title attr on hover label, also you can se…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Add BP user account links via a shortcode | |
* For use in pages or posts or widgets if enabled for shortcode parsing? | |
* Shortcode example: [hnla_bpuser_links where_to='activity/mentions' link_text='the text for link' title_attr='visit your @mentions' display_name='yes'] | |
* The display name is optional leave out for no display, name will simply display in a span element before anchor link | |
* | |
* @author Hugo - hnla | |
* @version 1.0 | |
* @licence GNU General Public License, version 2 | |
*/ | |
function hnla_bp_account_links($atts) { | |
$bp = buddypress(); | |
extract(shortcode_atts(array( | |
"where_to" => '', | |
'link_text' => '', | |
'title_attr' => '', | |
'display_name' => 'no' | |
), $atts)); | |
$hnla_url = sanitize_text_field( $where_to ); | |
$hnla_text = sanitize_text_field( $link_text ); | |
$hnla_title_attr = sanitize_text_field( $title_attr ); | |
$hnla_display_name = sanitize_text_field( $display_name ); | |
$hnla_loggedin_user = $bp->loggedin_user->id; | |
$hnla_user_data = bp_core_get_core_userdata($hnla_loggedin_user); | |
$hnla_user_name = $hnla_user_data->display_name; | |
if('yes' == $hnla_display_name ) : | |
$hnla_render_name = '<span class="users_display_name">' . $hnla_user_name . '</span>'; | |
else: | |
$hnla_render_name = ''; | |
endif; | |
return $hnla_render_name . '<a href="' . bp_core_get_user_domain($hnla_loggedin_user) . esc_attr($hnla_url) . '/" class="user-account-links" title="' . esc_attr($hnla_title_attr) . '"> ' . esc_attr($hnla_text) . ' </a>'; | |
} | |
add_shortcode('hnla_bpuser_links', 'hnla_bp_account_links'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment