PluginProbe
ElasticPress / 5.3.5
ElasticPress v5.3.5
5.3.5 5.3.4 3.6.5 3.6.6 4.0.0 4.0.1 4.1.0 4.2.0 4.2.1 4.2.2 4.3.0 4.3.1 4.4.0 4.4.1 4.5.0 4.5.1 4.5.2 4.6.0 4.6.1 4.7.0 4.7.1 4.7.2 5.0.0 5.0.1 5.0.2 All 108 releases
← All changes | includes/classes/REST/SearchOrdering.php +19 -1 5.0.05.3.5 View file →
@@ -70,9 +70,9 @@
70 70 *
71 71 * @return boolean
72 72 */
73 73 public function check_permission() {
74 - $capability = Utils\get_capability();
74 + $capability = Utils\get_capability( 'search-ordering' );
75 75
76 76 return current_user_can( $capability );
77 77 }
78 78
@@ -113,8 +113,10 @@
113 113 */
114 114 public function get_preview( $request ) {
115 115 $search = $request->get_param( 's' );
116 116
117 + add_filter( 'ep_autosuggest_contexts', [ $this, 'add_rest_api_context' ] );
118 +
117 119 $query = new \WP_Query(
118 120 [
119 121 's' => $search,
120 122 'exclude_pointers' => true,
@@ -120,7 +122,23 @@
120 122 'exclude_pointers' => true,
121 123 ]
122 124 );
123 125
126 + remove_filter( 'ep_autosuggest_contexts', [ $this, 'add_rest_api_context' ] );
127 +
124 128 return $query->posts;
129 + }
130 +
131 + /**
132 + * Add the rest context to the autosuggest contexts.
133 + *
134 + * This makes sure the search results preview matches the search results on the frontend.
135 + *
136 + * @since 5.3.0
137 + * @param array $contexts The contexts.
138 + * @return array The contexts.
139 + */
140 + public function add_rest_api_context( $contexts ) {
141 + $contexts[] = 'rest';
142 + return $contexts;
125 143 }
126 144 }