Skip to content
Open
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
4 changes: 2 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
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' => 'number',
'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,148 @@
<?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.
*
* Stored values are sanitised through the property schema before being
* returned, so the response matches the declared types (e.g. a numeric
* setting stored as the string "0.5" is returned as 0.5).
*
* @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 ( $schema['properties'] as $key => $property_schema ) {
if ( array_key_exists( $key, $values ) ) {
$result[ $key ] = rest_sanitize_value_from_schema( $values[ $key ], $property_schema, $key );
}
}

return $result;

}

}
Loading
Loading