Changeset 53408
- Timestamp:
- 05/17/2022 06:59:24 PM (2 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/capabilities.php
r53249 r53408 74 74 case 'delete_post': 75 75 case 'delete_page': 76 if ( ! isset( $args[0] ) ) { 77 if ( 'delete_post' === $cap ) { 78 /* translators: %s: Capability name. */ 79 $message = __( 'When checking for the %s capability, you must always check it against a specific post.' ); 80 } else { 81 /* translators: %s: Capability name. */ 82 $message = __( 'When checking for the %s capability, you must always check it against a specific page.' ); 83 } 84 85 _doing_it_wrong( 86 __FUNCTION__, 87 sprintf( $message, '<code>' . $cap . '</code>' ), 88 '6.1.0' 89 ); 90 91 $caps[] = 'do_not_allow'; 92 break; 93 } 94 76 95 $post = get_post( $args[0] ); 77 96 if ( ! $post ) { … … 93 112 if ( ! $post_type ) { 94 113 /* translators: 1: Post type, 2: Capability name. */ 95 _doing_it_wrong( __FUNCTION__, sprintf( __( 'The post type %1$s is not registered, so it may not be reliable to check the capability "%2$s" against a post of that type.' ), $post->post_type, $cap ), '4.4.0' ); 114 $message = __( 'The post type %1$s is not registered, so it may not be reliable to check the capability %2$s against a post of that type.' ); 115 116 _doing_it_wrong( 117 __FUNCTION__, 118 sprintf( 119 $message, 120 '<code>' . $post->post_type . '</code>', 121 '<code>' . $cap . '</code>' 122 ), 123 '4.4.0' 124 ); 125 96 126 $caps[] = 'edit_others_posts'; 97 127 break; … … 147 177 case 'edit_post': 148 178 case 'edit_page': 179 if ( ! isset( $args[0] ) ) { 180 if ( 'edit_post' === $cap ) { 181 /* translators: %s: Capability name. */ 182 $message = __( 'When checking for the %s capability, you must always check it against a specific post.' ); 183 } else { 184 /* translators: %s: Capability name. */ 185 $message = __( 'When checking for the %s capability, you must always check it against a specific page.' ); 186 } 187 188 _doing_it_wrong( 189 __FUNCTION__, 190 sprintf( $message, '<code>' . $cap . '</code>' ), 191 '6.1.0' 192 ); 193 194 $caps[] = 'do_not_allow'; 195 break; 196 } 197 149 198 $post = get_post( $args[0] ); 150 199 if ( ! $post ) { … … 164 213 if ( ! $post_type ) { 165 214 /* translators: 1: Post type, 2: Capability name. */ 166 _doing_it_wrong( __FUNCTION__, sprintf( __( 'The post type %1$s is not registered, so it may not be reliable to check the capability "%2$s" against a post of that type.' ), $post->post_type, $cap ), '4.4.0' ); 215 $message = __( 'The post type %1$s is not registered, so it may not be reliable to check the capability %2$s against a post of that type.' ); 216 217 _doing_it_wrong( 218 __FUNCTION__, 219 sprintf( 220 $message, 221 '<code>' . $post->post_type . '</code>', 222 '<code>' . $cap . '</code>' 223 ), 224 '4.4.0' 225 ); 226 167 227 $caps[] = 'edit_others_posts'; 168 228 break; … … 216 276 case 'read_post': 217 277 case 'read_page': 278 if ( ! isset( $args[0] ) ) { 279 if ( 'read_post' === $cap ) { 280 /* translators: %s: Capability name. */ 281 $message = __( 'When checking for the %s capability, you must always check it against a specific post.' ); 282 } else { 283 /* translators: %s: Capability name. */ 284 $message = __( 'When checking for the %s capability, you must always check it against a specific page.' ); 285 } 286 287 _doing_it_wrong( 288 __FUNCTION__, 289 sprintf( $message, '<code>' . $cap . '</code>' ), 290 '6.1.0' 291 ); 292 293 $caps[] = 'do_not_allow'; 294 break; 295 } 296 218 297 $post = get_post( $args[0] ); 219 298 if ( ! $post ) { … … 233 312 if ( ! $post_type ) { 234 313 /* translators: 1: Post type, 2: Capability name. */ 235 _doing_it_wrong( __FUNCTION__, sprintf( __( 'The post type %1$s is not registered, so it may not be reliable to check the capability "%2$s" against a post of that type.' ), $post->post_type, $cap ), '4.4.0' ); 314 $message = __( 'The post type %1$s is not registered, so it may not be reliable to check the capability %2$s against a post of that type.' ); 315 316 _doing_it_wrong( 317 __FUNCTION__, 318 sprintf( 319 $message, 320 '<code>' . $post->post_type . '</code>', 321 '<code>' . $cap . '</code>' 322 ), 323 '4.4.0' 324 ); 325 236 326 $caps[] = 'edit_others_posts'; 237 327 break; … … 250 340 if ( ! $status_obj ) { 251 341 /* translators: 1: Post status, 2: Capability name. */ 252 _doing_it_wrong( __FUNCTION__, sprintf( __( 'The post status %1$s is not registered, so it may not be reliable to check the capability "%2$s" against a post with that status.' ), get_post_status( $post ), $cap ), '5.4.0' ); 342 $message = __( 'The post status %1$s is not registered, so it may not be reliable to check the capability %2$s against a post with that status.' ); 343 344 _doing_it_wrong( 345 __FUNCTION__, 346 sprintf( 347 $message, 348 '<code>' . get_post_status( $post ) . '</code>', 349 '<code>' . $cap . '</code>' 350 ), 351 '5.4.0' 352 ); 353 253 354 $caps[] = 'edit_others_posts'; 254 355 break; … … 269 370 break; 270 371 case 'publish_post': 372 if ( ! isset( $args[0] ) ) { 373 /* translators: %s: Capability name. */ 374 $message = __( 'When checking for the %s capability, you must always check it against a specific post.' ); 375 376 _doing_it_wrong( 377 __FUNCTION__, 378 sprintf( $message, '<code>' . $cap . '</code>' ), 379 '6.1.0' 380 ); 381 382 $caps[] = 'do_not_allow'; 383 break; 384 } 385 271 386 $post = get_post( $args[0] ); 272 387 if ( ! $post ) { … … 278 393 if ( ! $post_type ) { 279 394 /* translators: 1: Post type, 2: Capability name. */ 280 _doing_it_wrong( __FUNCTION__, sprintf( __( 'The post type %1$s is not registered, so it may not be reliable to check the capability "%2$s" against a post of that type.' ), $post->post_type, $cap ), '4.4.0' ); 395 $message = __( 'The post type %1$s is not registered, so it may not be reliable to check the capability %2$s against a post of that type.' ); 396 397 _doing_it_wrong( 398 __FUNCTION__, 399 sprintf( 400 $message, 401 '<code>' . $post->post_type . '</code>', 402 '<code>' . $cap . '</code>' 403 ), 404 '4.4.0' 405 ); 406 281 407 $caps[] = 'edit_others_posts'; 282 408 break; … … 298 424 case 'add_user_meta': 299 425 $object_type = explode( '_', $cap )[1]; 300 $object_id = (int) $args[0]; 426 427 if ( ! isset( $args[0] ) ) { 428 if ( 'post' === $object_type ) { 429 /* translators: %s: Capability name. */ 430 $message = __( 'When checking for the %s capability, you must always check it against a specific post.' ); 431 } elseif ( 'comment' === $object_type ) { 432 /* translators: %s: Capability name. */ 433 $message = __( 'When checking for the %s capability, you must always check it against a specific comment.' ); 434 } elseif ( 'term' === $object_type ) { 435 /* translators: %s: Capability name. */ 436 $message = __( 'When checking for the %s capability, you must always check it against a specific term.' ); 437 } else { 438 /* translators: %s: Capability name. */ 439 $message = __( 'When checking for the %s capability, you must always check it against a specific user.' ); 440 } 441 442 _doing_it_wrong( 443 __FUNCTION__, 444 sprintf( $message, '<code>' . $cap . '</code>' ), 445 '6.1.0' 446 ); 447 448 $caps[] = 'do_not_allow'; 449 break; 450 } 451 452 $object_id = (int) $args[0]; 301 453 302 454 $object_subtype = get_object_subtype( $object_type, $object_id ); … … 393 545 break; 394 546 case 'edit_comment': 547 if ( ! isset( $args[0] ) ) { 548 /* translators: %s: Capability name. */ 549 $message = __( 'When checking for the %s capability, you must always check it against a specific comment.' ); 550 551 _doing_it_wrong( 552 __FUNCTION__, 553 sprintf( $message, '<code>' . $cap . '</code>' ), 554 '6.1.0' 555 ); 556 557 $caps[] = 'do_not_allow'; 558 break; 559 } 560 395 561 $comment = get_comment( $args[0] ); 396 562 if ( ! $comment ) { … … 533 699 case 'delete_term': 534 700 case 'assign_term': 701 if ( ! isset( $args[0] ) ) { 702 /* translators: %s: Capability name. */ 703 $message = __( 'When checking for the %s capability, you must always check it against a specific term.' ); 704 705 _doing_it_wrong( 706 __FUNCTION__, 707 sprintf( $message, '<code>' . $cap . '</code>' ), 708 '6.1.0' 709 ); 710 711 $caps[] = 'do_not_allow'; 712 break; 713 } 714 535 715 $term_id = (int) $args[0]; 536 716 $term = get_term( $term_id ); -
trunk/tests/phpunit/tests/user.php
r52650 r53408 1975 1975 ); 1976 1976 1977 // _doing_ wrong() should be called because the filter callback1977 // _doing_it_wrong() should be called because the filter callback 1978 1978 // adds a item with a 'name' that is the same as one generated by core. 1979 1979 $this->setExpectedIncorrectUsage( 'wp_user_personal_data_exporter' ); -
trunk/tests/phpunit/tests/user/capabilities.php
r52824 r53408 1596 1596 $editor = self::$users['editor']; 1597 1597 1598 $this->setExpectedIncorrectUsage( 'map_meta_cap' ); 1598 1599 foreach ( $caps as $cap ) { 1599 1600 // `null` represents a non-existent term ID. -
trunk/tests/phpunit/tests/user/mapMetaCap.php
r52010 r53408 4 4 * @group user 5 5 * @group capabilities 6 * @covers ::map_meta_cap 6 7 */ 7 8 class Tests_User_MapMetaCap extends WP_UnitTestCase { … … 411 412 $this->assertSame( array( 'manage_options' ), $caps ); 412 413 } 414 415 /** 416 * @dataProvider data_meta_caps_throw_doing_it_wrong_without_required_argument_provided 417 * @ticket 44591 418 * 419 * @param string $cap The meta capability requiring an argument. 420 */ 421 public function test_meta_caps_throw_doing_it_wrong_without_required_argument_provided( $cap ) { 422 $admin_user = self::$user_id; 423 $this->setExpectedIncorrectUsage( 'map_meta_cap' ); 424 $this->assertContains( 'do_not_allow', map_meta_cap( $cap, $admin_user ) ); 425 } 426 427 /** 428 * Data provider. 429 * 430 * @return array[] Test parameters { 431 * @type string $cap The meta capability requiring an argument. 432 * } 433 */ 434 public function data_meta_caps_throw_doing_it_wrong_without_required_argument_provided() { 435 return array( 436 array( 'delete_post' ), 437 array( 'delete_page' ), 438 array( 'edit_post' ), 439 array( 'edit_page' ), 440 array( 'read_post' ), 441 array( 'read_page' ), 442 array( 'publish_post' ), 443 array( 'edit_post_meta' ), 444 array( 'delete_post_meta' ), 445 array( 'add_post_meta' ), 446 array( 'edit_comment_meta' ), 447 array( 'delete_comment_meta' ), 448 array( 'add_comment_meta' ), 449 array( 'edit_term_meta' ), 450 array( 'delete_term_meta' ), 451 array( 'add_term_meta' ), 452 array( 'edit_user_meta' ), 453 array( 'delete_user_meta' ), 454 array( 'add_user_meta' ), 455 array( 'edit_comment' ), 456 array( 'edit_term' ), 457 array( 'delete_term' ), 458 array( 'assign_term' ), 459 ); 460 } 413 461 }
Note: See TracChangeset
for help on using the changeset viewer.