ap_user_can_view_post( integer|false $post_id = false, integer|false $user_id = false )

Description #

Check if user can view post

Parameters #

  • $post_id
    integer | false (Optional) Question or answer ID. Default value: false
  • $user_id
    integer | false (Optional) User ID. Default value: false

Source #

File: includes/class/roles-cap.php

function ap_user_can_view_post( $post_id = false, $user_id = false ) {
	if ( false === $user_id ) {
		$user_id = get_current_user_id();
	}

	if ( is_super_admin( $user_id ) ) {
		return true;
	}

	$post_o = is_object( $post_id ) ? $post_id : ap_get_post( $post_id );

	// Return false if not question or answer.
	if ( ! in_array( $post_o->post_type, array( 'question', 'answer' ), true ) ) {
		return false;
	}

	if ( 'private_post' === $post_o->post_status && ap_user_can_view_private_post( $post_o->ID, $user_id ) ) {
		return true;
	}

	if ( 'moderate' === $post_o->post_status && ap_user_can_view_moderate_post( $post_o->ID, $user_id ) ) {
		return true;
	}

	if ( 'future' === $post_o->post_status && ap_user_can_view_future_post( $post_o->ID, $user_id ) ) {
		return true;
	}

	if ( 'publish' === $post_o->post_status ) {
		return true;
	}

	return false;
}

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Add your comment