• thebigtine

    (@josephbydesign)


    Hey everyone,

    I’m working on a plugin that adds the admin info at the top of the admin menu. all going well except I can’t get the current users avatar. this is the code I have at the moment:

    function yobd_user_admin_menu_info() {
    
    	global $current_user;
    
    	get_currentuserinfo();
    
    	echo '<link rel="stylesheet" href="' . plugins_url( 'assets/css/user_info_in_admin_menu_style.css', __FILE__ ) . '" > ';
    
        ?>
        <script type="text/javascript">
            jQuery( document ).ready( function() {
                jQuery( '#adminmenuwrap' ).prepend( '<?php
                	echo '<div class="admin_user_menu_info_wrap">';
                		echo '<li>';
    	            		echo '<a href="' . get_edit_user_link() . '">';
    /* ===== this is the problem ===== */
    	            			echo '<img src="' . get_avatar( $current_user->ID, 64 ) . '">';
    	            		echo '</a>';
    	            	echo '</li>';
    
    	            	echo '<li>';
    	            		echo '<a href="' . get_edit_user_link() . '">';
    	            			echo '<p class="admin_user_menu_info_text admin_user_menu_info_name">';
    	            				echo $current_user->user_login . '';
    	            			echo '</p>';
    	            		echo '</a>';
    	            	echo '</li>';
    
    	            	echo '<li>';
    	            		echo '<a href="' . wp_logout_url() . '">';
    	            			echo '<p class="admin_user_menu_info_text admin_user_menu_info_logout">Logout</p>';
    	            		echo '</a>';
    	            	echo '</li>';
    
                	echo '</div>';
                ?>');
            });
        </script>
        <?php
    
    }
    
    	add_action( 'admin_footer', 'yobd_user_admin_menu_info' );
    
    ?>

    If i add a static url it works.
    Any other suggestions to tidy up the code would be great!

    Many thanks,
    Joe

  • The topic ‘Get current user avatar’ is closed to new replies.