PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.8.11
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.8.11
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.11, at includes/admin/settings/class-charitable-advanced-settings.php

443 lines 14.8 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_splash_version' ); // v1.8.6.
204
205 // Delete transients (related to notices).
206 $notice_slugs = array( 'campaign-builder', 'dashboard-reporting', 'five-star-review', 'expiringlicense', 'expiredlicense' );
207 foreach ( $notice_slugs as $slug ) {
208 delete_transient( 'charitable_' . $slug . '_banner' );
209 }
210
211 // Delete transients (related to dashboard).
212 delete_transient( 'wpch_dashboard_data_args' ); // v1.8.1.
213
214 // Delete transients (related to notices).
215 delete_transient( 'charitable_dashboard_notices' ); // v1.8.1.6.
216
217 // Delete transients (related to security checks and logs).
218 delete_transient( 'charitable_donation_security_checks' ); // v1.8.1.6.
219
220 // Delete transients (related to notifications).
221 delete_transient( 'charitable_autoshow_plugin_notifications' ); // v1.8.3.
222
223 // Delete transients (related to plugin versions).
224 delete_transient( '_charitable_plugin_versions' ); // v1.8.6.2.
225
226 // Delete all transients whose names start with "charitable-report".
227 charitable_delete_transients_from_keys( charitable_search_database_for_transients_by_prefix( 'charitable-report', '-' ) );
228
229 // Delete settings stored in user meta.
230 $user_meta_keys = array( 'charitable-pointer-slug-dismissed', 'charitable_dismissed_addons' ); // v1.8.1.5.
231 foreach ( $user_meta_keys as $meta_key ) {
232 delete_metadata( 'user', 0, $meta_key, '', true );
233 }
234
235 // Licenses info, added in v1.8.1.6.
236 delete_site_option( 'wpc_plugin_versions' );
237 wp_cache_delete( 'plugin_versions', 'charitable' ); // Depreciated item.
238 $empty_transient = new \stdClass();
239 set_site_transient( 'update_plugins', $empty_transient ); // Depreciated item.
240
241 // Clear Stripe webhook failure counter so stale notices don't persist after fixing the root cause.
242 delete_transient( 'charitable_stripe_webhook_verification_failures' );
243
244 // Allow an addon to hook into this.
245 do_action( 'charitable_after_clear_expired_options' );
246
247 charitable_get_admin_notices()->add_notice( 'Charitable cache has been cleared.', 'success', false, true );
248
249 // Document when the cache was cleared last.
250 update_option( 'charitable_cache_cleared', time() );
251
252 $values['clear_expire_options'] = false;
253
254 return $values;
255 }
256
257 /**
258 * Removes activity tables - "clears" them but also allows Charitable to turn around and reinstall them.
259 *
260 * @since 1.8.1
261 *
262 * @param mixed[] $values The parsed values combining old values & new values.
263 * @param mixed[] $new_values The newly submitted values.
264 * @return mixed[]
265 */
266 public function clear_activity_database( $values, $new_values ) {
267
268 /* If this option isn't in the return values or isn't checked off, leave. */
269 if ( ! isset( $new_values['clear_activity_database'] ) || '' === trim( $new_values['clear_activity_database'] ) ) {
270 return $values;
271 }
272
273 switch ( sanitize_text_field( $new_values['clear_activity_database'] ) ) {
274 case 'clear':
275 // Check and see if method exists.
276 if ( method_exists( charitable_get_table( 'donation_activities' ), 'clear_table' ) ) {
277 charitable_get_table( 'donation_activities' )->clear_table();
278 }
279 if ( method_exists( charitable_get_table( 'campaign_activities' ), 'clear_table' ) ) {
280 charitable_get_table( 'campaign_activities' )->clear_table();
281 }
282
283 // Allow an addon to hook into this.
284 do_action( 'charitable_after_clear_activity_database' );
285
286 charitable_get_admin_notices()->add_notice( 'Charitable activity have been cleared.', 'success', false, true );
287
288 $values['clear_activity_database'] = false;
289
290 break;
291
292 case 'remove':
293 // Check and see if method exists.
294 if ( method_exists( charitable_get_table( 'donation_activities' ), 'remove_table' ) ) {
295 charitable_get_table( 'donation_activities' )->remove_table();
296 }
297 if ( method_exists( charitable_get_table( 'campaign_activities' ), 'remove_table' ) ) {
298 charitable_get_table( 'campaign_activities' )->remove_table();
299 }
300
301 // Remove the upgrade option.
302 $ugprade_log_key = Charitable_Upgrade::get_instance()->get_upgrade_log_key();
303 $log = get_option( $ugprade_log_key );
304 if ( is_array( $log ) && array_key_exists( 'create_activity_tables', $log ) ) {
305 unset( $log['create_activity_tables'] );
306 update_option( $ugprade_log_key, $log );
307 }
308
309 // Allow an addon to hook into this.
310 do_action( 'charitable_after_remove_activity_database' );
311
312 charitable_get_admin_notices()->add_notice( 'Charitable activity tables have been removed.', 'success', false, true );
313
314 $values['clear_activity_database'] = false;
315
316 break;
317
318 default:
319 // do nothing.
320 break;
321 }
322
323 return $values;
324 }
325
326 /**
327 * Enable or disable minification.
328 *
329 * @since 1.8.1.9
330 *
331 * @param mixed[] $values The parsed values combining old values & new values.
332 * @param mixed[] $new_values The newly submitted values.
333 * @return mixed[]
334 */
335 public function minification_settings( $values, $new_values ) {
336
337 /* If this option isn't in the return values or isn't checked off, leave. */
338 if ( ! isset( $new_values['script_minification'] ) || '' === trim( $new_values['script_minification'] ) ) {
339 return $values;
340 }
341
342 switch ( sanitize_text_field( $new_values['script_minification'] ) ) {
343 case 'enable':
344 // Allow an addon to hook into this.
345 do_action( 'charitable_after_enable_minification' );
346
347 charitable_get_admin_notices()->add_notice( 'Charitable minification has been enabled.', 'success', false, true );
348
349 $values['script_minification'] = 'scripts-enabled';
350
351 break;
352
353 case 'disable':
354 // Allow an addon to hook into this.
355 do_action( 'charitable_after_disable_minification' );
356
357 charitable_get_admin_notices()->add_notice( 'Charitable minification has been disabled.', 'success', false, true );
358
359 $values['script_minification'] = 'scripts-disabled';
360
361 break;
362
363 default:
364 // do nothing.
365 break;
366 }
367
368 return $values;
369 }
370
371 /**
372 * Checks for updated license and invalidates status field if not set.
373 *
374 * @since 1.0.0
375 * @version 1.8.6.2 - clear transient _charitable_plugin_versions
376 *
377 * @param mixed[] $values The parsed values combining old values & new values.
378 * @param mixed[] $new_values The newly submitted values.
379 * @return mixed[]
380 */
381 public function save_license( $values, $new_values ) {
382 /* If we didn't just submit licenses, stop here. */
383 if ( ! isset( $new_values['licenses'] ) ) {
384 return $values;
385 }
386
387 $re_check = array_key_exists( 'recheck', $_POST ); // phpcs:ignore
388 $licenses = $new_values['licenses'];
389
390 // Delete transients (related to plugin versions).
391 delete_transient( '_charitable_plugin_versions' );
392
393 foreach ( $licenses as $product_key => $license ) {
394 $license = trim( $license );
395
396 if ( empty( $license ) ) {
397 $values['licenses'][ $product_key ] = '';
398 continue;
399 }
400
401 $license_data = charitable_get_helper( 'licenses' )->verify_license( $product_key, $license, $re_check );
402
403 if ( empty( $license_data ) ) {
404 continue;
405 }
406
407 $values['licenses'][ $product_key ] = $license_data;
408 }
409
410 return $values;
411 }
412
413 /**
414 * Enables/disables usage tracking, used for testing and debugging.
415 *
416 * @since 1.8.4
417 *
418 * @param mixed[] $values The parsed values combining old values & new values.
419 * @param mixed[] $new_values The newly submitted values.
420 */
421 public function update_user_tracking_option( $values, $new_values ) {
422
423 /* If this option isn't in the return values or isn't checked off then the user has opted out, leave. */
424 if ( ! isset( $new_values['charitable_usage_tracking'] ) || 0 === intval( $new_values['charitable_usage_tracking'] ) || '' === trim( $new_values['charitable_usage_tracking'] ) ) {
425 // remove the option.
426 $values['charitable_usage_tracking'] = false;
427 delete_option( 'charitable_usage_tracking' );
428 } else {
429 // add the option.
430 $values['charitable_usage_tracking'] = true;
431 update_option( 'charitable_usage_tracking', 1 );
432 // Send initial usage information just once (after that scheduled), now that we have permission.
433 if ( class_exists( 'Charitable_Tracking' ) ) {
434 Charitable_Tracking::get_instance()->send_checkins( false, true );
435 }
436 }
437
438 return $values;
439 }
440 }
441
442 endif;
443