ap_user_can_delete_post( mixed $post_id, integer|false $user_id = false )
Description #
Check if user can delete AnsPress posts.
Parameters #
- $post_idmixed (Required) Question or answer ID.
- $user_idinteger | false (Optional) User ID. Default value: false
Source #
File: includes/class/roles-cap.php
628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 | function ap_user_can_delete_post( $post_id , $user_id = false ) { if ( false === $user_id ) { $user_id = get_current_user_id(); } if ( is_super_admin( $user_id ) ) { return true; } $post_o = ap_get_post( $post_id ); $type = $post_o ->post_type; // Return if not question or answer post type. if ( ! in_array( $post_o ->post_type, array ( 'question' , 'answer' ), true ) ) { return false; } /** * Filter to hijack ap_user_can_delete_post. * * @param boolean|string $apply_filter Apply current filter, empty string by default. * @param integer|object $post_id Post ID or object. * @param integer $user_id User ID. * @return boolean * @since 2.4.6 */ $filter = apply_filters( 'ap_user_can_delete_post' , '' , $post_o ->ID, $user_id ); if ( true === $filter ) { return true; } elseif ( false === $filter ) { return false; } // User must not able to delete post if they cannot read post. if ( ! ap_user_can_read_post( $post_id , $user_id ) ) { return false; } if ( $user_id == $post_o ->post_author && user_can( $user_id , 'ap_delete_' . $type ) ) { // phpcs:ignore Universal.Operators.StrictComparisons.LooseEqual return true; } elseif ( user_can( $user_id , 'ap_delete_others_' . $type ) ) { return true; } return false; } |
Expand full source code Collapse full source code View on GitHub: includes/class/roles-cap.php:628
Add your comment