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
elasticpress / includes / classes / REST / MetaKeys.php

MetaKeys.php in ElasticPress 5.3.5, at includes/classes/REST/MetaKeys.php

67 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Meta Keys REST API Controller
4 *
5 * @since 5.0.0
6 * @package elasticpress
7 */
8
9 namespace ElasticPress\REST;
10
11 use ElasticPress\Features;
12 use ElasticPress\Indexables;
13
14 /**
15 * Meta Keys API controller class.
16 *
17 * @since 5.0.0
18 * @package elasticpress
19 */
20 class MetaKeys {
21
22 /**
23 * Register routes.
24 *
25 * Registers the route using its own endpoint and the previous facets
26 * endpoint, for backwards compatibility.
27 *
28 * @return void
29 */
30 public function register_routes() {
31 $args = [
32 'callback' => [ $this, 'get_meta_keys' ],
33 'methods' => 'GET',
34 'permission_callback' => [ $this, 'check_permission' ],
35 ];
36
37 register_rest_route( 'elasticpress/v1', 'meta-keys', $args );
38 register_rest_route( 'elasticpress/v1', 'facets/meta/keys', $args );
39 }
40
41 /**
42 * Check that the request has permission.
43 *
44 * @return boolean
45 */
46 public function check_permission() {
47 return current_user_can( 'edit_theme_options' );
48 }
49
50 /**
51 * Get indexed meta keys.
52 *
53 * @return array
54 */
55 public function get_meta_keys() {
56 $post_indexable = Indexables::factory()->get( 'post' );
57
58 try {
59 $meta_keys = $post_indexable->get_distinct_meta_field_keys();
60 } catch ( \Throwable $th ) {
61 $meta_keys = [];
62 }
63
64 return $meta_keys;
65 }
66 }
67