Example #1
0
/**
 * user_avatar_add_photo_step3 function.
 * The Third Step in the Process
 * Description: Deletes previous uploaded picture and creates a new cropped image in its place. 
 * @access public
 * @param mixed $uid
 * @return void
 */
function user_avatar_add_photo_step3($uid)
{
    check_admin_referer('user-avatar');
    if ($_POST['oitar'] > 1) {
        $_POST['x1'] = $_POST['x1'] * $_POST['oitar'];
        $_POST['y1'] = $_POST['y1'] * $_POST['oitar'];
        $_POST['width'] = $_POST['width'] * $_POST['oitar'];
        $_POST['height'] = $_POST['height'] * $_POST['oitar'];
    }
    if (!file_exists($_POST['attachment_file'])) {
        echo "<div class='error'><p>Sorry, No file available</p></div>";
        return true;
    }
    $original_file = $_POST['attachment_file'];
    $cropped_full = USER_AVATAR_UPLOAD_PATH . "{$uid}/" . time() . "-bpfull.jpg";
    $cropped_thumb = USER_AVATAR_UPLOAD_PATH . "{$uid}/" . time() . "-bpthumb.jpg";
    // delete the previous files
    user_avatar_delete_files($uid);
    if (!file_exists(USER_AVATAR_UPLOAD_PATH . "{$uid}/")) {
        mkdir(USER_AVATAR_UPLOAD_PATH . "{$uid}/");
    }
    // update the files
    $cropped_full = wp_crop_image($original_file, $_POST['x1'], $_POST['y1'], $_POST['width'], $_POST['height'], USER_AVATAR_FULL_WIDTH, USER_AVATAR_FULL_HEIGHT, false, $cropped_full);
    $cropped_thumb = wp_crop_image($original_file, $_POST['x1'], $_POST['y1'], $_POST['width'], $_POST['height'], USER_AVATAR_THUMB_WIDTH, USER_AVATAR_THUMB_HEIGHT, false, $cropped_thumb);
    /* Remove the original */
    @unlink($original_file);
    if (is_wp_error($cropped_full)) {
        wp_die(__('Image could not be processed.  Please go back and try again.'), __('Image Processing Error'));
    }
    ?>
	
	<script type="text/javascript">
		self.parent.user_avatar_refresh_image('<?php 
    echo get_avatar($uid, 150);
    ?>
');
	</script>
	<div id="user-avatar-step3">
		<h3>Here's your new profile picture...</h3>
		<span style="float:left;">
		<?php 
    echo get_avatar($uid, 150);
    ?>
		</span>
		<a id="user-avatar-step3-close" class="button" onclick="self.parent.tb_remove();" >Close</a>
	</div>
<?php 
}
Example #2
0
/**
 * user_avatar_delete function.
 * 
 * @access public
 * @return void
 */
function user_avatar_delete()
{
    global $pagenow;
    $current_user = wp_get_current_user();
    // If user clicks the remove avatar button, in URL deleter_avatar=true
    if (isset($_GET['delete_avatar']) && wp_verify_nonce($_GET['_nononce'], 'user_avatar') && ($_GET['u'] == $current_user->id || current_user_can('edit_users'))) {
        $user_id = $_GET['user_id'];
        if (is_numeric($user_id)) {
            $user_id = "?user_id=" . $user_id;
        }
        user_avatar_delete_files($_GET['u']);
        wp_redirect(get_option('siteurl') . '/wp-admin/' . $pagenow . $user_id);
    }
}