Search Results for 'bp_core_fetch_avatar'
-
Search Results
-
Hi ,
I want to check if the current member have an avatar or not in a front page, i try this too method
1. bp_get_user_has_avatar function return always false2 . if ( !bp_core_fetch_avatar( array( ‘item_id’ => $bp->displayed_user->id, ‘no_grav’ => true ) ) ) return always false too.
Any help thank you ?
**UPDATED**
-when multiple results show, it will show the AKA @ name properly now
-added the same limit on the results returned that the original code usedLike a lot of people, I want the auto suggest to look for display names and nice names. Below is my code to do just that. Im using a $wpdb->get_results to do my search. Im also changing up the displayed text to also include that users nice name so if the user is searching for “bob”. A user’s display name might be “bob9”, but there login = “I_am_bob” It will display avatar then display name then @username
example output
[avatar] bob9 AKA -> @i_am_bobWarning im not a coding master, but it seems to work for me. Below is the whole class-bplabs-autosuggest.php so just make a backup of your site, and overwrite inside class-bplabs-autosuggest.php with the code below
<?php /** * @package BP_Labs * @subpackage Mentions_Autosuggest */ // Exit if accessed directly if ( !defined( 'ABSPATH' ) ) exit; /** * Implements the <a href='http://buddypress.org/community/members/message/' rel='nofollow'>@message</a> autosuggest experiment. * * <a href='http://buddypress.org/community/members/since/' rel='nofollow'>@since</a> 1.0 */ class BPLabs_Autosuggest extends BPLabs_Beaker { /** * Enqueue javascript * * <a href='http://buddypress.org/community/members/since/' rel='nofollow'>@since</a> 1.0 */ public function enqueue_script() { $dir = WP_PLUGIN_URL . '/bp-labs/beakers/js/jquery.mentions'; if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) wp_enqueue_script( 'bplabs-autosuggest-js', "{$dir}.dev.js", array( 'jquery' ), '1.2' ); else wp_enqueue_script( 'bplabs-autosuggest-js', "{$dir}.js", array( 'jquery' ), '1.2' ); wp_localize_script( 'bplabs-autosuggest-js', 'BPMentions', array( 'error1' => __( 'Sorry, an error occurred.', 'bpl' ), 'error2' => _x( 'Please try again.', 'an error occurred', 'bpl' ), 'searching' => _x( 'Searching for members to mention... one moment please...', 'started a search', 'bpl' ) ) ); // This bit of javascript is what you could add directly to your theme $dir = WP_PLUGIN_URL . '/bp-labs/beakers/js/autosuggest'; if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) wp_enqueue_script( 'bplabs-autosuggest-theme-js', "{$dir}.dev.js", array( 'bplabs-autosuggest-js' ), '1.0' ); else wp_enqueue_script( 'bplabs-autosuggest-theme-js', "{$dir}.js", array( 'bplabs-autosuggest-js' ), '1.0' ); } /** * Enqueue CSS * * <a href='http://buddypress.org/community/members/since/' rel='nofollow'>@since</a> 1.0 */ public function enqueue_style() { $dir = WP_PLUGIN_URL . '/bp-labs/beakers/css/jquery.mentions'; if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) wp_enqueue_style( 'bplabs-autosuggest', "{$dir}.dev.css", array(), '1.0' ); else wp_enqueue_style( 'bplabs-autosuggest', "{$dir}.css", array(), '1.0' ); } /** * Add the AJAX callback for the mention_autosuggest() method. * * <a href='http://buddypress.org/community/members/since/' rel='nofollow'>@since</a> 1.0 */ protected function register_actions() { add_action( 'wp_ajax_activity_mention_autosuggest', array( 'BPLabs_Autosuggest', 'mention_autosuggest' ) ); } /** * AJAX receiver for the @mention autosuggest jQuery library. Performs a search on the string provided and returns matches. * * <a href='http://buddypress.org/community/members/global/' rel='nofollow'>@global</a> object $bp BuddyPress global settings * @return mixed Either HTML or JSON. If error, "-1" for missing parameters, "0" for no matches. * <a href='http://buddypress.org/community/members/see/' rel='nofollow'>@see</a> bp-labs/beakers/js/jquery.mentions.dev.js * <a href='http://buddypress.org/community/members/since/' rel='nofollow'>@since</a> 1.0 */ public function mention_autosuggest() { global $bp; if ( empty( $_POST ) || empty( $_POST ) ) exit( '-1' ); // Sanitise input $search_query = implode( '', (array) preg_replace( array( '|^https?<img src="smileys/irritated.gif" width="" height="" alt=":/" title=":/" class="bbcode_smiley" />/|i', '|*|', '|@|' ), '', $_POST ) ); if ( empty( $search_query ) ) exit( '-1' ); //$args = array( // 'count_total' => false, // 'number' => (int) $_POST, // 'search' => "{$search_query}*" //); if ( !empty( $bp->loggedin_user->id ) ) $args = array( $bp->loggedin_user->id ); if ( bp_is_username_compatibility_mode() ) { //$args = array( 'ID', 'user_login' ); //$args = 'login'; } else { //$args = array( 'ID', 'display_name' ); //$args = 'nicename'; } $args = apply_filters( 'bpl_mention_autosuggest_args', $args ); // Search users //TAO custom search using display name global $wpdb; $TAO_limit_results = (int) $_POST; $user_search_results = $wpdb->get_results( "SELECT ID, user_nicename, display_name, user_login FROM wp_users WHERE user_login like'%$search_query%' OR display_name like '%$search_query%' LIMIT 0, $TAO_limit_results" ); //print_r($user_search_results); echo "<br>"; echo 'Searching for members to mention with "' .$search_query .'" in their name.'; echo "<br>"; echo 'Click on the user you wish to mention.'; $args = array( 'search' => "*{$search_query}*" ); //$user_search_results = new WP_User_Query( $args ); //print_r($user_search_results); if ( empty( $user_search_results ) ) { // Return JSON if ( !empty( $_POST ) && 'json' == $_POST ) { exit( json_encode( false ) ); // Return HTML } else { printf( '<li class="section error"><span>%s</span> %s </li>', _x( 'No matches found.', 'no search results', 'bpl' ), _x( 'Please check your spelling.', 'no search results', 'bpl' ) ); exit(); } } // If logged in, get user's friends $friend_ids = array(); if ( !empty( $bp->loggedin_user->id ) && bp_is_active( 'friends' ) ) $friend_ids = friends_get_friend_user_ids( $bp->loggedin_user->id ); $search_results = array( 'friends' => array(), 'others' => array() ); // Build results foreach ( (array) $user_search_results as $user ) { $result = new stdClass; $result->avatar = bp_core_fetch_avatar( array( 'item_id' => $user->ID, 'width' => 30, 'height' => 30, 'type' => 'thumb', 'alt' => __( 'Profile picture of %s', 'bpl' ) ) ); $result->name = bp_core_get_user_displayname( $user->ID ); //TAO adding the nicename to do a AKA $result->TAO_user_nicename = $user->user_nicename; if ( bp_is_username_compatibility_mode() ) $result->id = $user->user_login; else $result->id = $user->user_nicename; if ( in_array( $user->ID, (array) $friend_ids ) ) $search_results[] = $result; else $search_results[] = $result; } apply_filters_ref_array( 'bpl_mention_autosuggest', array( &$search_results, $args ) ); // Return JSON if ( !empty( $_POST ) && 'json' == $_POST ) { exit( json_encode( $search_results ) ); // Return HTML } else { $html = array(); foreach ( $search_results as $section => $items ) { if ( empty( $items ) ) continue; // Friends and other users if ( 'friends' == $section || 'others' == $section ) { if ( 'friends' == $section ) { $html[] = sprintf( '<li class="section friends">%s </li>', __( 'Your friends', 'bpl' ) ); } elseif ( 'others' == $section ) { if ( !empty( $search_results ) ) $html[] = sprintf( '<li class="section other">%s </li>', sprintf( __( 'Other people on %s', 'bpl' ), get_bloginfo( 'name', 'display' ) ) ); else $html[] = sprintf( '<li class="section other">%s </li>', sprintf( __( 'People on %s', 'bpl' ), get_bloginfo( 'name', 'display' ) ) ); } foreach ( $items as $item ) $html[] = sprintf( '<li class="%s">%s </li>', esc_attr( $item->id ), $item->avatar . esc_html( $item->name ) . '   AKA ---> @' .$item->TAO_user_nicename ); // For third-party extensions } else { $custom_section = apply_filters( 'bpl_mention_autosuggest_custom_section', false, $section, $items ); if ( !empty( $custom_section ) ) $html = array_merge( $html, (array) $custom_section ); } } // Safety net if ( empty( $html ) ) $html[] = sprintf( '<li class="section error"><span>%s</span> %s </li>', _x( 'No matches found.', 'no search results', 'bpl' ), _x( 'Please check your spelling.', 'no search results', 'bpl' ) ); exit( apply_filters( 'bpl_mention_autosuggest_html', implode( PHP_EOL, $html ), $html ) ); } } } new BPLabs_Autosuggest(); ?>I built a custom widget with an activity stream so my client can set a group ID to display a “featured group” in the sidebar. The group avatar displays as well as the activity stream. All of the activity links work correctly, except for comments and favorites.
Comments goes to the home page and favorites returns a 404.
Favorites: http://www.prolifeplanet.com/activity/favorite/114/?_wpnonce=6d82795544
Here is my widget code:
`
add_action( ‘widgets_init’, ‘featured_bpgroup_widget’ );/**
* Register our widget
*/
function featured_bpgroup_widget() {
register_widget( ‘tfd_Featured_BPGroup’ );
}/**
* Add widget style
*/add_action(‘wp_enqueue_scripts’, ‘bpfg_styles’);
function bpfg_styles() {
wp_enqueue_style(‘bpfg-style’, plugin_dir_url(__FILE__) . ‘bpfg-style.css’);
}/*** Widget class ***/
class tfd_Featured_BPGroup extends WP_Widget {/**
* Widget setup.
*/
function tfd_Featured_BPGroup() {
/* Widget settings. */
$widget_ops = array( ‘classname’ => ‘bp_fgroup’, ‘description’ => __(‘A widget to display a featured buddy press group.’, ‘fgroup’) );/* Widget control settings. */
$control_ops = array( ‘width’ => 300, ‘height’ => 350, ‘id_base’ => ‘featured-bpgroup’ );/* Create the widget. */
$this->WP_Widget( ‘featured-bpgroup’, __(‘Featured BP Group’, ‘fgroup’), $widget_ops, $control_ops );
}/**
* How to display the widget on the screen.
*/
function widget( $args, $instance ) {
extract( $args );/* Our variables from the widget settings. */
$title = apply_filters(‘widget_title’, $instance );
$description = $instance;
if ( !$groupid = (int) $groupid )$groupid = 4;/* Before widget (defined by themes). */
echo $before_widget;/* Display the widget title if one was input (before and after defined by themes). */
if ( $title )
echo $before_title . $title . $after_title;/* Display Group Avatar */
$avatar = bp_core_fetch_avatar( array( ‘item_id’ => $groupid, ‘object’ => ‘group’, ‘type’ => ‘full’, ‘avatar_dir’ => ‘group-avatars’, ‘alt’ => $alt, /* ‘css_id’ => $id, */’class’ => $class/* , ‘width’ => ‘150px’, ‘height’ => ‘150px’ */ ) );printf( ‘
‘ . __(‘%1$s’, ‘fgroup’) . ‘
‘, $avatar );
/* Display User-Defined Group Description */
if ( $description )
printf( ‘‘ . __(‘%1$s’, ‘fgroup’) . ‘
‘, $description );
/* Display Group Activity */
if ( bp_has_activities (array ( ‘primary_id’ => $groupid, ‘max’ => ‘5’) ) ) : while ( bp_activities() ) : bp_the_activity();
locate_template( array( ‘activity/entry.php’ ), true, false );
endwhile; endif;
wp_reset_query();
/* After widget (defined by themes). */
echo $after_widget;
}/*** Update the widget settings. ***/
function update( $new_instance, $old_instance ) {
$instance = $old_instance;/*** Strip tags ***/
$instance = strip_tags( $new_instance );
$instance = (int) $new_instance;
$instance = strip_tags( $new_instance );return $instance;
}/*** Display widget setting controls on the widget panel. ***/
function form( $instance ) {/* Default widget settings. */
$defaults = array( ‘title’ => __(‘Featured Group’, ‘fgroup’));
$defaults = array( ‘groupid’ => __(‘4’, ‘fgroup’));
$instance = wp_parse_args( (array) $instance, $defaults ); ?><label for="get_field_id( ‘title’ ); ?>”>
<input id="get_field_id( ‘title’ ); ?>” name=”get_field_name( ‘title’ ); ?>” value=”” style=”width:100%;” />
Default: Featured Group<label for="get_field_id( ‘groupid’ ); ?>”>
<input id="get_field_id( ‘groupid’ ); ?>” name=”get_field_name( ‘groupid’ ); ?>” value=”” style=”width:100%;” />
Find the ID in the Network Admin Dashboard under “Buddypress/Group Management”.<label for="get_field_id( ‘description’ ); ?>”>
<input id="get_field_id( ‘description’ ); ?>” name=”get_field_name( ‘description’ ); ?>” value=”” style=”width:100%;” />
Optional: Enter a description or leave blank.<?php
}
}`Any idea what’s going on? The favorites and comments work fine from the other pages, just not from my widget.
Hi,
I’ve managed to setup a linkedin api to sync profiles. If the mystery man is displayed it gets replaced by the user’s linkedin avatar. However, I use the bp_before_profile_edit_content hook to display to linkedin sign in button. Therefor the linkedin avatar is only displayed on the edit page. How can I display the linkedin avatar on all pages? I guess I should use the filter bp_core_fetch_avatar, but I have no idea how.
This is the code so far: http://pastebin.com/3dGdMFeV
Thanks for any suggestions!
