ap_user_can_view_moderate_post( integer $post_id = null, integer $user_id = false )

Description #

Check if user can view a moderate post.

Parameters #

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

Changelog #

VersionDescription
unknownunknown
4.1.5Introduced.

Source #

File: includes/class/roles-cap.php

function ap_user_can_view_moderate_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_moderate' ) ) {
		return true;
	}

	$post_o = ap_get_post( $post_id );

	// Bail if not answer or question.
	if ( ! $post_o || ! ap_is_cpt( $post_o ) ) {
		return false;
	}

	if ( is_user_logged_in() && $post_o->post_author == $user_id ) { // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
		return true;
	}

	if ( ! is_user_logged_in() && '0' === $post_o->post_author && anspress()->session->post_in_session( $post_o ) ) {
		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