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 / misc-functions.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
misc-functions.php
354 lines
1 <?php
2
3 /**
4 * Gets a number of posts and displays them as options
5 *
6 * @param array $query_args Optional. Overrides defaults.
7 * @param bool $force Force the pages to be loaded even if not on settings
8 *
9 * @see: https://github.com/WebDevStudios/CMB2/wiki/Adding-your-own-field-types
10 * @return array An array of options that matches the CMB2 options array
11 */
12 function give_cmb2_get_post_options( $query_args, $force = false ) {
13
14 $post_options = [ '' => '' ]; // Blank option
15
16 if ( ( ! isset( $_GET['page'] ) || 'give-settings' != $_GET['page'] ) && ! $force ) {
17 return $post_options;
18 }
19
20 $args = wp_parse_args(
21 $query_args,
22 [
23 'post_type' => 'page',
24 'numberposts' => 10,
25 ]
26 );
27
28 $posts = get_posts( $args );
29
30 if ( $posts ) {
31 foreach ( $posts as $post ) {
32
33 $post_options[ $post->ID ] = $post->post_title;
34
35 }
36 }
37
38 return $post_options;
39 }
40
41
42 /**
43 * Featured Image Sizes
44 *
45 * Outputs an array for the "Featured Image Size" option found under Settings > Display Options.
46 *
47 * @since 1.4
48 *
49 * @global $_wp_additional_image_sizes
50 *
51 * @return array $sizes
52 */
53 function give_get_featured_image_sizes() {
54 global $_wp_additional_image_sizes;
55
56 $sizes = [];
57 $get_sizes = get_intermediate_image_sizes();
58 $core_image_sizes = [ 'thumbnail', 'medium', 'medium_large', 'large' ];
59
60 // This will help us to filter special characters from a string
61 $filter_slug_items = [ '_', '-' ];
62
63 foreach ( $get_sizes as $_size ) {
64
65 // Converting image size slug to title case
66 $sizes[ $_size ] = give_slug_to_title( $_size, $filter_slug_items );
67
68 if ( in_array( $_size, $core_image_sizes ) ) {
69 $sizes[ $_size ] .= ' (' . get_option( "{$_size}_size_w" ) . 'x' . get_option( "{$_size}_size_h" );
70 } elseif ( isset( $_wp_additional_image_sizes[ $_size ] ) ) {
71 $sizes[ $_size ] .= " ({$_wp_additional_image_sizes[ $_size ]['width']} x {$_wp_additional_image_sizes[ $_size ]['height']}";
72 }
73
74 // Based on the above image height check, label the respective resolution as responsive
75 if ( ( array_key_exists( $_size, $_wp_additional_image_sizes ) && ! $_wp_additional_image_sizes[ $_size ]['crop'] ) || ( in_array( $_size, $core_image_sizes ) && ! get_option( "{$_size}_crop" ) ) ) {
76 $sizes[ $_size ] .= ' - responsive';
77 }
78
79 $sizes[ $_size ] .= ')';
80
81 }
82
83 return apply_filters( 'give_get_featured_image_sizes', $sizes );
84 }
85
86
87 /**
88 * Slug to Title
89 *
90 * Converts a string with hyphen(-) or underscores(_) or any special character to a string with Title case
91 *
92 * @since 1.8.8
93 *
94 * @param string $string
95 * @param array $filters
96 *
97 * @return string $string
98 */
99 function give_slug_to_title( $string, $filters = [] ) {
100
101 foreach ( $filters as $filter_item ) {
102 $string = str_replace( $filter_item, ' ', $string );
103 }
104
105 // Return updated string after converting it to title case
106 return ucwords( $string );
107
108 }
109
110
111 /**
112 * Display the API Keys
113 *
114 * @since 1.0
115 * @return void
116 */
117 function give_api_callback() {
118
119 if ( ! current_user_can( 'manage_give_settings' ) ) {
120 return;
121 }
122
123 /**
124 * Fires before displaying API keys.
125 *
126 * @since 1.0
127 */
128 do_action( 'give_tools_api_keys_before' );
129
130 require_once GIVE_PLUGIN_DIR . 'includes/admin/class-api-keys-table.php';
131
132 $api_keys_table = new Give_API_Keys_Table();
133 $api_keys_table->prepare_items();
134 $api_keys_table->display();
135 ?>
136 <span class="give-metabox-description api-description">
137 <?php
138 echo sprintf(
139 /* translators: 1: http://docs.givewp.com/api 2: http://docs.givewp.com/addon-zapier */
140 __( 'You can create API keys for individual users within their profile edit screen. API keys allow users to use the <a href="%1$s" target="_blank">GiveWP REST API</a> to retrieve donation data in JSON or XML for external applications or devices, such as <a href="%2$s" target="_blank">Zapier</a>.', 'give' ),
141 esc_url( 'http://docs.givewp.com/api' ),
142 esc_url( 'http://docs.givewp.com/addon-zapier' )
143 );
144 ?>
145 </span>
146 <?php
147
148 /**
149 * Fires after displaying API keys.
150 *
151 * @since 1.0
152 */
153 do_action( 'give_tools_api_keys_after' );
154 }
155
156
157 /**
158 * Hide char in string
159 *
160 * @param string $str
161 * @param int $show_char_count
162 * @param string $replace
163 *
164 * @return string
165 * @since 2.5.0
166 */
167 function give_hide_char( $str, $show_char_count, $replace = '*' ) {
168 return str_repeat(
169 $replace,
170 strlen( $str ) - $show_char_count
171 ) . substr(
172 $str,
173 - $show_char_count,
174 $show_char_count
175 );
176 }
177
178
179 /**
180 * Format marKdown formatted string.
181 *
182 * @param string $readme Markdown format string
183 *
184 * @return string
185 * @since 2.5.0
186 */
187 function give_get_format_md( $readme ) {
188 $readme = preg_replace( '/`(.*?)`/', '<code>\\1</code>', $readme );
189 $readme = preg_replace( '/[\040]\*\*(.*?)\*\*/', ' <strong>\\1</strong>', $readme );
190 $readme = preg_replace( '/[\040]\*(.*?)\*/', ' <em>\\1</em>', $readme );
191 $readme = preg_replace( '/= (.*?) =/', '<h4>\\1</h4>', $readme );
192 $readme = preg_replace( '/\[(.*?)\]\((.*?)\)/', '<a href="\\2">\\1</a>', $readme );
193
194 return $readme;
195 }
196
197 /**
198 * Add-ons Render Feed
199 *
200 * Renders the add-ons page feed.
201 *
202 * @param string $feed_type
203 * @param bool $echo
204 *
205 * @return string
206 * @since 1.0
207 */
208 function give_add_ons_feed( $feed_type = '', $echo = true ) {
209
210 $addons_debug = false; // set to true to debug. NEVER LEAVE TRUE IN PRODUCTION.
211 $cache_key = $feed_type ? "give_add_ons_feed_{$feed_type}" : 'give_add_ons_feed';
212 $cache = Give_Cache::get( $cache_key, true );
213 $feed_url = Give_License::get_website_url() . 'downloads/feed/';
214
215 if ( false === $cache || ( true === $addons_debug && true === WP_DEBUG ) ) {
216 switch ( $feed_type ) {
217 case 'price-bundle':
218 $feed_url = Give_License::get_website_url() . 'downloads/feed/addons-price-bundles.php';
219 break;
220 case 'addons-directory':
221 $feed_url = Give_License::get_website_url() . 'downloads/feed/index.php';
222 break;
223 }
224
225 if ( function_exists( 'vip_safe_wp_remote_get' ) ) {
226 $feed = vip_safe_wp_remote_get( $feed_url, false, 3, 1, 20, [ 'sslverify' => false ] );
227 } else {
228 $feed = wp_remote_get( $feed_url, [ 'sslverify' => false ] );
229 }
230
231 if ( ! is_wp_error( $feed ) ) {
232 if ( ! empty( $feed['body'] ) ) {
233 $cache = wp_remote_retrieve_body( $feed );
234 Give_Cache::set( $cache_key, $cache, DAY_IN_SECONDS, true );
235 }
236 } else {
237 $cache = sprintf(
238 '<div class="error inline"><p>%s</p></div>',
239 esc_html__( 'There was an error retrieving the GiveWP add-ons list from the server. Please try again.', 'give' )
240 );
241 }
242 }
243
244 $cache = wp_kses_post( $cache );
245
246 if ( $echo ) {
247 echo $cache;
248 }
249
250 return $cache;
251 }
252
253 /**
254 * Handle installation and connection for SendWP via ajax
255 *
256 * @since 2.33.4 added nonce check
257 * @since 2.9.15
258 */
259 function give_sendwp_remote_install_handler () {
260
261 check_ajax_referer( 'give_sendwp_remote_install');
262
263 if ( ! current_user_can( 'manage_give_settings' ) ) {
264 wp_send_json_error( array(
265 'error' => __( 'You do not have permission to do this.', 'give' )
266 ) );
267 }
268
269 include_once ABSPATH . 'wp-admin/includes/plugin-install.php';
270 include_once ABSPATH . 'wp-admin/includes/file.php';
271 include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
272
273 $plugins = get_plugins();
274
275 if( ! array_key_exists( 'sendwp/sendwp.php', $plugins ) ) {
276
277 /*
278 * Use the WordPress Plugins API to get the plugin download link.
279 */
280 $api = plugins_api( 'plugin_information', array(
281 'slug' => 'sendwp',
282 ) );
283
284 if ( is_wp_error( $api ) ) {
285 wp_send_json_error( array(
286 'error' => $api->get_error_message(),
287 'debug' => $api
288 ) );
289 }
290
291 /*
292 * Use the AJAX Upgrader skin to quietly install the plugin.
293 */
294 $upgrader = new Plugin_Upgrader( new WP_Ajax_Upgrader_Skin() );
295 $install = $upgrader->install( $api->download_link );
296 if ( is_wp_error( $install ) ) {
297 wp_send_json_error( array(
298 'error' => $install->get_error_message(),
299 'debug' => $api
300 ) );
301 }
302
303 $activated = activate_plugin( $upgrader->plugin_info() );
304
305 } else {
306
307 $activated = activate_plugin( 'sendwp/sendwp.php' );
308
309 }
310
311 /*
312 * Final check to see if SendWP is available.
313 */
314 if( ! function_exists('sendwp_get_server_url') ) {
315 wp_send_json_error( array(
316 'error' => __( 'Something went wrong. SendWP was not installed correctly.', 'give' )
317 ) );
318 }
319
320 wp_send_json_success( array(
321 'partner_id' => 51154,
322 'register_url' => sendwp_get_server_url() . '_/signup',
323 'client_name' => sendwp_get_client_name(),
324 'client_url' => sendwp_get_client_url(),
325 'client_secret' => sendwp_get_client_secret(),
326 'client_redirect' => admin_url( '/edit.php?post_type=give_forms&page=give-settings&tab=emails&section=email-settings' ),
327 ) );
328 }
329 add_action( 'wp_ajax_give_sendwp_remote_install', 'give_sendwp_remote_install_handler' );
330
331 /**
332 * Handle deactivation of SendWP via ajax
333 *
334 * @since 2.33.4 add nonce check
335 * @since 2.9.15
336 */
337 function give_sendwp_disconnect () {
338
339 check_ajax_referer( 'give_sendwp_disconnect');
340
341 if ( ! current_user_can( 'manage_give_settings' ) ) {
342 wp_send_json_error( array(
343 'error' => __( 'You do not have permission to do this.', 'give' )
344 ) );
345 }
346
347 sendwp_disconnect_client();
348
349 deactivate_plugins( 'sendwp/sendwp.php' );
350
351 wp_send_json_success();
352 }
353 add_action( 'wp_ajax_give_sendwp_disconnect', 'give_sendwp_disconnect' );
354