AnsPress_reCcaptcha()
Description #
The reCaptcha class.
Source #
File: addons/free/recaptcha.php
class AnsPress_reCcaptcha {
/**
* Initialize the plugin by setting localization and loading public scripts
* and styles.
*
* @since 2.4.8 Removed `$ap` args.
*/
public static function init() {
ap_add_default_options([
'recaptcha_method' => 'post',
]);
anspress()->add_action( 'ap_form_addon-free_recaptcha', __CLASS__, 'options' );
anspress()->add_action( 'ap_question_form_fields', __CLASS__, 'ap_question_form_fields', 10, 2 );
anspress()->add_action( 'ap_answer_form_fields', __CLASS__, 'ap_question_form_fields', 10, 2 );
anspress()->add_action( 'ap_comment_form_fields', __CLASS__, 'ap_question_form_fields', 10, 2 );
}
/**
* Register Categories options
*/
public static function options() {
$opt = ap_opt();
$form = array(
'fields' => array(
'recaptcha_site_key' => array(
'label' => __( 'Recaptcha site key', 'anspress-question-answer' ),
'desc' => __( 'Enter your site key, if you dont have it get it from here https://www.google.com/recaptcha/admin', 'anspress-question-answer' ),
'value' => $opt['recaptcha_site_key'],
),
'recaptcha_secret_key' => array(
'label' => __( 'Recaptcha secret key', 'anspress-question-answer' ),
'desc' => __( 'Enter your secret key', 'anspress-question-answer' ),
'value' => $opt['recaptcha_secret_key'],
),
'recaptcha_method' => array(
'label' => __( 'Recaptcha Method', 'anspress-question-answer' ),
'desc' => __( 'Select method to use when verification keeps failing', 'anspress-question-answer' ),
'type' => 'select',
'options' => array(
'curl' => 'CURL',
'post' => 'POST',
),
'value' => $opt['recaptcha_method'],
),
),
);
return $form;
}
/**
* Add captcha field in question and answer form.
*
* @param array $form Form arguments.
* @return array
* @since 4.1.0
*/
public static function ap_question_form_fields( $form ) {
if ( ap_show_captcha_to_user() ) {
$form['fields']['captcha'] = array(
'label' => __( 'Prove that you are a human', 'anspress-question-answer' ),
'type' => 'captcha',
'order' => 100,
);
}
return $form;
}
}
Expand full source code Collapse full source code View on GitHub: addons/free/recaptcha.php:37
Add your comment