| @@ -162,9 +162,15 @@ | ||
| 162 | 162 | 'callback' => array($this, 'rest_replace'), |
| 163 | 163 | 'permission_callback' => array($this->core, 'can_access_settings') |
| 164 | 164 | )); |
| 165 | 165 | |
| 166 | + register_rest_route($this->namespace, '/snippets/delete_duplicates', array( | |
| 167 | + 'methods' => 'POST', | |
| 168 | + 'callback' => array($this, 'rest_delete_duplicates'), | |
| 169 | + 'permission_callback' => array($this->core, 'can_access_settings') | |
| 170 | + )); | |
| 166 | 171 | |
| 172 | + | |
| 167 | 173 | // SNIPPETS ENDPOINTS |
| 168 | 174 | $snippets = $this->snippet->select( |
| 169 | 175 | null, // offset |
| 170 | 176 | -1, // limit |
| @@ -802,8 +808,17 @@ | ||
| 802 | 808 | $result[] = $this->snippet->insert( $snippet ); |
| 803 | 809 | } |
| 804 | 810 | |
| 805 | 811 | return new WP_REST_Response([ 'success' => true, 'data' => $result ], 200); |
| 812 | + } catch (Exception $e) { | |
| 813 | + return new WP_REST_Response( ['success' => false, 'message' => $e->getMessage() ], 500 ); | |
| 814 | + } | |
| 815 | + } | |
| 816 | + | |
| 817 | + public function rest_delete_duplicates() { | |
| 818 | + try { | |
| 819 | + $result = $this->snippet->delete_duplicates(); | |
| 820 | + return new WP_REST_Response([ 'success' => true, 'data' => [ 'deleted' => $result ] ], 200); | |
| 806 | 821 | } catch (Exception $e) { |
| 807 | 822 | return new WP_REST_Response( ['success' => false, 'message' => $e->getMessage() ], 500 ); |
| 808 | 823 | } |
| 809 | 824 | } |