Example #1
0
/**
 * Returns an Avatar Option object for a given avatar option id.
 * 
 * @param string $service_id
 * @return object | null on not found
 */
function hma_get_avatar_option($service_id)
{
    foreach (hma_get_avatar_options() as $option) {
        if ($option->service_id == $service_id) {
            return $option;
        }
    }
}
Example #2
0
/**
 * Add avatar select/upload fields to wordpress admin edit user.
 *
 * @access public
 * @param mixed $user
 * @return void
 */
function hma_admin_add_avatar($user)
{
    ?>

	<script type="text/javascript">
		jQuery( document ).ready( function() {
			jQuery( '#hma_user_avatar' ).show();
			jQuery( 'form#your-profile' ).attr( 'enctype', 'multipart/form-data' );
		});
	</script>

	<style type="text/css">
		#hma_user_avatar { display: none; }
		#hma_user_avatar_select_row .hma_avatars { display: inline-block; width: 100px;  }
		#hma_user_avatar_select_row .hma_avatars input { margin-right: 5px; }
		#hma_user_avatar_file_row .avatar { display: block; float: left; margin-right: 20px;  }
		#hma_user_avatar_file_row #hma_user_avatar_file { display: inline-block; margin-bottom: 5px;  }
	</style>

	<div id="hma_user_avatar">

		<h3>User Avatar</h3>

		<table class="form-table">

			<?php 
    $avatar_options = hma_get_avatar_options();
    $current_avatar_service = get_user_meta($user->ID, 'user_avatar_option');
    if ($current_avatar_service) {
        ?>

			<tr id="hma_user_avatar_select_row">

				<th><label for="hma_user_avatar_file">Select which avatar is used</label></th>

	    		<td>
					<?php 
        foreach ($avatar_options as $avatar_option) {
            $avatar_option->set_user($user);
            if (!$avatar_option->get_avatar(60)) {
                continue;
            }
            ?>

		    		<div class="hma_avatars">

		    			<img src="<?php 
            echo $avatar_option->get_avatar(60);
            ?>
" height="60" width="60" alt="Avatar <?php 
            echo $avatar_option->service_name;
            ?>
" class="avatar" />

		    			<br/>

						<?php 
            // TODO for attribute?
            ?>

		    			<label>

		    				<input type="radio" name="hma_user_avatar_service" value="<?php 
            echo $avatar_option->service_id;
            ?>
"

		    					<?php 
            if (!empty($current_avatar_service)) {
                checked($avatar_option->service_id, $current_avatar_service);
            } else {
                checked($avatar_option->service_id, 'gravatar');
            }
            ?>
			    			/>

			    			<?php 
            echo $avatar_option->service_name;
            ?>

		    			</label>

		    		</div>

	    		<?php 
        }
        ?>

		    	</td>

			</tr>

		<?php 
    } else {
        ?>

			<tr id="hma_user_avatar_current_row">
				<th><label for="hma_user_avatar_file">Current Avatar</label></th>
	    		<td><?php 
        echo get_avatar($user->ID, 60);
        ?>
</td>
	    	</tr>

		<?php 
    }
    ?>

			<tr id="hma_user_avatar_file_row">

				<th><label for="hma_user_avatar_file">Upload new avatar</label></th>

				<td>
					<input type="file" name="hma_user_avatar_file" id="hma_user_avatar_file"><br/>
					<span class="description">If you would like to upload a new avatar image. Otherwise leave this empty.</span>
				</td>

			</tr>

		</table>
	</div>

<?php 
}