-
Notifications
You must be signed in to change notification settings - Fork 8
Abilities API: Plugin Settings: General #1112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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', | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is |
||
| '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. | ||
|
|
||
144 changes: 144 additions & 0 deletions
144
includes/mcp/abilities/settings/class-convertkit-mcp-ability-settings-get.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
|
|
||
| } | ||
|
|
||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 (keyedkit/general-*), andConvertKit_MCP::register_settings_abilities()also adds them (keyedkit/settings-general-*). Since both instances return the sameget_name(), I thinkwp_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?