Merge pull request 'fix(admin): repair email rollback and product taxonomy APIs' (#46) from worktree-fix-admin-api-gaps into main
Reviewed-on: CYL/wordpress-theme-aksrt#46
This commit is contained in:
commit
67fdf83db3
3 files changed
+38
-1
No files matched your search
@@ -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
|
* GET /shop/products — 商品列表,支持 search、status、page、per_page
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -168,6 +168,13 @@ class AKSRT_Admin_Shop_Controller extends AKSRT_Admin_Controller_Base {
|
|||||||
'permission_callback' => [$this, 'check_permission'],
|
'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
|
// Product list
|
||||||
register_rest_route(self::API_NAMESPACE, '/shop/products', [
|
register_rest_route(self::API_NAMESPACE, '/shop/products', [
|
||||||
'methods' => 'GET',
|
'methods' => 'GET',
|
||||||
|
|||||||
@@ -261,7 +261,7 @@ class AKSRT_Admin_Tools_Controller extends AKSRT_Admin_Controller_Base {
|
|||||||
|
|
||||||
$page = max(1, (int) $request->get_param('page'));
|
$page = max(1, (int) $request->get_param('page'));
|
||||||
$per_page = min(100, max(1, (int) $request->get_param('per_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]);
|
return $this->success(['data' => $data]);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user