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;
}

2 Comments

  1. Despite multiple submitted Support requests, the plugin’s developer has not answered and appears uninterested. I’d consider paying premium if there was any kind of support or if the developer cared. However, due to the lack of responsiveness, I will be exploring for other options.

    Reply
  2. AnsPress is designed with developers in mind and can be easily customized to meet your specific requirements. Overriding any aspect of the template layouts is possible. Our source code adheres to WordPress coding standards and is well-documented. We’re working on a documentation site that should be up and running soon.

    Reply

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