ap_user_can_view_private_post( mixed $_post = null, integer|false $user_id = false )
Description #
Check if user have permission to view post.
Parameters #
- $_postmixed (Optional) Post. Default value: null
- $user_idinteger | false (Optional) user ID. Default value: false
Source #
File: includes/class/roles-cap.php
function ap_user_can_view_private_post( $_post = null, $user_id = false ) { if ( false === $user_id ) { $user_id = get_current_user_id(); } if ( is_super_admin( $user_id ) || user_can( $user_id, 'ap_view_private' ) ) { return true; } $post_o = is_object( $_post ) ? $_post : ap_get_post( $_post ); if ( ! $post_o || 0 == $user_id || ! ap_is_cpt( $post_o ) ) { // phpcs:ignore Universal.Operators.StrictComparisons.LooseEqual return false; } // Return false if the post status is not set to private_post. if ( 'private_post' !== $post_o->post_status ) { return false; } if ( $post_o->post_author == $user_id ) { // phpcs:ignore Universal.Operators.StrictComparisons.LooseEqual return true; } // Also allow question author to see all private answers. if ( 'answer' === $post_o->post_type ) { $question = ap_get_post( $post_o->post_parent ); if ( $question->post_author == $user_id ) { // phpcs:ignore Universal.Operators.StrictComparisons.LooseEqual return true; } } return false; }
Expand full source code Collapse full source code View on GitHub: includes/class/roles-cap.php:768
Add your comment