Function Reference: geodir_recaptcha_init

Summary

Init GD ReCaptcha plugin.

Package

GeoDirectory_ReCaptcha

Parameters

$admin
(bool) (required) Is this admin page?.

Default: None
$admin_ajax
(bool) (required) Is this a admin ajax request?.

Default: None

Change Log

Since: 1.0.0

Actions

‘geodir_recaptcha_init’ [Line: 476]

Source File

geodir_recaptcha_init() is located in geodir_recaptcha/includes/gdcaptcha_functions.php [Line: 386]

Source Code

function geodir_recaptcha_init( $admin=false, $admin_ajax = false ) {
	$admin = is_admin();
	$admin_ajax = ( defined( 'DOING_AJAX' ) && DOING_AJAX );
	
	if ( geodir_recaptcha_check_role() ) { // disbale captcha as per user role settings
		return;
	}
	
	$load_css = false;
	// registration form
	if ( !$admin && get_option( 'geodir_recaptcha_registration' ) ) {
		if ( !is_multisite() ) {
			// general wordpress signup
			add_action( 'register_form', 'geodir_recaptcha_registration_form' );
		} else {
			add_action( 'signup_extra_fields', 'geodir_recaptcha_registration_form' );
		}
		// general geodirectory signup
		add_action( 'social_connect_form', 'geodir_recaptcha_registration_form' );
		add_action( 'register_post', 'geodir_recaptcha_registration_check', 0, 3 );
		
		$load_css = true;
	}
	
	// add listing form
	if ( get_option( 'geodir_recaptcha_add_listing' ) ) {
		
		$post_info = NULL;
		if ( isset( $_REQUEST['pid'] ) && $_REQUEST['pid'] != '' ) {
			$post_id = $_REQUEST['pid'];
			$post_info = get_post( $post_id );
		}
		
		if ( empty( $post_info ) ) {
			add_action( 'geodir_after_main_form_fields', 'geodir_recaptcha_add_listing_form', 0 );
			$load_css = true;
		}
	}
	
	// comments form
	if ( !$admin && get_option( 'geodir_recaptcha_comments' ) ) {
		add_action( 'comment_form_after_fields', 'geodir_recaptcha_comments_form', 100 );
		add_action( 'comment_form_logged_in_after', 'geodir_recaptcha_comments_form', 100 );
		add_action( 'pre_comment_on_post', 'geodir_recaptcha_comments_check', 0, 1 );
		add_action( 'comment_on_trash', 'geodir_recaptcha_comments_check', 0, 1 );
		add_action( 'comment_on_draft', 'geodir_recaptcha_comments_check', 0, 1 );
		add_action( 'comment_on_password_protected', 'geodir_recaptcha_comments_check', 0, 1 );
		$load_css = true;
	}
	
	// send to form
	if ( ( !$admin || $admin && $admin_ajax ) && get_option( 'geodir_recaptcha_send_to_friend' ) ) {
		add_action( 'geodir_after_stf_form_field', 'geodir_recaptcha_send_to_friend_form' );
		$load_css = true;
	}
	
	// send enquiry form
	if ( ( !$admin || $admin && $admin_ajax ) && get_option( 'geodir_recaptcha_send_enquery' ) ) {
		add_action( 'geodir_after_inquiry_form_field', 'geodir_recaptcha_send_enquery_form' );
		$load_css = true;
	}
		
	// claim listing form
	if ( ( !$admin || $admin && $admin_ajax ) && get_option( 'geodir_recaptcha_claim_listing' ) ) {
		add_action( 'geodir_after_claim_form_field', 'geodir_recaptcha_claim_listing_form' );
		$load_css = true;
	}
	
	// buddypress registration form
	if ( !$admin && get_option( 'geodir_recaptcha_buddypress' ) ) {
		add_action( 'bp_before_registration_submit_buttons', 'geodir_recaptcha_bp_registration_form' );
		add_action( 'bp_signup_validate', 'geodir_recaptcha_bp_registration_check' );
		
		$load_css = true;
	}
	
	if ( $load_css ) {
		wp_register_style( 'gd-captcha-style', GEODIR_RECAPTCHA_PLUGIN_URL . '/css/gd-captcha-style.css', array(), GEODIR_RECAPTCHA_VERSION);
		wp_enqueue_style( 'gd-captcha-style' );
	}
	
	add_action( 'wp_ajax_geodir_recaptcha_check', 'geodir_recaptcha_ajax_check' );
	add_action( 'wp_ajax_nopriv_geodir_recaptcha_check', 'geodir_recaptcha_ajax_check' );

    /**
     * Functions added to this hook will be executed after init.
     *
     * @since 1.0.0
     * @package GeoDirectory_ReCaptcha
     */
	do_action( 'geodir_recaptcha_init' );
}