ap_user_can_ask( integer|boolean $user_id = false )

Description #

Check if a user can ask a question.

Parameters #

  • $user_id
    integer | boolean (Optional) User_id. Default value: false

Changelog #

VersionDescription
4.1.0Updated to use new option post_question_per.
2.4.6Introduced.

Source #

File: includes/class/roles-cap.php

function ap_user_can_ask( $user_id = false ) {
	if ( false === $user_id ) {
		$user_id = get_current_user_id();
	}

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

	/**
	 * Filter to hijack ap_user_can_ask function.
	 *
	 * @param  boolean|string   $filter     Apply this filter, empty string by default.
	 * @param  integer          $user_id    User ID.
	 * @return boolean
	 * @since  2.4.6
	 */
	$filter = apply_filters( 'ap_user_can_ask', '', $user_id );

	if ( true === $filter ) {
		return true;
	} elseif ( false === $filter ) {
		return false;
	}

	$option = ap_opt( 'post_question_per' );
	if ( 'have_cap' === $option && is_user_logged_in() && user_can( $user_id, 'ap_new_question' ) ) {
		return true;
	} elseif ( 'logged_in' === $option && is_user_logged_in() ) {
		return true;
	} elseif ( 'anyone' === $option ) {
		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