PluginProbe
Code Engine – PHP Snippets, AI Functions & Automation for WordPress / 0.3.4
Code Engine – PHP Snippets, AI Functions & Automation for WordPress v0.3.4
0.5.6 0.5.5 0.5.4 0.5.3 0.5.2 0.5.1 0.5.0 0.4.9 0.4.8 0.4.7 0.4.6 trunk 0.0.1 0.0.2 0.2.8 0.2.9 0.3.0 0.3.1 0.3.2 0.3.3 0.3.4 0.3.5 0.3.6 0.3.7 0.3.8 All 32 releases
← All changes | classes/rest.php +0 -86 trunk0.3.4 View file →
@@ -71,19 +71,8 @@
71 71 'permission_callback' => array( $this->core, 'can_access_settings' ),
72 72 'callback' => array( $this, 'rest_server_clock' ),
73 73 ) );
74 74
75 - register_rest_route( $this->namespace, '/fetch_posts', array(
76 - 'methods' => 'POST',
77 - 'permission_callback' => array( $this->core, 'can_access_features' ),
78 - 'callback' => array( $this, 'rest_fetch_posts' ),
79 - 'args' => array(
80 - 'search' => array( 'required' => false ),
81 - 'offset' => array( 'required' => false, 'default' => 0 ),
82 - 'limit' => array( 'required' => false, 'default' => 10 ),
83 - )
84 - ) );
85 -
86 75 #endregion
87 76
88 77 #region REST AI Engine
89 78 register_rest_route( $this->namespace, '/ai_read_comments', array(
@@ -162,15 +151,9 @@
162 151 'callback' => array($this, 'rest_replace'),
163 152 'permission_callback' => array($this->core, 'can_access_settings')
164 153 ));
165 154
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 - ));
171 155
172 -
173 156 // SNIPPETS ENDPOINTS
174 157 $snippets = $this->snippet->select(
175 158 null, // offset
176 159 -1, // limit
@@ -445,68 +428,8 @@
445 428
446 429 return new WP_REST_Response( [ 'success' => true, 'time' => $now ], 200 );
447 430 }
448 431
449 - function rest_fetch_posts( $request ) {
450 - try {
451 - $params = $request->get_json_params();
452 - $search = isset($params['search']) ? $params['search'] : '';
453 - $offset = isset($params['offset']) ? intval($params['offset']) : 0;
454 - $limit = isset($params['limit']) ? intval($params['limit']) : 10;
455 -
456 - global $wpdb;
457 - $searchPlaceholder = $search ? '%' . $search . '%' : '';
458 - $where_search_clause = $search ? $wpdb->prepare(
459 - "AND ( p.post_title LIKE %s OR p.post_content LIKE %s OR p.post_name LIKE %s ) ",
460 - $searchPlaceholder,
461 - $searchPlaceholder,
462 - $searchPlaceholder
463 - ) : '';
464 -
465 - $posts = $wpdb->get_results(
466 - $wpdb->prepare(
467 - "SELECT p.ID, p.post_title, p.post_date, p.post_status, u.display_name as author
468 - FROM $wpdb->posts p
469 - LEFT JOIN $wpdb->users u ON p.post_author = u.ID
470 - WHERE p.post_type = 'post'
471 - AND p.post_status IN ('publish', 'draft', 'private')
472 - $where_search_clause
473 - ORDER BY p.post_date DESC
474 - LIMIT %d, %d",
475 - $offset,
476 - $limit
477 - ),
478 - OBJECT
479 - );
480 -
481 - $posts_count = (int)$wpdb->get_var(
482 - "SELECT COUNT(*)
483 - FROM $wpdb->posts p
484 - WHERE p.post_type = 'post'
485 - AND p.post_status IN ('publish', 'draft', 'private')
486 - $where_search_clause"
487 - );
488 -
489 - $data = array_map(function($post) {
490 - return [
491 - 'id' => $post->ID,
492 - 'title' => $post->post_title,
493 - 'date' => $post->post_date,
494 - 'author' => $post->author,
495 - 'status' => $post->post_status
496 - ];
497 - }, $posts);
498 -
499 - return new WP_REST_Response([
500 - 'success' => true,
501 - 'data' => $data,
502 - 'total' => $posts_count
503 - ], 200);
504 - } catch (Exception $e) {
505 - return new WP_REST_Response(['success' => false, 'message' => $e->getMessage()], 500);
506 - }
507 - }
508 -
509 432 #endregion
510 433
511 434 #region AI Engine
512 435
@@ -808,17 +731,8 @@
808 731 $result[] = $this->snippet->insert( $snippet );
809 732 }
810 733
811 734 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);
821 735 } catch (Exception $e) {
822 736 return new WP_REST_Response( ['success' => false, 'message' => $e->getMessage() ], 500 );
823 737 }
824 738 }