function upload_flag($id) { $result = false; $validated = !empty($_FILES['icl_edit_languages']['tmp_name'][$id]['flag_file']); if ($validated) { $filename = basename($_FILES['icl_edit_languages']['name'][$id]['flag_file']); $target_path = $this->upload_dir . '/' . $filename; $wpml_wp_api = new WPML_WP_API(); $mime = $wpml_wp_api->get_file_mime_type($_FILES['icl_edit_languages']['tmp_name'][$id]['flag_file']); $allowed_mime_types = array_values($this->allowed_flag_mime_types); $validated = in_array($mime, $allowed_mime_types, true); if ($validated && move_uploaded_file($_FILES['icl_edit_languages']['tmp_name'][$id]['flag_file'], $target_path)) { if (function_exists('wp_get_image_editor') && 'image/svg+xml' !== $mime) { $image = wp_get_image_editor($target_path); if (!is_wp_error($image)) { $image->resize(18, 12, true); $image->save($target_path); } } $result = $filename; } } if (!$validated) { $error_message = __('There was an error uploading the file, please try again!', 'sitepress'); if (!empty($_FILES['icl_edit_languages']['error'][$id]['flag_file'])) { switch ($_FILES['icl_edit_languages']['error'][$id]['flag_file']) { case UPLOAD_ERR_INI_SIZE: $error_message = __('The uploaded file exceeds the upload_max_filesize directive in php.ini.', 'sitepress'); break; case UPLOAD_ERR_FORM_SIZE: $error_message = sprintf(__('The uploaded file exceeds %s bytes.', 'sitepress'), $this->max_file_size); break; case UPLOAD_ERR_PARTIAL: $error_message = __('The uploaded file was only partially uploaded.', 'sitepress'); break; case UPLOAD_ERR_NO_FILE: $error_message = __('No file was uploaded.', 'sitepress'); break; case UPLOAD_ERR_NO_TMP_DIR: $error_message = __('Missing a temporary folder.', 'sitepress'); break; case UPLOAD_ERR_CANT_WRITE: $error_message = __('Failed to write file to disk.', 'sitepress'); break; case UPLOAD_ERR_EXTENSION: $error_message = __('A PHP extension stopped the file upload. PHP does not provide a way to ascertain which extension caused the file upload to stop; examining the list of loaded extensions with phpinfo() may help.', 'sitepress'); break; } } $this->error($error_message); } return $result; }