PluginProbe
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages / 3.4.4
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages v3.4.4
3.4.4 3.4.3 3.4.2 3.4.1 3.4.0 3.3.9 3.3.8 3.3.7 3.3.6 3.3.5 3.3.4 3.3.3 3.3.2 3.3.1 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.2.7 2.2.8 2.2.9 2.3.0 All 197 releases
convertkit / includes / mcp / abilities / settings / class-convertkit-mcp-ability-settings-get.php

class-convertkit-mcp-ability-settings-get.php in Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages 3.4.4, at includes/mcp/abilities/settings/class-convertkit-mcp-ability-settings-get.php

149 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Kit MCP Ability: Get Settings.
4 *
5 * @package ConvertKit
6 * @author ConvertKit
7 */
8
9 /**
10 * Ability that returns the current values of a Kit settings group.
11 *
12 * Produces an ability named `kit/settings-<name>-get` (e.g. `kit/settings-general-get`).
13 *
14 * @package ConvertKit
15 * @author ConvertKit
16 */
17 class ConvertKit_MCP_Ability_Settings_Get extends ConvertKit_MCP_Ability_Settings {
18
19 /**
20 * Sets whether the ability is readonly.
21 *
22 * @since 3.4.0
23 *
24 * @var bool
25 */
26 private $readonly = true; // @phpstan-ignore-line
27
28 /**
29 * Sets whether the ability is idempotent.
30 *
31 * @since 3.4.0
32 *
33 * @var bool
34 */
35 private $idempotent = true; // @phpstan-ignore-line
36
37 /**
38 * Returns the operation suffix used in the ability name.
39 *
40 * @since 3.4.0
41 *
42 * @return string
43 */
44 protected function get_operation() {
45
46 return 'get';
47
48 }
49
50 /**
51 * Returns the ability's human-readable label.
52 *
53 * @since 3.4.0
54 *
55 * @return string
56 */
57 public function get_label() {
58
59 return sprintf(
60 /* translators: %s: Settings Title, e.g. 'General Settings'. */
61 __( 'Get Kit Plugin %s', 'convertkit' ),
62 $this->settings->get_title()
63 );
64
65 }
66
67 /**
68 * Returns the ability's human-readable description.
69 *
70 * @since 3.4.0
71 *
72 * @return string
73 */
74 public function get_description() {
75
76 return sprintf(
77 /* translators: %s: Settings Title, e.g. 'General Settings'. */
78 __( 'Returns the current values of the Kit Plugin "%s".', 'convertkit' ),
79 $this->settings->get_title()
80 );
81
82 }
83
84 /**
85 * Returns the ability's input JSON Schema.
86 *
87 * Get takes no input.
88 *
89 * @since 3.4.0
90 *
91 * @return array
92 */
93 public function get_input_schema() {
94
95 return array(
96 'type' => 'object',
97 'properties' => new stdClass(),
98 );
99
100 }
101
102 /**
103 * Returns the ability's output JSON Schema.
104 *
105 * @since 3.4.0
106 *
107 * @return array
108 */
109 public function get_output_schema() {
110
111 return $this->get_public_schema();
112
113 }
114
115 /**
116 * Executes the ability: returns the current settings, scoped to the keys
117 * declared in the public schema.
118 *
119 * Stored values are sanitised through the property schema before being
120 * returned, so the response matches the declared types (e.g. a numeric
121 * setting stored as the string "0.5" is returned as 0.5).
122 *
123 * @since 3.4.0
124 *
125 * @param array $input Ability input (unused).
126 * @return array|WP_Error
127 */
128 public function execute_callback( $input ) {
129
130 $values = $this->settings->get();
131 $schema = $this->get_public_schema();
132 $result = array();
133
134 if ( ! isset( $schema['properties'] ) || ! is_array( $schema['properties'] ) ) {
135 return $result;
136 }
137
138 foreach ( $schema['properties'] as $key => $property_schema ) {
139 if ( array_key_exists( $key, $values ) ) {
140 $result[ $key ] = rest_sanitize_value_from_schema( $values[ $key ], $property_schema, $key );
141 }
142 }
143
144 return $result;
145
146 }
147
148 }
149