function upme_delete_profile_images() { global $user; $user_id = isset($_POST['user_id']) ? $_POST['user_id'] : ''; $custom_field_name = isset($_POST['field_name']) ? $_POST['field_name'] : ''; if (is_user_logged_in()) { $current_user_id = get_current_user_id(); if (current_user_can('edit_user', $current_user_id)) { $image_url = esc_url(get_the_author_meta($custom_field_name, $user_id)); $del_status = upme_delete_uploads_folder_files($image_url); if ($del_status && delete_user_meta($user_id, $custom_field_name)) { echo json_encode(array("status" => TRUE)); } else { echo json_encode(array("status" => FALSE)); } //upme_path } } die; }
function process_registration_upload($array, $upload_status, $params = array()) { $username = isset($params['username']) ? $params['username'] : ''; /* File upload conditions */ $this->allowed_extensions = array("image/gif", "image/jpeg", "image/png"); $this->allowed_exts = array('gif', 'png', 'jpeg', 'jpg'); $this->allowed_non_image_extensions = apply_filters('upme_non_image_extensions', array()); $this->allowed_non_image_exts = apply_filters('upme_non_image_exts', array()); $settings = get_option('upme_options'); // Set default to 500KB $this->max_size = 512000; $this->image_height = 0; $this->image_width = 0; // Setting Max File Size set from admin if (isset($settings['avatar_max_size']) && $settings['avatar_max_size'] > 0) { $this->max_size = $settings['avatar_max_size'] * 1024 * 1024; } if (isset($_FILES)) { foreach ($_FILES as $key => $array) { extract($array); if ($name) { $clean_file = true; if (in_array($type, $this->allowed_extensions)) { // Security Check Start // Checking for Image size. If this is a valid image (not tempered) then this function will return width and height and other values in return. $image_data = @getimagesize($tmp_name); if (!isset($image_data[0]) || !isset($image_data[1])) { $clean_file = false; } else { $this->image_height = $image_data[1]; $this->image_width = $image_data[0]; } // Security Check End } $clean_key = $key; /* UPME action for adding restrictions before uploading files */ $before_upload_profile_files_params = array(); do_action('upme_register_before_upload_profile_files', $username, $clean_key, $before_upload_profile_files_params); /* END action */ $field_label = $this->upme_fileds_meta_value_array[$clean_key]; // $upload_status 1 - Validation and $upload_status 2 - Uploading if ($upload_status == '1') { if (!in_array($type, $this->allowed_extensions) && !in_array($type, $this->allowed_non_image_extensions)) { $this->errors[$clean_key] = sprintf(__('The file you have selected for %s has a file extension that is not allowed. Please choose a different file.', 'upme'), $field_label) . '<br/>'; } elseif ($size > $this->max_size) { $this->errors[$clean_key] = sprintf(__('The file you have selected for %s exceeds the maximum allowed file size.', 'upme'), $field_label) . '<br/>'; } elseif ($clean_file == false) { $this->errors[$clean_key] = sprintf(__('The file you selected for %s appears to be corrupt or not a real image file.', 'upme'), $field_label) . '<br/>'; } elseif (!preg_match("/.(" . implode("|", $this->allowed_exts) . ")\$/i", $name) && !preg_match("/.(" . implode("|", $this->allowed_non_image_exts) . ")\$/i", $name)) { $this->errors[$clean_key] = sprintf(__('The file you have selected for %s has a file extension that is not allowed. Please choose a different file.', 'upme'), $field_label) . '<br/>'; } else { $upload_file_custom_validation_params = array('username' => $username, 'key' => $key, 'height' => $this->image_height, 'width' => $this->image_width, 'field_label' => $field_label); $custom_errors = apply_filters('upme_registration_upload_file_custom_validation', array('status' => false, 'msg' => ''), $upload_file_custom_validation_params); if ($custom_errors['status']) { $this->errors[$clean_key] = $custom_errors['msg']; } } } else { if ($upload_status == '2') { /* Upload image */ // Checking for valid uploads folder if ($upload_dir = upme_get_uploads_folder_details()) { $target_path = $upload_dir['basedir'] . "/upme/"; // Checking for upload directory, if not exists then new created. if (!is_dir($target_path)) { mkdir($target_path, 0777); } $base_name = sanitize_file_name(basename($name)); $target_path = $target_path . time() . '_' . $base_name; $nice_url = $upload_dir['baseurl'] . "/upme/"; $nice_url = $nice_url . time() . '_' . $base_name; move_uploaded_file($tmp_name, $target_path); /* Clean the previous file allocated for the current upload field */ $current_field_url = get_user_meta($this->userid, $clean_key, true); if ('' != $current_field_url) { upme_delete_uploads_folder_files($current_field_url); } /* Now we have the nice url */ /* Store in usermeta */ update_user_meta($this->userid, $clean_key, $nice_url); } } } /* UPME action for removing restrictions after uploading files */ $after_upload_profile_files_params = array(); do_action('upme_registration_after_upload_profile_files', $username, $clean_key, $after_upload_profile_files_params); /* END action */ } } } }