From 7c56afa37617bbe297a30d556f59fe7abcc49d8a Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 11 Jul 2026 12:20:33 +0800 Subject: [PATCH] fix(admin): repair email rollback and product taxonomy APIs Call the existing Email_Rollback::list_pending method instead of the missing list_recent_changes method that caused /email-rollback/users to fatal. Add the product taxonomy route expected by ProductEditorDrawer and return category/tag options for the editor. --- ...min-shop-controller-product-operations.php | 30 +++++++++++++++++++ .../class-aksrt-admin-shop-controller.php | 7 +++++ .../class-aksrt-admin-tools-controller.php | 2 +- 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/inc/classes/admin/class-aksrt-admin-shop-controller-product-operations.php b/inc/classes/admin/class-aksrt-admin-shop-controller-product-operations.php index 18c919e9..7208a479 100644 --- a/inc/classes/admin/class-aksrt-admin-shop-controller-product-operations.php +++ b/inc/classes/admin/class-aksrt-admin-shop-controller-product-operations.php @@ -46,6 +46,36 @@ trait AKSRT_Admin_Shop_Controller_Product_Operations { ]); } + public function get_product_taxonomy(): WP_REST_Response { + $format_terms = static function (string $taxonomy): array { + if (!taxonomy_exists($taxonomy)) { + return []; + } + + $terms = get_terms([ + 'taxonomy' => $taxonomy, + 'hide_empty' => false, + ]); + if (is_wp_error($terms)) { + return []; + } + + return array_map(static function (WP_Term $term): array { + return [ + 'id' => $term->term_id, + 'name' => $term->name, + ]; + }, $terms); + }; + + return $this->success([ + 'data' => [ + 'categories' => $format_terms('aksrt_product_cat'), + 'tags' => $format_terms('aksrt_product_tag'), + ], + ]); + } + /** * GET /shop/products — 商品列表,支持 search、status、page、per_page */ diff --git a/inc/classes/admin/class-aksrt-admin-shop-controller.php b/inc/classes/admin/class-aksrt-admin-shop-controller.php index 5a8a8ff5..2232e69f 100644 --- a/inc/classes/admin/class-aksrt-admin-shop-controller.php +++ b/inc/classes/admin/class-aksrt-admin-shop-controller.php @@ -168,6 +168,13 @@ class AKSRT_Admin_Shop_Controller extends AKSRT_Admin_Controller_Base { 'permission_callback' => [$this, 'check_permission'], ]); + // Product taxonomy options used by the product editor. + register_rest_route(self::API_NAMESPACE, '/shop/products/taxonomy', [ + 'methods' => 'GET', + 'callback' => [$this, 'get_product_taxonomy'], + 'permission_callback' => [$this, 'check_permission'], + ]); + // Product list register_rest_route(self::API_NAMESPACE, '/shop/products', [ 'methods' => 'GET', diff --git a/inc/classes/admin/class-aksrt-admin-tools-controller.php b/inc/classes/admin/class-aksrt-admin-tools-controller.php index 4a96f2bb..fc695cd6 100644 --- a/inc/classes/admin/class-aksrt-admin-tools-controller.php +++ b/inc/classes/admin/class-aksrt-admin-tools-controller.php @@ -261,7 +261,7 @@ class AKSRT_Admin_Tools_Controller extends AKSRT_Admin_Controller_Base { $page = max(1, (int) $request->get_param('page')); $per_page = min(100, max(1, (int) $request->get_param('per_page'))); - $data = AKSRT_Email_Rollback::list_recent_changes($page, $per_page); + $data = AKSRT_Email_Rollback::list_pending($page, $per_page); return $this->success(['data' => $data]); }