Make WordPress Core

Changeset 55177


Ignore:
Timestamp:
02/01/2023 06:36:08 PM (16 months ago)
Author:
hellofromTonya
Message:

REST API: Declare 'edit_css' capability in links within WP_REST_Global_Styles_Controller.

Updates the Global Styles endpoint to expose the 'edit_css' capability via action links.

References:

  • Gutenberg PR 46815 Part of an effort to hide custom CSS setting for users without 'edit_css' capability.

Follow-up to [52342], [52051].

Props mamaduka, dsas, glendaviesnz, mmtr86, talldanwp, timothyblynjacobs.
Fixes #57526.

Location:
trunk
Files:
2 edited

Legend:

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

    r54817 r55177  
    432432     *
    433433     * @since 5.9.0
     434     * @since 6.2.0 Added 'edit-css' action.
    434435     *
    435436     * @return array List of link relations.
     
    441442        if ( current_user_can( $post_type->cap->publish_posts ) ) {
    442443            $rels[] = 'https://api.w.org/action-publish';
     444        }
     445
     446        if ( current_user_can( 'edit_css' ) ) {
     447            $rels[] = 'https://api.w.org/action-edit-css';
    443448        }
    444449
  • trunk/tests/phpunit/tests/rest-api/rest-global-styles-controller.php

    r54402 r55177  
    514514        $this->assertSameSetsWithIndex( $data, $expected );
    515515    }
     516
     517    /**
     518     * @covers WP_REST_Global_Styles_Controller::get_available_actions
     519     */
     520    public function test_assign_edit_css_action_admin() {
     521        wp_set_current_user( self::$admin_id );
     522
     523        $request = new WP_REST_Request( 'GET', '/wp/v2/global-styles/' . self::$global_styles_id );
     524        $request->set_param( 'context', 'edit' );
     525        $response = rest_do_request( $request );
     526        $links    = $response->get_links();
     527
     528        // Admins can only edit css on single site.
     529        if ( is_multisite() ) {
     530            $this->assertArrayNotHasKey( 'https://api.w.org/action-edit-css', $links );
     531        } else {
     532            $this->assertArrayHasKey( 'https://api.w.org/action-edit-css', $links );
     533        }
     534    }
    516535}
Note: See TracChangeset for help on using the changeset viewer.