PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 3.6.8
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v3.6.8
3.7.5 3.7.4 3.7.3 3.7.2 1-final 3.7.1 3.7.0 3.6.8 3.6.7 3.6.6 3.6.5 3.6.4 3.6.3 3.6.2 3.6.1 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.10 All 111 releases
← All changes | includes/API/Conditions.php +30 -10 3.0.83.6.8 View file →
@@ -95,28 +95,46 @@
95 95 public function autocomplete( WP_REST_Request $request ): WP_REST_Response {
96 96 $query = $request->get_param( 'query' );
97 97 $type = $query['query_type'] ?? '';
98 98
99 - if ( empty( $type ) ) {
100 - // FIXME: need throw error maybe
99 + $allowed_fields = [
100 + 'authors' => [ 'ID', 'user_nicename', 'display_name' ],
101 + 'posts' => [ 'ID', 'post_title', 'post_name' ],
102 + 'taxonomy' => [ 'term_id', 'slug', 'name' ],
103 + ];
104 +
105 + if ( empty( $type ) || ! isset( $allowed_fields[ $type ] ) ) {
101 106 return $this->success( [] );
102 107 }
103 108
104 109 $by_field = $query['field'] ?? '';
105 110
106 - if ( empty( $by_field ) ) {
107 - // FIXME: need throw error maybe
111 + if ( empty( $by_field ) || ! in_array( $by_field, $allowed_fields[ $type ], true ) ) {
108 112 return $this->success( [] );
109 113 }
110 114
115 + if ( 'authors' === $type && ! current_user_can( 'list_users' ) ) {
116 + return $this->success( [] );
117 + }
118 +
111 119 $payload = sanitize_text_field( $request->get_param( 'payload' ) );
112 120 $args = [ 'search' => $payload ];
121 + if ( is_numeric( $payload ) ) {
122 + $args = [ 'post__in' => [ (int) $payload ] ];
123 + }
113 124
114 - if ( isset( $query['query'] ) ) {
115 - $args = wp_parse_args( $query['query'], $args );
125 + if ( isset( $query['query'] ) && is_array( $query['query'] ) ) {
126 + $safe_query_keys = [
127 + 'post_type', 'posts_per_page', 'number', 'orderby', 'order',
128 + 'taxonomy', 'parent', 'hide_empty',
129 + ];
130 + $safe_query = array_intersect_key( $query['query'], array_flip( $safe_query_keys ) );
131 + $args = wp_parse_args( $safe_query, $args );
116 132 }
117 133
118 - $results = [];
134 + $results = [];
135 + $data = [];
136 + $data_key = '';
119 137
120 138 switch ( $type ) {
121 139 case 'taxonomy':
122 140 $_default = [ 'hide_empty' => false ];
@@ -123,11 +141,13 @@
123 141 $data = get_terms( wp_parse_args( $args, $_default ) );
124 142 $data_key = 'name';
125 143 break;
126 144 case 'posts':
127 - $args['s'] = $args['search'];
128 - $data = get_posts( $args );
129 - $data_key = 'post_title';
145 + $args['s'] = $args['search'];
146 + $args['post_status'] = 'publish';
147 + $args['perm'] = 'readable';
148 + $data = get_posts( $args );
149 + $data_key = 'post_title';
130 150 break;
131 151 case 'authors':
132 152 $args['search_columns'] = [ 'user_nicename', 'user_login' ];
133 153 $args['search'] = "*{$args['search']}*";