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

221 lines 5.3 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' => __( 'Dangerous Settings', 'charitable' ),
79 'type' => 'heading',
80 'class' => 'section-heading dangerous-settings',
81 'priority' => 100,
82 ),
83 'delete_data_on_uninstall' => array(
84 'label_for' => __( 'Reset Data', 'charitable' ),
85 'type' => 'checkbox',
86 'help' => __( 'DELETE ALL DATA 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 can remove and refresh Charitable items in the database.', '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.
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', false );
167
168 // Allow an addon to hook into this.
169 do_action( 'charitable_clear_expired_options' );
170
171 charitable_get_admin_notices()->add_notice( 'Charitable cache has been cleared.', 'success', false, true );
172
173 $values['clear_expire_options'] = false;
174
175 return $values;
176 }
177
178 /**
179 * Checks for updated license and invalidates status field if not set.
180 *
181 * @since 1.0.0
182 *
183 * @param mixed[] $values The parsed values combining old values & new values.
184 * @param mixed[] $new_values The newly submitted values.
185 * @return mixed[]
186 */
187 public function save_license( $values, $new_values ) {
188 /* If we didn't just submit licenses, stop here. */
189 if ( ! isset( $new_values['licenses'] ) ) {
190 return $values;
191 }
192
193 $re_check = array_key_exists( 'recheck', $_POST );
194 $licenses = $new_values['licenses'];
195
196 foreach ( $licenses as $product_key => $license ) {
197 $license = trim( $license );
198
199 if ( empty( $license ) ) {
200 $values['licenses'][ $product_key ] = '';
201 continue;
202 }
203
204 $license_data = charitable_get_helper( 'licenses' )->verify_license( $product_key, $license, $re_check );
205
206 if ( empty( $license_data ) ) {
207 continue;
208 }
209
210 $values['licenses'][ $product_key ] = $license_data;
211 }
212
213 return $values;
214 }
215
216
217
218 }
219
220 endif;
221