| @@ -124,12 +124,47 @@ | ||
| 124 | 124 | } |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | /** |
| 128 | + * Whether the site owner has left telemetry switched on. | |
| 129 | + * | |
| 130 | + * Defaults to enabled, matching the setting's own default — but an | |
| 131 | + * absent option must not be read as consent to something the user | |
| 132 | + * turned off, so the value is taken from the same key the settings | |
| 133 | + * screen writes. | |
| 134 | + */ | |
| 135 | + public static function is_enabled(): bool { | |
| 136 | + $settings = get_option('f12-doi-settings', []); | |
| 137 | + | |
| 138 | + if (!is_array($settings) || !array_key_exists('telemetry', $settings)) { | |
| 139 | + return true; | |
| 140 | + } | |
| 141 | + | |
| 142 | + return (int) $settings['telemetry'] === 1; | |
| 143 | + } | |
| 144 | + | |
| 145 | + /** | |
| 128 | 146 | * Static: send snapshot |
| 147 | + * | |
| 148 | + * Currently unwired: no cron schedules this any more (see core/cron.php). | |
| 149 | + * The transport is kept — including the payload — so that switching it | |
| 150 | + * back on is a matter of scheduling the job again once a reachable | |
| 151 | + * endpoint exists, rather than rewriting it from memory. | |
| 129 | 152 | */ |
| 130 | 153 | public static function send_snapshot(): void { |
| 131 | - $logger = Logger::getInstance(); | |
| 154 | + $logger = Logger::getInstance(); | |
| 155 | + | |
| 156 | + // The consent check belongs here rather than at the call site: this | |
| 157 | + // method is public and was previously reachable from a cron job that | |
| 158 | + // never asked. Anything that calls it in future inherits the check. | |
| 159 | + if (!self::is_enabled()) { | |
| 160 | + $logger->debug("Telemetry skipped — disabled in settings", [ | |
| 161 | + 'plugin' => FORGE12_OPTIN_SLUG, | |
| 162 | + ]); | |
| 163 | + | |
| 164 | + return; | |
| 165 | + } | |
| 166 | + | |
| 132 | 167 | $payload = self::build_payload(); |
| 133 | 168 | |
| 134 | 169 | $logger->debug("Telemetry Payload prepared", [ |
| 135 | 170 | 'plugin' => FORGE12_OPTIN_SLUG, |
| @@ -169,6 +204,8 @@ | ||
| 169 | 204 | } |
| 170 | 205 | } |
| 171 | 206 | } |
| 172 | 207 | |
| 173 | -// Cron Hook registrieren | |
| 174 | -add_action('f12_cf7_doubleoptin_daily_telemetry', [Telemetry::class, 'send_snapshot']); | |
| 208 | +// Kein Cron-Hook mehr: der Tagesjob ist abgeschafft (siehe core/cron.php, das | |
| 209 | +// bestehende Planungen auch wieder austrägt). Die Bindung bleibt bewusst weg, | |
| 210 | +// damit ein Event, das auf einer alten Installation noch im WP-Cron steht, bis | |
| 211 | +// zum Aufräumen ins Leere läuft statt an einen toten Endpoint zu posten. | |