Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions admin/section/class-convertkit-admin-section-base.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,26 @@ public function __construct() {

}

/**
* Registers this settings section's MCP abilities.
*
* @since 3.4.0
*
* @param array $abilities Abilities to Register.
* @return array
*/
public function register_abilities( $abilities ) {

return array_merge(
$abilities,
array(
'kit/' . $this->settings->get_name() . '-get' => new ConvertKit_MCP_Ability_Settings_Get( $this->settings ),
'kit/' . $this->settings->get_name() . '-update' => new ConvertKit_MCP_Ability_Settings_Update( $this->settings ),
)
);

}

/**
* Helper method to determine if we're viewing the current settings screen.
*
Expand Down
7 changes: 5 additions & 2 deletions admin/section/class-convertkit-admin-section-general.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ public function __construct() {
$this->settings_key = $this->settings::SETTINGS_NAME;

// Define the programmatic name, Title and Tab Text.
$this->name = 'general';
$this->title = __( 'General Settings', 'convertkit' );
$this->name = $this->settings->get_name();
$this->title = $this->settings->get_title();
$this->tab_text = __( 'General', 'convertkit' );

// Define settings sections.
Expand Down Expand Up @@ -93,6 +93,9 @@ public function __construct() {
add_action( 'convertkit_admin_settings_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
add_action( 'convertkit_admin_settings_enqueue_styles', array( $this, 'enqueue_styles' ) );

// Register MCP abilities.
add_filter( 'convertkit_abilities', array( $this, 'register_abilities' ) );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might be misreading the flow here, but aren't these settings abilities now getting registered through two paths? This filter seems to call register_abilities() on the base section (keyed kit/general-*), and ConvertKit_MCP::register_settings_abilities() also adds them (keyed kit/settings-general-*). Since both instances return the same get_name(), I think wp_register_ability() could end up being called twice with the same name, but I'm not 100% sure how the dedup works. Could you double-check whether that is the case?


parent::__construct();

$this->check_credentials();
Expand Down
116 changes: 116 additions & 0 deletions includes/class-convertkit-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,122 @@ public function usage_tracking() {

}

/**
* Returns this settings group's programmatic name.
*
* @since 3.4.0
*
* @return string
*/
public function get_name() {

return 'general';

}

/**
* Returns the title of this settings group.
*
* @since 3.4.0
*
* @return string
*/
public function get_title() {

return __( 'General Settings', 'convertkit' );

}

/**
* Returns the keys in this settings group that hold credentials or other
* sensitive values.
*
* @since 3.4.0
*
* @return string[]
*/
public function get_secret_keys() {

return array(
'access_token',
'refresh_token',
'token_expires',
'api_key',
'api_secret',
'recaptcha_secret_key',
);

}

/**
* Returns the JSON Schema describing this settings group, in the shape
* stored by save() / returned by get(), excluding secret keys.
*
* @since 3.4.0
*
* @return array
*/
public function get_schema() {

return array(
'type' => 'object',
'additionalProperties' => false,
'properties' => array(
'non_inline_form' => array(
'type' => 'array',
'items' => array( 'type' => 'integer' ),
'description' => __( 'IDs of non-inline Forms to display site-wide.', 'convertkit' ),
),
'non_inline_form_honor_none_setting' => array(
'type' => 'string',
'enum' => array( '', 'on' ),
'description' => __( 'Whether the site-wide non-inline Form honors a per-Page / per-Post "None" Form setting.', 'convertkit' ),
),
'non_inline_form_limit_per_session' => array(
'type' => 'string',
'enum' => array( '', 'on' ),
'description' => __( 'Whether to limit non-inline Form display to once per session.', 'convertkit' ),
),
'recaptcha_site_key' => array(
'type' => 'string',
'description' => __( 'Google reCAPTCHA v3 site key.', 'convertkit' ),
),
'recaptcha_minimum_score' => array(
'type' => 'float',

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is float a valid type or should this be number instead?

'minimum' => 0,
'maximum' => 1,
'description' => __( 'Minimum Google reCAPTCHA v3 score (0.0 - 1.0) below which a request is treated as spam.', 'convertkit' ),
),
'debug' => array(
'type' => 'string',
'enum' => array( '', 'on' ),
'description' => __( 'Whether debug logging is enabled.', 'convertkit' ),
),
'no_scripts' => array(
'type' => 'string',
'enum' => array( '', 'on' ),
'description' => __( 'Whether the Plugin\'s frontend JavaScript is disabled.', 'convertkit' ),
),
'no_css' => array(
'type' => 'string',
'enum' => array( '', 'on' ),
'description' => __( 'Whether the Plugin\'s frontend CSS is disabled.', 'convertkit' ),
),
'no_add_new_button' => array(
'type' => 'string',
'enum' => array( '', 'on' ),
'description' => __( 'Whether the "Add New" button for Landing Pages / Member Content is hidden in the WordPress Admin.', 'convertkit' ),
),
'usage_tracking' => array(
'type' => 'string',
'enum' => array( '', 'on' ),
'description' => __( 'Whether anonymous usage tracking is enabled.', 'convertkit' ),
),
),
);

}

/**
* The default settings, used when the ConvertKit Plugin Settings haven't been saved
* e.g. on a new installation.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
<?php
/**
* Kit MCP Ability: Get Settings.
*
* @package ConvertKit
* @author ConvertKit
*/

/**
* Ability that returns the current values of a Kit settings group.
*
* Produces an ability named `kit/settings-<name>-get` (e.g. `kit/settings-general-get`).
*
* @package ConvertKit
* @author ConvertKit
*/
class ConvertKit_MCP_Ability_Settings_Get extends ConvertKit_MCP_Ability_Settings {

/**
* Sets whether the ability is readonly.
*
* @since 3.4.0
*
* @var bool
*/
private $readonly = true; // @phpstan-ignore-line

/**
* Sets whether the ability is idempotent.
*
* @since 3.4.0
*
* @var bool
*/
private $idempotent = true; // @phpstan-ignore-line

/**
* Returns the operation suffix used in the ability name.
*
* @since 3.4.0
*
* @return string
*/
protected function get_operation() {

return 'get';

}

/**
* Returns the ability's human-readable label.
*
* @since 3.4.0
*
* @return string
*/
public function get_label() {

return sprintf(
/* translators: %s: Settings Title, e.g. 'General Settings'. */
__( 'Get Kit Plugin %s', 'convertkit' ),
$this->settings->get_title()
);

}

/**
* Returns the ability's human-readable description.
*
* @since 3.4.0
*
* @return string
*/
public function get_description() {

return sprintf(
/* translators: %s: Settings Title, e.g. 'General Settings'. */
__( 'Returns the current values of the Kit Plugin "%s".', 'convertkit' ),
$this->settings->get_title()
);

}

/**
* Returns the ability's input JSON Schema.
*
* Get takes no input.
*
* @since 3.4.0
*
* @return array
*/
public function get_input_schema() {

return array(
'type' => 'object',
'properties' => new stdClass(),
);

}

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

return $this->get_public_schema();

}

/**
* Executes the ability: returns the current settings, scoped to the keys
* declared in the public schema.
*
* @since 3.4.0
*
* @param array $input Ability input (unused).
* @return array|WP_Error
*/
public function execute_callback( $input ) {

$values = $this->settings->get();
$schema = $this->get_public_schema();
$result = array();

if ( ! isset( $schema['properties'] ) || ! is_array( $schema['properties'] ) ) {
return $result;
}

foreach ( array_keys( $schema['properties'] ) as $key ) {
if ( array_key_exists( $key, $values ) ) {
$result[ $key ] = $values[ $key ];
}
}

return $result;

}

}
Loading
Loading