ap_user_can_view_future_post( integer $post_id = null, integer $user_id = false )
Description #
Check if user can view a future post.
Parameters #
- $post_idinteger (Optional) Post ID. Default value: null
- $user_idinteger (Optional) User ID. Default value: false
Changelog #
Source #
File: includes/class/roles-cap.php
function ap_user_can_view_future_post( $post_id = 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_future' ) ) { return true; } $_post = ap_get_post( $post_id ); // Bail if not answer or question. if ( ! $_post || ! ap_is_cpt( $_post ) ) { return false; } // Return false if the post status is not set to future. if ( 'future' !== $_post->post_status ) { return false; } if ( is_user_logged_in() && $_post && $_post->post_author == $user_id ) { // phpcs:ignore Universal.Operators.StrictComparisons.LooseEqual return true; } $session_type = 'answer' === $_post->post_type ? 'answers' : 'questions'; $session_posts = anspress()->session->get( $session_type ); if ( is_array( $session_posts ) && ! is_user_logged_in() && '0' === $_post->post_author && in_array( $_post->ID, $session_posts ) ) { // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict return true; } return false; }
Expand full source code Collapse full source code View on GitHub: includes/class/roles-cap.php:855
Add your comment