| 1 |
<?php |
| 2 |
/** |
| 3 |
* Google reCAPTCHA v3 |
| 4 |
* |
| 5 |
* @package Welcart |
| 6 |
*/ |
| 7 |
|
| 8 |
/** |
| 9 |
* Google reCAPTCHA v3 |
| 10 |
*/ |
| 11 |
class USCES_GOOGLE_RECAPTCHA { |
| 12 |
|
| 13 |
/** |
| 14 |
* Option value |
| 15 |
* |
| 16 |
* @var array |
| 17 |
*/ |
| 18 |
public static $opts; |
| 19 |
|
| 20 |
/** |
| 21 |
* Class Constructor |
| 22 |
*/ |
| 23 |
public function __construct() { |
| 24 |
|
| 25 |
self::initialize_data(); |
| 26 |
|
| 27 |
if ( is_admin() ) { |
| 28 |
add_action( 'usces_action_admin_system_extentions', array( $this, 'setting_form' ) ); |
| 29 |
add_action( 'init', array( $this, 'save_data' ) ); |
| 30 |
} |
| 31 |
} |
| 32 |
|
| 33 |
/** |
| 34 |
* Initialize |
| 35 |
*/ |
| 36 |
public function initialize_data() { |
| 37 |
global $usces; |
| 38 |
$options = get_option( 'usces_ex', array() ); |
| 39 |
$options['system']['google_recaptcha']['status'] = ! isset( $options['system']['google_recaptcha']['status'] ) ? 0 : (int) $options['system']['google_recaptcha']['status']; |
| 40 |
$options['system']['google_recaptcha']['site_key'] = ! isset( $options['system']['google_recaptcha']['site_key'] ) ? '' : $options['system']['google_recaptcha']['site_key']; |
| 41 |
$options['system']['google_recaptcha']['secret_key'] = ! isset( $options['system']['google_recaptcha']['secret_key'] ) ? '' : $options['system']['google_recaptcha']['secret_key']; |
| 42 |
$options['system']['google_recaptcha']['score'] = ! isset( $options['system']['google_recaptcha']['score'] ) ? '0.5' : $options['system']['google_recaptcha']['score']; |
| 43 |
update_option( 'usces_ex', $options ); |
| 44 |
self::$opts = $options['system']['google_recaptcha']; |
| 45 |
} |
| 46 |
|
| 47 |
/** |
| 48 |
* Save option data |
| 49 |
*/ |
| 50 |
public function save_data() { |
| 51 |
global $usces; |
| 52 |
|
| 53 |
if ( isset( $_POST['usces_google_recaptcha_option_update'] ) ) { |
| 54 |
check_admin_referer( 'admin_system', 'wc_nonce' ); |
| 55 |
if ( ! current_user_can( 'wel_manage_setting' ) ) { |
| 56 |
wp_die( __( 'You do not have sufficient permissions to access this page.' ) ); |
| 57 |
} |
| 58 |
|
| 59 |
self::$opts['status'] = filter_input( INPUT_POST, 'google_recaptcha_status', FILTER_VALIDATE_INT ); |
| 60 |
self::$opts['site_key'] = filter_input( INPUT_POST, 'site_key', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); |
| 61 |
self::$opts['secret_key'] = filter_input( INPUT_POST, 'secret_key', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); |
| 62 |
self::$opts['score'] = filter_input( INPUT_POST, 'score', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); |
| 63 |
|
| 64 |
if ( ! self::$opts['status'] ) { |
| 65 |
update_option( 'usces_recaptcha_condition', '' ); |
| 66 |
} |
| 67 |
|
| 68 |
$options = get_option( 'usces_ex', array() ); |
| 69 |
$options['system']['google_recaptcha'] = self::$opts; |
| 70 |
update_option( 'usces_ex', $options ); |
| 71 |
} |
| 72 |
} |
| 73 |
|
| 74 |
/** |
| 75 |
* Setting form |
| 76 |
*/ |
| 77 |
public function setting_form() { |
| 78 |
$status = ( self::$opts['status'] || self::$opts['status'] ) ? '<span class="running">' . __( 'Running', 'usces' ) . '</span>' : '<span class="stopped">' . __( 'Stopped', 'usces' ) . '</span>'; |
| 79 |
$condition = get_option( 'usces_recaptcha_condition', '' ); |
| 80 |
if ( 'response_OK' === $condition ) { |
| 81 |
$condition_str = '<span class="running">response_OK</span>'; |
| 82 |
} elseif ( 'response_NG' === $condition || 'response_ERROR' === $condition ) { |
| 83 |
$condition_str = '<span class="stopped">' . $condition . '</span>'; |
| 84 |
} else { |
| 85 |
$condition_str = ''; |
| 86 |
} |
| 87 |
?> |
| 88 |
<form action="" method="post" name="option_form" id="google_recaptcha_form"> |
| 89 |
<div class="postbox"> |
| 90 |
<div class="postbox-header"> |
| 91 |
<h2><span><?php esc_html_e( 'Google reCAPTCHA v3', 'usces' ); ?></span><?php wel_esc_script_e( $status ); ?><span><?php wel_esc_script_e( $condition_str ); ?></span></h2> |
| 92 |
<div class="handle-actions"><button type="button" class="handlediv" id="google_recaptcha"><span class="screen-reader-text"><?php echo esc_html( sprintf( __( 'Toggle panel: %s' ), __( 'Google reCAPTCHA v3', 'usces' ) ) ); ?></span><span class="toggle-indicator"></span></button></div> |
| 93 |
</div> |
| 94 |
<div class="inside"> |
| 95 |
<table class="form_table"> |
| 96 |
<tr height="35"> |
| 97 |
<th class="system_th"><a style="cursor:pointer;" onclick="toggleVisibility('ex_google_recaptcha_status');"><?php esc_html_e( 'Google reCAPTCHA v3', 'usces' ); ?></a></th> |
| 98 |
<td width="10"><input name="google_recaptcha_status" id="google_recaptcha_status0" type="radio" value="0"<?php checked( self::$opts['status'], 0 ); ?> /></td><td width="100"><label for="google_recaptcha_status0"><?php esc_html_e( 'disable', 'usces' ); ?></label></td> |
| 99 |
<td width="10"><input name="google_recaptcha_status" id="google_recaptcha_status1" type="radio" value="1"<?php checked( self::$opts['status'], 1 ); ?> /></td><td width="100"><label for="google_recaptcha_status1"><?php esc_html_e( 'enable', 'usces' ); ?></label></td> |
| 100 |
<td><div id="ex_google_recaptcha_status" class="explanation"><?php esc_html_e( 'Enable Google reCAPTCHA v3.', 'usces' ); ?><br><?php printf( __( 'You can register your new site <a href="%s" target="_blank">here</a>.', 'usces' ), 'https://www.google.com/recaptcha/admin/create' ); ?><?php _e( 'Select "reCAPTCHA v3" as the reCAPTCHA type.', 'usces' ); ?></div></td> |
| 101 |
</tr> |
| 102 |
</table> |
| 103 |
<table class="form_table"> |
| 104 |
<tr height="35"> |
| 105 |
<th class="system_th"><a style="cursor:pointer;" onclick="toggleVisibility('ex_google_recaptcha_site_key');"><?php esc_html_e( 'Site Key', 'usces' ); ?></a></th> |
| 106 |
<td width="10"><input name="site_key" id="site_key" type="text" value="<?php echo esc_attr( self::$opts['site_key'] ); ?>" /></td> |
| 107 |
<td><div id="ex_google_recaptcha_site_key" class="explanation"><?php esc_html_e( 'The site key to use when displaying the reCAPTCHA.', 'usces' ); ?></div></td> |
| 108 |
<td><div id="error_google_recaptcha_site_key" class="explanation"><?php esc_html_e( 'Please enter the site key.', 'usces' ); ?></div></td> |
| 109 |
</tr> |
| 110 |
<tr height="35"> |
| 111 |
<th class="system_th"><a style="cursor:pointer;" onclick="toggleVisibility('ex_google_recaptcha_secret_key');"><?php esc_html_e( 'Secret Key', 'usces' ); ?></a></th> |
| 112 |
<td width="10"><input name="secret_key" id="secret_key" type="text" value="<?php echo esc_attr( self::$opts['secret_key'] ); ?>" /></td> |
| 113 |
<td><div id="ex_google_recaptcha_secret_key" class="explanation"><?php esc_html_e( 'The secret key used for validation. It must not be public.', 'usces' ); ?></div></td> |
| 114 |
<td><div id="error_google_recaptcha_secret_key" class="explanation"><?php esc_html_e( 'Please enter the secret key.', 'usces' ); ?></div></td> |
| 115 |
</tr> |
| 116 |
<tr height="35"> |
| 117 |
<th class="system_th"><a style="cursor:pointer;" onclick="toggleVisibility('ex_google_recaptcha_score');"><?php esc_html_e( 'Score', 'usces' ); ?></a></th> |
| 118 |
<td width="10"> |
| 119 |
<select name="score" id="score"> |
| 120 |
<option value="1.0" <?php selected( '1.0', self::$opts['score'] ); ?>>1.0</option> |
| 121 |
<option value="0.9" <?php selected( '0.9', self::$opts['score'] ); ?>>0.9</option> |
| 122 |
<option value="0.8" <?php selected( '0.8', self::$opts['score'] ); ?>>0.8</option> |
| 123 |
<option value="0.7" <?php selected( '0.7', self::$opts['score'] ); ?>>0.7</option> |
| 124 |
<option value="0.6" <?php selected( '0.6', self::$opts['score'] ); ?>>0.6</option> |
| 125 |
<option value="0.5" <?php selected( '0.5', self::$opts['score'] ); ?>>0.5(Default)</option> |
| 126 |
<option value="0.4" <?php selected( '0.4', self::$opts['score'] ); ?>>0.4</option> |
| 127 |
<option value="0.3" <?php selected( '0.3', self::$opts['score'] ); ?>>0.3</option> |
| 128 |
<option value="0.2" <?php selected( '0.2', self::$opts['score'] ); ?>>0.2</option> |
| 129 |
<option value="0.1" <?php selected( '0.1', self::$opts['score'] ); ?>>0.1</option> |
| 130 |
<option value="0.0" <?php selected( '0.0', self::$opts['score'] ); ?>>0.0</option> |
| 131 |
</select> |
| 132 |
<td><div id="ex_google_recaptcha_score" class="explanation"><?php esc_html_e( 'Set the threshold for scores returned by Google to determine whether to treat them as human. The closer the score is to 0.0, the more likely it is to be a bot, while a score closer to 1.0 indicates a higher likelihood of being human. The default value is set to 0.5.', 'usces' ); ?></div></td> |
| 133 |
</tr> |
| 134 |
</table> |
| 135 |
<hr /> |
| 136 |
<input name="usces_google_recaptcha_option_update" type="submit" class="button button-primary" value="<?php esc_attr_e( 'change decision', 'usces' ); ?>" /> |
| 137 |
</div> |
| 138 |
</div><!--postbox--> |
| 139 |
<?php wp_nonce_field( 'admin_system', 'wc_nonce' ); ?> |
| 140 |
</form> |
| 141 |
<?php |
| 142 |
} |
| 143 |
} |
| 144 |
|