ap_user_can_select_answer( mixed $_post = null, integer|false $user_id = false )

Description #

Check if user can select an answer.

Parameters #

  • $_post
    mixed (Optional) Post. Default value: null
  • $user_id
    integer | false (Optional) user id. Default value: false

Changelog #

VersionDescription
unknownunknown
4.1.6Introduced.

Source #

File: includes/class/roles-cap.php

function ap_user_can_select_answer( $_post = null, $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_select_answer. This filter will be applied if filter
	 * returns a boolean value. To baypass return an empty string.
	 *
	 * @param string|boolean    $filter         Apply this filter.
	 * @param mixed   $_post Question ID.
	 * @param integer $user_id User ID.
	 */
	$filter = apply_filters( 'ap_user_can_select_answer', '', $_post, $user_id );

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

	$answer = ap_get_post( $_post );

	// If not answer then return false.
	if ( 'answer' !== $answer->post_type ) {
		return false;
	}

	$question = ap_get_post( $answer->post_parent );

	if ( is_user_logged_in() && (string) $user_id === $question->post_author ) {
		return true;
	}

	// Allow moderators to toggle best answer.
	if ( user_can( $user_id, 'ap_toggle_best_answer' ) ) {
		return true;
	}

	return false;
}

Leave a Reply

Your email address will not be published. Required fields are marked *

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

Add your comment