| @@ -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 | } |