ap_show_captcha_to_user( integer|false $user_id = false )

Description #

Check if user can by pass a captcha.

Parameters #

  • $user_id
    integer | false (Optional) User ID. Default value: false

Changelog #

VersionDescription
4.1.8Introduced.

Source #

File: includes/class/roles-cap.php

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

	// Return false if super admin or ap_moderator.
	if ( is_super_admin( $user_id ) || user_can( $user_id, 'ap_moderator' ) ) {
		return false;
	}

	if ( apply_filters( 'ap_show_captcha', false, $user_id ) ) {
		return false;
	}

	$current_user = wp_get_current_user();
	$opt          = array_keys( ap_opt( 'recaptcha_exclude_roles' ) );
	$intersect    = array_intersect( $current_user->roles, $opt );

	if ( ! empty( $intersect ) && count( $intersect ) > 0 ) {
		return false;
	}

	if ( ap_opt( 'recaptcha_site_key' ) !== '' ) {
		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