Make WordPress Core

Changeset 56082


Ignore:
Timestamp:
06/28/2023 03:33:23 AM (15 months 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.

Location:
trunk
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/package-lock.json

    r56076 r56082  
    1272912729            "version": "1.1.0",
    1273012730            "resolved": "https://registry.npmjs.org/from2-string/-/from2-string-1.1.0.tgz",
    12731             "integrity": "sha1-GCgrJ9CKJnyzAwzSuLSw8hKvdSo=",
     12731            "integrity": "sha512-m8vCh+KnXXXBtfF2VUbiYlQ+nczLcntB0BrtNgpmLkHylhObe9WF1b2LZjBBzrZzA6P4mkEla6ZYQoOUTG8cYA==",
    1273212732            "requires": {
    1273312733                "from2": "^2.0.3"
     
    2180021800            "version": "1.1.6",
    2180121801            "resolved": "https://registry.npmjs.org/promise-polyfill/-/promise-polyfill-1.1.6.tgz",
    21802             "integrity": "sha1-zQTv9G9clcOn0EVZHXm14+AfEtc="
     21802            "integrity": "sha512-7rrONfyLkDEc7OJ5QBkqa4KI4EBhCd340xRuIUPGCfu13znS+vx+VDdrT9ODAJHlXm7w4lbxN3DRjyv58EuzDg=="
    2180321803        },
    2180421804        "prompts": {
     
    2398723987            "version": "1.0.0",
    2398823988            "resolved": "https://registry.npmjs.org/stream-from-promise/-/stream-from-promise-1.0.0.tgz",
    23989             "integrity": "sha1-djaH9913fkyJT2QIMz/Gs/yKYbs="
     23989            "integrity": "sha512-j84KLkudt+gr8KJ21RB02btPLx61uGbrLnewsWz6QKmsz8/c4ZFqXw6mJh5+G4oRN7DgDxdbjPxnpySpg1mUig=="
    2399023990        },
    2399123991        "stream-to-string": {
     
    2537525375            "version": "2.0.2",
    2537625376            "resolved": "https://registry.npmjs.org/toposort/-/toposort-2.0.2.tgz",
    25377             "integrity": "sha1-riF2gXXRVZ1IvvNUILL0li8JwzA="
     25377            "integrity": "sha512-0a5EOkAUp8D4moMi2W8ZF8jcga7BgZd91O/yabJCFY8az+XSzeGyTKs0Aoo897iV1Nj6guFq8orWDS96z91oGg=="
    2537825378        },
    2537925379        "totalist": {
  • trunk/src/wp-includes/rest-api.php

    r56052 r56082  
    316316    // Block Types.
    317317    $controller = new WP_REST_Block_Types_Controller();
     318    $controller->register_routes();
     319
     320    // Global Styles revisions.
     321    $controller = new WP_REST_Global_Styles_Revisions_Controller();
    318322    $controller->register_routes();
    319323
  • 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;
  • trunk/src/wp-settings.php

    r56052 r56082  
    262262require ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-attachments-controller.php';
    263263require ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-global-styles-controller.php';
     264require ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-global-styles-revisions-controller.php';
    264265require ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-post-types-controller.php';
    265266require ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-post-statuses-controller.php';
  • trunk/tests/phpunit/tests/rest-api/rest-schema-setup.php

    r55457 r56082  
    135135            '/wp/v2/comments/(?P<id>[\\d]+)',
    136136            '/wp/v2/global-styles/(?P<id>[\/\w-]+)',
     137            '/wp/v2/global-styles/(?P<parent>[\d]+)/revisions',
    137138            '/wp/v2/global-styles/themes/(?P<stylesheet>[\/\s%\w\.\(\)\[\]\@_\-]+)/variations',
    138139            '/wp/v2/global-styles/themes/(?P<stylesheet>[^\/:<>\*\?"\|]+(?:\/[^\/:<>\*\?"\|]+)?)',
  • trunk/tests/qunit/fixtures/wp-api-generated.js

    r56052 r56082  
    96199619            ]
    96209620        },
     9621        "/wp/v2/global-styles/(?P<parent>[\\d]+)/revisions": {
     9622            "namespace": "wp/v2",
     9623            "methods": [
     9624                "GET"
     9625            ],
     9626            "endpoints": [
     9627                {
     9628                    "methods": [
     9629                        "GET"
     9630                    ],
     9631                    "args": {
     9632                        "parent": {
     9633                            "description": "The ID for the parent of the revision.",
     9634                            "type": "integer",
     9635                            "required": false
     9636                        },
     9637                        "context": {
     9638                            "description": "Scope under which the request is made; determines fields present in response.",
     9639                            "type": "string",
     9640                            "enum": [
     9641                                "view",
     9642                                "embed",
     9643                                "edit"
     9644                            ],
     9645                            "default": "view",
     9646                            "required": false
     9647                        },
     9648                        "page": {
     9649                            "description": "Current page of the collection.",
     9650                            "type": "integer",
     9651                            "default": 1,
     9652                            "minimum": 1,
     9653                            "required": false
     9654                        },
     9655                        "per_page": {
     9656                            "description": "Maximum number of items to be returned in result set.",
     9657                            "type": "integer",
     9658                            "minimum": 1,
     9659                            "maximum": 100,
     9660                            "required": false
     9661                        },
     9662                        "offset": {
     9663                            "description": "Offset the result set by a specific number of items.",
     9664                            "type": "integer",
     9665                            "required": false
     9666                        }
     9667                    }
     9668                }
     9669            ]
     9670        },
    96219671        "/wp/v2/global-styles/themes/(?P<stylesheet>[\\/\\s%\\w\\.\\(\\)\\[\\]\\@_\\-]+)/variations": {
    96229672            "namespace": "wp/v2",
Note: See TracChangeset for help on using the changeset viewer.