wpcf7_recaptcha_enqueue_scripts()CF7 1.0

Enqueues frontend scripts for reCAPTCHA.

Хуки из функции

Возвращает

null. Ничего (null).

Использование

wpcf7_recaptcha_enqueue_scripts();

Код wpcf7_recaptcha_enqueue_scripts() CF7 5.9.3

function wpcf7_recaptcha_enqueue_scripts() {
	$service = WPCF7_RECAPTCHA::get_instance();

	if ( ! $service->is_active() ) {
		return;
	}

	$url = 'https://www.google.com/recaptcha/api.js';

	if ( apply_filters( 'wpcf7_use_recaptcha_net', false ) ) {
		$url = 'https://www.recaptcha.net/recaptcha/api.js';
	}

	wp_register_script( 'google-recaptcha',
		add_query_arg(
			array(
				'render' => $service->get_sitekey(),
			),
			$url
		),
		array(),
		'3.0',
		array( 'in_footer' => true )
	);

	$assets = array();
	$asset_file = wpcf7_plugin_path( 'modules/recaptcha/index.asset.php' );

	if ( file_exists( $asset_file ) ) {
		$assets = include( $asset_file );
	}

	$assets = wp_parse_args( $assets, array(
		'dependencies' => array(),
		'version' => WPCF7_VERSION,
	) );

	wp_register_script(
		'wpcf7-recaptcha',
		wpcf7_plugin_url( 'modules/recaptcha/index.js' ),
		array_merge(
			$assets['dependencies'],
			array(
				'google-recaptcha',
				'wp-polyfill',
			)
		),
		$assets['version'],
		array( 'in_footer' => true )
	);

	wp_enqueue_script( 'wpcf7-recaptcha' );

	wp_localize_script( 'wpcf7-recaptcha',
		'wpcf7_recaptcha',
		array(
			'sitekey' => $service->get_sitekey(),
			'actions' => apply_filters( 'wpcf7_recaptcha_actions', array(
				'homepage' => 'homepage',
				'contactform' => 'contactform',
			) ),
		)
	);
}