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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ the initial snapshot of the prototype.

### Added

- Backport the three info abilities introduced in WordPress 6.9. Sites that already register them keep their native implementation.

- Repository scaffold and tooling: Composer contract for `wordpress/abilities`
(type `library`, zero runtime dependencies, PSR-4 `WordPress\Abilities\` →
`src/`), WPCS and PHPStan lint configs (`composer run lint:phpcs`,
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ Full rules, the promotion path, and the rename protocol are in

| Name | Tier | Category | Notes |
|---|---|---|---|
| `core/get-site-info` | core | site | Reads site settings, optionally limited to selected fields. Requires `manage_options`. |
| `core/get-user-info` | core | user | Reads the signed-in user's own profile. The 6.9 package copy is excluded from REST. |
| `core/get-environment-info` | core | site | Reads the runtime and database versions and the WordPress environment type. Requires `manage_options`. |
| `core/content-query` | core | content | Backport of the readonly content query ability landed in WordPress core 7.2 (`core_since: 7.2`). On 7.2+ core provides it and the Registrar skips it; on 6.9–7.1 the package serves it under the same name. Requires the `show_in_abilities` support feature (polyfilled where core lacks it). |
| `core/settings-get` | core | site | Backport of the readonly settings get ability landed in WordPress core 7.2 (`core_since: 7.2`). On 7.2+ core provides it and the Registrar skips it; on 6.9–7.1 the package serves it under the same name. Requires the `setting_show_in_abilities` support feature (polyfilled where core lacks it: core's own settings are flagged and registered before the ability reads them, as on 7.2). |
| `core/users-query` | core | user | Backport of the readonly users query ability landed in WordPress core 7.2 (`core_since: 7.2`). On 7.2+ core provides it and the Registrar skips it; on 6.9–7.1 the package serves it under the same name. Needs no support feature beyond the Abilities API. |
Expand Down
72 changes: 72 additions & 0 deletions src/Info/Abstract_Info_Ability.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php
/**
* Adapter for the registration arrays used by the WordPress 6.9 info abilities.
*
* @package WordPress\Abilities
*/

declare( strict_types = 1 );

namespace WordPress\Abilities\Info;

use WordPress\Abilities\Abstract_Core_Ability;

/**
* Keeps each original registration together, including values shared by its
* schemas and callbacks. Core's class-based abilities use separate methods.
*/
abstract class Abstract_Info_Ability extends Abstract_Core_Ability {
/**
* Registration arguments, evaluated once per ability instance.
*
* @var array<string, mixed>
*/
private array $args;

/**
* Returns the arguments from the original wp_register_ability() call.
*
* @return array<string, mixed>
*/
abstract protected function registration_args(): array;

protected function prepare(): void {
$this->args = $this->registration_args();
}

protected function label(): string {
return $this->args['label'];
}

protected function description(): string {
return $this->args['description'];
}

protected function category_slug(): string {
return $this->args['category'];
}

protected function input_schema(): array {
return $this->args['input_schema'] ?? array();
}

protected function output_schema(): array {
return $this->args['output_schema'];
}

protected function make_execute_callback(): callable {
return $this->args['execute_callback'];
}

protected function make_permission_callback(): callable {
return $this->args['permission_callback'];
}

protected function required_capabilities(): array {
return array();
}

protected function ability_meta(): array {
return $this->args['meta'];
}
}
79 changes: 79 additions & 0 deletions src/Info/Get_Environment_Info.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php
/**
* WordPress 6.9 registration for core/get-environment-info.
*
* @package WordPress\Abilities
*/

declare( strict_types = 1 );

namespace WordPress\Abilities\Info;

/** Provides the core/get-environment-info ability when Core has not registered it. */
final class Get_Environment_Info extends Abstract_Info_Ability {
protected function ability_name(): string {
return 'core/get-environment-info';
}

protected function registration_args(): array {
$category_site = 'site';
return 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).' ),
'category' => $category_site,
'output_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.' ),
),
),
'additionalProperties' => false,
),
'execute_callback' => static function (): array {
global $wpdb;

$env = wp_get_environment_type();
$php_version = phpversion();
$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,
'db_server_info' => $db_server_info,
'wp_version' => $wp_version,
);
},
'permission_callback' => static function (): bool {
return current_user_can( 'manage_options' );
},
'meta' => array(
'annotations' => array(
'readonly' => true,
'destructive' => false,
'idempotent' => true,
),
'show_in_rest' => true,
),
);
}
}
103 changes: 103 additions & 0 deletions src/Info/Get_Site_Info.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<?php
/**
* WordPress 6.9 registration for core/get-site-info.
*
* @package WordPress\Abilities
*/

declare( strict_types = 1 );

namespace WordPress\Abilities\Info;

/** Provides the core/get-site-info ability when Core has not registered it. */
final class Get_Site_Info extends Abstract_Info_Ability {
protected function ability_name(): string {
return 'core/get-site-info';
}

protected function registration_args(): array {
$category_site = 'site';
$site_info_properties = array(
'name' => array(
'type' => 'string',
'description' => __( 'The site title.' ),
),
'description' => array(
'type' => 'string',
'description' => __( 'The site tagline.' ),
),
'url' => array(
'type' => 'string',
'description' => __( 'The site home URL.' ),
),
'wpurl' => array(
'type' => 'string',
'description' => __( 'The WordPress installation URL.' ),
),
'admin_email' => array(
'type' => 'string',
'description' => __( 'The site administrator email address.' ),
),
'charset' => array(
'type' => 'string',
'description' => __( 'The site character encoding.' ),
),
'language' => array(
'type' => 'string',
'description' => __( 'The site language locale code.' ),
),
'version' => array(
'type' => 'string',
'description' => __( 'The WordPress version.' ),
),
);
$site_info_fields = array_keys( $site_info_properties );
return array(
'label' => __( 'Get Site Information' ),
'description' => __( 'Returns site information configured in WordPress. By default returns all fields, or optionally a filtered subset.' ),
'category' => $category_site,
'input_schema' => array(
'type' => 'object',
'properties' => array(
'fields' => array(
'type' => 'array',
'items' => array(
'type' => 'string',
'enum' => $site_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' => $site_info_properties,
'additionalProperties' => false,
),
'execute_callback' => static function ( $input = array() ) use ( $site_info_fields ): array {
$input = is_array( $input ) ? $input : array();
$requested_fields = ! empty( $input['fields'] ) ? $input['fields'] : $site_info_fields;

$result = array();
foreach ( $requested_fields as $field ) {
$result[ $field ] = get_bloginfo( $field );
}

return $result;
},
'permission_callback' => static function (): bool {
return current_user_can( 'manage_options' );
},
'meta' => array(
'annotations' => array(
'readonly' => true,
'destructive' => false,
'idempotent' => true,
),
'show_in_rest' => true,
),
);
}
}
83 changes: 83 additions & 0 deletions src/Info/Get_User_Info.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php
/**
* WordPress 6.9 registration for core/get-user-info.
*
* @package WordPress\Abilities
*/

declare( strict_types = 1 );

namespace WordPress\Abilities\Info;

/** Provides the core/get-user-info ability when Core has not registered it. */
final class Get_User_Info extends Abstract_Info_Ability {
protected function ability_name(): string {
return 'core/get-user-info';
}

protected function registration_args(): array {
$category_user = 'user';
return array(
'label' => __( 'Get User Information' ),
'description' => __( 'Returns basic profile details for the current authenticated user to support personalization, auditing, and access-aware behavior.' ),
'category' => $category_user,
'output_schema' => array(
'type' => 'object',
'required' => array( 'id', 'display_name', 'user_nicename', 'user_login', 'roles', 'locale' ),
'properties' => array(
'id' => array(
'type' => 'integer',
'description' => __( 'The user ID.' ),
),
'display_name' => array(
'type' => 'string',
'description' => __( 'The display name of the user.' ),
),
'user_nicename' => array(
'type' => 'string',
'description' => __( 'The URL-friendly name for the user.' ),
),
'user_login' => array(
'type' => 'string',
'description' => __( 'The login username for the user.' ),
),
'roles' => array(
'type' => 'array',
'description' => __( 'The roles assigned to the user.' ),
'items' => array(
'type' => 'string',
),
),
'locale' => array(
'type' => 'string',
'description' => __( 'The locale string for the user, such as en_US.' ),
),
),
'additionalProperties' => false,
),
'execute_callback' => static function (): array {
$current_user = wp_get_current_user();

return array(
'id' => $current_user->ID,
'display_name' => $current_user->display_name,
'user_nicename' => $current_user->user_nicename,
'user_login' => $current_user->user_login,
'roles' => $current_user->roles,
'locale' => get_user_locale( $current_user ),
);
},
'permission_callback' => static function (): bool {
return is_user_logged_in();
},
'meta' => array(
'annotations' => array(
'readonly' => true,
'destructive' => false,
'idempotent' => true,
),
'show_in_rest' => false,
),
);
}
}
33 changes: 33 additions & 0 deletions src/Manifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,39 @@ private function __construct() {}
*/
public static function all(): array {
return array(
'core/get-site-info' => array(
'name' => 'core/get-site-info',
'class' => Info\Get_Site_Info::class,
'category' => 'site',
'tier' => self::TIER_CORE,
'min_wp_version' => '6.9',
'core_since' => '6.9',
'requires' => array(),
'renamed_from' => null,
'proposal' => 'https://core.trac.wordpress.org/ticket/64146',
),
'core/get-user-info' => array(
'name' => 'core/get-user-info',
'class' => Info\Get_User_Info::class,
'category' => 'user',
'tier' => self::TIER_CORE,
'min_wp_version' => '6.9',
'core_since' => '6.9',
'requires' => array(),
'renamed_from' => null,
'proposal' => 'https://core.trac.wordpress.org/ticket/64146',
),
'core/get-environment-info' => array(
'name' => 'core/get-environment-info',
'class' => Info\Get_Environment_Info::class,
'category' => 'site',
'tier' => self::TIER_CORE,
'min_wp_version' => '6.9',
'core_since' => '6.9',
'requires' => array(),
'renamed_from' => null,
'proposal' => 'https://core.trac.wordpress.org/ticket/64146',
),
'core/content-query' => array(
'name' => 'core/content-query',
/*
Expand Down
Loading
Loading