-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Abilities API: Unify schema conventions across core abilities #11984
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
Open
gziolo
wants to merge
8
commits into
WordPress:trunk
Choose a base branch
from
gziolo:enhance/unify-core-abilities-schemas
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+158
−49
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a661b2a
Abilities API: Add schema property titles to core/get-site-info and c…
gziolo 130b414
Abilities API: Allow filtering core/get-environment-info output by fi…
gziolo 5d4019c
Abilities API: Expose core/get-user-info via REST.
gziolo 71be3d1
Abilities API: Normalize core ability schema titles and lock field se…
gziolo dca3efb
Abilities API: Refine schema descriptions for AI consumers.
gziolo 2bb19f2
Tests: Drop low-value comments in core ability schema tests.
gziolo 96c1a70
Tests: Drop low-value comments inside core ability schema-registratio…
gziolo 0e2cab2
Tests: Correct @ticket references on new core/get-environment-info te…
gziolo 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
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -46,35 +46,43 @@ function wp_register_core_abilities(): void { | |||||||
| $site_info_properties = array( | ||||||||
| 'name' => array( | ||||||||
| 'type' => 'string', | ||||||||
| 'title' => __( 'Site Title' ), | ||||||||
| 'description' => __( 'The site title.' ), | ||||||||
| ), | ||||||||
| 'description' => array( | ||||||||
| 'type' => 'string', | ||||||||
| 'title' => __( 'Tagline' ), | ||||||||
| 'description' => __( 'The site tagline.' ), | ||||||||
| ), | ||||||||
| 'url' => array( | ||||||||
| 'type' => 'string', | ||||||||
| 'description' => __( 'The site home URL.' ), | ||||||||
| 'title' => __( 'Site Address (URL)' ), | ||||||||
| 'description' => __( 'The public URL where visitors access the site. May differ from the WordPress installation URL.' ), | ||||||||
| ), | ||||||||
| 'wpurl' => array( | ||||||||
| 'type' => 'string', | ||||||||
| 'description' => __( 'The WordPress installation URL.' ), | ||||||||
| 'title' => __( 'WordPress Address (URL)' ), | ||||||||
| 'description' => __( 'The URL where WordPress core files are served. May differ from the public site URL.' ), | ||||||||
| ), | ||||||||
| 'admin_email' => array( | ||||||||
| 'type' => 'string', | ||||||||
| 'title' => __( 'Administration Email Address' ), | ||||||||
| 'description' => __( 'The site administrator email address.' ), | ||||||||
| ), | ||||||||
| 'charset' => array( | ||||||||
| 'type' => 'string', | ||||||||
| 'title' => __( 'Site Charset' ), | ||||||||
| 'description' => __( 'The site character encoding.' ), | ||||||||
| ), | ||||||||
| 'language' => array( | ||||||||
| 'type' => 'string', | ||||||||
| 'description' => __( 'The site language locale code.' ), | ||||||||
| 'title' => __( 'Site Language' ), | ||||||||
| 'description' => __( 'The site locale in dash form (e.g. en-US).' ), | ||||||||
| ), | ||||||||
| 'version' => array( | ||||||||
| 'type' => 'string', | ||||||||
| 'description' => __( 'The WordPress version.' ), | ||||||||
| 'title' => __( 'WordPress Version' ), | ||||||||
| 'description' => __( 'The WordPress core version running on this site.' ), | ||||||||
| ), | ||||||||
| ); | ||||||||
| $site_info_fields = array_keys( $site_info_properties ); | ||||||||
|
|
@@ -138,7 +146,7 @@ function wp_register_core_abilities(): void { | |||||||
| 'id' => array( | ||||||||
| 'type' => 'integer', | ||||||||
| 'title' => __( 'User ID' ), | ||||||||
| 'description' => __( 'Unique numeric identifier for the user.' ), | ||||||||
| 'description' => __( 'Unique identifier for the user.' ), | ||||||||
| ), | ||||||||
| 'display_name' => array( | ||||||||
| 'type' => 'string', | ||||||||
|
|
@@ -186,7 +194,7 @@ function wp_register_core_abilities(): void { | |||||||
| 'description' => array( | ||||||||
| 'type' => 'string', | ||||||||
| 'title' => __( 'Biographical Info' ), | ||||||||
| 'description' => __( 'User-authored biography, often shown on author pages.' ), | ||||||||
| 'description' => __( 'User-authored biography. May be empty.' ), | ||||||||
| ), | ||||||||
| 'user_url' => array( | ||||||||
| 'type' => 'string', | ||||||||
|
|
@@ -253,58 +261,81 @@ function wp_register_core_abilities(): void { | |||||||
| 'destructive' => false, | ||||||||
| 'idempotent' => true, | ||||||||
| ), | ||||||||
| 'show_in_rest' => false, | ||||||||
| 'show_in_rest' => true, | ||||||||
| ), | ||||||||
| ) | ||||||||
| ); | ||||||||
|
|
||||||||
| $environment_info_properties = array( | ||||||||
| 'environment' => array( | ||||||||
| 'type' => 'string', | ||||||||
| 'title' => __( 'Environment Type' ), | ||||||||
| 'description' => __( 'The site\'s runtime environment classification.' ), | ||||||||
| 'enum' => array( 'production', 'staging', 'development', 'local' ), | ||||||||
| ), | ||||||||
| 'php_version' => array( | ||||||||
| 'type' => 'string', | ||||||||
| 'title' => __( 'PHP Version' ), | ||||||||
| 'description' => __( 'The PHP runtime version executing WordPress.' ), | ||||||||
| ), | ||||||||
| 'db_server_info' => array( | ||||||||
| 'type' => 'string', | ||||||||
| 'title' => __( 'Database Server Info' ), | ||||||||
| 'description' => __( 'The database server vendor and version string reported by the driver.' ), | ||||||||
| ), | ||||||||
| 'wp_version' => array( | ||||||||
| 'type' => 'string', | ||||||||
| 'title' => __( 'WordPress Version' ), | ||||||||
| 'description' => __( 'The WordPress core version running on this site.' ), | ||||||||
| ), | ||||||||
| ); | ||||||||
| $environment_info_fields = array_keys( $environment_info_properties ); | ||||||||
|
|
||||||||
| wp_register_ability( | ||||||||
| 'core/get-environment-info', | ||||||||
| array( | ||||||||
| 'label' => __( 'Get Environment Info' ), | ||||||||
| 'description' => __( 'Returns core details about the site\'s runtime context for diagnostics and compatibility (environment, PHP runtime, database server info, WordPress version).' ), | ||||||||
| 'description' => __( 'Returns core details about the site\'s runtime context for diagnostics and compatibility (environment, PHP runtime, database server info, WordPress version). By default returns all fields, or optionally a filtered subset.' ), | ||||||||
| 'category' => $category_site, | ||||||||
| 'output_schema' => array( | ||||||||
| 'input_schema' => array( | ||||||||
| 'type' => 'object', | ||||||||
| 'required' => array( 'environment', 'php_version', 'db_server_info', 'wp_version' ), | ||||||||
| 'properties' => array( | ||||||||
| 'environment' => array( | ||||||||
| 'type' => 'string', | ||||||||
| 'description' => __( 'The site\'s runtime environment classification (can be one of these: production, staging, development, local).' ), | ||||||||
| 'enum' => array( 'production', 'staging', 'development', 'local' ), | ||||||||
| ), | ||||||||
| 'php_version' => array( | ||||||||
| 'type' => 'string', | ||||||||
| 'description' => __( 'The PHP runtime version executing WordPress.' ), | ||||||||
| ), | ||||||||
| 'db_server_info' => array( | ||||||||
| 'type' => 'string', | ||||||||
| 'description' => __( 'The database server vendor and version string reported by the driver.' ), | ||||||||
| ), | ||||||||
| 'wp_version' => array( | ||||||||
| 'type' => 'string', | ||||||||
| 'description' => __( 'The WordPress core version running on this site.' ), | ||||||||
| 'fields' => array( | ||||||||
| 'type' => 'array', | ||||||||
| 'items' => array( | ||||||||
| 'type' => 'string', | ||||||||
| 'enum' => $environment_info_fields, | ||||||||
| ), | ||||||||
| 'description' => __( 'Optional: Limit response to specific fields. If omitted, all fields are returned.' ), | ||||||||
| ), | ||||||||
| ), | ||||||||
| 'additionalProperties' => false, | ||||||||
| 'default' => array(), | ||||||||
| ), | ||||||||
| 'output_schema' => array( | ||||||||
| 'type' => 'object', | ||||||||
| 'properties' => $environment_info_properties, | ||||||||
| 'additionalProperties' => false, | ||||||||
| ), | ||||||||
| 'execute_callback' => static function (): array { | ||||||||
| 'execute_callback' => static function ( $input = array() ) use ( $environment_info_fields ): array { | ||||||||
| global $wpdb; | ||||||||
|
|
||||||||
| $env = wp_get_environment_type(); | ||||||||
| $php_version = phpversion(); | ||||||||
| $db_server_info = ''; | ||||||||
| $input = is_array( $input ) ? $input : array(); | ||||||||
|
Member
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.
Suggested change
This addresses the following PHPStan issue: |
||||||||
| $requested_fields = ! empty( $input['fields'] ) ? $input['fields'] : $environment_info_fields; | ||||||||
|
|
||||||||
| $db_server_info = ''; | ||||||||
| if ( method_exists( $wpdb, 'db_server_info' ) ) { | ||||||||
| $db_server_info = $wpdb->db_server_info() ?? ''; | ||||||||
| } | ||||||||
| $wp_version = get_bloginfo( 'version' ); | ||||||||
|
|
||||||||
| return array( | ||||||||
| 'environment' => $env, | ||||||||
| 'php_version' => $php_version, | ||||||||
| $all = array( | ||||||||
| 'environment' => wp_get_environment_type(), | ||||||||
| 'php_version' => phpversion(), | ||||||||
| 'db_server_info' => $db_server_info, | ||||||||
| 'wp_version' => $wp_version, | ||||||||
| 'wp_version' => get_bloginfo( 'version' ), | ||||||||
| ); | ||||||||
|
|
||||||||
| return array_intersect_key( $all, array_flip( $requested_fields ) ); | ||||||||
| }, | ||||||||
| 'permission_callback' => static function (): bool { | ||||||||
| return current_user_can( 'manage_options' ); | ||||||||
|
|
||||||||
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
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.
It turns out that the WordPress version is included in two site abilities. I’ve aligned the title and description to reflect this.