Skip to content
Closed
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
d228880
Initial commit.
ramonjd Nov 23, 2023
545ab8e
Adding title to schema.
ramonjd Nov 23, 2023
c78632b
Remove permissions checks and favour parent's
ramonjd Nov 23, 2023
19a1472
Remove duplicated tests
ramonjd Nov 23, 2023
d21c06b
Reverting post type registration changes as it assigns an autosave co…
ramonjd Nov 23, 2023
1951603
Regenerated fixture
ramonjd Nov 23, 2023
d6fba2e
Revert introducing title in schema
ramonjd Nov 23, 2023
a5a0eae
Reinstating global styles revision controller tests that were duplica…
ramonjd Jan 3, 2024
b252d46
Update src/wp-includes/rest-api/endpoints/class-wp-rest-global-styles…
ramonjd Dec 22, 2023
5e7499b
Excluding search, include and exclude from the collection query params
ramonjd Jan 3, 2024
e7d8ddd
Now that https://github.com/WordPress/wordpress-develop/pull/5655 has…
ramonjd Jan 31, 2024
5610ff8
Pulling across changes from https://github.com/WordPress/wordpress-de…
ramonjd Feb 7, 2024
b90bac9
Implementing latest round of feedback:
ramonjd Feb 8, 2024
151dcbb
Apply suggestions from code review
spacedmonkey Feb 13, 2024
aa78d5d
Fix lints
jonnynews Feb 13, 2024
5ce4f0a
Remove ideas
jonnynews Feb 13, 2024
315daba
Fix
jonnynews Feb 13, 2024
010cb54
Add allow_batch parameter.
jonnynews Feb 13, 2024
550190d
Be overly safe with `__construct` method.
jonnynews Feb 13, 2024
cb3019b
Apply suggestions from code review
spacedmonkey Feb 13, 2024
0dea2cc
Add 'allow_batch' option to API endpoints in WP API
jonnynews Feb 13, 2024
18ef3eb
Implemented feedback from Github PR #6105
ramonjd May 18, 2024
60cb37b
remove_post_type_support to disable autosave endpoints for global styles
ramonjd May 28, 2024
71fc3a8
annotations
ramonjd May 28, 2024
c3d6d00
Undo typo
swissspidy May 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Implementing latest round of feedback:
removing __construct, get_item and update_item in favour of the parent class methods

Add $allow_batch property, setting it to false
  • Loading branch information
ramonjd committed May 28, 2024
commit b90bac9de04de671417db66151a439969fa52dfa
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,12 @@
*/
class WP_REST_Global_Styles_Controller extends WP_REST_Posts_Controller {
/**
* Constructor.
* Whether the controller supports batching.
*
* @since 5.9.0
* @since 6.5.0 Extends class from WP_REST_Posts_Controller.
*
* @param string $post_type Post type.
* @since 6.5.0
* @var array
*/
public function __construct( $post_type ) {
$this->post_type = $post_type;
$obj = get_post_type_object( $post_type );
$this->rest_base = ! empty( $obj->rest_base ) ? $obj->rest_base : $obj->name;
$this->namespace = ! empty( $obj->rest_namespace ) ? $obj->rest_namespace : 'wp/v2';
}
protected $allow_batch = array( 'v1' => false );

/**
* Registers the controllers routes.
Expand Down Expand Up @@ -194,24 +187,6 @@ public function check_read_permission( $post ) {
return current_user_can( 'read_post', $post->ID );
}

/**
* Returns the given global styles config.
*
* @since 5.9.0
*
* @param WP_REST_Request $request The request instance.
*
* @return WP_REST_Response|WP_Error
*/
public function get_item( $request ) {
$post = $this->get_post( $request['id'] );
if ( is_wp_error( $post ) ) {
return $post;
}

return $this->prepare_item_for_response( $post, $request );
}

/**
* Checks if a given request has access to write a single global styles config.
*
Expand All @@ -237,43 +212,6 @@ public function update_item_permissions_check( $request ) {
return true;
}

/**
* Updates a single global style config.
*
* @since 5.9.0
*
* @param WP_REST_Request $request Full details about the request.
* @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
*/
public function update_item( $request ) {
$post_before = $this->get_post( $request['id'] );
if ( is_wp_error( $post_before ) ) {
return $post_before;
}

$changes = $this->prepare_item_for_database( $request );
if ( is_wp_error( $changes ) ) {
return $changes;
}

$result = wp_update_post( wp_slash( (array) $changes ), true, false );
if ( is_wp_error( $result ) ) {
return $result;
}

$post = get_post( $request['id'] );
$fields_update = $this->update_additional_fields_for_object( $post, $request );
if ( is_wp_error( $fields_update ) ) {
return $fields_update;
}

wp_after_insert_post( $post, true, $post_before );

$response = $this->prepare_item_for_response( $post, $request );

return rest_ensure_response( $response );
}

/**
* Prepares a single global styles config for update.
*
Expand Down