PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.8.13.1
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.8.13.1
1.8.13.1 1.8.13 1.8.12.3 1.8.12.2 1.8.12.1 1.8.12 1.8.11.3 1.8.11.2 1.8.11.1 1.8.11 1.6.6 1.6.60 1.6.7 1.6.8 1.6.9 1.7.0 1.7.0.1 1.7.0.11 1.7.0.12 1.7.0.14 1.7.0.2 1.7.0.3 1.7.0.5 1.7.0.6 1.7.0.7 All 212 releases
charitable / includes / admin / settings / class-charitable-advanced-settings.php

class-charitable-advanced-settings.php in Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) 1.8.13.1, at includes/admin/settings/class-charitable-advanced-settings.php

446 lines 15.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Charitable Advanced Settings UI.
4 *
5 * @package Charitable/Classes/Charitable_Advanced_Settings
6 * @author David Bisset
7 * @copyright Copyright (c) 2023, WP Charitable LLC
8 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
9 * @since 1.0.0
10 * @version 1.8.1
11 */
12
13 // Exit if accessed directly.
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit;
16 }
17
18 if ( ! class_exists( 'Charitable_Advanced_Settings' ) ) :
19
20 /**
21 * Charitable_Advanced_Settings
22 *
23 * @final
24 * @since 1.0.0
25 */
26 final class Charitable_Advanced_Settings {
27
28 /**
29 * The single instance of this class.
30 *
31 * @var Charitable_Advanced_Settings|null
32 */
33 private static $instance = null;
34
35 /**
36 * Create object instance.
37 *
38 * @since 1.0.0
39 */
40 private function __construct() {
41 }
42
43 /**
44 * Returns and/or create the single instance of this class.
45 *
46 * @since 1.2.0
47 *
48 * @return Charitable_Advanced_Settings
49 */
50 public static function get_instance() {
51 if ( is_null( self::$instance ) ) {
52 self::$instance = new self();
53 }
54
55 return self::$instance;
56 }
57
58 /**
59 * Add the advanced tab settings fields.
60 *
61 * @since 1.0.0
62 * @since 1.8.1.4 Added the 'charitable_settings_advanced_fields' filter.
63 *
64 * @return array<string,array>
65 */
66 public function add_advanced_fields() {
67 if ( ! charitable_is_settings_view( 'advanced' ) ) {
68 return array();
69 }
70
71 return apply_filters(
72 'charitable_settings_advanced_fields',
73 array(
74 'section_hidden_advanced' => array(
75 'title' => '',
76 'type' => 'hidden',
77 'priority' => 10000,
78 'value' => 'advanced',
79 ),
80 'section_dangerous' => array(
81 'title' => __( 'Advanced Settings', 'charitable' ),
82 'type' => 'heading',
83 'class' => 'section-heading',
84 'priority' => 100,
85 ),
86 'delete_data_on_uninstall' => array(
87 'label_for' => __( 'Reset Data', 'charitable' ),
88 'type' => 'checkbox',
89 'help' => '<span style="color:red;font-weight:bold;">' . __( 'DELETE ALL DATA', 'charitable' ) . '</span> ' . __( 'when uninstalling the plugin.', 'charitable' ),
90 'priority' => 105,
91 ),
92 'clear_expire_options' => array(
93 'label_for' => __( 'Clear Cache', 'charitable' ),
94 'type' => 'checkbox',
95 'help' => __( 'This removes and refreshes temporarily stored items in the database specific to Charitable.', 'charitable' ),
96 'priority' => 120,
97 ),
98 'clear_activity_database' => array(
99 'label_for' => __( 'Activity Database', 'charitable' ),
100 'type' => 'select',
101 'options' => array(
102 '' => __( 'No action', 'charitable' ), // phpcs:ignore
103 'clear' => __( 'Clear database records', 'charitable' ),
104 'remove' => __( 'Remove database tables', 'charitable' ),
105 ),
106 'help' => __( 'This clears or removes the custom database tables related to activities tracked by Charitable.', 'charitable' ),
107 'priority' => 150,
108 ),
109 'disable_campaign_legacy_mode' => array(
110 'label_for' => __( 'Disable Legacy Mode', 'charitable' ),
111 'type' => 'checkbox',
112 'help' => /* translators: %1$s: URL to the documentation. */
113 sprintf( __( 'Determines ability for admin users to add new legacy campaigns. <a href="%1$s">Learn More</a>.', 'charitable' ), 'https://www.wpcharitable.com/documentation/legacy-campaigns/' ),
114 'priority' => 155,
115 'default' => true,
116 ),
117 'charitable_usage_tracking' => array(
118 'label_for' => __( 'Usage Tracking', 'charitable' ),
119 'type' => 'checkbox',
120 'help' => /* translators: %1$s: URL to the documentation. */
121 sprintf( __( 'Allows us to better help you as we know which WordPress configurations, themes and plugins we should test. <a href="%1$s">Learn More</a>.', 'charitable' ), 'https://www.wpcharitable.com/documentation/usage-tracking/' ),
122 'priority' => 155,
123 'default' => false,
124 ),
125 'section_hidden_licenses' => array(
126 'title' => '',
127 'type' => 'hidden',
128 'priority' => 10000,
129 'value' => 'licenses',
130 'save' => false,
131 ),
132 'section_licenses' => array(
133 'title' => __( 'Legacy Licenses', 'charitable' ),
134 'type' => 'heading',
135 'class' => 'section-heading',
136 'priority' => 202,
137 ),
138 'licenses' => array(
139 'title' => false,
140 'callback' => array( $this, 'render_licenses_table' ),
141 'priority' => 204,
142 ),
143 )
144 );
145 }
146
147 /**
148 * Add the licenses group.
149 *
150 * @since 1.0.0
151 *
152 * @param string[] $groups Settings groups.
153 * @return string[]
154 */
155 public function add_licenses_group( $groups ) {
156 $groups['licenses'] = array();
157 return $groups;
158 }
159
160 /**
161 * Render the licenses table.
162 *
163 * @since 1.0.0
164 *
165 * @return void
166 */
167 public function render_licenses_table() {
168 charitable_admin_view( 'settings/licenses' );
169 }
170
171 /**
172 * Removes select options that might be causing trouble or unwanted notices, mostly items that we done pre-1.7.0. Also known as 'clear cache' or 'clearing cache'.
173 *
174 * @since 1.7.0.7
175 * @version 1.8.1.12 Added expiringlicense and expiredlicense.
176 * @version 1.8.3 Added charitable_notifications.
177 * @version 1.8.3.1 Added charitable_cache_cleared.
178 * @version 1.8.6 Added charitable_splash_version.
179 *
180 * @param mixed[] $values The parsed values combining old values & new values.
181 * @param mixed[] $new_values The newly submitted values.
182 * @return mixed[]
183 */
184 public function clear_expired_options( $values, $new_values ) {
185
186 /* If this option isn't in the return values or isn't checked off, leave. */
187 if ( ! isset( $new_values['clear_expire_options'] ) || 0 === intval( $new_values['clear_expire_options'] ) ) {
188 return $values;
189 }
190
191 // Remove the options.
192 delete_option( 'charitable_doing_upgrade' );
193 delete_option( 'charitable_third_party_warnings' );
194 delete_option( 'charitable_campaign_builder_templates' ); // v1.8.0.
195 delete_option( 'charitable_growth_tool_notices' ); // v1.8.1.6.
196 delete_option( 'charitable_lite_settings_upgrade' );
197 delete_option( 'charitable_lite_reports_upgrade' );
198 delete_option( 'charitable_builder_onboarding' ); // v1.8.1.12.
199 delete_option( 'charitable_onboarding_checklist' ); // v1.8.2.
200 delete_option( 'charitable_notifications' ); // v1.8.3.
201 delete_option( 'charitable_usage_tracking_last_checkin' ); // v1.8.4.
202 delete_option( 'charitable_tracking_last_checkin' ); // v1.8.4.
203 delete_option( 'charitable_telemetry_send_failures' ); // v1.8.12.
204 delete_option( 'charitable_splash_version' ); // v1.8.6.
205
206 // Delete transients (related to notices).
207 $notice_slugs = array( 'campaign-builder', 'dashboard-reporting', 'five-star-review', 'expiringlicense', 'expiredlicense' );
208 foreach ( $notice_slugs as $slug ) {
209 delete_transient( 'charitable_' . $slug . '_banner' );
210 }
211
212 // Delete transients (related to dashboard).
213 delete_transient( 'wpch_dashboard_data_args' ); // v1.8.1.
214
215 // Delete transients (related to notices).
216 delete_transient( 'charitable_dashboard_notices' ); // v1.8.1.6.
217
218 // Delete transients (related to security checks and logs).
219 delete_transient( 'charitable_donation_security_checks' ); // v1.8.1.6.
220
221 // Delete transients (related to notifications).
222 delete_transient( 'charitable_autoshow_plugin_notifications' ); // v1.8.3.
223
224 // Delete transients (related to plugin versions).
225 delete_transient( '_charitable_plugin_versions' ); // v1.8.6.2.
226 delete_transient( '_charitable_plugin_versions_failed' ); // v1.8.13.1.
227
228 // Delete all transients whose names start with "charitable-report".
229 charitable_delete_transients_from_keys( charitable_search_database_for_transients_by_prefix( 'charitable-report', '-' ) );
230
231 // Delete settings stored in user meta.
232 $user_meta_keys = array( 'charitable-pointer-slug-dismissed', 'charitable_dismissed_addons' ); // v1.8.1.5.
233 foreach ( $user_meta_keys as $meta_key ) {
234 delete_metadata( 'user', 0, $meta_key, '', true );
235 }
236
237 // Licenses info, added in v1.8.1.6.
238 delete_site_option( 'wpc_plugin_versions' );
239 wp_cache_delete( 'plugin_versions', 'charitable' ); // Depreciated item.
240 $empty_transient = new \stdClass();
241 set_site_transient( 'update_plugins', $empty_transient ); // Depreciated item.
242
243 // Clear Stripe webhook failure counter so stale notices don't persist after fixing the root cause.
244 delete_transient( 'charitable_stripe_webhook_verification_failures' );
245
246 // Allow an addon to hook into this.
247 do_action( 'charitable_after_clear_expired_options' );
248
249 charitable_get_admin_notices()->add_notice( 'Charitable cache has been cleared.', 'success', false, true );
250
251 // Document when the cache was cleared last.
252 update_option( 'charitable_cache_cleared', time() );
253
254 $values['clear_expire_options'] = false;
255
256 return $values;
257 }
258
259 /**
260 * Removes activity tables - "clears" them but also allows Charitable to turn around and reinstall them.
261 *
262 * @since 1.8.1
263 *
264 * @param mixed[] $values The parsed values combining old values & new values.
265 * @param mixed[] $new_values The newly submitted values.
266 * @return mixed[]
267 */
268 public function clear_activity_database( $values, $new_values ) {
269
270 /* If this option isn't in the return values or isn't checked off, leave. */
271 if ( ! isset( $new_values['clear_activity_database'] ) || '' === trim( $new_values['clear_activity_database'] ) ) {
272 return $values;
273 }
274
275 switch ( sanitize_text_field( $new_values['clear_activity_database'] ) ) {
276 case 'clear':
277 // Check and see if method exists.
278 if ( method_exists( charitable_get_table( 'donation_activities' ), 'clear_table' ) ) {
279 charitable_get_table( 'donation_activities' )->clear_table();
280 }
281 if ( method_exists( charitable_get_table( 'campaign_activities' ), 'clear_table' ) ) {
282 charitable_get_table( 'campaign_activities' )->clear_table();
283 }
284
285 // Allow an addon to hook into this.
286 do_action( 'charitable_after_clear_activity_database' );
287
288 charitable_get_admin_notices()->add_notice( 'Charitable activity have been cleared.', 'success', false, true );
289
290 $values['clear_activity_database'] = false;
291
292 break;
293
294 case 'remove':
295 // Check and see if method exists.
296 if ( method_exists( charitable_get_table( 'donation_activities' ), 'remove_table' ) ) {
297 charitable_get_table( 'donation_activities' )->remove_table();
298 }
299 if ( method_exists( charitable_get_table( 'campaign_activities' ), 'remove_table' ) ) {
300 charitable_get_table( 'campaign_activities' )->remove_table();
301 }
302
303 // Remove the upgrade option.
304 $ugprade_log_key = Charitable_Upgrade::get_instance()->get_upgrade_log_key();
305 $log = get_option( $ugprade_log_key );
306 if ( is_array( $log ) && array_key_exists( 'create_activity_tables', $log ) ) {
307 unset( $log['create_activity_tables'] );
308 update_option( $ugprade_log_key, $log );
309 }
310
311 // Allow an addon to hook into this.
312 do_action( 'charitable_after_remove_activity_database' );
313
314 charitable_get_admin_notices()->add_notice( 'Charitable activity tables have been removed.', 'success', false, true );
315
316 $values['clear_activity_database'] = false;
317
318 break;
319
320 default:
321 // do nothing.
322 break;
323 }
324
325 return $values;
326 }
327
328 /**
329 * Enable or disable minification.
330 *
331 * @since 1.8.1.9
332 *
333 * @param mixed[] $values The parsed values combining old values & new values.
334 * @param mixed[] $new_values The newly submitted values.
335 * @return mixed[]
336 */
337 public function minification_settings( $values, $new_values ) {
338
339 /* If this option isn't in the return values or isn't checked off, leave. */
340 if ( ! isset( $new_values['script_minification'] ) || '' === trim( $new_values['script_minification'] ) ) {
341 return $values;
342 }
343
344 switch ( sanitize_text_field( $new_values['script_minification'] ) ) {
345 case 'enable':
346 // Allow an addon to hook into this.
347 do_action( 'charitable_after_enable_minification' );
348
349 charitable_get_admin_notices()->add_notice( 'Charitable minification has been enabled.', 'success', false, true );
350
351 $values['script_minification'] = 'scripts-enabled';
352
353 break;
354
355 case 'disable':
356 // Allow an addon to hook into this.
357 do_action( 'charitable_after_disable_minification' );
358
359 charitable_get_admin_notices()->add_notice( 'Charitable minification has been disabled.', 'success', false, true );
360
361 $values['script_minification'] = 'scripts-disabled';
362
363 break;
364
365 default:
366 // do nothing.
367 break;
368 }
369
370 return $values;
371 }
372
373 /**
374 * Checks for updated license and invalidates status field if not set.
375 *
376 * @since 1.0.0
377 * @version 1.8.6.2 - clear transient _charitable_plugin_versions
378 *
379 * @param mixed[] $values The parsed values combining old values & new values.
380 * @param mixed[] $new_values The newly submitted values.
381 * @return mixed[]
382 */
383 public function save_license( $values, $new_values ) {
384 /* If we didn't just submit licenses, stop here. */
385 if ( ! isset( $new_values['licenses'] ) ) {
386 return $values;
387 }
388
389 $re_check = array_key_exists( 'recheck', $_POST ); // phpcs:ignore
390 $licenses = $new_values['licenses'];
391
392 // Delete transients (related to plugin versions).
393 delete_transient( '_charitable_plugin_versions' );
394 delete_transient( '_charitable_plugin_versions_failed' );
395
396 foreach ( $licenses as $product_key => $license ) {
397 $license = trim( $license );
398
399 if ( empty( $license ) ) {
400 $values['licenses'][ $product_key ] = '';
401 continue;
402 }
403
404 $license_data = charitable_get_helper( 'licenses' )->verify_license( $product_key, $license, $re_check );
405
406 if ( empty( $license_data ) ) {
407 continue;
408 }
409
410 $values['licenses'][ $product_key ] = $license_data;
411 }
412
413 return $values;
414 }
415
416 /**
417 * Enables/disables usage tracking, used for testing and debugging.
418 *
419 * @since 1.8.4
420 *
421 * @param mixed[] $values The parsed values combining old values & new values.
422 * @param mixed[] $new_values The newly submitted values.
423 */
424 public function update_user_tracking_option( $values, $new_values ) {
425
426 /* If this option isn't in the return values or isn't checked off then the user has opted out, leave. */
427 if ( ! isset( $new_values['charitable_usage_tracking'] ) || 0 === intval( $new_values['charitable_usage_tracking'] ) || '' === trim( $new_values['charitable_usage_tracking'] ) ) {
428 // remove the option.
429 $values['charitable_usage_tracking'] = false;
430 delete_option( 'charitable_usage_tracking' );
431 } else {
432 // add the option.
433 $values['charitable_usage_tracking'] = true;
434 update_option( 'charitable_usage_tracking', 1 );
435 // Send initial usage information just once (after that scheduled), now that we have permission.
436 if ( class_exists( 'Charitable_Tracking' ) ) {
437 Charitable_Tracking::get_instance()->send_checkins( false, true );
438 }
439 }
440
441 return $values;
442 }
443 }
444
445 endif;
446