convertkit
/
includes
/
mcp
/
abilities
/
category-settings
/
class-convertkit-mcp-ability-category-settings-get.php
class-convertkit-mcp-ability-category-settings-get.php in Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages 3.4.4, at includes/mcp/abilities/category-settings/class-convertkit-mcp-ability-category-settings-get.php
| 1 | <?php |
| 2 | /** |
| 3 | * Kit MCP Ability: Get Category Settings. |
| 4 | * |
| 5 | * @package ConvertKit |
| 6 | * @author ConvertKit |
| 7 | */ |
| 8 | |
| 9 | /** |
| 10 | * Ability that returns the current Kit settings for a Category. |
| 11 | * |
| 12 | * Produces an ability named `kit/category-settings-get`. |
| 13 | * |
| 14 | * @package ConvertKit |
| 15 | * @author ConvertKit |
| 16 | */ |
| 17 | class ConvertKit_MCP_Ability_Category_Settings_Get extends ConvertKit_MCP_Ability_Category_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 Category 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, form_position) for the given Category (WordPress `category` taxonomy term).', '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( 'term_id' ), |
| 88 | 'properties' => array( |
| 89 | 'term_id' => array( |
| 90 | 'type' => 'integer', |
| 91 | 'description' => __( 'The Category (term) 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 | $term_id = isset( $input['term_id'] ) ? absint( $input['term_id'] ) : 0; |
| 110 | |
| 111 | // Bail if the term does not exist or is not a Category. |
| 112 | $valid = $this->validate_term( $term_id ); |
| 113 | if ( is_wp_error( $valid ) ) { |
| 114 | return $valid; |
| 115 | } |
| 116 | |
| 117 | // Load the Category's settings. |
| 118 | $term_settings = new ConvertKit_Term( $term_id ); |
| 119 | $settings = $term_settings->get(); |
| 120 | |
| 121 | // Cast `form` to int and `form_position` to string so the output |
| 122 | // exactly matches the declared schema, regardless of how the value |
| 123 | // was stored (defaults may be '' for form, but the schema wants int). |
| 124 | $form = isset( $settings['form'] ) && $settings['form'] !== '' ? (int) $settings['form'] : 0; |
| 125 | $form_position = isset( $settings['form_position'] ) ? (string) $settings['form_position'] : ''; |
| 126 | |
| 127 | return array( |
| 128 | 'term_id' => $term_id, |
| 129 | 'form' => $form, |
| 130 | 'form_position' => $form_position, |
| 131 | ); |
| 132 | |
| 133 | } |
| 134 | |
| 135 | } |
| 136 |