[ $this, 'get_meta_keys' ], 'methods' => 'GET', 'permission_callback' => [ $this, 'check_permission' ], ]; register_rest_route( 'elasticpress/v1', 'meta-keys', $args ); register_rest_route( 'elasticpress/v1', 'facets/meta/keys', $args ); } /** * Check that the request has permission. * * @return boolean */ public function check_permission() { return current_user_can( 'edit_theme_options' ); } /** * Get indexed meta keys. * * @return array */ public function get_meta_keys() { $post_indexable = Indexables::factory()->get( 'post' ); try { $meta_keys = $post_indexable->get_distinct_meta_field_keys(); } catch ( \Throwable $th ) { $meta_keys = []; } return $meta_keys; } }