PluginProbe ʕ •ᴥ•ʔ
LatePoint – Calendar Booking Plugin for Appointments and Events / 5.2.11
LatePoint – Calendar Booking Plugin for Appointments and Events v5.2.11
5.6.6 5.6.5 5.6.4 5.6.3 5.6.2 5.6.1 5.6.0 5.5.2 5.5.1 5.5.0 5.4.2 trunk 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.1.8 5.1.9 5.1.91 5.1.92 5.1.93 5.1.94 5.2.0 5.2.1 5.2.10 5.2.11 5.2.2 5.2.3 5.2.4 5.2.5 5.2.6 5.2.7 5.2.8 5.2.9 5.3.0 5.3.1 5.3.2 5.4.0 5.4.1
latepoint / lib / abilities / abstract-ability.php
latepoint / lib / abilities Last commit date
activities 3 months ago agents 3 months ago analytics 3 months ago bookings 3 months ago calendar 3 months ago configs 3 months ago customers 3 months ago locations 3 months ago orders 3 months ago services 3 months ago abstract-ability.php 3 months ago class-latepoint-abilities.php 3 months ago
abstract-ability.php
111 lines
1 <?php
2 /**
3 * Abstract base class for all LatePoint abilities.
4 *
5 * @package LatePoint\Abilities
6 * @since 5.3.0
7 */
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit;
11 }
12
13 abstract class LatePointAbstractAbility {
14
15 protected string $id;
16 protected string $category = 'latepoint';
17 protected string $label = '';
18 protected string $description = '';
19 protected string $permission = 'manage_options';
20 protected bool $read_only = true;
21 protected bool $destructive = false;
22 protected bool $idempotent = false;
23
24 public function __construct() {
25 $this->configure();
26 }
27
28 /**
29 * Set $id, $label, $description, $permission, $read_only, $destructive.
30 */
31 abstract protected function configure(): void;
32
33 abstract public function get_input_schema(): array;
34
35 abstract public function get_output_schema(): array;
36
37 /**
38 * @param array $args
39 * @return array|\WP_Error
40 */
41 abstract public function execute( array $args );
42
43 public function get_id(): string {
44 return $this->id;
45 }
46
47 public function check_permission(): bool {
48 return OsRolesHelper::can_user( $this->permission );
49 }
50
51 public function to_definition(): array {
52 return [
53 'label' => $this->label,
54 'description' => $this->description,
55 'category' => $this->category,
56 'permission_callback' => [ $this, 'check_permission' ],
57 'input_schema' => $this->get_input_schema(),
58 'output_schema' => $this->get_output_schema(),
59 'execute_callback' => [ $this, 'execute' ],
60 'meta' => $this->build_meta(),
61 ];
62 }
63
64 protected function build_meta(): array {
65
66 // Default annotations, normally read-only
67 $annotations = [
68 'readOnlyHint' => $this->read_only,
69 'idempotentHint' => $this->idempotent,
70 'destructiveHint' => false,
71 'priority' => $this->read_only ? 1.0 : 2.0,
72 ];
73
74 // Destructive overrides everything.
75 if ( $this->destructive ) {
76 $annotations['readOnlyHint'] = false;
77 $annotations['destructiveHint'] = true;
78 $annotations['priority'] = 3.0;
79 }
80
81 $meta = [
82 'annotations' => $annotations,
83 'show_in_rest' => true,
84 'mcp' => [
85 'public' => true,
86 'type' => 'tool',
87 ],
88 ];
89
90 return $meta;
91 }
92
93 protected static function pagination(): array {
94 return [
95 'page' => [
96 'type' => 'integer',
97 'default' => 1,
98 'minimum' => 1,
99 'description' => __( 'Page number.', 'latepoint' ),
100 ],
101 'per_page' => [
102 'type' => 'integer',
103 'default' => 20,
104 'minimum' => 1,
105 'maximum' => 100,
106 'description' => __( 'Items per page.', 'latepoint' ),
107 ],
108 ];
109 }
110 }
111