Commit 8092f75721 for wordpress.org
commit 8092f75721f784efbb69ea445f443bbb4fed2aea
Author: jorgefilipecosta <jorgefilipecosta@git.wordpress.org>
Date: Fri Oct 16 22:47:46 2026 +0000
REST API: Add the homepage and posts page action links to pages.
Adds the `action-set-homepage` and `action-set-posts-page` links to the published pages the current user can set as the homepage or as the posts page, in the `edit` context, and their link description objects to the pages schema. Both change the site settings, so they require `manage_options`, and the current homepage and posts page get neither. The editor uses them for its "Set as homepage" and "Set as posts page" actions.
Developed in https://github.com/WordPress/wordpress-develop/pull/14347 and https://github.com/WordPress/gutenberg/pull/84932.
Follow-up to [64343].
Props jorgefilipecosta, oandregal, chihsuan.
Fixes #66327.
Built from https://develop.svn.wordpress.org/trunk@64433
git-svn-id: http://core.svn.wordpress.org/trunk@63583 1a063a9b-81f0-0310-95a4-ce76da25c4cd
diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
index e276afe5a7..1ba3604190 100644
--- a/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
+++ b/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
@@ -2333,7 +2333,7 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
* Gets the link relations available for the post and current user.
*
* @since 4.9.8
- * @since 7.2.0 Added the `action-trash` link relation.
+ * @since 7.2.0 Added the `action-trash`, `action-set-homepage`, and `action-set-posts-page` link relations.
*
* @param WP_Post $post Post object.
* @param WP_REST_Request $request Request object.
@@ -2382,6 +2382,18 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
}
}
+ /*
+ * Setting a page as the homepage or as the posts page changes the site settings,
+ * so it requires the same capability as the settings route. The current homepage
+ * and posts page get neither link.
+ */
+ if ( 'page' === $post_type->name && 'publish' === $post->post_status && current_user_can( 'manage_options' ) ) {
+ if ( (int) get_option( 'page_on_front' ) !== $post->ID && (int) get_option( 'page_for_posts' ) !== $post->ID ) {
+ $rels[] = 'https://api.w.org/action-set-homepage';
+ $rels[] = 'https://api.w.org/action-set-posts-page';
+ }
+ }
+
$taxonomies = wp_list_filter( get_object_taxonomies( $this->post_type, 'objects' ), array( 'show_in_rest' => true ) );
foreach ( $taxonomies as $tax ) {
@@ -2853,7 +2865,7 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
* Retrieves Link Description Objects that should be added to the Schema for the posts collection.
*
* @since 4.9.8
- * @since 7.2.0 Added the `action-trash` link relation.
+ * @since 7.2.0 Added the `action-trash`, `action-set-homepage`, and `action-set-posts-page` link relations.
*
* @return array
*/
@@ -2934,6 +2946,20 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
'href' => $href,
);
+ if ( 'page' === $this->post_type ) {
+ $links[] = array(
+ 'rel' => 'https://api.w.org/action-set-homepage',
+ 'title' => __( 'The current user can set this page as the homepage.' ),
+ 'href' => $href,
+ );
+
+ $links[] = array(
+ 'rel' => 'https://api.w.org/action-set-posts-page',
+ 'title' => __( 'The current user can set this page as the posts page.' ),
+ 'href' => $href,
+ );
+ }
+
$taxonomies = wp_list_filter( get_object_taxonomies( $this->post_type, 'objects' ), array( 'show_in_rest' => true ) );
foreach ( $taxonomies as $tax ) {
diff --git a/wp-includes/version.php b/wp-includes/version.php
index 160306ba95..00ff0a96a4 100644
--- a/wp-includes/version.php
+++ b/wp-includes/version.php
@@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
-$wp_version = '7.2-alpha-64432';
+$wp_version = '7.2-alpha-64433';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.