| @@ 379-400 (lines=22) @@ | ||
| 376 | * @param string $context the type of permission to check, either `read`, `write`, or `delete` |
|
| 377 | * @return bool true if the current user has the permissions to perform the context on the post |
|
| 378 | */ |
|
| 379 | private function check_permission( $post, $context ) { |
|
| 380 | ||
| 381 | if ( ! is_a( $post, 'WP_Post' ) ) |
|
| 382 | $post = get_post( $post ); |
|
| 383 | ||
| 384 | if ( is_null( $post ) ) |
|
| 385 | return false; |
|
| 386 | ||
| 387 | $post_type = get_post_type_object( $post->post_type ); |
|
| 388 | ||
| 389 | if ( 'read' === $context ) |
|
| 390 | return current_user_can( $post_type->cap->read_private_posts, $post->ID ); |
|
| 391 | ||
| 392 | elseif ( 'edit' === $context ) |
|
| 393 | return current_user_can( $post_type->cap->edit_post, $post->ID ); |
|
| 394 | ||
| 395 | elseif ( 'delete' === $context ) |
|
| 396 | return current_user_can( $post_type->cap->delete_post, $post->ID ); |
|
| 397 | ||
| 398 | else |
|
| 399 | return false; |
|
| 400 | } |
|
| 401 | ||
| 402 | } |
|
| 403 | ||
| @@ 440-461 (lines=22) @@ | ||
| 437 | * @param string $context the type of permission to check, either `read`, `write`, or `delete` |
|
| 438 | * @return bool true if the current user has the permissions to perform the context on the post |
|
| 439 | */ |
|
| 440 | private function check_permission( $post, $context ) { |
|
| 441 | ||
| 442 | if ( ! is_a( $post, 'WP_Post' ) ) { |
|
| 443 | $post = get_post( $post ); |
|
| 444 | } |
|
| 445 | ||
| 446 | if ( is_null( $post ) ) { |
|
| 447 | return false; |
|
| 448 | } |
|
| 449 | ||
| 450 | $post_type = get_post_type_object( $post->post_type ); |
|
| 451 | ||
| 452 | if ( 'read' === $context ) { |
|
| 453 | return ( 'revision' !== $post->post_type && current_user_can( $post_type->cap->read_private_posts, $post->ID ) ); |
|
| 454 | } elseif ( 'edit' === $context ) { |
|
| 455 | return current_user_can( $post_type->cap->edit_post, $post->ID ); |
|
| 456 | } elseif ( 'delete' === $context ) { |
|
| 457 | return current_user_can( $post_type->cap->delete_post, $post->ID ); |
|
| 458 | } else { |
|
| 459 | return false; |
|
| 460 | } |
|
| 461 | } |
|
| 462 | ||
| 463 | } |
|
| 464 | ||