Make WordPress Core


Ignore:
Timestamp:
06/28/2023 03:33:23 AM (3 years ago)
Author:
isabel_brison
Message:

REST API: add revisions endpoint for global styles.

Adds an endpoint that returns revisions to the global styles custom post.

Props ramonopoly, peterwilsoncc, spacedmonkey, mukesh27, timothyblynjacobs.
Fixes #58524.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-global-styles-controller.php

    r55725 r56082  
    421421         *
    422422         * @since 5.9.0
     423         * @since 6.3.0 Adds revisions count and rest URL href to version-history.
    423424         *
    424425         * @param integer $id ID.
    … …  
    433434                        ),
    434435                );
     436
     437                if ( post_type_supports( $this->post_type, 'revisions' ) ) {
     438                        $revisions       = wp_get_latest_revision_id_and_total_count( $id );
     439                        $revisions_count = ! is_wp_error( $revisions ) ? $revisions['count'] : 0;
     440                        $revisions_base  = sprintf( '/%s/%d/revisions', $base, $id );
     441                        $links['version-history'] = array(
     442                                'href'  => rest_url( $revisions_base ),
     443                                'count' => $revisions_count,
     444                        );
     445                }
    435446
    436447                return $links;
Note: See TracChangeset for help on using the changeset viewer.