Create a Function that echos User Avatar linked to current Gravity Forms Entry

I am using Gravity Forms and Gravity View to create a job management system. The issue I am running into is I want to display the avatar of the user that created the Gravity Form Entry. Currently I created a shortcode that will echo the current users avatar which works. But, that is technically a work around. I would like to properly do it so it will echo the avatar of the user that created the entry and not just the current user logged in.

Currently I have my custom shortcode placed in Gravity View and here is my functions.php code:

/* Add Avatar to Job List */

function shortcode_user_avatar() {
if(is_user_logged_in()) { // check if user is logged in
global $current_user; // get current user’s information
get_currentuserinfo();
return get_avatar( $current_user -> ID,100 ); // display the logged-in user’s avatar
}
else {
// if not logged in, show default avatar. change URL to show your own default avatar
return get_avatar( ‘http://1.gravatar.com/avatar/ad524503a11cd5ca435acc9bb6523536?s=64’, 24 );
}
}
add_shortcode(‘display-user-avatar’,’shortcode_user_avatar’);

What I need is so somehow add either these two lines of code inside that shortcode to display the avatar of the user that created the entry.

public static function filter_avatar( $avatar = ”, $note ) {

if( ‘gravityview’ === $note->note_type && -1 === (int)$note->user_id ) {
$avatar = sprintf( ‘<img src=”%s” width=”48″ height=”48″ alt=”GravityView” class=”avatar avatar-48 gravityview-avatar” />’, esc_url_raw( plugins_url( ‘assets/images/floaty-avatar.png’, GRAVITYVIEW_FILE ) ) );
}

return $avatar;
}

or

static public function display_note( $note, $show_delete = false ) {

if( ! is_object( $note ) ) {
return ”;
}

$note_content = array(
‘avatar’ => get_avatar( $note->user_id, 48 ),
‘user_name’ => $note->user_name,
‘user_email’ => $note->user_email,
‘added_on’ => esc_html__( ‘{date_created_formatted}’, ‘gravityview’ ),
‘value’ => wpautop( esc_html( $note->value ) ),
‘date_created’ => $note->date_created,
‘date_created_formatted’ => GFCommon::format_date( $note->date_created, false ),
‘user_id’ => intval( $note->user_id ),
‘note_type’ => $note->note_type,
‘note_id’ => intval( $note->id ),
);

Any suggestions will be helpful! I am more front-end so this is still new to me :/

Read more here:: Create a Function that echos User Avatar linked to current Gravity Forms Entry

Leave a Reply

Your email address will not be published. Required fields are marked *