Support

Account

Home Forums Bug Reports User image field doesn't return what it should – admin Reply To: User image field doesn't return what it should – admin

  • Sure James

    I made a short version of it.

    Forgot to mention, wp version is 4.7.1

    
    // The field - set in user profile
    // Note that return_format is set to 'array'
    
    	if( function_exists('acf_add_local_field_group') ):
    
    		acf_add_local_field_group(array (
    			'key' => 'group_58018033d8b8a',
    			'title' => 'Profile Avatar',
    			'fields' => array (
    				array (
    					'key' => 'field_5801803c55db7',
    					'label' => 'Avatar',
    					'name' => 'custom_avatar',
    					'type' => 'image',
    					'required' => 0,
    					'conditional_logic' => 0,
    					'return_format' => 'array',
    					'preview_size' => 'thumbnail',
    					'library' => 'all',
    				),
    			),
    			'location' => array (
    				array (
    					array (
    						'param' => 'user_form',
    						'operator' => '==',
    						'value' => 'edit',
    					),
    				),
    			),
    			'position' => 'normal',
    			'style' => 'default',
    			'label_placement' => 'top',
    			'instruction_placement' => 'label',
    			'active' => 1,
    		));
    
    	endif;
    
    	// Stuff happening
    
    	function admin_avatar() { ?>
    
    		<style>
    			#acf-custom-avatar {width: 50%;box-sizing: border-box; padding: 0 12px;}
    			#user-meta {float: right; width: 50%; color: white;}
    		</style>
    
    		<?php
    
    		global $current_user;
    
    		$avatar = get_field('custom_avatar', 'user_' . $current_user->ID ); 
    		
    		echo '<div style="padding-top: 22px;">';
    
    		if( $avatar ) :
    		
    			echo '<img id="acf-custom-avatar" src="' . $avatar['url'] . '">';
    		
    		endif;
    
    		echo '<span id="user-meta">Howdy<br>' . $current_user->display_name . '</span></div>'; 
    
    			
    	}
    
    	add_filter('adminmenu', 'admin_avatar');