/** * Modify the output of the field on the fronted profile. * * @since 1.2.0 * @param string $value the value of the field. * @param object $field field details. * @return string the formatted field value. */ public static function output_html($value, $field) { $files = $value; $output = ''; // Display files if they're images. if (wpum_is_multi_array($files)) { foreach ($files as $key => $file) { $extension = !empty($extension) ? $extension : substr(strrchr($file['url'], '.'), 1); if (3 !== strlen($extension) || in_array($extension, array('jpg', 'gif', 'png', 'jpeg', 'jpe'))) { $output .= '<span class="wpum-uploaded-file-preview"><img src="' . esc_url($file['url']) . '" /></span>'; } else { $output .= ' <span class="wpum-uploaded-file-name"><code>' . esc_html(basename($file['url'])) . '</code></span>'; } } // We have a single file. } else { $extension = !empty($extension) ? $extension : substr(strrchr($files['url'], '.'), 1); if (3 !== strlen($extension) || in_array($extension, array('jpg', 'gif', 'png', 'jpeg', 'jpe'))) { $output .= '<span class="wpum-uploaded-file-preview"><img src="' . esc_url($files['url']) . '" /></span>'; } else { $output .= ' <span class="wpum-uploaded-file-name"><code>' . esc_html(basename($files['url'])) . '</code></span>'; } } return $output; }
$allowed_mime_types = array_keys(!empty($field['allowed_mime_types']) ? $field['allowed_mime_types'] : get_allowed_mime_types()); $field_name = isset($field['name']) ? $field['name'] : $key; // Store current field files. $field_files = isset($field['value']) ? $field['value'] : ''; ?> <?php if (!is_page(wpum_get_core_page_id('register'))) { ?> <div class="wpum-uploaded-files"> <?php if (!empty($field['value']) && !is_wp_error($field['value'])) { // Check if we have multiple files. if (wpum_is_multi_array($field_files)) { foreach ($field_files as $key => $file) { get_wpum_template('form-fields/uploaded-file-html.php', array('key' => $key, 'name' => 'current_' . $field_name, 'value' => $file['url'], 'field' => $field, 'field_name' => $field_name, 'number' => $key)); } // We have single file. } else { get_wpum_template('form-fields/uploaded-file-html.php', array('key' => $key, 'name' => 'current_' . $field_name, 'value' => $field_files, 'field' => $field, 'field_name' => $field_name)); } } ?> </div> <?php if (!empty($field_files)) { ?>
/** * Remove the avatar of a user. * * @access public * @since 1.0.0 * @return void */ public function remove_user_file() { $form = esc_attr($_REQUEST['submitted_form']); check_ajax_referer($form, 'wpum_removal_nonce'); $field_id = $_REQUEST['field_id']; $user_id = get_current_user_id(); // Functionality to remove avatar. if ($field_id == 'user_avatar') { if ($field_id && is_user_logged_in()) { delete_user_meta($user_id, "current_{$field_id}"); // Deletes previously selected avatar. $previous_avatar = get_user_meta($user_id, "_current_{$field_id}_path", true); if ($previous_avatar) { wp_delete_file($previous_avatar); } delete_user_meta($user_id, "_current_{$field_id}_path"); $return = array('valid' => true, 'message' => apply_filters('wpum_avatar_deleted_success_message', __('Your profile picture has been deleted.', 'wpum'))); wp_send_json_success($return); } else { $return = array('valid' => false, 'message' => __('Something went wrong.', 'wpum')); wp_send_json_error($return); } // This is needed for all the other field types. } else { if ($field_id && is_user_logged_in()) { $field_files = get_user_meta($user_id, $field_id, true); $field_files = maybe_unserialize($field_files); if (is_array($field_files)) { if (wpum_is_multi_array($field_files)) { foreach ($field_files as $key => $file) { wp_delete_file($file['path']); } } else { wp_delete_file($field_files['path']); } } delete_user_meta($user_id, $field_id); $return = array('valid' => true, 'message' => apply_filters('wpum_files_deleted_success_message', __('Files successfully removed.', 'wpum'))); wp_send_json_success($return); } } }