PluginProbe
Elementor Website Builder – more than just a page builder / 3.35.8
Elementor Website Builder – more than just a page builder v3.35.8
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 4.1.0-beta1 4.1.0-dev1 All 452 releases
← All changes | modules/wp-rest/classes/post-query.php +11 -30 4.1.43.35.8 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.
@@ -60,17 +54,14 @@
60 54 ],
61 55 ], 200 );
62 56 }
63 57
64 - $keys_format_map = $this->filter_keys_conversion_map(
65 - $params[ self::KEYS_CONVERSION_MAP_KEY ] ?? self::ALLOWED_KEYS_CONVERSION_MAP,
66 - self::ALLOWED_KEYS_CONVERSION_MAP
67 - );
58 + $keys_format_map = $params[ self::KEYS_CONVERSION_MAP_KEY ];
68 59 $requested_count = $params[ self::ITEMS_COUNT_KEY ] ?? 0;
69 60 $validated_count = max( $requested_count, 1 );
70 61 $post_count = min( $validated_count, self::MAX_RESPONSE_COUNT );
71 62 $is_public_only = $params[ self::IS_PUBLIC_KEY ] ?? true;
72 - $post_types = $this->get_post_types_from_params( $request );
63 + $post_types = $this->get_post_types_from_params( $params );
73 64
74 65 $query_args = [
75 66 'post_type' => array_keys( $post_types ),
76 67 'numberposts' => $post_count,
@@ -103,24 +94,18 @@
103 94 return new \WP_REST_Response( [
104 95 'success' => true,
105 96 'data' => [
106 97 'value' => $posts
107 - ->filter( function ( $post ) {
108 - return current_user_can( 'read_post', $post->ID );
109 - } )
110 98 ->map( function ( $post ) use ( $keys_format_map, $post_type_labels ) {
111 - $post_type_label = $post->post_type;
99 + $post_object = (array) $post;
112 100
113 - if ( isset( $post_type_labels[ $post->post_type ] ) ) {
114 - $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 + }
115 106 }
116 107
117 - $post_object = [
118 - 'ID' => $post->ID,
119 - 'post_title' => $post->post_title,
120 - 'post_type' => $post_type_label,
121 - ];
122 -
123 108 return $this->translate_keys( $post_object, $keys_format_map );
124 109 } )
125 110 ->all(),
126 111 ],
@@ -146,12 +131,8 @@
146 131
147 132 remove_filter( 'posts_search', [ $this, 'customize_post_query' ], $priority, $accepted_args );
148 133 }
149 134
150 - protected function permission_check( \WP_REST_Request $request ): bool {
151 - return current_user_can( 'edit_posts' );
152 - }
153 -
154 135 protected function get_endpoint_registration_args(): array {
155 136 return [
156 137 self::INCLUDED_TYPE_KEY => [
157 138 'description' => 'Included post types',
@@ -235,11 +216,11 @@
235 216 self::TAX_QUERY_KEY,
236 217 ];
237 218 }
238 219
239 - private function get_post_types_from_params( \WP_REST_Request $request ) {
240 - $included_types = $request->get_param( self::INCLUDED_TYPE_KEY );
241 - $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 ];
242 223 $post_type_query_args = [
243 224 'public' => true,
244 225 ];
245 226