From 6117c60e9768833d9d7bab50d6620b27b6824b7a Mon Sep 17 00:00:00 2001 From: sy-records <52o@qq52o.cn> Date: Fri, 28 Jun 2024 09:12:52 +0800 Subject: [PATCH] Use wp_get_mime_types instead of get_allowed_mime_types --- aliyun-oss-wordpress.php | 7 +++---- oss-commands.php | 23 +++++++++++++++++++++++ readme.txt | 8 +++++++- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/aliyun-oss-wordpress.php b/aliyun-oss-wordpress.php index 9961fd7..45892f5 100644 --- a/aliyun-oss-wordpress.php +++ b/aliyun-oss-wordpress.php @@ -3,7 +3,7 @@ Plugin Name: OSS Aliyun Plugin URI: https://github.com/sy-records/aliyun-oss-wordpress Description: 使用阿里云对象存储 OSS 作为附件存储空间。(This is a plugin that uses Aliyun Object Storage Service for attachments remote saving.) -Version: 1.4.13 +Version: 1.4.14 Author: 沈唁 Author URI: https://qq52o.me License: Apache2.0 @@ -19,7 +19,7 @@ use OSS\Credentials\CredentialsProvider; use AlibabaCloud\Credentials\Credential; use OSS\Credentials\StaticCredentialsProvider; -define('OSS_VERSION', '1.4.13'); +define('OSS_VERSION', '1.4.14'); define('OSS_BASEFOLDER', plugin_basename(dirname(__FILE__))); if (!function_exists('get_home_path')) { @@ -237,7 +237,7 @@ function oss_delete_oss_files(array $files) */ function oss_upload_attachments($metadata) { - $mime_types = get_allowed_mime_types(); + $mime_types = wp_get_mime_types(); $image_mime_types = [ $mime_types['jpg|jpeg|jpe'], $mime_types['gif'], @@ -246,7 +246,6 @@ function oss_upload_attachments($metadata) $mime_types['tiff|tif'], $mime_types['webp'], $mime_types['ico'], - $mime_types['heic'], ]; // 例如mp4等格式 上传后根据配置选择是否删除 删除后媒体库会显示默认图片 点开内容是正常的 // 图片在缩略图处理 diff --git a/oss-commands.php b/oss-commands.php index 1fad8e5..87d4162 100644 --- a/oss-commands.php +++ b/oss-commands.php @@ -96,6 +96,29 @@ class OSS_CLI_Commands WP_CLI::error("Failed: {$path}"); } } + + /** + * 删除 OSS 中的文件 + * + * ## OPTIONS + * + * + * : 需要删除 OSS 中的文件 key + * + * ## EXAMPLES + * + * wp oss delete-file 2021/01/1.jpg + * + * @when after_wp_load + * @subcommand delete-file + */ + public function delete_file($args, $assoc_args) + { + [$key] = $args; + WP_CLI::line("Deleting file [{$key}] from OSS..."); + + oss_delete_oss_file($key); + } } WP_CLI::add_command('oss', 'OSS_CLI_Commands', ['shortdesc' => 'Commands used to operate OSS.']); diff --git a/readme.txt b/readme.txt index 153bf88..f1acc73 100644 --- a/readme.txt +++ b/readme.txt @@ -5,7 +5,7 @@ Tags: oss, 阿里云, 对象存储, aliyun Requires at least: 4.6 Tested up to: 6.5 Requires PHP: 7.1 -Stable tag: 1.4.13 +Stable tag: 1.4.14 License: Apache2.0 License URI: http://www.apache.org/licenses/LICENSE-2.0.html @@ -76,6 +76,12 @@ License URI: http://www.apache.org/licenses/LICENSE-2.0.html == Changelog == += 1.4.14 = + +- 支持 `wp-cli` 命令删除文件 +- Use wp_get_mime_types instead of get_allowed_mime_types +- 修复 heic 格式图片上传失败问题 + = 1.4.13 = - 支持 `wp-cli` 命令上传文件