PluginProbe
Elementor Website Builder – more than just a page builder / 3.35.0-dev4
Elementor Website Builder – more than just a page builder v3.35.0-dev4
4.3.1 4.3.0 4.3.0-beta3 4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 All 454 releases
← All changes | modules/wp-rest/classes/post-query.php +19 -51 4.2.0-beta13.35.0-dev4 View file →
@@ -12,14 +12,8 @@
12 12 class Post_Query extends Base {
13 13 const ENDPOINT = 'post';
14 14 const SEARCH_FILTER_ACCEPTED_ARGS = 2;
15 15 const DEFAULT_FORBIDDEN_POST_TYPES = [ 'e-floating-buttons', 'e-landing-page', 'elementor_library', 'attachment', 'revision', 'nav_menu_item', 'custom_css', 'customize_changeset' ];
16 - const SEARCH_IN_CONTENT_KEY = 'search_in_content';
17 - const ALLOWED_KEYS_CONVERSION_MAP = [
18 - 'ID' => 'id',
19 - 'post_title' => 'label',
20 - 'post_type' => 'groupLabel',
21 - ];
22 16
23 17 /**
24 18 * @param string $search_term The original search query.
25 19 * @param \WP_Query $wp_query The WP_Query instance.
@@ -30,15 +24,10 @@
30 24 $is_custom_search = $wp_query->get( 'custom_search' ) ?? false;
31 25
32 26 if ( $is_custom_search && ! empty( $term ) ) {
33 27 $escaped = esc_sql( $term );
34 - $search_in_content = $wp_query->get( self::SEARCH_IN_CONTENT_KEY ) ?? false;
35 28 $search_term .= ' AND (';
36 29 $search_term .= "post_title LIKE '%{$escaped}%'";
37 - if ( $search_in_content ) {
38 - $search_term .= " OR post_content LIKE '%{$escaped}%'";
39 - $search_term .= " OR post_excerpt LIKE '%{$escaped}%'";
40 - }
41 30 if ( ctype_digit( $term ) ) {
42 31 $search_term .= ' OR ID = ' . intval( $term );
43 32 } else {
44 33 $search_term .= " OR ID LIKE '%{$escaped}%'";
@@ -65,28 +54,24 @@
65 54 ],
66 55 ], 200 );
67 56 }
68 57
69 - $keys_format_map = $this->filter_keys_conversion_map(
70 - $params[ self::KEYS_CONVERSION_MAP_KEY ] ?? self::ALLOWED_KEYS_CONVERSION_MAP,
71 - self::ALLOWED_KEYS_CONVERSION_MAP
72 - );
58 + $keys_format_map = $params[ self::KEYS_CONVERSION_MAP_KEY ];
73 59 $requested_count = $params[ self::ITEMS_COUNT_KEY ] ?? 0;
74 60 $validated_count = max( $requested_count, 1 );
75 61 $post_count = min( $validated_count, self::MAX_RESPONSE_COUNT );
76 62 $is_public_only = $params[ self::IS_PUBLIC_KEY ] ?? true;
77 - $post_types = $this->get_post_types_from_params( $request );
63 + $post_types = $this->get_post_types_from_params( $params );
78 64
79 65 $query_args = [
80 - 'post_type' => array_keys( $post_types ),
81 - 'numberposts' => $post_count,
82 - 'suppress_filters' => false,
83 - 'custom_search' => true,
84 - 'search_term' => $term,
85 - self::SEARCH_IN_CONTENT_KEY => $params[ self::SEARCH_IN_CONTENT_KEY ] ?? false,
86 - 'post_status' => $is_public_only ? 'publish' : 'any',
87 - 'orderby' => 'ID',
88 - 'order' => 'ASC',
66 + 'post_type' => array_keys( $post_types ),
67 + 'numberposts' => $post_count,
68 + 'suppress_filters' => false,
69 + 'custom_search' => true,
70 + 'search_term' => $term,
71 + 'post_status' => $is_public_only ? 'publish' : 'any',
72 + 'orderby' => 'ID',
73 + 'order' => 'ASC',
89 74 ];
90 75
91 76 if ( ! empty( $params[ self::META_QUERY_KEY ] ) && is_array( $params[ self::META_QUERY_KEY ] ) ) {
92 77 $query_args['meta_query'] = $params[ self::META_QUERY_KEY ];
@@ -109,24 +94,18 @@
109 94 return new \WP_REST_Response( [
110 95 'success' => true,
111 96 'data' => [
112 97 'value' => $posts
113 - ->filter( function ( $post ) {
114 - return current_user_can( 'read_post', $post->ID );
115 - } )
116 98 ->map( function ( $post ) use ( $keys_format_map, $post_type_labels ) {
117 - $post_type_label = $post->post_type;
99 + $post_object = (array) $post;
118 100
119 - if ( isset( $post_type_labels[ $post->post_type ] ) ) {
120 - $post_type_label = $post_type_labels[ $post->post_type ];
101 + if ( isset( $post_object['post_type'] ) ) {
102 + $pt_name = $post_object['post_type'];
103 + if ( isset( $post_type_labels[ $pt_name ] ) ) {
104 + $post_object['post_type'] = $post_type_labels[ $pt_name ];
105 + }
121 106 }
122 107
123 - $post_object = [
124 - 'ID' => $post->ID,
125 - 'post_title' => $post->post_title,
126 - 'post_type' => $post_type_label,
127 - ];
128 -
129 108 return $this->translate_keys( $post_object, $keys_format_map );
130 109 } )
131 110 ->all(),
132 111 ],
@@ -152,12 +131,8 @@
152 131
153 132 remove_filter( 'posts_search', [ $this, 'customize_post_query' ], $priority, $accepted_args );
154 133 }
155 134
156 - protected function permission_check( \WP_REST_Request $request ): bool {
157 - return current_user_can( 'edit_posts' );
158 - }
159 -
160 135 protected function get_endpoint_registration_args(): array {
161 136 return [
162 137 self::INCLUDED_TYPE_KEY => [
163 138 'description' => 'Included post types',
@@ -216,14 +191,8 @@
216 191 'required' => false,
217 192 'default' => null,
218 193 'sanitize_callback' => fn ( ...$args ) => self::sanitize_string_array( ...$args ),
219 194 ],
220 - self::SEARCH_IN_CONTENT_KEY => [
221 - 'description' => 'Whether to search within post content and excerpt in addition to title',
222 - 'type' => 'boolean',
223 - 'required' => false,
224 - 'default' => false,
225 - ],
226 195 ];
227 196 }
228 197
229 198 protected static function get_allowed_param_keys(): array {
@@ -234,9 +203,8 @@
234 203 self::META_QUERY_KEY,
235 204 self::TAX_QUERY_KEY,
236 205 self::IS_PUBLIC_KEY,
237 206 self::ITEMS_COUNT_KEY,
238 - self::SEARCH_IN_CONTENT_KEY,
239 207 ];
240 208 }
241 209
242 210 protected static function get_keys_to_encode(): array {
@@ -248,11 +216,11 @@
248 216 self::TAX_QUERY_KEY,
249 217 ];
250 218 }
251 219
252 - private function get_post_types_from_params( \WP_REST_Request $request ) {
253 - $included_types = $request->get_param( self::INCLUDED_TYPE_KEY );
254 - $excluded_types = $request->get_param( self::EXCLUDED_TYPE_KEY );
220 + private function get_post_types_from_params( $params ) {
221 + $included_types = $params[ self::INCLUDED_TYPE_KEY ];
222 + $excluded_types = $params[ self::EXCLUDED_TYPE_KEY ];
255 223 $post_type_query_args = [
256 224 'public' => true,
257 225 ];
258 226