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

222 lines 5.5 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) 2022, WP Charitable LLC
8 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
9 * @since 1.0.0
10 * @version 1.2.0
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 *
63 * @return array<string,array>
64 */
65 public function add_advanced_fields() {
66 if ( ! charitable_is_settings_view( 'advanced' ) ) {
67 return array();
68 }
69
70 return array(
71 'section' => array(
72 'title' => '',
73 'type' => 'hidden',
74 'priority' => 10000,
75 'value' => 'advanced',
76 ),
77 'section_dangerous' => array(
78 'title' => __( 'Advanced Settings', 'charitable' ),
79 'type' => 'heading',
80 'class' => 'section-heading',
81 'priority' => 100,
82 ),
83 'delete_data_on_uninstall' => array(
84 'label_for' => __( 'Reset Data', 'charitable' ),
85 'type' => 'checkbox',
86 'help' => '<span style="color:red;font-weight:bold;">' . __( 'DELETE ALL DATA' ) . '</span> ' . __( 'when uninstalling the plugin.', 'charitable' ),
87 'priority' => 105,
88 ),
89 'clear_expire_options' => array(
90 'label_for' => __( 'Clear Cache', 'charitable' ),
91 'type' => 'checkbox',
92 'help' => __( 'This removes and refreshes items in the database specific to Charitable.', 'charitable' ),
93 'priority' => 120,
94 ),
95 'section' => array(
96 'title' => '',
97 'type' => 'hidden',
98 'priority' => 10000,
99 'value' => 'licenses',
100 'save' => false,
101 ),
102 'section_licenses' => array(
103 'title' => __( 'Legacy Licenses', 'charitable' ),
104 'type' => 'heading',
105 'class' => 'section-heading',
106 'priority' => 202,
107 ),
108 'licenses' => array(
109 'title' => false,
110 'callback' => array( $this, 'render_licenses_table' ),
111 'priority' => 204,
112 ),
113 );
114
115 foreach ( charitable_get_helper( 'licenses' )->get_products() as $key => $product ) {
116 $fields[ $key ] = array(
117 'type' => 'text',
118 'render' => false,
119 'priority' => 206,
120 );
121 }
122
123 }
124
125 /**
126 * Add the licenses group.
127 *
128 * @since 1.0.0
129 *
130 * @param string[] $groups Settings groups.
131 * @return string[]
132 */
133 public function add_licenses_group( $groups ) {
134 $groups['licenses'] = array();
135 return $groups;
136 }
137
138 /**
139 * Render the licenses table.
140 *
141 * @since 1.0.0
142 *
143 * @return void
144 */
145 public function render_licenses_table() {
146 charitable_admin_view( 'settings/licenses' );
147 }
148
149 /**
150 * 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'.
151 *
152 * @since 1.7.0.7
153 *
154 * @param mixed[] $values The parsed values combining old values & new values.
155 * @param mixed[] $new_values The newly submitted values.
156 * @return mixed[]
157 */
158 public function clear_expired_options( $values, $new_values ) {
159
160 /* If this option isn't in the return values or isn't checked off, leave. */
161 if ( ! isset( $new_values['clear_expire_options'] ) || 0 === intval( $new_values['clear_expire_options'] ) ) {
162 return $values;
163 }
164
165 // Remove the options.
166 delete_option( 'charitable_doing_upgrade' );
167 delete_option( 'charitable_third_party_warnings' );
168
169 // Allow an addon to hook into this.
170 do_action( 'charitable_clear_expired_options' );
171
172 charitable_get_admin_notices()->add_notice( 'Charitable cache has been cleared.', 'success', false, true );
173
174 $values['clear_expire_options'] = false;
175
176 return $values;
177 }
178
179 /**
180 * Checks for updated license and invalidates status field if not set.
181 *
182 * @since 1.0.0
183 *
184 * @param mixed[] $values The parsed values combining old values & new values.
185 * @param mixed[] $new_values The newly submitted values.
186 * @return mixed[]
187 */
188 public function save_license( $values, $new_values ) {
189 /* If we didn't just submit licenses, stop here. */
190 if ( ! isset( $new_values['licenses'] ) ) {
191 return $values;
192 }
193
194 $re_check = array_key_exists( 'recheck', $_POST );
195 $licenses = $new_values['licenses'];
196
197 foreach ( $licenses as $product_key => $license ) {
198 $license = trim( $license );
199
200 if ( empty( $license ) ) {
201 $values['licenses'][ $product_key ] = '';
202 continue;
203 }
204
205 $license_data = charitable_get_helper( 'licenses' )->verify_license( $product_key, $license, $re_check );
206
207 if ( empty( $license_data ) ) {
208 continue;
209 }
210
211 $values['licenses'][ $product_key ] = $license_data;
212 }
213
214 return $values;
215 }
216
217
218
219 }
220
221 endif;
222