group = Brizy_Editor_Accounts_AbstractAccount::RECAPTCHA_GROUP; $json_obj->service = self::SERVICE_NAME; return Brizy_Editor_Accounts_AbstractAccount::createFromSerializedData( get_object_vars( $json_obj ) ); } throw new Exception( 'Invalid json provided.' ); } public function getSiteKey() { return $this->get( 'sitekey' ); } /** * @throws Exception */ public function validate() { if ( ! isset( $_REQUEST['secretkey'] ) ) { throw new Exception( 'Invalid secret provided' ); } if ( ! isset( $_REQUEST['response'] ) ) { throw new Exception( 'Invalid response provided' ); } $http = new WP_Http(); $response = $http->post( 'https://www.google.com/recaptcha/api/siteverify', array( 'body' => array( 'secret' => $_REQUEST['secretkey'], 'response' => $_REQUEST['response'] ) ) ); $body = wp_remote_retrieve_body( $response ); $responseJsonObject = json_decode( $body ); if ( ! is_object( $responseJsonObject ) || ! $responseJsonObject->success ) { throw new Exception( "Unable to validate account" ); } return true; } }