PluginProbe
BlockSpare – Gutenberg Blocks, AI Content Generator & Site Builder for News, Magazine & Blogs / 5.0.1
BlockSpare – Gutenberg Blocks, AI Content Generator & Site Builder for News, Magazine & Blogs v5.0.1
5.0.1 4.1.0 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.1.0 1.1.1 1.1.2 1.2.0 1.2.1 1.2.2 1.2.3 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 2.1.2 2.5.0 2.5.3 All 39 releases
blockspare / inc / theme-builder / class-blockspare-tb-conditions-controller.php

class-blockspare-tb-conditions-controller.php in BlockSpare – Gutenberg Blocks, AI Content Generator & Site Builder for News, Magazine & Blogs 5.0.1, at inc/theme-builder/class-blockspare-tb-conditions-controller.php

62 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 defined('ABSPATH') || exit;
4
5
6 class Blockspare_TB_Conditions_Controller extends WP_REST_Controller
7 {
8
9 protected $namespace = 'stbldr/v1';
10 protected $rest_base = 'conditions';
11
12 /**
13 * @var Blockspare_TB_Condition_Registry
14 */
15 private $registry;
16
17 /**
18 * @param Blockspare_TB_Condition_Registry $registry Shared condition registry.
19 */
20 public function __construct(Blockspare_TB_Condition_Registry $registry)
21 {
22 $this->registry = $registry;
23 }
24
25 public function register_routes()
26 {
27 register_rest_route(
28 $this->namespace,
29 '/' . $this->rest_base,
30 array(
31 array(
32 'methods' => WP_REST_Server::READABLE,
33 'callback' => array($this, 'get_items'),
34 'permission_callback' => array($this, 'get_items_permissions_check'),
35 ),
36 )
37 );
38 }
39
40 /**
41 * Only users who can edit templates need to know what conditions exist.
42 */
43 public function get_items_permissions_check($request)
44 {
45 return current_user_can('edit_pages');
46 }
47
48 public function get_items($request)
49 {
50 $items = array();
51
52 foreach ($this->registry->all() as $condition) {
53 $items[] = array(
54 'slug' => $condition->get_slug(),
55 'label' => $condition->get_label(),
56 );
57 }
58
59 return rest_ensure_response($items);
60 }
61 }
62