| 1 |
<?php |
| 2 |
/** |
| 3 |
* Kit MCP Resource: reference base class. |
| 4 |
* |
| 5 |
* @package ConvertKit |
| 6 |
* @author ConvertKit |
| 7 |
*/ |
| 8 |
|
| 9 |
/** |
| 10 |
* Base class for static reference resources: Markdown documents that describe |
| 11 |
* how the Plugin works (its mental model), so the model can read them as |
| 12 |
* context instead of guessing. |
| 13 |
* |
| 14 |
* @package ConvertKit |
| 15 |
* @author ConvertKit |
| 16 |
*/ |
| 17 |
abstract class ConvertKit_MCP_Resource_Reference extends ConvertKit_MCP_Resource { |
| 18 |
|
| 19 |
/** |
| 20 |
* Returns the Markdown content lines for this reference document. |
| 21 |
* |
| 22 |
* @since 3.5.0 |
| 23 |
* |
| 24 |
* @return array |
| 25 |
*/ |
| 26 |
abstract protected function get_content_lines(); |
| 27 |
|
| 28 |
/** |
| 29 |
* Permission callback. |
| 30 |
* |
| 31 |
* Reference docs are non-sensitive and readable by anyone who can edit |
| 32 |
* posts — the audience that uses the MCP tools. |
| 33 |
* |
| 34 |
* @since 3.5.0 |
| 35 |
* |
| 36 |
* @param array $input Resource input (unused). |
| 37 |
* @return bool|WP_Error |
| 38 |
*/ |
| 39 |
public function permission_callback( $input ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found |
| 40 |
|
| 41 |
if ( ! current_user_can( 'edit_posts' ) ) { |
| 42 |
return new WP_Error( |
| 43 |
'convertkit_mcp_resource_permission_callback', |
| 44 |
__( 'You do not have permission for this operation.', 'convertkit' ) |
| 45 |
); |
| 46 |
} |
| 47 |
|
| 48 |
return true; |
| 49 |
|
| 50 |
} |
| 51 |
|
| 52 |
/** |
| 53 |
* Executes the resource: return the Markdown document. |
| 54 |
* |
| 55 |
* @since 3.5.0 |
| 56 |
* |
| 57 |
* @param array $input Resource input (unused). |
| 58 |
* @return string|WP_Error |
| 59 |
*/ |
| 60 |
public function execute_callback( $input ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found |
| 61 |
|
| 62 |
return implode( "\n", $this->get_content_lines() ); |
| 63 |
|
| 64 |
} |
| 65 |
|
| 66 |
} |
| 67 |
|