Skip to content

Commit

Permalink
refactor: rename to give-cloudflare-turnstile
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Waldstein committed Oct 23, 2024
1 parent 428b275 commit 3f33148
Show file tree
Hide file tree
Showing 15 changed files with 45 additions and 45 deletions.
2 changes: 1 addition & 1 deletion give-cloudflare-turnstile.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Requires PHP: 7.2
* Author: GiveWP
* Author URI: https://givewp.com/
* Text Domain: givewp-cloudflare-turnstile
* Text Domain: give-cloudflare-turnstile
* Domain Path: /languages
* License: GPLv3
*/
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"author": "GiveWP",
"license": "ISC",
"files": [
"givewp-cloudflare-turnstile.php",
"give-cloudflare-turnstile.php",
"build",
"src",
"vendor/composer",
Expand Down
2 changes: 1 addition & 1 deletion src/Addon/Links.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function __invoke($actions): array
'settings' => sprintf(
'<a href="%s">%s</a>',
esc_url($settings->getSettingsUrl()),
__('Settings', 'givewp-cloudflare-turnstile')
__('Settings', 'give-cloudflare-turnstile')
),
);

Expand Down
2 changes: 1 addition & 1 deletion src/Addon/Notices.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static function giveVersionError(): void
{
Give()->notices->register_notice(
[
'id' => 'givewp-cloudflare-turnstile-activation-error',
'id' => 'give-cloudflare-turnstile-activation-error',
'type' => 'error',
'description' => View::load('admin/notices/give-version-error'),
'show' => true,
Expand Down
6 changes: 3 additions & 3 deletions src/Addon/resources/views/admin/notices/give-inactive.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php defined( 'ABSPATH' ) or exit; ?>

<strong><?php esc_attr_e( 'Activation Error:', 'givewp-cloudflare-turnstile' ); ?></strong>
<?php esc_attr_e( 'You must have', 'givewp-cloudflare-turnstile' ); ?> <a href="https://givewp.com" target="_blank">Give</a>
<?php printf(/* translators: %s: GiveWP Add-on name. */ esc_html__( 'plugin installed and activated for the %s add-on to activate', 'givewp-cloudflare-turnstile' ), esc_attr(GIVE_CLOUDFLARE_TURNSTILE_NAME) ); ?>
<strong><?php esc_attr_e( 'Activation Error:', 'give-cloudflare-turnstile' ); ?></strong>
<?php esc_attr_e( 'You must have', 'give-cloudflare-turnstile' ); ?> <a href="https://givewp.com" target="_blank">Give</a>
<?php printf(/* translators: %s: GiveWP Add-on name. */ esc_html__( 'plugin installed and activated for the %s add-on to activate', 'give-cloudflare-turnstile' ), esc_attr(GIVE_CLOUDFLARE_TURNSTILE_NAME) ); ?>
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php defined( 'ABSPATH' ) or exit; ?>

<strong><?php esc_attr_e( 'Activation Error:', 'givewp-cloudflare-turnstile' ); ?></strong>
<?php esc_attr_e( 'You must have', 'givewp-cloudflare-turnstile' ); ?> <a href="https://givewp.com" target="_blank">Give</a>
<?php esc_attr_e( 'version', 'givewp-cloudflare-turnstile' ); ?> <?php echo esc_attr(GIVE_CLOUDFLARE_TURNSTILE_MIN_GIVE_VERSION); ?>
<?php printf(/* translators: %1$s: GiveWP Add-on name. */ esc_html__( 'for the %1$s add-on to activate', 'givewp-cloudflare-turnstile' ), esc_attr(GIVE_CLOUDFLARE_TURNSTILE_NAME) ); ?>
<strong><?php esc_attr_e( 'Activation Error:', 'give-cloudflare-turnstile' ); ?></strong>
<?php esc_attr_e( 'You must have', 'give-cloudflare-turnstile' ); ?> <a href="https://givewp.com" target="_blank">Give</a>
<?php esc_attr_e( 'version', 'give-cloudflare-turnstile' ); ?> <?php echo esc_attr(GIVE_CLOUDFLARE_TURNSTILE_MIN_GIVE_VERSION); ?>
<?php printf(/* translators: %1$s: GiveWP Add-on name. */ esc_html__( 'for the %1$s add-on to activate', 'give-cloudflare-turnstile' ), esc_attr(GIVE_CLOUDFLARE_TURNSTILE_NAME) ); ?>
.

Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function __invoke(DonationForm $form, int $formId)

/** @var TurnstileField $field */
$field = TurnstileField::make('turnstile')
->label(__('Please verify you are human', 'givewp-cloudflare-turnstile'))
->label(__('Please verify you are human', 'give-cloudflare-turnstile'))
->defaultValue('')
->rules('required', new TurnstileFieldRule());

Expand Down
2 changes: 1 addition & 1 deletion src/FormExtension/DonationForm/Actions/EnqueueScripts.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ public function __invoke()
'before'
);

wp_set_script_translations($turnstileFieldScriptHandle, 'givewp-cloudflare-turnstile', GIVE_CLOUDFLARE_TURNSTILE_DIR . "languages");
wp_set_script_translations($turnstileFieldScriptHandle, 'give-cloudflare-turnstile', GIVE_CLOUDFLARE_TURNSTILE_DIR . "languages");
}
}
8 changes: 4 additions & 4 deletions src/FormExtension/DonationForm/Rules/TurnstileFieldRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,23 @@ public function __invoke($value, Closure $fail, string $key, array $values)
$secretKey = $settings->getSecretKey();

if (empty($siteKey) || empty($secretKey)) {
Log::error(__('Turnstile missing credentials.', 'givewp-cloudflare-turnstile'), [
Log::error(__('Turnstile missing credentials.', 'give-cloudflare-turnstile'), [
'formId' => $values['formId'] ?? null,
]);

$fail(__('Permission denied.', 'givewp-cloudflare-turnstile'));
$fail(__('Permission denied.', 'give-cloudflare-turnstile'));
}

$response = $this->verifyToken($secretKey, $value);

if (!$response->isSuccess()) {
Log::spam(__('Turnstile verification failed.', 'givewp-cloudflare-turnstile'), [
Log::spam(__('Turnstile verification failed.', 'give-cloudflare-turnstile'), [
'response' => $response,
'errorMessages' => $response->getErrorMessages() ?? [],
'formId' => $values['formId'] ?? null,
]);

$fail(__('Permission denied.', 'givewp-cloudflare-turnstile'));
$fail(__('Permission denied.', 'give-cloudflare-turnstile'));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default function TurnstileField({
const fieldName = inputProps.name;
const setFormError = useCallback(() =>
setError('FORM_ERROR', {
message: __('You must be a human.', 'givewp-cloudflare-turnstile')
message: __('You must be a human.', 'give-cloudflare-turnstile')
}), [setError]
);

Expand Down
16 changes: 8 additions & 8 deletions src/Settings/Actions/RegisterGlobalSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,17 @@ protected function getSettings(): array
public function getEnableSettings(): array
{
return [
'name' => __('Enable Cloudflare Turnstile', 'givewp-cloudflare-turnstile'),
'name' => __('Enable Cloudflare Turnstile', 'give-cloudflare-turnstile'),
'desc' => __(
'If enabled, this option will add a Cloudflare Turnstile widget to all donation forms',
'givewp-cloudflare-turnstile'
'give-cloudflare-turnstile'
),
'id' => SettingKeys::ENABLED,
'type' => 'radio_inline',
'default' => 'disabled',
'options' => [
'enabled' => __('Enabled', 'givewp-cloudflare-turnstile'),
'disabled' => __('Disabled', 'givewp-cloudflare-turnstile'),
'enabled' => __('Enabled', 'give-cloudflare-turnstile'),
'disabled' => __('Disabled', 'give-cloudflare-turnstile'),
],
];
}
Expand All @@ -69,10 +69,10 @@ public function getApiSiteKeySettings(): array
{
return [
'id' => SettingKeys::SITE_KEY,
'name' => __('Cloudflare Turnstile Site Key', 'givewp-cloudflare-turnstile'),
'name' => __('Cloudflare Turnstile Site Key', 'give-cloudflare-turnstile'),
'desc' => __(
'Enter your Cloudflare Site Key here. This key is required to connect to the Cloudflare API.',
'givewp-cloudflare-turnstile'
'give-cloudflare-turnstile'
),
'type' => 'api_key',
];
Expand All @@ -85,10 +85,10 @@ public function getApiSecretKeySettings(): array
{
return [
'id' => SettingKeys::SECRET_KEY,
'name' => __('Cloudflare Turnstile Secret Key', 'givewp-cloudflare-turnstile'),
'name' => __('Cloudflare Turnstile Secret Key', 'give-cloudflare-turnstile'),
'desc' => __(
'Enter your Cloudflare Turnstile Secret key here. This key is required to connect to the Cloudflare API.',
'givewp-cloudflare-turnstile'
'give-cloudflare-turnstile'
),
'type' => 'api_key',
];
Expand Down
2 changes: 1 addition & 1 deletion src/Settings/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function register()
public function boot()
{
add_filter('give_get_sections_security', function($sections) {
$sections['cloudflare_turnstile'] = __('Cloudflare Turnstile', 'givewp-cloudflare-turnstile');
$sections['cloudflare_turnstile'] = __('Cloudflare Turnstile', 'give-cloudflare-turnstile');

return $sections;
});
Expand Down
14 changes: 7 additions & 7 deletions src/Turnstile/ValueObjects/TurnstileVerifyResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,27 +68,27 @@ public function getErrorMessage(string $code): ?string
{
switch ($code) {
case 'missing-input-secret':
return __("The secret parameter was not passed.", 'givewp-cloudflare-turnstile');
return __("The secret parameter was not passed.", 'give-cloudflare-turnstile');
case 'invalid-input-secret':
return __("The secret parameter was invalid or did not exist.", 'givewp-cloudflare-turnstile');
return __("The secret parameter was invalid or did not exist.", 'give-cloudflare-turnstile');
case 'missing-input-response':
return __("The response parameter (token) was not passed.", 'givewp-cloudflare-turnstile');
return __("The response parameter (token) was not passed.", 'give-cloudflare-turnstile');
case 'invalid-input-response':
return __(
"The response parameter (token) is invalid or has expired. Most of the time, this means a fake token has been used. If the error persists, contact customer support.",
'givewp-cloudflare-turnstile'
'give-cloudflare-turnstile'
);
case 'bad-request':
return __("The request was rejected because it was malformed.", 'givewp-cloudflare-turnstile');
return __("The request was rejected because it was malformed.", 'give-cloudflare-turnstile');
case 'timeout-or-duplicate':
return __(
"The response parameter (token) has already been validated before. This means that the token was issued five minutes ago and is no longer valid, or it was already redeemed.",
'givewp-cloudflare-turnstile'
'give-cloudflare-turnstile'
);
case 'internal-error':
return __(
"An internal error happened while validating the response. The request can be retried.",
'givewp-cloudflare-turnstile'
'give-cloudflare-turnstile'
);
default:
return 'Invalid response';
Expand Down
20 changes: 10 additions & 10 deletions tests/Unit/Turnstile/ValueObjects/TestTurnstileVerifyResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ public function testShouldGetErrorMessages(): void
]);

$this->assertEquals([
__("The secret parameter was not passed.", 'givewp-cloudflare-turnstile'),
__("The secret parameter was invalid or did not exist.", 'givewp-cloudflare-turnstile'),
__("The secret parameter was not passed.", 'give-cloudflare-turnstile'),
__("The secret parameter was invalid or did not exist.", 'give-cloudflare-turnstile'),
], $turnstileVerifyResponse->getErrorMessages());
}

Expand All @@ -65,14 +65,14 @@ public function testShouldGetErrorMessages(): void
public function errorMessagesProvider(): array
{
return [
['missing-input-secret', __("The secret parameter was not passed.", 'givewp-cloudflare-turnstile')],
['invalid-input-secret', __("The secret parameter was invalid or did not exist.", 'givewp-cloudflare-turnstile')],
['missing-input-response', __("The response parameter (token) was not passed.", 'givewp-cloudflare-turnstile')],
['invalid-input-response', __("The response parameter (token) is invalid or has expired. Most of the time, this means a fake token has been used. If the error persists, contact customer support.", 'givewp-cloudflare-turnstile')],
['bad-request', __("The request was rejected because it was malformed.", 'givewp-cloudflare-turnstile')],
['timeout-or-duplicate', __("The response parameter (token) has already been validated before. This means that the token was issued five minutes ago and is no longer valid, or it was already redeemed.", 'givewp-cloudflare-turnstile')],
['internal-error', __("An internal error happened while validating the response. The request can be retried.", 'givewp-cloudflare-turnstile')],
['', __("Invalid response", 'givewp-cloudflare-turnstile')],
['missing-input-secret', __("The secret parameter was not passed.", 'give-cloudflare-turnstile')],
['invalid-input-secret', __("The secret parameter was invalid or did not exist.", 'give-cloudflare-turnstile')],
['missing-input-response', __("The response parameter (token) was not passed.", 'give-cloudflare-turnstile')],
['invalid-input-response', __("The response parameter (token) is invalid or has expired. Most of the time, this means a fake token has been used. If the error persists, contact customer support.", 'give-cloudflare-turnstile')],
['bad-request', __("The request was rejected because it was malformed.", 'give-cloudflare-turnstile')],
['timeout-or-duplicate', __("The response parameter (token) has already been validated before. This means that the token was issued five minutes ago and is no longer valid, or it was already redeemed.", 'give-cloudflare-turnstile')],
['internal-error', __("An internal error happened while validating the response. The request can be retried.", 'give-cloudflare-turnstile')],
['', __("Invalid response", 'give-cloudflare-turnstile')],
];
}

Expand Down
2 changes: 1 addition & 1 deletion tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

require __DIR__ . '/../../give/vendor/autoload.php';

(new Bootstrap(__DIR__ . '/../givewp-cloudflare-turnstile.php'))->load();
(new Bootstrap(__DIR__ . '/../give-cloudflare-turnstile.php'))->load();

0 comments on commit 3f33148

Please sign in to comment.