# convertkit/3.4.5/includes/mcp/abilities/content/class-convertkit-mcp-ability-content.php

Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages, version 3.4.5. 187 lines.

- Page: https://pluginprobe.com/plugins/convertkit/3.4.5/code/includes/mcp/abilities/content/class-convertkit-mcp-ability-content.php
- Raw: https://pluginprobe.com/plugins/convertkit/3.4.5/raw/includes/mcp/abilities/content/class-convertkit-mcp-ability-content.php
- Modified: 2026-08-28T10:49:42+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/convertkit/3.4.5/code/includes/mcp/abilities/content/class-convertkit-mcp-ability-content.php#L10-L20`.

```php
<?php
/**
 * Kit MCP Ability: Content base class.
 *
 * @package ConvertKit
 * @author ConvertKit
 */

/**
 * Base class for abilities that insert, update or remove a Kit element
 * (Broadcast, Form, Form Trigger, Product) within a WordPress Post's content.
 *
 * Each subclass represents a single verb (list / insert / update / delete).
 *
 * @package ConvertKit
 * @author  ConvertKit
 */
abstract class ConvertKit_MCP_Ability_Content extends ConvertKit_MCP_Ability {

	/**
	 * The block this ability operates on.
	 *
	 * @since   3.4.0
	 *
	 * @var     ConvertKit_Block
	 */
	protected $block;

	/**
	 * Constructor.
	 *
	 * @since   3.4.0
	 *
	 * @param   ConvertKit_Block $block  The block instance this ability targets.
	 */
	public function __construct( $block ) {

		$this->block = $block;

	}

	/**
	 * Returns the ability name, derived from the Kit element's name and the verb
	 * returned by get_verb().
	 *
	 * For example, the Form element's insert ability is named `kit/form-insert`.
	 *
	 * @since   3.4.0
	 *
	 * @return  string
	 */
	public function get_name() {

		return 'kit/' . $this->block->get_name() . '-' . $this->get_verb();

	}

	/**
	 * Returns the verb this ability represents.
	 *
	 * @since   3.4.0
	 *
	 * @return  string
	 */
	abstract public function get_verb();

	/**
	 * Only permit an ability to be executed if the current user can edit the given post.
	 *
	 * @since   3.4.0
	 *
	 * @param   array $input   Ability input.
	 * @return  bool|WP_Error
	 */
	public function permission_callback( $input ) {

		// Get Post ID.
		$post_id = isset( $input['post_id'] ) ? absint( $input['post_id'] ) : 0;

		// Bail if no Post ID is provided.
		if ( ! $post_id ) {
			return new WP_Error(
				'convertkit_mcp_missing_post_id',
				__( 'A post_id is required.', 'convertkit' )
			);
		}

		// Bail if the current user does not have permission to edit the post.
		if ( ! current_user_can( 'edit_post', $post_id ) ) {
			return new WP_Error(
				'convertkit_mcp_cannot_edit_post',
				__( 'You do not have permission to edit this post.', 'convertkit' )
			);
		}

		return true;

	}

	/**
	 * Returns the ability's output JSON Schema.
	 *
	 * @since   3.4.0
	 *
	 * @return  array
	 */
	public function get_output_schema() {

		return array(
			'type'       => 'object',
			'required'   => array( 'post_id', 'occurrence_index' ),
			'properties' => array(
				'post_id'          => array(
					'type'        => 'integer',
					'description' => __( 'The Post/Page/Custom Post Type ID.', 'convertkit' ),
				),
				'occurrence_index' => array(
					'type'        => 'integer',
					'description' => __( 'The zero-based occurrence index of the Kit element in the post.', 'convertkit' ),
				),
			),
		);

	}

	/**
	 * Returns JSON Schema properties derived from the block's get_fields(),
	 * suitable for use as the `attrs` object in an Abilities API input schema.
	 *
	 * Used by verb subclasses whose input schema includes an `attrs` object
	 * (insert, update).
	 *
	 * @since   3.4.0
	 *
	 * @return  array
	 */
	protected function get_input_schema_properties() {

		// Define properties.
		$properties = array();
		$fields     = $this->block->get_fields();

		foreach ( $fields as $field_name => $field ) {
			$properties[ $field_name ] = array(
				'description' => isset( $field['label'] ) ? (string) $field['label'] : '',
				'type'        => $this->get_input_schema_property_type( $field ),
			);
		}

		return $properties;

	}

	/**
	 * Returns the JSON Schema type for the given field definition.
	 *
	 * @since   3.4.0
	 *
	 * @param   array $field   Field definition.
	 * @return  string
	 */
	private function get_input_schema_property_type( $field ) {

		$type = isset( $field['type'] ) ? (string) $field['type'] : 'string';

		switch ( $type ) {
			case 'resource':
			case 'text':
			case 'color':
			case 'select':
				return 'string';

			case 'number':
				return 'integer';

			case 'toggle':
				return 'boolean';

			default:
				// Unknown field type — fall back to string.
				return 'string';
		}

	}

}

```
