Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ protected function prepare_links( $id ) {
* Get the link relations available for the post and current user.
*
* @since 5.9.0
* @since 6.2.0 Added 'edit-css' action.
*
* @return array List of link relations.
*/
Expand All @@ -442,6 +443,10 @@ protected function get_available_actions() {
$rels[] = 'https://api.w.org/action-publish';
}

if ( current_user_can( 'edit_css' ) ) {
$rels[] = 'https://api.w.org/action-edit-css';
}
Comment on lines +446 to +448
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's an unanswered question from the Gutenberg PR

I couldn't find documentation on how these URLs are generated/created. So I need to double-check if https://api.w.org/action-edit-css is the correct format.

Pinging @TimothyBJacobs @spacedmonkey for review.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All similar action URLs lead to a 404 page - https://api.wordpress.org/action-unfiltered-html.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TimothyBJacobs, @spacedmonkey, can you confirm that it's okay to use this URL?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for missing this the first time round. The URLs don't actually point anywhere. That URL is fine to use.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @TimothyBJacobs!


return $rels;
}

Expand Down
19 changes: 19 additions & 0 deletions tests/phpunit/tests/rest-api/rest-global-styles-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -513,4 +513,23 @@ public function test_get_theme_items() {
);
$this->assertSameSetsWithIndex( $data, $expected );
}

/**
* @covers WP_REST_Global_Styles_Controller::get_available_actions
*/
public function test_assign_edit_css_action_admin() {
wp_set_current_user( self::$admin_id );

$request = new WP_REST_Request( 'GET', '/wp/v2/global-styles/' . self::$global_styles_id );
$request->set_param( 'context', 'edit' );
$response = rest_do_request( $request );
$links = $response->get_links();

// Admins can only edit css on single site.
if ( is_multisite() ) {
$this->assertArrayNotHasKey( 'https://api.w.org/action-edit-css', $links );
} else {
$this->assertArrayHasKey( 'https://api.w.org/action-edit-css', $links );
}
}
Comment on lines +520 to +534
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job @Mamaduka 👏

}