Changeset 9167 for sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-login/functions.php
- Timestamp:
- 10/09/2019 07:07:07 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-login/functions.php
r9154 r9167 75 75 function wporg_login_register_scripts() { 76 76 wp_register_script( 'recaptcha-api', 'https://www.google.com/recaptcha/api.js', array(), '2' ); 77 wp_add_inline_script( 'recaptcha-api', 'function onSubmit(token) { document.getElementById("registerform").submit(); }' ); 77 wp_add_inline_script( 78 'recaptcha-api', 79 'function onSubmit(token) { 80 var form = document.getElementById("registerform"); 81 82 if ( form.dataset.submitReady ) { 83 form.submit(); 84 } else { 85 // Still waiting on reCaptcha V3, disable/please wait the submit button. 86 form.dataset.submitReady = true; 87 document.getElementById("wp-submit").disabled = true; 88 document.getElementById("wp-submit").value = ' . json_encode( __( 'Please Wait..', 'wporg') ) . '; 89 } 90 }' 91 ); 78 92 79 93 wp_register_script( 'wporg-registration', get_template_directory_uri() . '/js/registration.js', array( 'recaptcha-api', 'jquery' ), '20170219' ); … … 99 113 ).then( function( token ) { 100 114 // Add the token to the "primary" form 101 var input = document.createElement( "input" ); 115 var input = document.createElement( "input" ), 116 form = document.getElementsByTagName("form")[0]; 117 102 118 input.setAttribute( "type", "hidden" ); 103 119 input.setAttribute( "name", "_reCaptcha_v3_token" ); 104 120 input.setAttribute( "value", token ); 105 121 106 document.getElementsByTagName("form")[0].appendChild( input ); 122 form.appendChild( input ); 123 124 if ( form.dataset.submitReady ) { 125 form.submit(); 126 } else { 127 form.dataset.submitReady = true; 128 } 107 129 }); 108 130 }' … … 305 327 */ 306 328 function wporg_login_recaptcha_api( $token, $key ) { 329 // Just a basic cache for multiple calls on the same token on the same pageload. 330 static $cache = array(); 331 307 332 $verify = array( 308 333 'secret' => $key, … … 310 335 'response' => $token, 311 336 ); 312 313 $resp = wp_remote_post( 'https://www.google.com/recaptcha/api/siteverify', array( 'body' => $verify ) ); 314 if ( is_wp_error( $resp ) || 200 != wp_remote_retrieve_response_code( $resp ) ) { 315 return false; 316 } 317 318 return json_decode( wp_remote_retrieve_body( $resp ), true ); 319 } 337 $cache_key = implode( ':', $verify ); 338 339 if ( ! isset( $cache[ $cache_key ] ) ) { 340 $resp = wp_remote_post( 'https://www.google.com/recaptcha/api/siteverify', array( 'body' => $verify ) ); 341 if ( is_wp_error( $resp ) || 200 != wp_remote_retrieve_response_code( $resp ) ) { 342 $cache[ $cache_key ] = false; 343 return false; 344 } 345 346 $cache[ $cache_key ] = json_decode( wp_remote_retrieve_body( $resp ), true ); 347 } 348 349 return $cache[ $cache_key ]; 350 }
Note: See TracChangeset
for help on using the changeset viewer.