Make WordPress Core


Ignore:
Timestamp:
02/01/2023 06:36:08 PM (2 years 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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.