PluginProbe
Double Opt-In for Contact Form 7 – Secure, GDPR-Compliant Email Verification / 5.5.0
Double Opt-In for Contact Form 7 – Secure, GDPR-Compliant Email Verification v5.5.0
5.5.0 5.4.0 5.3.2 5.3.1 5.1.6 5.1.5 trunk 2.1.5 2.11 2.12 2.13 2.15 3.0.0 3.0.1 3.0.2 3.0.3 3.0.5 3.0.51 3.0.60 3.0.61 3.0.62 3.0.70 3.0.71 3.0.72 3.1.0 All 34 releases
double-opt-in / src / Addon / AddonFeatureToggle.php

AddonFeatureToggle.php in Double Opt-In for Contact Form 7 – Secure, GDPR-Compliant Email Verification 5.5.0, at src/Addon/AddonFeatureToggle.php

46 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Addon Feature Toggle helper.
4 *
5 * Reads the per-addon settings option managed by Core's
6 * AddonSettingsPage (`f12_doi_addon_{id}_settings`) and reports whether
7 * the addon's feature is currently enabled. Distinct from WP plugin
8 * activation: a plugin can be active in WordPress while the user has
9 * temporarily paused its feature here.
10 *
11 * Default `true` matches the convention "activating the plugin =
12 * opting in to its default behaviour" (Akismet-style). Addons that
13 * inherit a legacy on/off setting (e.g. `f12-doi-settings.mx_validation_enabled`)
14 * implement their own `isFeatureEnabled()` with a fallback chain — see
15 * `MxValidator::isFeatureEnabled()` for the reference pattern.
16 *
17 * @package Forge12\DoubleOptIn\Addon
18 * @since 4.4.0
19 */
20
21 namespace Forge12\DoubleOptIn\Addon;
22
23 if ( ! defined( 'ABSPATH' ) ) {
24 exit;
25 }
26
27 final class AddonFeatureToggle {
28
29 private const OPTION_PREFIX = 'f12_doi_addon_';
30 private const OPTION_SUFFIX = '_settings';
31
32 /**
33 * Is the addon's feature currently enabled?
34 *
35 * @param string $addonId Internal addon ID matching `AddonInterface::getId()`.
36 * @param bool $default Returned when the option has not been written yet.
37 */
38 public static function isEnabled( string $addonId, bool $default = true ): bool {
39 $settings = get_option( self::OPTION_PREFIX . $addonId . self::OPTION_SUFFIX, null );
40 if ( is_array( $settings ) && array_key_exists( 'enabled', $settings ) ) {
41 return (bool) $settings['enabled'];
42 }
43 return $default;
44 }
45 }
46