Make WordPress Core


Ignore:
Timestamp:
09/30/2025 05:05:21 PM (11 months ago)
Author:
desrosj
Message:

Grouped backports for the 5.2 branch.

  • REST API: Increase the specificity of capability checks for collections when the edit context is in use.
  • Menus: Prevent HTML in menu item titles from being rendered unexpectedly.

Merges [60814], [60815], [60816] to the 5.2 branch.

Props andraganescu, desrosj, ehti, hurayraiit, iandunn, joehoyle, johnbillion, jorbin, mnelson4, noisysocks, peterwilsoncc, phillsav, rmccue, timothyblynjacobs, vortfu, westonruter , whyisjake, zieladam.

Location:
branches/5.2
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/5.2

  • branches/5.2/tests/phpunit/tests/rest-api/rest-tags-controller.php

    r44510 r60834  
    12701270        }
    12711271
     1272        /**
     1273         * @group 1018470
     1274         */
     1275        public function test_cannot_get_single_term_with_edit_context_if_disallowed() {
     1276                add_filter(
     1277                        'map_meta_cap',
     1278                        static function ( $caps, $cap ) {
     1279                                if ( 'edit_term' === $cap ) {
     1280                                        return array( 'do_not_allow' );
     1281                                }
     1282
     1283                                return $caps;
     1284                        },
     1285                        10,
     1286                        2
     1287                );
     1288
     1289                $term = self::factory()->term->create();
     1290
     1291                wp_set_current_user( self::$editor );
     1292
     1293                $request = new WP_REST_Request( 'GET', '/wp/v2/tags/' . $term );
     1294                $request->set_query_params( array( 'context' => 'edit' ) );
     1295                $response = rest_do_request( $request );
     1296                $this->assertErrorResponse( 'rest_forbidden_context', $response, 403 );
     1297        }
     1298
     1299        /**
     1300         * @group 1018470
     1301         */
     1302        public function test_cannot_see_single_term_in_collection_with_edit_context_if_disallowed() {
     1303                add_filter(
     1304                        'map_meta_cap',
     1305                        static function ( $caps, $cap ) {
     1306                                if ( 'edit_term' === $cap ) {
     1307                                        return array( 'do_not_allow' );
     1308                                }
     1309
     1310                                return $caps;
     1311                        },
     1312                        10,
     1313                        2
     1314                );
     1315
     1316                $term = self::factory()->term->create();
     1317
     1318                wp_set_current_user( self::$editor );
     1319
     1320                $request = new WP_REST_Request( 'GET', '/wp/v2/tags' );
     1321                $request->set_query_params(
     1322                        array(
     1323                                'context' => 'edit',
     1324                                'include' => $term,
     1325                        )
     1326                );
     1327                $response = rest_do_request( $request );
     1328                $data     = $response->get_data();
     1329
     1330                $this->assertIsArray( $data );
     1331                $this->assertEmpty( $data );
     1332        }
     1333
    12721334        public function additional_field_get_callback( $object, $request ) {
    12731335                return 123;
Note: See TracChangeset for help on using the changeset viewer.