Search Results for 'bp_core_fetch_avatar'
-
Search Results
-
Hi Guys,
I would like to show members from the same region when logged in and here is the code I have used but now working:
<!–?php </p–>
bp_loggedin_user_id();
$user_id = 14 ;
$myfield = xprofile_get_field_data( ‘State’, 14);
echo $myfield;xprofile_get_field_data(‘field=Bundesland’, 14);
?><!–?php </p–>
}
$sql=”select * from `
glft448_bp_xprofile_data where value = ‘”.$state.”‘”;
$con1 = mysql_query(“SELECT distinct user_id FROMglft448_bp_xprofile_dataWHEREvalue= ‘”.$state.”‘”);while($queRes1 = mysql_fetch_array($con1))
{
?>
<!–?php $queRes1[‘user_id’];<br ?–> // echo bp_core_get_userlink($queRes1[‘user_id’]);
?>
<a href=”"<?php”>” >
<!–?php echo bp_core_fetch_avatar ( array( ‘item_id’ =–>$queRes1[‘user_id’] , ‘type’ => ‘thumb’ ) ); ?></a><!–?php </p–>
}
$sqlt=”select * from `glft448_bp_xprofile_data where value = ‘”.$state.”‘”;
$con2 = mysql_query(“SELECT * FROMglft448_bp_xprofile_dataWHEREuser_id= ‘”.$user_id.”‘ ANDfield_id= ‘1’ “);while($queRes2 = mysql_fetch_array($con2))
{
?>
<b> <!–?php //echo $queRes2[‘value’]; ?–></b>
I added that code to the text version of the page editor but it’s showing like that on the profile page.
What am I missing?
Thanks
i’m trying to get user info from facebook when a user tries to login through facebook on my website ,Wordpress website, I have been struggling to retrieve users’ birthday, email, first name, last name and interests and so on what is the code to get them. I’m newly to facebook apps so I don’t know what to do and what is the procedure
All what i can retrieve is the email, name and create username according to the url user name
some clear code would be useful Thank you
This is my code location in my directory:
wp-content/themes/themeName/framework/functions/facebook_login.php<?php function fb_head(){ if( is_user_logged_in()) return; ?> <div id="fb-root"></div> <script> // Additional JS functions here window.fbAsyncInit = function() { FB.init({ appId : '<?php echo sq_option('fb_app_id'); ?>', // App ID version : 'v2.0', status : true, // check login status cookie : true, // enable cookies to allow the server to access the session xfbml : true, // parse XFBML oauth : true }); // Additional init code here }; // Load the SDK asynchronously (function(d){ var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0]; if (d.getElementById(id)) {return;} js = d.createElement('script'); js.id = id; js.async = true; js.src = "//connect.facebook.net/en_US/sdk.js"; ref.parentNode.insertBefore(js, ref); }(document)); </script> <?php } add_action( 'kleo_after_body', 'fb_head' ); function fb_footer(){ ?> <script type="text/javascript"> var ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?>'; jQuery('.facebook_connect').click(function(){ var context = jQuery(this).closest("form"); if (jQuery(".tos_register", context).length > 0) { if (! jQuery(".tos_register", context).is(":checked")) { alert('<?php echo apply_filters('kleo_fb_tos_alert',__("You must agree with the terms and conditions.",'kleo_framework'));?>'); return false; } } FB.login(function(FB_response){ if( FB_response.status === 'connected' ){ fb_intialize(FB_response); } }, {scope: 'public_profile,email'}); }); function fb_intialize(FB_response){ FB.api( '/me', 'GET', {'fields':'id,email,verified,name'}, function(FB_userdata){ jQuery.ajax({ type: 'POST', url: ajaxurl, data: {"action": "fb_intialize", "FB_userdata": FB_userdata, "FB_response": FB_response}, success: function(user){ if( user.error ){ alert( user.error ); } else if( user.loggedin ){ if( user.type === 'login' ) { window.location.reload(); } else if( user.type === 'register' ) { window.location = user.url; } } } }); } ); }; </script> <?php } add_action( 'wp_footer', 'fb_footer' ); if (!function_exists('fb_button')): function fb_button() { ?> <a href="#" class="facebook_connect radius button facebook"><i class="icon-facebook-sign"></i> <?php _e("LOG IN WITH Facebook", 'kleo_framework');?></a> <?php } endif; if (!function_exists('fb_register_button')): function fb_register_button() { ?> <a href="#" class="facebook_connect radius small button facebook"><i class="icon-facebook-sign"></i> <?php _e("Register using Facebook", 'kleo_framework');?></a> <?php } endif; if (!function_exists('fb_register_button_front')): function fb_register_button_front() { ?> <a href="#" class="facebook_connect radius button facebook"><i class="icon-facebook"></i></a> <?php } endif; add_action('fb_popup_button', 'fb_button' ); if (sq_option('facebook_register', 0) == 1) { add_action('fb_popup_register_button', 'fb_register_button' ); add_action('fb_popup_register_button_front', 'fb_register_button_front' ); } function wp_ajax_fb_intialize(){ @error_reporting( 0 ); // Don't break the JSON result header( 'Content-type: application/json' ); if( !isset( $_REQUEST['FB_response'] ) || !isset( $_REQUEST['FB_userdata'] )) die( json_encode( array( 'error' => __('Authenication required.', 'kleo_framework') ))); $FB_response = $_REQUEST['FB_response']; $FB_userdata = $_REQUEST['FB_userdata']; $FB_userid = $FB_userdata['id']; if( !$FB_userid ) die( json_encode( array( 'error' => __('Please connect your facebook account.', 'kleo_framework') ))); global $wpdb; //check if we already have matched our facebook account $user_ID = $wpdb->get_var( "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '_fbid' AND meta_value = '$FB_userid'" ); //if facebook is not connected if( !$user_ID ){ $user_email = $FB_userdata['email']; $user_ID = $wpdb->get_var( "SELECT ID FROM $wpdb->users WHERE user_email = '".$wpdb->escape($user_email)."'" ); $redirect = ''; //if we have a registered user with this Facebook email if(!$user_ID ) { if ( !get_option( 'users_can_register' )) { die( json_encode( array( 'error' => __('Registration is not open at this time. Please come back later.', 'kleo_framework') ))); } if (sq_option('facebook_register', 0) == 0) { die( json_encode( array( 'error' => __('Registration using Facebook is not currently allowed. Please use our Register page', 'kleo_framework') ))); } extract( $FB_userdata ); $display_name = $name; if( empty( $verified ) || !$verified ) die( json_encode( array( 'error' => __('Your facebook account is not verified. You have to verify your account before proceed login or registering on this site.', 'kleo_framework') ))); $user_email = $email; if ( empty( $user_email )) die( json_encode( array( 'error' => __('Please re-connect your facebook account as we couldn\'t find your email address.', 'kleo_framework') ))); if( empty( $name )) die( json_encode( array( 'error' => 'empty_name', __('We didn\'t find your name. Please complete your facebook account before proceeding.', 'kleo_framework') ))); $user_login = sanitize_title_with_dashes( sanitize_user( $display_name, true )); if ( username_exists( $user_login )) { $user_login = $user_login. time(); } $user_pass = wp_generate_password( 12, false ); $userdata = compact( 'user_login', 'user_email', 'user_pass', 'display_name' ); $userdata = apply_filters('kleo_fb_register_data', $userdata); $user_ID = wp_insert_user( $userdata ); if ( is_wp_error( $user_ID )) die( json_encode( array( 'error' => $user_ID->get_error_message()))); //send email with password wp_new_user_notification( $user_ID, wp_unslash( $user_pass ) ); //add Facebook image update_user_meta($user_ID, 'kleo_fb_picture', 'https://graph.facebook.com/' . $id . '/picture'); do_action('fb_register_action',$user_ID); update_user_meta( $user_ID, '_fbid', (int) $id ); $logintype = 'register'; $redirect = apply_filters('kleo_fb_register_redirect',bp_core_get_user_domain( $user_ID ).'profile/edit/group/1/?fb=registered'); } else { update_user_meta( $user_ID, '_fbid', (int) $FB_userdata['id'] ); //add Facebook image update_user_meta($user_ID, 'kleo_fb_picture', 'https://graph.facebook.com/' . (int) $FB_userdata['id'] . '/picture'); $logintype = 'login'; } } else { $logintype = 'login'; } wp_set_auth_cookie( $user_ID, false, false ); die( json_encode( array( 'loggedin' => true, 'type' => $logintype, 'url' => $redirect ))); } add_action( 'wp_ajax_nopriv_fb_intialize', 'wp_ajax_fb_intialize' ); //If registered via Facebook -> show message add_action( 'template_notices', 'kleo_fb_register_message' ); if (!function_exists('kleo_fb_register_message')): function kleo_fb_register_message() { if (isset($_GET['fb']) && $_GET['fb'] == 'registered') { echo '<div class="clearfix"></div><br><div class="alert-box success" id="message" data-alert>'; echo __('Thank you for registering. Please make sure to complete your profile fields below.', 'kleo_framework'); echo '</div>'; } } endif; //display Facebook avatar if(sq_option('facebook_avatar', 1) == 1) { //show Facebook avatar in WP add_filter('get_avatar', 'kleo_fb_show_avatar', 5, 5); //show Facebook avatar in Buddypress add_filter('bp_core_fetch_avatar', 'kleo_fb_bp_show_avatar', 3, 5); //show Facebook avatar in Buddypress - url version add_filter('bp_core_fetch_avatar_url','kleo_fb_bp_show_avatar_url', 3, 2); } function kleo_fb_show_avatar($avatar = '', $id_or_email, $size = 96, $default = '', $alt = false) { $id = 0; if (is_numeric($id_or_email)) { $id = $id_or_email; } else if (is_string($id_or_email)) { $u = get_user_by('email', $id_or_email); $id = $u->id; } else if (is_object($id_or_email)) { $id = $id_or_email->user_id; } if ($id == 0) return $avatar; //if we have an avatar uploaded and is not Gravatar return it if(strpos($avatar, home_url()) !== FALSE && strpos($avatar, 'gravatar') === FALSE) return $avatar; //if we don't have a Facebook photo $pic = get_user_meta($id, 'kleo_fb_picture', true); if (!$pic || $pic == '') return $avatar; $avatar = preg_replace('/src=("|\').*?("|\')/i', 'src=\'' . $pic . apply_filters('fb_show_avatar_params', '?width=580&height=580') . '\'', $avatar); return $avatar; } function kleo_fb_bp_show_avatar($avatar = '', $params, $id) { if(!is_numeric($id) || strpos($avatar, 'gravatar') === false) return $avatar; //if we have an avatar uploaded and is not Gravatar return it if(strpos($avatar, home_url()) !== FALSE && strpos($avatar, 'gravatar') === FALSE) return $avatar; $pic = get_user_meta($id, 'kleo_fb_picture', true); if (!$pic || $pic == '') return $avatar; $avatar = preg_replace('/src=("|\').*?("|\')/i', 'src=\'' . $pic. apply_filters('fb_show_avatar_params', '?width=580&height=580') . '\'', $avatar); return $avatar; } function kleo_fb_bp_show_avatar_url($gravatar, $params) { //if we have an avatar uploaded and is not Gravatar return it if(strpos($gravatar, home_url()) !== FALSE && strpos($gravatar, 'gravatar') === FALSE) return $gravatar; $pic = get_user_meta($params['item_id'], 'kleo_fb_picture', true); if (!$pic || $pic == '') return $gravatar; return $pic. apply_filters('fb_show_avatar_params', '?width=580&height=580'); } ?>Hello.
So I’m trying to do a member loop that shows only members with avatars.
Here is my code:
template member loop file has this line:
bp_has_members( gd_custom_ids( 'What are your interests?', $interests ) . '&per_page=6&type=random')functions.php
/********* SEARCH MEMBERS BASED ON PROFILE FIELDS *********/ function gd_custom_ids( $field_name, $field_value = '' ) { if ( empty( $field_name ) ) return ''; global $wpdb; $field_id = xprofile_get_field_id_from_name( $field_name ); if ( !empty( $field_id ) ) $query = "SELECT user_id FROM " . $wpdb->prefix . "bp_xprofile_data WHERE field_id = " . $field_id; else return ''; if ( $field_value != '' ) $query .= " AND value LIKE '%" . $field_value . "%'"; /* LIKE is slow. If you're sure the value has not been serialized, you can do this: $query .= " AND value = '" . $field_value . "'"; */ $custom_ids = $wpdb->get_col( $query ); $i = 0; $user_ids_loop = array(); foreach ($custom_ids as $custom_id){ if(gd_check_avatar($custom_id)){ $user_ids_loop[$i] = $custom_id; $i++; } } if ( !empty( $user_ids_loop ) ) { // convert the array to a csv string $custom_ids_str = 'include=' . implode(",", $custom_ids); return $custom_ids_str; } else return ''; } /********* CHECK IF MEMBER HAVE AVATARS *********/ function gd_check_avatar($user_id){ // Check for avatar. $fbavatar = false; $user_info = get_userdata($user_id); $username=$user_info->user_login; // Check what information is missing? Avatar? Profile info? $username = strtolower($username); $userfbavatar = get_user_meta($user_ID, 'facebook_uid', true); if (!empty( $userfbavatar ) ) { $fbavatar= true; //echo "DEBUG: user has a FB photo<br/>"; } if (bp_core_fetch_avatar( array( 'item_id' => $bp->loggedin_user->id, 'no_grav' => true,'html'=> false ) ) != bp_core_avatar_default() ) { $has_photo = true; //echo "DEBUG: user has a photo<br/>"; } if ( $has_photo || $fbavatar) { $avatarchk = true; } if(!$avatarchk){ $avatarchk=false;} return $avatarchk; }I have ~6,000 members on my site.
I get this error:
[30-May-2014 06:59:51 UTC] PHP Fatal error: Allowed memory size of 41943040 bytes exhausted (tried to allocate 64 bytes) in /Users/giova/Sites/lam.dev/wp-content/mu-plugins/wpengine-common/patterns.php on line 331 [30-May-2014 06:59:51 UTC] PHP Fatal error: Unknown: Cannot use output buffering in output buffering display handlers in Unknown on line 0I assume that the for loop in function gd_check_avatar() is not helping.
What would be the best way to do this to reduce resources and still get only members with avatars?
Or at least, sort the members so that the first members have an avatar.
Thanks!
Giovanni
Still trying to wrap my head around taking advantage of these built in filters..
I need to change the alt-text here so that the member’s Full name is not shown. We’re using the “Usernames Only” plugin but it does not cover a few usages of our users’ names, such as in alt-text on /members avatars, as well as in pictures.php.
So first… avatars. The function in question:
function bp_member_avatar( $args = '' ) { echo apply_filters( 'bp_member_avatar', bp_get_member_avatar( $args ) ); } function bp_get_member_avatar( $args = '' ) { global $members_template; $fullname = !empty( $members_template->member->fullname ) ? $members_template->member->fullname : $members_template->member->display_name; $defaults = array( 'type' => 'thumb', 'width' => false, 'height' => false, 'class' => 'avatar', 'id' => false, 'alt' => sprintf( __( 'Profile picture of %s', 'buddypress' ), $fullname ) ); $r = wp_parse_args( $args, $defaults ); extract( $r, EXTR_SKIP ); return apply_filters( 'bp_get_member_avatar', bp_core_fetch_avatar( array( 'item_id' => $members_template->member->id, 'type' => $type, 'alt' => $alt, 'css_id' => $id, 'class' => $class, 'width' => $width, 'height' => $height, 'email' => $members_template->member->user_email ) ) ); }and what I tried:
/* Hide FUll Name from member avatar */add_filter('bp_member_avatar', 'mm_hide_name_in_alt_text'); function mm_hide_name_in_alt_text() { $defaults = array( 'type' => 'thumb', 'width' => false, 'height' => false, 'class' => 'avatar', 'id' => false, 'alt' => 'Profile Picture' ); return $defaults; }Looking to understand why this isn’t working?
Topic: Theme development woes
Hey there guys,
I’ve been following Buddypress’ progress over the last few months and with the new theme development strategies in BP 1.8+ I’m finding it very difficult to develop my own theme.
All the documentation on the BP Codex seems to either be outdated, or extremely vague and gives no guidance onto how to develop your own theme.
The current way I’ve been developing is starting out with Eddie Machado’s bones and adding php files based on the Template Hierarchy, then calling Buddypress functions within the documents. As an example:
<?php $ud = get_userdata( bp_displayed_user_id() ); ?> <div id="wrapper-main" class = "cf"> <div id="profilesidebar"> <?php bp_core_fetch_avatar( array( 'item_id' => $ud->ID,'type'=>'full','width'=>450,'height'=>450 ) ); ?> <?php echo $ud->user_login; ?> </div>Is this the correct way to go about developing a theme? and if not, where am I going wrong?
– Sythen.Hi,
I’m using BuddyPress on my website (gowc.fr) for several month, I was using a “hack” in functions.php to use my WP avatar in BuddyPress and it was working like a charm until the last version of BuddyPress. I have updated the plugin yesterday and now all my members have the default avatar instead of their custom avatar.The code I was using in functions.php :
add_filter('bp_core_fetch_avatar_no_grav', '__return_true'); add_filter( 'bp_core_fetch_avatar', 'revert_to_default_wp_avatar', 80, 3 );//late load function revert_to_default_wp_avatar( $img, $params, $item_id ){ //we are concerned only with users if( $params['object']!='user' ) return $img; //check if user has uploaded an avatar //if not then revert back to wordpress core get_avatar method //remove the filter first, or else it will go in infinite loop remove_filter( 'bp_core_fetch_avatar', 'revert_to_default_wp_avatar', 80, 3 ); if( !emi_user_has_avatar( $item_id ) ){ $width = $params['width']; // Set image width if ( false !== $width ) { $img_width = $width; } elseif ( 'thumb' == $width ) { $img_width = bp_core_avatar_thumb_width(); } else { $img_width = bp_core_avatar_full_width(); } $img = get_avatar( $item_id, $img_width ); } //add the filter back again add_filter( 'bp_core_fetch_avatar', 'revert_to_default_wp_avatar', 80, 3 ); return $img; } /** * Check if the given user has an uploaded avatar * @return boolean */ function emi_user_has_avatar( $user_id=false ) { if( !$user_id ){ $user_id = bp_loggedin_user_id(); } if ( bp_core_fetch_avatar( array( 'item_id' => $user_id, 'no_grav' => true,'html'=> false ) ) != bp_core_avatar_default() ) return true; return false; }Please help me to solve this annoying issue.
Thanks
This seemed to be a simple task, but I’ve been struggling to get it working.
I wish to check on user login if they have uploaded an avatar or if they are using the auto-generated gravatar. For now, I am just trying to get it to redirect to the upload page (I’ll likely pop up a light box, display a notice, or restrict functions in the future).
I have done some searching, and after some tweaking, this is what I have come up with:
function uaol_get_user_has_avatar() { global $bp; $avatar = bp_core_fetch_avatar( array( 'item_id' => $bp->loggedin_user->id, 'no_grav' => true, 'html'=>false) ); $pos = strpos($avatar, 'wavatar'); if ($pos === false) { return true;} else { return false; } } function buddypress_redirect_if_no_avatar($redirect_url,$request_url,$user) { $redirect_url = bp_core_get_user_domain($user->ID)."/profile/change-avatar/"; return $redirect_url; } if( !uaol_get_user_has_avatar()){ add_filter("login_redirect","buddypress_redirect_if_no_avatar",100,3); }This however does not redirect anyone. Can someone point me in the right direction?