| 1 |
<?php |
| 2 |
/** |
| 3 |
* Kit MCP Resource: Account. |
| 4 |
* |
| 5 |
* @package ConvertKit |
| 6 |
* @author ConvertKit |
| 7 |
*/ |
| 8 |
|
| 9 |
/** |
| 10 |
* Exposes the connected Kit account (name, plan, primary email) as an MCP |
| 11 |
* Resource (`kit://account`), read from the cached account data. |
| 12 |
* |
| 13 |
* @package ConvertKit |
| 14 |
* @author ConvertKit |
| 15 |
*/ |
| 16 |
class ConvertKit_MCP_Resource_Account extends ConvertKit_MCP_Resource { |
| 17 |
|
| 18 |
/** |
| 19 |
* Returns the resource name. |
| 20 |
* |
| 21 |
* @since 3.5.0 |
| 22 |
* |
| 23 |
* @return string |
| 24 |
*/ |
| 25 |
public function get_name() { |
| 26 |
|
| 27 |
return 'kit/account'; |
| 28 |
|
| 29 |
} |
| 30 |
|
| 31 |
/** |
| 32 |
* Returns the resource URI. |
| 33 |
* |
| 34 |
* @since 3.5.0 |
| 35 |
* |
| 36 |
* @return string |
| 37 |
*/ |
| 38 |
public function get_uri() { |
| 39 |
|
| 40 |
return 'kit://account'; |
| 41 |
|
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* Returns the resource label. |
| 46 |
* |
| 47 |
* @since 3.5.0 |
| 48 |
* |
| 49 |
* @return string |
| 50 |
*/ |
| 51 |
public function get_label() { |
| 52 |
|
| 53 |
return __( 'Kit Account', 'convertkit' ); |
| 54 |
|
| 55 |
} |
| 56 |
|
| 57 |
/** |
| 58 |
* Returns the resource description. |
| 59 |
* |
| 60 |
* @since 3.5.0 |
| 61 |
* |
| 62 |
* @return string |
| 63 |
*/ |
| 64 |
public function get_description() { |
| 65 |
|
| 66 |
return __( 'The connected Kit account (name, plan type, primary email address), as JSON. Read this to confirm which account the site is connected to before making changes. An empty object means no account is connected yet.', 'convertkit' ); |
| 67 |
|
| 68 |
} |
| 69 |
|
| 70 |
/** |
| 71 |
* Returns the resource content's MIME type. |
| 72 |
* |
| 73 |
* @since 3.5.0 |
| 74 |
* |
| 75 |
* @return string |
| 76 |
*/ |
| 77 |
public function get_mime_type() { |
| 78 |
|
| 79 |
return 'application/json'; |
| 80 |
|
| 81 |
} |
| 82 |
|
| 83 |
/** |
| 84 |
* Executes the resource: return the cached account data as JSON. |
| 85 |
* |
| 86 |
* @since 3.5.0 |
| 87 |
* |
| 88 |
* @param array $input Resource input (unused). |
| 89 |
* @return string|WP_Error |
| 90 |
*/ |
| 91 |
public function execute_callback( $input ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found |
| 92 |
|
| 93 |
// Bail with an empty object if the account resource class isn't available. |
| 94 |
if ( ! class_exists( 'ConvertKit_Resource_Account' ) ) { |
| 95 |
return '{}'; |
| 96 |
} |
| 97 |
|
| 98 |
$account = new ConvertKit_Resource_Account(); |
| 99 |
$data = $account->get(); |
| 100 |
|
| 101 |
// get() returns false when nothing is cached; normalise to an empty object. |
| 102 |
if ( ! is_array( $data ) ) { |
| 103 |
return '{}'; |
| 104 |
} |
| 105 |
|
| 106 |
return (string) wp_json_encode( $data ); |
| 107 |
|
| 108 |
} |
| 109 |
|
| 110 |
} |
| 111 |
|