| @@ -9,10 +9,8 @@ | ||
| 9 | 9 | namespace ContentControl\RestAPI; |
| 10 | 10 | |
| 11 | 11 | use WP_User_Query, WP_REST_Controller, WP_REST_Response, WP_REST_Server, WP_Error; |
| 12 | 12 | |
| 13 | -use function ContentControl\plugin; | |
| 14 | - | |
| 15 | 13 | defined( 'ABSPATH' ) || exit; |
| 16 | 14 | |
| 17 | 15 | /** |
| 18 | 16 | * Rest API Object Search Controller Class. |
| @@ -45,9 +43,9 @@ | ||
| 45 | 43 | [ |
| 46 | 44 | [ |
| 47 | 45 | 'methods' => WP_REST_Server::READABLE, |
| 48 | 46 | 'callback' => [ $this, 'object_search' ], |
| 49 | - 'permission_callback' => [ $this, 'object_search_permissions' ], | |
| 47 | + 'permission_callback' => '__return_true', // Read only, so anyone can view. | |
| 50 | 48 | 'args' => [ |
| 51 | 49 | 'nonce' => [ |
| 52 | 50 | 'description' => __( 'Nonce', 'content-control' ), |
| 53 | 51 | 'type' => 'string', |
| @@ -94,17 +92,8 @@ | ||
| 94 | 92 | ); |
| 95 | 93 | } |
| 96 | 94 | |
| 97 | 95 | /** |
| 98 | - * Check whether the current user may search objects used by plugin settings. | |
| 99 | - * | |
| 100 | - * @return bool | |
| 101 | - */ | |
| 102 | - public function object_search_permissions() { | |
| 103 | - return current_user_can( plugin()->get_permission( 'manage_settings' ) ); | |
| 104 | - } | |
| 105 | - | |
| 106 | - /** | |
| 107 | 96 | * Get block type list. |
| 108 | 97 | * |
| 109 | 98 | * @param \WP_REST_Request<array<string,mixed>> $request Request object. |
| 110 | 99 | * |
| @@ -113,9 +102,9 @@ | ||
| 113 | 102 | public function object_search( $request ) { |
| 114 | 103 | $nonce = $request->get_param( 'nonce' ); |
| 115 | 104 | $params = $request->get_params(); |
| 116 | 105 | |
| 117 | - if ( ! isset( $nonce ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $nonce ) ), 'content_control_object_search_nonce' ) ) { | |
| 106 | + if ( ! isset( $nonce ) || ! wp_verify_nonce( sanitize_key( wp_unslash( $nonce ) ), 'content_control_object_search_nonce' ) ) { | |
| 118 | 107 | wp_send_json_error(); |
| 119 | 108 | } |
| 120 | 109 | |
| 121 | 110 | try { |
| @@ -269,8 +258,11 @@ | ||
| 269 | 258 | |
| 270 | 259 | $results['totalCount'] += (int) $query['totalCount']; |
| 271 | 260 | break; |
| 272 | 261 | } |
| 262 | + | |
| 263 | + // Take out keys which were only used to deduplicate. | |
| 264 | + $results['items'] = array_values( $results['items'] ); | |
| 273 | 265 | |
| 274 | 266 | return new WP_REST_Response( $results, 200 ); |
| 275 | 267 | } catch ( \Exception $e ) { |
| 276 | 268 | return new WP_Error( '500', __( 'Something went wrong, the results could not be returned.', 'content-control' ), [ 'status' => 500 ] ); |