Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: add global settings for honeypot field #7546

Merged
merged 14 commits into from
Oct 15, 2024
Merged
1 change: 1 addition & 0 deletions give.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ final class Give
Give\BetaFeatures\ServiceProvider::class,
Give\FormTaxonomies\ServiceProvider::class,
Give\DonationSpam\ServiceProvider::class,
Give\Settings\ServiceProvider::class
];

/**
Expand Down
2 changes: 1 addition & 1 deletion src/DonationForms/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ protected function registerPostStatus()
private function registerHoneyPotField(): void
{
add_action('givewp_donation_form_schema', function (DonationFormModel $form, int $formId) {
if (apply_filters('givewp_donation_forms_honeypot_enabled', false, $formId)) {
if (apply_filters('givewp_donation_forms_honeypot_enabled', give_is_setting_enabled(give_get_option( 'givewp_donation_forms_honeypot_enabled', 'disabled')), $formId)) {
(new AddHoneyPotFieldToDonationForms())($form);
}
}, 10, 2);
Expand Down
19 changes: 19 additions & 0 deletions src/Settings/Security/Actions/RegisterSection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Give\Settings\Security\Actions;

/**
* @unreleased
*/
class RegisterSection
{
/**
* @unreleased
*/
public function __invoke(array $sections): array
{
$sections['security'] = __('Security', 'give');

return $sections;
}
}
60 changes: 60 additions & 0 deletions src/Settings/Security/Actions/RegisterSettings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

namespace Give\Settings\Security\Actions;

/**
* @unreleased
*/
class RegisterSettings
{
/**
* @unreleased
*/
public function __invoke(array $settings): array
{
if ('security' !== give_get_current_setting_section()) {
return $settings;
}

return $this->getSettings();
}

/**
* @unreleased
*/
protected function getSettings(): array
{
return [
[
'id' => 'give_title_settings_advanced_security_1',
'type' => 'title',
],
$this->getHoneypotSettings(),
[
'id' => 'give_title_settings_advanced_security_1',
'type' => 'sectionend',
],
];
}

/**
* @unreleased
*/
public function getHoneypotSettings(): array
{
return [
'name' => __('Enable Honeypot Field', 'give'),
'desc' => __(
'If enabled, this option will add a honeypot security measure to all donation forms',
'give'
),
'id' => 'givewp_donation_forms_honeypot_enabled',
'type' => 'radio_inline',
'default' => 'disabled',
'options' => [
'enabled' => __('Enabled', 'give'),
'disabled' => __('Disabled', 'give'),
],
];
}
}
40 changes: 40 additions & 0 deletions src/Settings/ServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace Give\Settings;

use Give\Helpers\Hooks;
use Give\ServiceProviders\ServiceProvider as ServiceProviderInterface;
use Give\Settings\Security\Actions\RegisterSection;
use Give\Settings\Security\Actions\RegisterSettings;

/**
* Class ServiceProvider
*
* @unreleased
*/
class ServiceProvider implements ServiceProviderInterface
{
/**
* @unreleased
*/
public function register()
{
}

/**
* @unreleased
*/
public function boot()
{
$this->registerSecuritySettings();
}

/**
* @unreleased
*/
private function registerSecuritySettings(): void
{
Hooks::addFilter('give_get_sections_advanced', RegisterSection::class);
Hooks::addFilter('give_get_settings_advanced', RegisterSettings::class);
}
}
Loading