Example #1
0
/**
 * Output the HTML used for the metabox and settings section
 *
 * @since 0.1.0
 *
 * @param  object $user
 */
function wp_user_avatars_section_content($user = null)
{
    // Bail if no user
    if (empty($user->ID)) {
        return;
    }
    ?>

	<table class="form-table">

		<?php 
    // User needs caps to edit avatar
    if (current_user_can('edit_avatar', $user->ID)) {
        ?>

			<tr>
				<th scope="row"><label for="wp-user-avatars"><?php 
        esc_html_e('Upload', 'wp-user-avatars');
        ?>
</label></th>
				<td id="wp-user-avatars-photo">
					<?php 
        add_filter('pre_option_avatar_rating', '__return_null');
        echo get_user_avatar($user->ID, 250);
        remove_filter('pre_option_avatar_rating', '__return_null');
        ?>
				</td>
				<td id="wp-user-avatars-actions">

					<?php 
        // User needs additional caps to upload avatars
        if (current_user_can('upload_avatar', $user->ID)) {
            ?>

						<div>
							<input type="file" name="wp-user-avatars" id="wp-user-avatars" class="standard-text" />
						</div>

					<?php 
        }
        ?>

					<div>

						<?php 
        // Prevent errors if not enqueued successfully
        if (did_action('wp_enqueue_media')) {
            ?>

							<a href="#" class="button hide-if-no-js" id="wp-user-avatars-media">
								<?php 
            esc_html_e('Choose from Media', 'wp-user-avatars');
            ?>
							</a> &nbsp;

						<?php 
        }
        ?>

						<?php 
        // User needs additional caps to remove existing avatar
        if (current_user_can('remove_avatar', $user->ID)) {
            ?>

							<?php 
            $remove_url = add_query_arg(array('action' => 'remove-wp-user-avatars', 'user_id' => $user->ID, '_wpnonce' => false));
            ?>

							<a href="<?php 
            echo esc_url($remove_url);
            ?>
" class="button item-delete submitdelete deletion" id="wp-user-avatars-remove"<?php 
            if (empty($user->wp_user_avatars)) {
                echo ' style="display:none;"';
            }
            ?>
>
								<?php 
            esc_html_e('Remove', 'wp-user-avatars');
            ?>
							</a>

						<?php 
        }
        ?>

					</div>

					<?php 
        wp_nonce_field('wp_user_avatars_nonce', '_wp_user_avatars_nonce', false);
        ?>

				</td>
			</tr>

		<?php 
    }
    ?>

		<?php 
    // User needs additional caps to edit ratings
    if (current_user_can('edit_avatar_rating', $user->ID)) {
        ?>

			<tr>
				<th scope="row"><?php 
        esc_html_e('Rating', 'wp-user-avatars');
        ?>
</th>
				<td id="wp-user-avatars-ratings" colspan="2" <?php 
        if (empty($user->wp_user_avatars)) {
            echo ' class="fancy-hidden"';
        }
        ?>
>
					<fieldset <?php 
        disabled(empty($user->wp_user_avatars));
        ?>
>
						<legend class="screen-reader-text"><span><?php 
        esc_html_e('Rating', 'wp-user-avatars');
        ?>
</span></legend>
						<?php 
        // User rating
        if (empty($user->wp_user_avatars_rating) || !array_key_exists($user->wp_user_avatars_rating, wp_user_avatars_get_ratings())) {
            $user->wp_user_avatars_rating = 'G';
        }
        // Output the rating form field
        wp_user_avatars_user_rating_form_field($user);
        ?>

					</fieldset>
				</td>
			</tr>

		<?php 
    }
    ?>

	</table>

<?php 
}
Example #2
0
/**
 * Output the rating field radio options for a given user object
 *
 * @since 0.1.0
 *
 * @param WP_User $user
 */
function wp_user_avatars_user_rating_form_field(WP_User $user)
{
    // Start an output buffer
    ob_start();
    // Output ratings
    foreach (wp_user_avatars_get_ratings() as $key => $rating) {
        ?>

		<label>
			<input type="radio" name="wp_user_avatars_rating" title="<?php 
        echo esc_html($rating);
        ?>
" value="<?php 
        echo esc_attr($key);
        ?>
" <?php 
        checked($user->wp_user_avatars_rating, $key);
        ?>
 />
			<span class="wp-user-avatar-rating"><?php 
        echo esc_html(strtoupper($key));
        ?>
</span>
			<span class="wp-user-avatar-rating-description"> &mdash; <?php 
        echo esc_html($rating);
        ?>
</span>
		</label>
		<br>

	<?php 
    }
    // Output the buffer
    echo ob_get_clean();
}