• Resolved vetomacht

    (@vetomacht)


    Hi Omar,

    I followed the Installation instructions and put
    thumbnailphoto:octet:adi_thumbnailphoto into the User Meta of the AD Integratioin plugin.

    The AD fieldname for thumbnail in your plugin is of course
    adi_thumbnailphoto

    The sync works fine, my user Pictures are beeing uploaded into the correct Directory on my ftp.

    But somehow the Pictures wont Show up. As you mentioned in another Support article I put These lines of code into my theme files where the thumbnail should Show up.

    <?php
    $userID = get_the_author_meta('ID');
    $user = get_userdata( $userID );
    echo $user->adt_user_photo_url;
    ?>

    But then the Picture just disappears. Completly gone, even the Default Picture from wordpress. Probably my installed theme is causing the Problem. Here is the original Piece of code in my theme:

    <?php // GET CURRENT USER ID
    $user_ID = get_current_user_id();
    echo get_avatar( $user_ID );
    ?>

    This is the theme I am using:
    https://themeforest.net/item/woffice-intranetextranet-wordpress-theme/11671924

    Thank you in advance for your Support.

    https://www.ads-software.com/plugins/active-directory-thumbnails/

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Omar Mir

    (@mirwindsor-omar)

    I think to use that you need to be inside the loop.
    https://codex.www.ads-software.com/Function_Reference/get_the_author_meta

    So, get_current_user_id is for the current user, not the author info. Try this:

    <?php // GET CURRENT USER ID
    $user_ID = get_current_user_id();
    $user_data_adt = get_userdata( $userID );
    echo $user_data_adt->adt_user_photo_url;
    ?>

    Try that? Make sure the user that you could see BEFORE you made the code change has an image inside saved from AD. Really the issue here SEEMS to be the call to get_the_author_meta outside the loop which the codex says:
    (integer) If a user ID is passed to the function, it will return data for the specified user ID. Required if not in the loop. In the loop current author ID will be used.

    Thread Starter vetomacht

    (@vetomacht)

    Hi Omar,

    thank for your response. Unfortunately your code doesn’t work aswell but I read the codex entry which was very helpful. Since I want to show the profile picture in my header.php I am not in the loop and if I got that right, it means I have to pass $userID to the function.

    Propably I should have mentioned that I added the following code to my functions.php to remove the default gravatar.
    Could that cause a problem? Also the theme works with Buddypress.

    add_action('wp_enqueue_scripts', 'woffice_child_scripts');
    function remove_gravatar ($avatar, $id_or_email, $size, $default, $alt) {
            $test1 = get_usermeta( $id_or_email->user_id, 'adt_user_photo_url' );
            $test2 = get_usermeta( $id_or_email, 'adt_user_photo_url' );
            if($test1 <> null) {
                    $default = $test1;
            }
            else if ($test2 <> null) {
                    $default = $test2;
            }
            else {
                    $default="add a url to a default avatar picture else the picture will be a blank box";
            }
            return "<img alt='{$alt}' src='{$default}' class='avatar avatar-{$size} photo avatar-default' height='{$size}' width='{$size}' />";
    }
    add_filter('get_avatar', 'remove_gravatar', 1, 5);

    Thanks for your support Omar, I’m really glad. ??

    Plugin Author Omar Mir

    (@mirwindsor-omar)

    I assume then getting the user ID and passing it to your function was sufficient and all is working?

    Thread Starter vetomacht

    (@vetomacht)

    Hi Omar,

    no unfortunately it’s not working. When I replace the code with yours, the avatar disappears. :/

    Plugin Author Omar Mir

    (@mirwindsor-omar)

    Alright this is too hard to fix this way I think. Can you send me a zip of your theme file (with all the changes you have made?) And let me know exactly where you are trying to place the picture and I wi test on my server. Or if it’s even possible provide me access to your server (this feels wrong to even ask).

    I need to do some more development on this plugin it seems to make it more friendly ??

    Thread Starter vetomacht

    (@vetomacht)

    Hey Omar, thank you for offering me your support. I sent you and e-mail to [email protected] I hope that’s the correct address ??

    Plugin Author Omar Mir

    (@mirwindsor-omar)

    Hey so I its using the avatar and all you need to do is use the existing filter to modify it.

    add_filter( 'get_avatar' , 'my_custom_avatar' , 1 , 5 );
    
    function my_custom_avatar( $avatar, $id_or_email, $size, $default, $alt ) {
    	$user = false;
    
    	if ( is_numeric( $id_or_email ) ) {
    		$id = (int) $id_or_email;
    		$user = get_user_by( 'id' , $id );
    	} elseif ( is_object( $id_or_email ) ) {
    		if ( ! empty( $id_or_email->user_id ) ) {
    			$id = (int) $id_or_email->user_id;
    			$user = get_user_by( 'id' , $id );
    		}
    	} else {
    		$user = get_user_by( 'email', $id_or_email );
    	}
    
    	if ( $user && is_object( $user ) ) {
    		$avatar = "<img alt='{$alt}' src='{$user->adt_user_photo_url}' class='avatar avatar-{$size} photo' height='{$size}' width='{$size}' />";
    	} else {
    		return $avatar;
    	}
    
    	return $avatar;
    }

    And once done you can see the result here: Screenshot

    This should work in the most basic sense. You may want to check that the user has a value set in the adt_user_photo_url and if he/she doesn’t then just return the default avatar.

    If you REALLY wanted to you could modify the header file but this seems cleaner and likely provides the proper integration.

    You can add the code to either the theme functions.php or child theme functions.php or however else you are managing the functions.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Avatar not showing’ is closed to new replies.