wpcf7_recaptcha_enqueue_scripts()
Enqueues frontend scripts for reCAPTCHA.
Хуки из функции
Возвращает
null. Ничего (null).
Использование
wpcf7_recaptcha_enqueue_scripts();
Код wpcf7_recaptcha_enqueue_scripts() wpcf7 recaptcha enqueue scripts CF7 6.1.5
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 = include wpcf7_plugin_path( 'modules/recaptcha/index.asset.php' );
$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' );
$wpcf7_recaptcha_obj = array(
'sitekey' => $service->get_sitekey(),
'actions' => apply_filters( 'wpcf7_recaptcha_actions', array(
'homepage' => 'homepage',
'contactform' => 'contactform',
) ),
);
wp_add_inline_script( 'wpcf7-recaptcha',
sprintf(
'var wpcf7_recaptcha = %s;',
wp_json_encode( $wpcf7_recaptcha_obj, JSON_PRETTY_PRINT )
),
'before'
);
}