Make WordPress Core


Ignore:
Timestamp:
05/28/2026 07:46:15 AM (3 months ago)
Author:
gziolo
Message:

Abilities API: Unify schema conventions across core abilities

Align core/get-site-info, core/get-user-info, and core/get-environment-info on a shared blueprint: every output property carries a Title Case title and a description, core/get-environment-info gains the optional fields input parameter the other two already accept, and core/get-user-info is exposed via REST. Descriptions are also tightened for programmatic consumers, and registration tests now lock the exact ordered set of property keys.

Props gziolo, westonruter.
Fixes #65355.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/abilities.php

    r62419 r62426  
    4747                'name'        => array(
    4848                        'type'        => 'string',
     49                        'title'       => __( 'Site Title' ),
    4950                        'description' => __( 'The site title.' ),
    5051                ),
    5152                'description' => array(
    5253                        'type'        => 'string',
     54                        'title'       => __( 'Tagline' ),
    5355                        'description' => __( 'The site tagline.' ),
    5456                ),
    5557                'url'         => array(
    5658                        'type'        => 'string',
    57                         'description' => __( 'The site home URL.' ),
     59                        'title'       => __( 'Site Address (URL)' ),
     60                        'description' => __( 'The public URL where visitors access the site. May differ from the WordPress installation URL.' ),
    5861                ),
    5962                'wpurl'       => array(
    6063                        'type'        => 'string',
    61                         'description' => __( 'The WordPress installation URL.' ),
     64                        'title'       => __( 'WordPress Address (URL)' ),
     65                        'description' => __( 'The URL where WordPress core files are served. May differ from the public site URL.' ),
    6266                ),
    6367                'admin_email' => array(
    6468                        'type'        => 'string',
     69                        'title'       => __( 'Administration Email Address' ),
    6570                        'description' => __( 'The site administrator email address.' ),
    6671                ),
    6772                'charset'     => array(
    6873                        'type'        => 'string',
     74                        'title'       => __( 'Site Charset' ),
    6975                        'description' => __( 'The site character encoding.' ),
    7076                ),
    7177                'language'    => array(
    7278                        'type'        => 'string',
    73                         'description' => __( 'The site language locale code.' ),
     79                        'title'       => __( 'Site Language' ),
     80                        'description' => __( 'The site locale in dash form (e.g. en-US).' ),
    7481                ),
    7582                'version'     => array(
    7683                        'type'        => 'string',
    77                         'description' => __( 'The WordPress version.' ),
     84                        'title'       => __( 'WordPress Version' ),
     85                        'description' => __( 'The WordPress core version running on this site.' ),
    7886                ),
    7987        );
     
    139147                        'type'        => 'integer',
    140148                        'title'       => __( 'User ID' ),
    141                         'description' => __( 'Unique numeric identifier for the user.' ),
     149                        'description' => __( 'Unique identifier for the user.' ),
    142150                ),
    143151                'display_name'  => array(
     
    187195                        'type'        => 'string',
    188196                        'title'       => __( 'Biographical Info' ),
    189                         'description' => __( 'User-authored biography, often shown on author pages.' ),
     197                        'description' => __( 'User-authored biography. May be empty.' ),
    190198                ),
    191199                'user_url'      => array(
     
    254262                                        'idempotent'  => true,
    255263                                ),
    256                                 'show_in_rest' => false,
    257                         ),
    258                 )
    259         );
     264                                'show_in_rest' => true,
     265                        ),
     266                )
     267        );
     268
     269        $environment_info_properties = array(
     270                'environment'    => array(
     271                        'type'        => 'string',
     272                        'title'       => __( 'Environment Type' ),
     273                        'description' => __( 'The site\'s runtime environment classification.' ),
     274                        'enum'        => array( 'production', 'staging', 'development', 'local' ),
     275                ),
     276                'php_version'    => array(
     277                        'type'        => 'string',
     278                        'title'       => __( 'PHP Version' ),
     279                        'description' => __( 'The PHP runtime version executing WordPress.' ),
     280                ),
     281                'db_server_info' => array(
     282                        'type'        => 'string',
     283                        'title'       => __( 'Database Server Info' ),
     284                        'description' => __( 'The database server vendor and version string reported by the driver.' ),
     285                ),
     286                'wp_version'     => array(
     287                        'type'        => 'string',
     288                        'title'       => __( 'WordPress Version' ),
     289                        'description' => __( 'The WordPress core version running on this site.' ),
     290                ),
     291        );
     292        $environment_info_fields     = array_keys( $environment_info_properties );
    260293
    261294        wp_register_ability(
     
    263296                array(
    264297                        'label'               => __( 'Get Environment Info' ),
    265                         'description'         => __( 'Returns core details about the site\'s runtime context for diagnostics and compatibility (environment, PHP runtime, database server info, WordPress version).' ),
     298                        '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.' ),
    266299                        'category'            => $category_site,
     300                        'input_schema'        => array(
     301                                'type'                 => 'object',
     302                                'properties'           => array(
     303                                        'fields' => array(
     304                                                'type'        => 'array',
     305                                                'items'       => array(
     306                                                        'type' => 'string',
     307                                                        'enum' => $environment_info_fields,
     308                                                ),
     309                                                'description' => __( 'Optional: Limit response to specific fields. If omitted, all fields are returned.' ),
     310                                        ),
     311                                ),
     312                                'additionalProperties' => false,
     313                                'default'              => array(),
     314                        ),
    267315                        'output_schema'       => array(
    268316                                'type'                 => 'object',
    269                                 'required'             => array( 'environment', 'php_version', 'db_server_info', 'wp_version' ),
    270                                 'properties'           => array(
    271                                         'environment'    => array(
    272                                                 'type'        => 'string',
    273                                                 'description' => __( 'The site\'s runtime environment classification (can be one of these: production, staging, development, local).' ),
    274                                                 'enum'        => array( 'production', 'staging', 'development', 'local' ),
    275                                         ),
    276                                         'php_version'    => array(
    277                                                 'type'        => 'string',
    278                                                 'description' => __( 'The PHP runtime version executing WordPress.' ),
    279                                         ),
    280                                         'db_server_info' => array(
    281                                                 'type'        => 'string',
    282                                                 'description' => __( 'The database server vendor and version string reported by the driver.' ),
    283                                         ),
    284                                         'wp_version'     => array(
    285                                                 'type'        => 'string',
    286                                                 'description' => __( 'The WordPress core version running on this site.' ),
    287                                         ),
    288                                 ),
    289                                 'additionalProperties' => false,
    290                         ),
    291                         'execute_callback'    => static function (): array {
     317                                'properties'           => $environment_info_properties,
     318                                'additionalProperties' => false,
     319                        ),
     320                        'execute_callback'    => static function ( $input = array() ) use ( $environment_info_fields ): array {
    292321                                global $wpdb;
    293322
    294                                 $env          = wp_get_environment_type();
    295                                 $php_version  = phpversion();
    296                                 $db_server_info  = '';
     323                                /** @var array{ fields?: string[] } $input */
     324                                $input            = is_array( $input ) ? $input : array();
     325                                $requested_fields = ! empty( $input['fields'] ) ? $input['fields'] : $environment_info_fields;
     326
     327                                $db_server_info = '';
    297328                                if ( method_exists( $wpdb, 'db_server_info' ) ) {
    298329                                        $db_server_info = $wpdb->db_server_info() ?? '';
    299330                                }
    300                                 $wp_version   = get_bloginfo( 'version' );
    301 
    302                                 return array(
    303                                         'environment'    => $env,
    304                                         'php_version'    => $php_version,
     331
     332                                $all = array(
     333                                        'environment'    => wp_get_environment_type(),
     334                                        'php_version'    => phpversion(),
    305335                                        'db_server_info' => $db_server_info,
    306                                         'wp_version'     => $wp_version,
     336                                        'wp_version'     => get_bloginfo( 'version' ),
    307337                                );
     338
     339                                return array_intersect_key( $all, array_flip( $requested_fields ) );
    308340                        },
    309341                        'permission_callback' => static function (): bool {
Note: See TracChangeset for help on using the changeset viewer.