1 | <?php |
||
6 | class Jetpack_ReCaptcha { |
||
7 | |||
8 | /** |
||
9 | * URL to which requests are POSTed. |
||
10 | * |
||
11 | * @const string |
||
12 | */ |
||
13 | const VERIFY_URL = 'https://www.google.com/recaptcha/api/siteverify'; |
||
14 | |||
15 | /** |
||
16 | * Site key to use in HTML code. |
||
17 | * |
||
18 | * @var string |
||
19 | */ |
||
20 | private $site_key; |
||
21 | |||
22 | /** |
||
23 | * Shared secret for the site. |
||
24 | * |
||
25 | * @var string |
||
26 | */ |
||
27 | private $secret_key; |
||
28 | |||
29 | /** |
||
30 | * Config for reCAPTCHA instance. |
||
31 | * |
||
32 | * @var array |
||
33 | */ |
||
34 | private $config; |
||
35 | |||
36 | /** |
||
37 | * Error codes returned from reCAPTCHA API. |
||
38 | * |
||
39 | * @see https://developers.google.com/recaptcha/docs/verify |
||
40 | * |
||
41 | * @var array |
||
42 | */ |
||
43 | private $error_codes; |
||
44 | |||
45 | /** |
||
46 | * Create a configured instance to use the reCAPTCHA service. |
||
47 | * |
||
48 | * @param string $site_key Site key to use in HTML code. |
||
49 | * @param string $secret_key Shared secret between site and reCAPTCHA server. |
||
50 | * @param array $config Config array to optionally configure reCAPTCHA instance. |
||
51 | */ |
||
52 | public function __construct( $site_key, $secret_key, $config = array() ) { |
||
67 | |||
68 | /** |
||
69 | * Get default config for this reCAPTCHA instance. |
||
70 | * |
||
71 | * @return array Default config |
||
72 | */ |
||
73 | public function get_default_config() { |
||
85 | |||
86 | /** |
||
87 | * Calls the reCAPTCHA siteverify API to verify whether the user passes |
||
88 | * CAPTCHA test. |
||
89 | * |
||
90 | * @param string $response The value of 'g-recaptcha-response' in the submitted |
||
91 | * form. |
||
92 | * @param string $remote_ip The end user's IP address. |
||
93 | * |
||
94 | * @return bool|WP_Error Returns true if verified. Otherwise WP_Error is returned. |
||
95 | */ |
||
96 | public function verify( $response, $remote_ip ) { |
||
142 | |||
143 | /** |
||
144 | * Get siteverify request parameters. |
||
145 | * |
||
146 | * @param string $response The value of 'g-recaptcha-response' in the submitted |
||
147 | * form. |
||
148 | * @param string $remote_ip The end user's IP address. |
||
149 | * |
||
150 | * @return array |
||
151 | */ |
||
152 | public function get_verify_request_params( $response, $remote_ip ) { |
||
162 | |||
163 | /** |
||
164 | * Get reCAPTCHA HTML to render. |
||
165 | * |
||
166 | * @return string |
||
167 | */ |
||
168 | public function get_recaptcha_html() { |
||
188 | } |
||
189 |