Make WordPress Core

Changeset 64388


Ignore:
Timestamp:
10/16/2026 10:28:45 AM (29 hours ago)
Author:
jorgefilipecosta
Message:

Abilities API: Add the core/content-query ability.

Adds a read-only core/content-query ability that returns a page of the posts of one post type, optionally filtered by IDs, slugs, status, author, or parent. Until now, Core had no ability to read posts. The code lives in the new private WP_Abilities_Content class, and the ability is registered in a new content category.
Post types opt in with the new show_in_abilities argument of register_post_type(), which defaults to false. Only true exposes a post type, and the post and page post types set it.

Developed in ​https://github.com/WordPress/ai/pull/739 and ​https://github.com/WordPress/wordpress-develop/pull/12195.

Props jorgefilipecosta, gziolo, peterwilsoncc, ovidiu-galatan, justlevine, ugyensupport, dkotter, jason_the_adams, jasonbahl, jeffpaul.
Fixes #66268.

Location:
trunk
Files:
3 added
3 edited

Legend:

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

    r64346 r64388  
    1010declare( strict_types = 1 );
    1111
     12require_once __DIR__ . '/abilities/class-wp-abilities-content.php';
    1213require_once __DIR__ . '/abilities/class-wp-abilities-settings.php';
    1314require_once __DIR__ . '/abilities/class-wp-abilities-users.php';
    … …  
    1718 *
    1819 * @since 6.9.0
    19  * @since 7.2.0 Added the `uncategorized` category.
     20 * @since 7.2.0 Added the `content` and `uncategorized` categories.
    2021 */
    2122function wp_register_core_ability_categories(): void {
    … …  
    3738
    3839        wp_register_ability_category(
     40                'content',
     41                array(
     42                        'label'       => __( 'Content' ),
     43                        'description' => __( 'Abilities that retrieve or manage posts and other content.' ),
     44                )
     45        );
     46
     47        wp_register_ability_category(
    3948                'uncategorized',
    4049                array(
    … …  
    4958 *
    5059 * @since 6.9.0
    51  * @since 7.2.0 Added the `core/settings-get` and `core/users-query` abilities.
     60 * @since 7.2.0 Added the `core/content-query`, `core/settings-get`, and `core/users-query` abilities.
    5261 *
    5362 * @global wpdb $wpdb WordPress database abstraction object.
    … …  
    371380        // Register the user abilities (currently the read-only `core/users-query`).
    372381        ( new WP_Abilities_Users() )->register();
     382
     383        // Register the content abilities (currently the read-only `core/content-query`).
     384        ( new WP_Abilities_Content() )->register();
    373385}
  • trunk/src/wp-includes/class-wp-post-type.php

    r63541 r64388  
    373373         */
    374374        public $show_in_rest;
     375
     376        /**
     377         * Whether this post type should be exposed through the Abilities API.
     378         *
     379         * Default false. If true, the core content abilities can access the post type's
     380         * posts, subject to the current user's capabilities.
     381         *
     382         * @since 7.2.0
     383         * @var bool $show_in_abilities
     384         */
     385        public $show_in_abilities;
    375386
    376387        /**
    … …  
    554565                        'delete_with_user'                => null,
    555566                        'show_in_rest'                    => false,
     567                        'show_in_abilities'               => false,
    556568                        'rest_base'                       => false,
    557569                        'rest_namespace'                  => false,
    … …  
    583595                        $args['rest_namespace'] = 'wp/v2';
    584596                }
     597
     598                // Only `true` exposes the post type, so other values, such as arrays, can be given a meaning later.
     599                $args['show_in_abilities'] = true === $args['show_in_abilities'];
    585600
    586601                // If not set, default to the setting for 'show_ui'.
  • trunk/src/wp-includes/post.php

    r64245 r64388  
    5151                        ),
    5252                        'show_in_rest'          => true,
     53                        'show_in_abilities'     => true,
    5354                        'rest_base'             => 'posts',
    5455                        'rest_controller_class' => 'WP_REST_Posts_Controller',
    … …  
    8586                        ),
    8687                        'show_in_rest'          => true,
     88                        'show_in_abilities'     => true,
    8789                        'rest_base'             => 'pages',
    8890                        'rest_controller_class' => 'WP_REST_Posts_Controller',
    … …  
    16921694 * @since 5.3.0 The `supports` argument will now accept an array of arguments for a feature.
    16931695 * @since 5.9.0 The `rest_namespace` argument was added.
     1696 * @since 7.2.0 The `show_in_abilities` argument was added.
    16941697 *
    16951698 * @global array $wp_post_types List of post types.
    … …  
    17371740 *     @type bool         $show_in_rest                    Whether to include the post type in the REST API. Set this to true
    17381741 *                                                         for the post type to be available in the block editor.
     1742 *     @type bool         $show_in_abilities               Whether to expose this post type through the Abilities API, so the
     1743 *                                                         core content abilities can access its posts, subject to the current
     1744 *                                                         user's capabilities. Default false.
    17391745 *     @type string       $rest_base                       To change the base URL of REST API route. Default is $post_type.
    17401746 *     @type string       $rest_namespace                  To change the namespace URL of REST API route. Default is wp/v2.
Note: See TracChangeset for help on using the changeset viewer.