This repository was archived by the owner on Feb 23, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -94,6 +94,20 @@ public static function get_patterns_ai_data_post() {
94
94
return $ posts [0 ] ?? null ;
95
95
}
96
96
97
+ /**
98
+ * Delete the post that has the generated data by the AI for the patterns.
99
+ *
100
+ * @return \WP_Post|null
101
+ */
102
+ public static function delete_patterns_ai_data_post () {
103
+ $ patterns_ai_data_post = self ::get_patterns_ai_data_post ();
104
+
105
+ if ( isset ( $ patterns_ai_data_post ) ) {
106
+ return wp_delete_post ( $ patterns_ai_data_post ->ID , true );
107
+ }
108
+ }
109
+
110
+
97
111
/**
98
112
* Upsert the patterns AI data.
99
113
*
Original file line number Diff line number Diff line change 3
3
namespace Automattic \WooCommerce \StoreApi \Routes \V1 \AI ;
4
4
5
5
use Automattic \WooCommerce \Blocks \AI \Connection ;
6
+ use Automattic \WooCommerce \Blocks \Patterns \PatternsHelper ;
6
7
use Automattic \WooCommerce \Blocks \Patterns \PatternUpdater ;
7
8
use Automattic \WooCommerce \StoreApi \Routes \V1 \AbstractRoute ;
8
9
@@ -57,6 +58,11 @@ public function get_args() {
57
58
],
58
59
],
59
60
],
61
+ [
62
+ 'methods ' => \WP_REST_Server::DELETABLE ,
63
+ 'callback ' => [ $ this , 'get_response ' ],
64
+ 'permission_callback ' => [ Middleware::class, 'is_authorized ' ],
65
+ ],
60
66
'schema ' => [ $ this ->schema , 'get_public_item_schema ' ],
61
67
'allow_batch ' => [ 'v1 ' => true ],
62
68
];
@@ -91,4 +97,16 @@ protected function get_route_post_response( \WP_REST_Request $request ) {
91
97
return $ this ->error_to_response ( $ e );
92
98
}
93
99
}
100
+
101
+ /**
102
+ * Remove patterns generated by AI.
103
+ *
104
+ * @param \WP_REST_Request $request Request object.
105
+ *
106
+ * @return bool|string|\WP_Error|\WP_REST_Response
107
+ */
108
+ protected function get_route_delete_response ( \WP_REST_Request $ request ) {
109
+ PatternsHelper::delete_patterns_ai_data_post ();
110
+ return rest_ensure_response ( array ( 'removed ' => true ) );
111
+ }
94
112
}
You can’t perform that action at this time.
0 commit comments