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 / post-settings / class-convertkit-mcp-ability-post-settings-get.php

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

140 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 Ability: Get Post Settings.
4 *
5 * @package ConvertKit
6 * @author ConvertKit
7 */
8
9 /**
10 * Ability that returns the current Kit settings for a Post/Page/Custom Post Type.
11 *
12 * Produces an ability named `kit/post-settings-get`.
13 *
14 * @package ConvertKit
15 * @author ConvertKit
16 */
17 class ConvertKit_MCP_Ability_Post_Settings_Get extends ConvertKit_MCP_Ability_Post_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 __( 'Get Kit Post Settings', 'convertkit' );
60
61 }
62
63 /**
64 * Returns the ability's human-readable description.
65 *
66 * @since 3.4.0
67 *
68 * @return string
69 */
70 public function get_description() {
71
72 return __( 'Returns the current Kit settings (form, landing_page, tag, restrict_content) for the given Post, Page or Custom Post Type.', 'convertkit' );
73
74 }
75
76 /**
77 * Returns the ability's input JSON Schema.
78 *
79 * @since 3.4.0
80 *
81 * @return array
82 */
83 public function get_input_schema() {
84
85 return array(
86 'type' => 'object',
87 'required' => array( 'post_id' ),
88 'properties' => array(
89 'post_id' => array(
90 'type' => 'integer',
91 'description' => __( 'The Post/Page/Custom Post Type ID to read Kit settings for.', 'convertkit' ),
92 'minimum' => 1,
93 ),
94 ),
95 );
96
97 }
98
99 /**
100 * Executes the ability.
101 *
102 * @since 3.4.0
103 *
104 * @param array $input Ability input.
105 * @return array|WP_Error
106 */
107 public function execute_callback( $input ) {
108
109 $post_id = isset( $input['post_id'] ) ? absint( $input['post_id'] ) : 0;
110
111 // Bail if the Post does not exist.
112 if ( ! get_post( $post_id ) ) {
113 return new WP_Error(
114 'convertkit_mcp_post_not_found',
115 sprintf(
116 /* translators: %d: Post ID. */
117 __( 'Post %d does not exist.', 'convertkit' ),
118 $post_id
119 )
120 );
121 }
122
123 // Load the Post's settings.
124 $post_settings = new ConvertKit_Post( $post_id );
125 $settings = $post_settings->get();
126
127 // Cast values to string so they match the output schema (Post storage
128 // keeps them as strings, but defense-in-depth for numeric coercion).
129 return array(
130 'post_id' => $post_id,
131 'form' => (string) $settings['form'],
132 'landing_page' => (string) $settings['landing_page'],
133 'tag' => (string) $settings['tag'],
134 'restrict_content' => (string) $settings['restrict_content'],
135 );
136
137 }
138
139 }
140