Make WordPress Core


Ignore:
Timestamp:
01/15/2025 12:44:43 PM (5 months ago)
Author:
swissspidy
Message:

REST API: Improve autosave and revision endpoints for templates and template parts.

Fixes those endpoints for file-based templates and template parts, as templates based on theme files can't be revisioned or autosaved.

Props antonvlasenko, swissspidy, spacedmonkey, kadamwhite.
Fixes #61970.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-template-revisions-controller.php

    r58156 r59605  
    171171                'rest_post_invalid_parent',
    172172                __( 'Invalid template parent ID.' ),
    173                 array( 'status' => 404 )
     173                array( 'status' => WP_Http::NOT_FOUND )
     174            );
     175        }
     176
     177        $parent_post_id = isset( $template->wp_id ) ? (int) $template->wp_id : 0;
     178
     179        if ( $parent_post_id <= 0 ) {
     180            return new WP_Error(
     181                'rest_invalid_template',
     182                __( 'Templates based on theme files can\'t have revisions.' ),
     183                array( 'status' => WP_Http::BAD_REQUEST )
    174184            );
    175185        }
Note: See TracChangeset for help on using the changeset viewer.