PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 3.2.2
GiveWP – Donation Plugin and Fundraising Platform v3.2.2
4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 2.32.0 2.33.0 2.33.1 2.33.2 2.33.3 2.33.4 2.33.5 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.5.0 2.5.1 2.5.10 2.5.11 2.5.12 2.5.13 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.2 2.6.3 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.9.0 2.9.1 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.10.0 3.11.0 3.12.0 3.12.1 3.12.2 3.12.3 3.13.0 3.14.0 3.14.1 3.14.2 3.15.0 3.15.1 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.17.0 3.17.1 3.17.2 3.18.0 3.19.0 3.19.1 3.19.2 3.19.3 3.19.4 3.2.0 3.2.1 3.2.2 3.20.0 3.21.0 3.21.1 3.22.0 3.22.1 3.22.2 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 3.6.0 3.6.1 3.6.2 3.7.0 3.8.0 3.9.0 4.0.0 4.1.0 4.1.1 4.10.0 4.10.1 4.11.0 4.12.0 4.13.0 4.13.1 4.13.2 4.14.0 4.14.1 4.14.2 4.14.3 4.14.4 4.14.5 4.14.6 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.1 4.7.0 4.7.1 4.8.0 4.8.1 4.9.0 trunk 1.9.0 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.2 2.11.3 2.12.0 2.12.1 2.12.2 2.12.3 2.13.0 2.13.1 2.13.2 2.13.3 2.13.4 2.14.0 2.15.0 2.16.0 2.16.1 2.17.0 2.17.1 2.17.3 2.18.0 2.18.1 2.19.1 2.19.2 2.19.3 2.19.4 2.19.5 2.19.6 2.19.7 2.19.8 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.20.0 2.20.1 2.20.2 2.21.0 2.21.1 2.21.2 2.21.3 2.21.4 2.22.0 2.22.1 2.22.2 2.22.3 2.23.0 2.23.1 2.23.2 2.24.0 2.24.1 2.24.2 2.25.0 2.25.1 2.25.2 2.25.3 2.26.0 2.27.0 2.27.1 2.27.2 2.27.3 2.28.0 2.29.0 2.29.1 2.29.2
give / includes / admin / admin-filters.php
give / includes / admin Last commit date
add-ons 4 years ago donors 4 years ago emails 3 years ago forms 3 years ago payments 3 years ago reports 4 years ago settings 2 years ago shortcodes 4 years ago tools 2 years ago upgrades 3 years ago views 3 years ago abstract-admin-settings-page.php 6 years ago admin-actions.php 3 years ago admin-filters.php 3 years ago admin-footer.php 2 years ago admin-pages.php 3 years ago class-addon-activation-banner.php 4 years ago class-admin-settings.php 4 years ago class-api-keys-table.php 4 years ago class-blank-slate.php 3 years ago class-give-admin.php 5 years ago class-give-html-elements.php 6 years ago class-i18n-module.php 4 years ago dashboard-widgets.php 3 years ago give-metabox-functions.php 3 years ago import-functions.php 3 years ago misc-functions.php 2 years ago plugins.php 3 years ago setting-page-functions.php 6 years ago
admin-filters.php
278 lines
1 <?php
2 /**
3 * Admin Filters
4 *
5 * @package Give
6 * @subpackage Admin/Filters
7 * @copyright Copyright (c) 2016, GiveWP
8 * @license https://opensource.org/licenses/gpl-license GNU Public License
9 * @since 1.0
10 */
11
12 // Exit if accessed directly.
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit;
15 }
16
17 /**
18 * Sanitize number of decimals setting field.
19 *
20 * 1. User can only set absolute integer value as number of decimals.
21 * 2. number_decimals setting will be zero if no decimal separator defined
22 *
23 * @since 1.8
24 * @used-by Give_Plugin_Settings::give_settings()
25 *
26 * @param string $value
27 *
28 * @return mixed
29 */
30 function __give_sanitize_number_decimals_setting_field( $value ) {
31 $value_changed = false;
32 $show_notice = false;
33 $old_value = $value;
34
35 if ( isset( $_POST['decimal_separator'] ) ) {
36 $value = ! empty( $_POST['decimal_separator'] ) ? $value : 0;
37 $value_changed = true;
38 }
39
40 if ( $value_changed && ( $old_value !== $value ) ) {
41 Give_Admin_Settings::add_error( 'give-number-decimal', __( 'The \'Number of Decimals\' option has been automatically set to zero because the \'Decimal Separator\' is not set.', 'give' ) );
42 }
43
44 $value = absint( $value );
45 $is_currency_set_to_bitcoin = ( 'XBT' === give_get_option( 'currency' ) && ! isset( $_POST['currency'] ) ) || 'XBT' === $_POST['currency'];
46
47 if ( $is_currency_set_to_bitcoin && 8 < $value ) {
48 $value = 8;
49 $show_notice = true;
50 } elseif ( ! $is_currency_set_to_bitcoin && 6 <= $value ) {
51 $value = 5;
52 $show_notice = true;
53 }
54
55 if ( $show_notice ) {
56 Give_Admin_Settings::add_error(
57 'give-number-decimal',
58 sprintf(
59 __( 'The \'Number of Decimals\' option has been automatically set to %s because you entered a number higher than the maximum allowed.', 'give' ),
60 $value
61 )
62 );
63 }
64
65 return absint( $value );
66 }
67
68 add_filter( 'give_admin_settings_sanitize_option_number_decimals', '__give_sanitize_number_decimals_setting_field', 10 );
69
70
71 /**
72 * Sanitize number of decimals setting field.
73 *
74 * 1. User can only set absolute integer value as number of decimals.
75 * 2. number_decimals setting will be zero if no decimal separator defined
76 *
77 * @since 1.8
78 * @used-by Give_Plugin_Settings::give_settings()
79 *
80 * @param string $value
81 *
82 * @return mixed
83 */
84 function __give_validate_decimal_separator_setting_field( $value ) {
85 $thousand_separator = isset( $_POST['thousands_separator'] ) ? give_clean( $_POST['thousands_separator'] ) : '';
86 $decimal_separator = isset( $_POST['decimal_separator'] ) ? give_clean( $_POST['decimal_separator'] ) : '';
87
88 if ( $decimal_separator === $thousand_separator ) {
89 $value = '';
90 $_POST['number_decimals'] = 0;
91 Give_Admin_Settings::add_error( 'give-decimal-separator', __( 'The \'Decimal Separator\' option has automatically been set to empty because it can not be equal to the \'Thousand Separator\'', 'give' ) );
92 }
93
94 return $value;
95 }
96
97 add_filter( 'give_admin_settings_sanitize_option_decimal_separator', '__give_validate_decimal_separator_setting_field', 10 );
98
99 /**
100 * Change $delimiter text to symbol.
101 *
102 * @since 1.8.14
103 *
104 * @param string $delimiter
105 *
106 * @return string $delimiter.
107 */
108 function __give_import_delimiter_set_callback( $delimiter ) {
109 $delimite_type = array(
110 'csv' => ',',
111 'tab-separated-values' => "\t",
112 );
113
114 return ( array_key_exists( $delimiter, $delimite_type ) ? $delimite_type[ $delimiter ] : ',' );
115 }
116
117 add_filter( 'give_import_delimiter_set', '__give_import_delimiter_set_callback', 10 );
118
119 /**
120 * Give unset the page id from the core setting data from the json files.
121 *
122 * @since 1.8.17
123 *
124 * @param array $json_to_array Data from json file
125 * @param string $type
126 *
127 * @return array $json_to_array
128 */
129 function give_import_core_settings_merge_pages( $json_to_array, $type ) {
130 if ( 'merge' === $type ) {
131 unset( $json_to_array['success_page'] );
132 unset( $json_to_array['failure_page'] );
133 unset( $json_to_array['history_page'] );
134 }
135
136 return $json_to_array;
137 }
138
139 add_filter( 'give_import_core_settings_data', 'give_import_core_settings_merge_pages', 11, 2 );
140
141 /**
142 * Give check the image size from the core setting data from the json files.
143 *
144 * @since 1.8.17
145 *
146 * @param $json_to_array
147 * @param string $type
148 *
149 * @return array $json_to_array
150 */
151 function give_import_core_settings_merge_image_size( $json_to_array, $type ) {
152 if ( 'merge' === $type ) {
153 // Featured image sizes import under Display Options > Post Types > Featured Image Size.
154 if (
155 ! empty( $json_to_array['form_featured_img'] )
156 && ! empty( $json_to_array['featured_image_size'] )
157 && give_is_setting_enabled( $json_to_array['form_featured_img'] )
158 ) {
159 $images_sizes = get_intermediate_image_sizes();
160
161 if ( ! in_array( $json_to_array['featured_image_size'], $images_sizes, true ) ) {
162 unset( $json_to_array['featured_image_size'] );
163 }
164 }
165 }
166
167 return $json_to_array;
168 }
169
170 add_filter( 'give_import_core_settings_data', 'give_import_core_settings_merge_image_size', 12, 2 );
171
172 /**
173 * Give upload the image logo from the core setting data from the json files.
174 *
175 * @since 1.8.17
176 *
177 * @param $json_to_array
178 * @param string $type
179 *
180 * @return array $json_to_array
181 */
182 function give_import_core_settings_merge_upload_image( $json_to_array, $type ) {
183 if ( 'merge' === $type ) {
184 // Emails > Email Settings > Logo.
185 if ( ! empty( $json_to_array['email_logo'] ) ) {
186
187 // Need to require these files.
188 if ( ! function_exists( 'media_handle_upload' ) ) {
189 require_once ABSPATH . 'wp-admin/includes/image.php';
190 require_once ABSPATH . 'wp-admin/includes/file.php';
191 require_once ABSPATH . 'wp-admin/includes/media.php';
192 }
193
194 $url = $json_to_array['email_logo'];
195 $new_url = media_sideload_image( $url, 0, null, 'src' );
196 if ( ! is_wp_error( $new_url ) ) {
197 $json_to_array['email_logo'] = $new_url;
198 } else {
199 unset( $json_to_array['email_logo'] );
200 }
201 }
202 }
203
204 return $json_to_array;
205 }
206
207 add_filter( 'give_import_core_settings_data', 'give_import_core_settings_merge_upload_image', 13, 2 );
208
209 /**
210 * Give unset the license key from the core setting data from the json files.
211 *
212 * @since 1.8.17
213 *
214 * @param array $json_to_array Data from json file
215 * @param string $type
216 *
217 * @return array $json_to_array
218 */
219 function give_import_core_settings_merge_license_key( $json_to_array, $type ) {
220 if ( 'merge' === $type ) {
221 foreach ( $json_to_array as $key => $value ) {
222 $is_license_key = strpos( '_license_key', $key );
223 if ( ! empty( $is_license_key ) ) {
224 unset( $json_to_array[ $key ] );
225 }
226 }
227 }
228
229 return $json_to_array;
230 }
231
232 add_filter( 'give_import_core_settings_data', 'give_import_core_settings_merge_license_key', 14, 2 );
233
234 /**
235 * Give merge the json data and setting data.
236 *
237 * @since 1.8.17
238 *
239 * @param $json_to_array
240 * @param $type
241 * @param $host_give_options
242 *
243 * @return array $json_to_array
244 */
245 function give_import_core_settings_merge_data( $json_to_array, $type, $host_give_options ) {
246 if ( 'merge' === $type ) {
247 $json_to_array_merge = array_merge( $host_give_options, $json_to_array );
248 $json_to_array = $json_to_array_merge;
249 }
250
251 return $json_to_array;
252 }
253
254 add_filter( 'give_import_core_settings_data', 'give_import_core_settings_merge_data', 1000, 3 );
255
256 /**
257 * Backward Compatibility - Cleanup User Roles.
258 *
259 * @param array $caps List of capabilities.
260 *
261 * @since 1.8.17
262 *
263 * @return mixed
264 */
265 function give_bc_1817_cleanup_user_roles( $caps ) {
266
267 if (
268 ! give_has_upgrade_completed( 'v1817_cleanup_user_roles' ) &&
269 ! isset( $caps['view_give_payments'] )
270 ) {
271 give_v1817_process_cleanup_user_roles();
272 }
273
274 return $caps;
275 }
276
277 add_filter( 'user_has_cap', 'give_bc_1817_cleanup_user_roles' );
278