PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.8.13
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.8.13
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 1.7.0.9 All 211 releases
← All changes | includes/admin/settings/class-charitable-advanced-settings.php +373 -22 1.6.60 → 1.8.13 View file →
@@ -2,13 +2,13 @@
2 2 /**
3 3 * Charitable Advanced Settings UI.
4 4 *
5 5 * @package Charitable/Classes/Charitable_Advanced_Settings
6 - * @author Eric Daams
7 - * @copyright Copyright (c) 2022, Studio 164a
6 + * @author David Bisset
7 + * @copyright Copyright (c) 2023, WP Charitable LLC
8 8 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
9 9 * @since 1.0.0
10 - * @version 1.2.0
10 + * @version 1.8.1
11 11 */
12 12
13 13 // Exit if accessed directly.
14 14 if ( ! defined( 'ABSPATH' ) ) {
@@ -57,9 +57,10 @@
57 57
58 58 /**
59 59 * Add the advanced tab settings fields.
60 60 *
61 - * @since 1.0.0
61 + * @since 1.0.0
62 + * @since 1.8.1.4 Added the 'charitable_settings_advanced_fields' filter.
62 63 *
63 64 * @return array<string,array>
64 65 */
65 66 public function add_advanced_fields() {
@@ -66,27 +67,377 @@
66 67 if ( ! charitable_is_settings_view( 'advanced' ) ) {
67 68 return array();
68 69 }
69 70
70 - return array(
71 - 'section' => array(
72 - 'title' => '',
73 - 'type' => 'hidden',
74 - 'priority' => 10000,
75 - 'value' => 'advanced',
76 - ),
77 - 'section_dangerous' => array(
78 - 'title' => __( 'Dangerous Settings', 'charitable' ),
79 - 'type' => 'heading',
80 - 'priority' => 100,
81 - ),
82 - 'delete_data_on_uninstall' => array(
83 - 'label_for' => __( 'Reset Data', 'charitable' ),
84 - 'type' => 'checkbox',
85 - 'help' => __( 'DELETE ALL DATA when uninstalling the plugin.', 'charitable' ),
86 - 'priority' => 105,
87 - ),
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 + )
88 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 +
227 + // Delete all transients whose names start with "charitable-report".
228 + charitable_delete_transients_from_keys( charitable_search_database_for_transients_by_prefix( 'charitable-report', '-' ) );
229 +
230 + // Delete settings stored in user meta.
231 + $user_meta_keys = array( 'charitable-pointer-slug-dismissed', 'charitable_dismissed_addons' ); // v1.8.1.5.
232 + foreach ( $user_meta_keys as $meta_key ) {
233 + delete_metadata( 'user', 0, $meta_key, '', true );
234 + }
235 +
236 + // Licenses info, added in v1.8.1.6.
237 + delete_site_option( 'wpc_plugin_versions' );
238 + wp_cache_delete( 'plugin_versions', 'charitable' ); // Depreciated item.
239 + $empty_transient = new \stdClass();
240 + set_site_transient( 'update_plugins', $empty_transient ); // Depreciated item.
241 +
242 + // Clear Stripe webhook failure counter so stale notices don't persist after fixing the root cause.
243 + delete_transient( 'charitable_stripe_webhook_verification_failures' );
244 +
245 + // Allow an addon to hook into this.
246 + do_action( 'charitable_after_clear_expired_options' );
247 +
248 + charitable_get_admin_notices()->add_notice( 'Charitable cache has been cleared.', 'success', false, true );
249 +
250 + // Document when the cache was cleared last.
251 + update_option( 'charitable_cache_cleared', time() );
252 +
253 + $values['clear_expire_options'] = false;
254 +
255 + return $values;
256 + }
257 +
258 + /**
259 + * Removes activity tables - "clears" them but also allows Charitable to turn around and reinstall them.
260 + *
261 + * @since 1.8.1
262 + *
263 + * @param mixed[] $values The parsed values combining old values & new values.
264 + * @param mixed[] $new_values The newly submitted values.
265 + * @return mixed[]
266 + */
267 + public function clear_activity_database( $values, $new_values ) {
268 +
269 + /* If this option isn't in the return values or isn't checked off, leave. */
270 + if ( ! isset( $new_values['clear_activity_database'] ) || '' === trim( $new_values['clear_activity_database'] ) ) {
271 + return $values;
272 + }
273 +
274 + switch ( sanitize_text_field( $new_values['clear_activity_database'] ) ) {
275 + case 'clear':
276 + // Check and see if method exists.
277 + if ( method_exists( charitable_get_table( 'donation_activities' ), 'clear_table' ) ) {
278 + charitable_get_table( 'donation_activities' )->clear_table();
279 + }
280 + if ( method_exists( charitable_get_table( 'campaign_activities' ), 'clear_table' ) ) {
281 + charitable_get_table( 'campaign_activities' )->clear_table();
282 + }
283 +
284 + // Allow an addon to hook into this.
285 + do_action( 'charitable_after_clear_activity_database' );
286 +
287 + charitable_get_admin_notices()->add_notice( 'Charitable activity have been cleared.', 'success', false, true );
288 +
289 + $values['clear_activity_database'] = false;
290 +
291 + break;
292 +
293 + case 'remove':
294 + // Check and see if method exists.
295 + if ( method_exists( charitable_get_table( 'donation_activities' ), 'remove_table' ) ) {
296 + charitable_get_table( 'donation_activities' )->remove_table();
297 + }
298 + if ( method_exists( charitable_get_table( 'campaign_activities' ), 'remove_table' ) ) {
299 + charitable_get_table( 'campaign_activities' )->remove_table();
300 + }
301 +
302 + // Remove the upgrade option.
303 + $ugprade_log_key = Charitable_Upgrade::get_instance()->get_upgrade_log_key();
304 + $log = get_option( $ugprade_log_key );
305 + if ( is_array( $log ) && array_key_exists( 'create_activity_tables', $log ) ) {
306 + unset( $log['create_activity_tables'] );
307 + update_option( $ugprade_log_key, $log );
308 + }
309 +
310 + // Allow an addon to hook into this.
311 + do_action( 'charitable_after_remove_activity_database' );
312 +
313 + charitable_get_admin_notices()->add_notice( 'Charitable activity tables have been removed.', 'success', false, true );
314 +
315 + $values['clear_activity_database'] = false;
316 +
317 + break;
318 +
319 + default:
320 + // do nothing.
321 + break;
322 + }
323 +
324 + return $values;
325 + }
326 +
327 + /**
328 + * Enable or disable minification.
329 + *
330 + * @since 1.8.1.9
331 + *
332 + * @param mixed[] $values The parsed values combining old values & new values.
333 + * @param mixed[] $new_values The newly submitted values.
334 + * @return mixed[]
335 + */
336 + public function minification_settings( $values, $new_values ) {
337 +
338 + /* If this option isn't in the return values or isn't checked off, leave. */
339 + if ( ! isset( $new_values['script_minification'] ) || '' === trim( $new_values['script_minification'] ) ) {
340 + return $values;
341 + }
342 +
343 + switch ( sanitize_text_field( $new_values['script_minification'] ) ) {
344 + case 'enable':
345 + // Allow an addon to hook into this.
346 + do_action( 'charitable_after_enable_minification' );
347 +
348 + charitable_get_admin_notices()->add_notice( 'Charitable minification has been enabled.', 'success', false, true );
349 +
350 + $values['script_minification'] = 'scripts-enabled';
351 +
352 + break;
353 +
354 + case 'disable':
355 + // Allow an addon to hook into this.
356 + do_action( 'charitable_after_disable_minification' );
357 +
358 + charitable_get_admin_notices()->add_notice( 'Charitable minification has been disabled.', 'success', false, true );
359 +
360 + $values['script_minification'] = 'scripts-disabled';
361 +
362 + break;
363 +
364 + default:
365 + // do nothing.
366 + break;
367 + }
368 +
369 + return $values;
370 + }
371 +
372 + /**
373 + * Checks for updated license and invalidates status field if not set.
374 + *
375 + * @since 1.0.0
376 + * @version 1.8.6.2 - clear transient _charitable_plugin_versions
377 + *
378 + * @param mixed[] $values The parsed values combining old values & new values.
379 + * @param mixed[] $new_values The newly submitted values.
380 + * @return mixed[]
381 + */
382 + public function save_license( $values, $new_values ) {
383 + /* If we didn't just submit licenses, stop here. */
384 + if ( ! isset( $new_values['licenses'] ) ) {
385 + return $values;
386 + }
387 +
388 + $re_check = array_key_exists( 'recheck', $_POST ); // phpcs:ignore
389 + $licenses = $new_values['licenses'];
390 +
391 + // Delete transients (related to plugin versions).
392 + delete_transient( '_charitable_plugin_versions' );
393 +
394 + foreach ( $licenses as $product_key => $license ) {
395 + $license = trim( $license );
396 +
397 + if ( empty( $license ) ) {
398 + $values['licenses'][ $product_key ] = '';
399 + continue;
400 + }
401 +
402 + $license_data = charitable_get_helper( 'licenses' )->verify_license( $product_key, $license, $re_check );
403 +
404 + if ( empty( $license_data ) ) {
405 + continue;
406 + }
407 +
408 + $values['licenses'][ $product_key ] = $license_data;
409 + }
410 +
411 + return $values;
412 + }
413 +
414 + /**
415 + * Enables/disables usage tracking, used for testing and debugging.
416 + *
417 + * @since 1.8.4
418 + *
419 + * @param mixed[] $values The parsed values combining old values & new values.
420 + * @param mixed[] $new_values The newly submitted values.
421 + */
422 + public function update_user_tracking_option( $values, $new_values ) {
423 +
424 + /* If this option isn't in the return values or isn't checked off then the user has opted out, leave. */
425 + if ( ! isset( $new_values['charitable_usage_tracking'] ) || 0 === intval( $new_values['charitable_usage_tracking'] ) || '' === trim( $new_values['charitable_usage_tracking'] ) ) {
426 + // remove the option.
427 + $values['charitable_usage_tracking'] = false;
428 + delete_option( 'charitable_usage_tracking' );
429 + } else {
430 + // add the option.
431 + $values['charitable_usage_tracking'] = true;
432 + update_option( 'charitable_usage_tracking', 1 );
433 + // Send initial usage information just once (after that scheduled), now that we have permission.
434 + if ( class_exists( 'Charitable_Tracking' ) ) {
435 + Charitable_Tracking::get_instance()->send_checkins( false, true );
436 + }
437 + }
438 +
439 + return $values;
89 440 }
90 441 }
91 442
92 443 endif;