PluginProbe
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages / 3.4.3
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages v3.4.3
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 2.3.1 All 196 releases
convertkit / includes / mcp / resources / class-convertkit-mcp-resource-settings.php

class-convertkit-mcp-resource-settings.php in Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages 3.4.3, at includes/mcp/resources/class-convertkit-mcp-resource-settings.php

139 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Kit MCP Resource: Settings.
4 *
5 * @package ConvertKit
6 * @author ConvertKit
7 */
8
9 /**
10 * Exposes the current Plugin settings (general, broadcasts, restrict content)
11 * as an MCP Resource (`kit://settings`), keyed by settings group.
12 *
13 * Values are single-sourced from the `kit/settings-*-get` tools, so secret
14 * keys are excluded and the resource never drifts from the tools.
15 *
16 * @package ConvertKit
17 * @author ConvertKit
18 */
19 class ConvertKit_MCP_Resource_Settings extends ConvertKit_MCP_Resource {
20
21 /**
22 * Returns the resource name.
23 *
24 * @since 3.5.0
25 *
26 * @return string
27 */
28 public function get_name() {
29
30 return 'kit/settings';
31
32 }
33
34 /**
35 * Returns the resource URI.
36 *
37 * @since 3.5.0
38 *
39 * @return string
40 */
41 public function get_uri() {
42
43 return 'kit://settings';
44
45 }
46
47 /**
48 * Returns the resource label.
49 *
50 * @since 3.5.0
51 *
52 * @return string
53 */
54 public function get_label() {
55
56 return __( 'Kit Settings', 'convertkit' );
57
58 }
59
60 /**
61 * Returns the resource description.
62 *
63 * @since 3.5.0
64 *
65 * @return string
66 */
67 public function get_description() {
68
69 return __( 'The current Kit Plugin settings, as JSON keyed by group (general, broadcasts, restrict-content). Secret keys are excluded. Read this to see the current configuration before updating settings.', 'convertkit' );
70
71 }
72
73 /**
74 * Returns the resource content's MIME type.
75 *
76 * @since 3.5.0
77 *
78 * @return string
79 */
80 public function get_mime_type() {
81
82 return 'application/json';
83
84 }
85
86 /**
87 * Permission callback.
88 *
89 * Settings are restricted to users who can manage options, matching the
90 * settings tools and the Plugin's own settings screens.
91 *
92 * @since 3.5.0
93 *
94 * @param array $input Resource input (unused).
95 * @return bool|WP_Error
96 */
97 public function permission_callback( $input ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found
98
99 if ( ! current_user_can( 'manage_options' ) ) {
100 return new WP_Error(
101 'convertkit_mcp_resource_permission_callback',
102 __( 'You do not have permission to read Kit Plugin settings.', 'convertkit' )
103 );
104 }
105
106 return true;
107
108 }
109
110 /**
111 * Executes the resource: return each settings group's current values as JSON.
112 *
113 * @since 3.5.0
114 *
115 * @param array $input Resource input.
116 * @return string|WP_Error
117 */
118 public function execute_callback( $input ) {
119
120 // Settings groups exposed over MCP, matching the registered settings tools.
121 $groups = array(
122 new ConvertKit_Settings(),
123 new ConvertKit_Settings_Broadcasts(),
124 new ConvertKit_Settings_Restrict_Content(),
125 );
126
127 $result = array();
128 foreach ( $groups as $settings ) {
129 $get = new ConvertKit_MCP_Ability_Settings_Get( $settings );
130 $values = $get->execute_callback( $input );
131 $result[ $settings->get_name() ] = is_wp_error( $values ) ? array() : $values;
132 }
133
134 return (string) wp_json_encode( $result );
135
136 }
137
138 }
139