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() ) { |
||
66 | |||
67 | /** |
||
68 | * Get default config for this reCAPTCHA instance. |
||
69 | * |
||
70 | * @return array Default config |
||
71 | */ |
||
72 | public function get_default_config() { |
||
84 | |||
85 | /** |
||
86 | * Calls the reCAPTCHA siteverify API to verify whether the user passes |
||
87 | * CAPTCHA test. |
||
88 | * |
||
89 | * @param string $response The value of 'g-recaptcha-response' in the submitted |
||
90 | * form. |
||
91 | * @param string $remote_ip The end user's IP address. |
||
92 | * |
||
93 | * @return bool|WP_Error Returns true if verified. Otherwise WP_Error is returned. |
||
94 | */ |
||
95 | public function verify( $response, $remote_ip ) { |
||
133 | |||
134 | /** |
||
135 | * Get siteverify request parameters. |
||
136 | * |
||
137 | * @param string $response The value of 'g-recaptcha-response' in the submitted |
||
138 | * form. |
||
139 | * @param string $remote_ip The end user's IP address. |
||
140 | * |
||
141 | * @return array |
||
142 | */ |
||
143 | public function get_verify_request_params( $response, $remote_ip ) { |
||
153 | |||
154 | /** |
||
155 | * Get reCAPTCHA HTML to render. |
||
156 | * |
||
157 | * @return string |
||
158 | */ |
||
159 | public function get_recaptcha_html() { |
||
179 | } |
||
180 |