ap_user_can_restore( null|WP_Post|int $_post = null, boolean|integer $user_id = false )

Description #

Check if user can restore question or answer.

Parameters #

  • $_post
    null | WP_Post | int (Optional) Post id or object. Default value: null
  • $user_id
    boolean | integer (Optional) User ID. Default value: false

Changelog #

VersionDescription
3.0.0Introduced.

Source #

File: includes/class/roles-cap.php

function ap_user_can_restore( $_post = null, $user_id = false ) {
	if ( false === $user_id ) {
		$user_id = get_current_user_id();
	}

	// Bail if super.
	if ( is_super_admin( $user_id ) ) {
		return true;
	}

	$_post = is_object( $_post ) ? $_post : ap_get_post( $_post );

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

	if ( user_can( $user_id, 'ap_restore_posts' ) || (int) $_post->post_author === $user_id ) {
		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