PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.5.9
GiveWP – Donation Plugin and Fundraising Platform v2.5.9
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 6 years ago donors 6 years ago emails 6 years ago forms 6 years ago payments 6 years ago reports 7 years ago settings 6 years ago shortcodes 6 years ago tools 6 years ago upgrades 6 years ago views 6 years ago abstract-admin-settings-page.php 6 years ago admin-actions.php 6 years ago admin-filters.php 7 years ago admin-footer.php 6 years ago admin-pages.php 6 years ago class-addon-activation-banner.php 6 years ago class-admin-settings.php 6 years ago class-api-keys-table.php 7 years ago class-blank-slate.php 6 years ago class-give-admin.php 6 years ago class-give-html-elements.php 7 years ago class-give-welcome.php 6 years ago class-i18n-module.php 6 years ago dashboard-widgets.php 6 years ago give-metabox-functions.php 6 years ago import-functions.php 7 years ago misc-functions.php 6 years ago plugins.php 6 years ago setting-page-functions.php 6 years ago welcome.php 6 years ago
misc-functions.php
269 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 = array( '' => '' ); // 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, array(
22 'post_type' => 'page',
23 'numberposts' => 10,
24 )
25 );
26
27 $posts = get_posts( $args );
28
29 if ( $posts ) {
30 foreach ( $posts as $post ) {
31
32 $post_options[ $post->ID ] = $post->post_title;
33
34 }
35 }
36
37 return $post_options;
38 }
39
40
41 /**
42 * Featured Image Sizes
43 *
44 * Outputs an array for the "Featured Image Size" option found under Settings > Display Options.
45 *
46 * @since 1.4
47 *
48 * @global $_wp_additional_image_sizes
49 *
50 * @return array $sizes
51 */
52 function give_get_featured_image_sizes() {
53 global $_wp_additional_image_sizes;
54
55 $sizes = array();
56 $get_sizes = get_intermediate_image_sizes();
57 $core_image_sizes = array( 'thumbnail', 'medium', 'medium_large', 'large' );
58
59 // This will help us to filter special characters from a string
60 $filter_slug_items = array( '_', '-' );
61
62 foreach ( $get_sizes as $_size ) {
63
64 // Converting image size slug to title case
65 $sizes[ $_size ] = give_slug_to_title( $_size, $filter_slug_items );
66
67 if ( in_array( $_size, $core_image_sizes ) ) {
68 $sizes[ $_size ] .= ' (' . get_option( "{$_size}_size_w" ) . 'x' . get_option( "{$_size}_size_h" );
69 } elseif ( isset( $_wp_additional_image_sizes[ $_size ] ) ) {
70 $sizes[ $_size ] .= " ({$_wp_additional_image_sizes[ $_size ]['width']} x {$_wp_additional_image_sizes[ $_size ]['height']}";
71 }
72
73 // Based on the above image height check, label the respective resolution as responsive
74 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" ) ) ) {
75 $sizes[ $_size ] .= ' - responsive';
76 }
77
78 $sizes[ $_size ] .= ')';
79
80 }
81
82 return apply_filters( 'give_get_featured_image_sizes', $sizes );
83 }
84
85
86 /**
87 * Slug to Title
88 *
89 * Converts a string with hyphen(-) or underscores(_) or any special character to a string with Title case
90 *
91 * @since 1.8.8
92 *
93 * @param string $string
94 * @param array $filters
95 *
96 * @return string $string
97 */
98 function give_slug_to_title( $string, $filters = array() ) {
99
100 foreach ( $filters as $filter_item ) {
101 $string = str_replace( $filter_item, ' ', $string );
102 }
103
104 // Return updated string after converting it to title case
105 return ucwords( $string );
106
107 }
108
109
110 /**
111 * Display the API Keys
112 *
113 * @since 1.0
114 * @return void
115 */
116 function give_api_callback() {
117
118 if ( ! current_user_can( 'manage_give_settings' ) ) {
119 return;
120 }
121
122 /**
123 * Fires before displaying API keys.
124 *
125 * @since 1.0
126 */
127 do_action( 'give_tools_api_keys_before' );
128
129 require_once GIVE_PLUGIN_DIR . 'includes/admin/class-api-keys-table.php';
130
131 $api_keys_table = new Give_API_Keys_Table();
132 $api_keys_table->prepare_items();
133 $api_keys_table->display();
134 ?>
135 <span class="give-metabox-description api-description">
136 <?php
137 echo sprintf(
138 /* translators: 1: http://docs.givewp.com/api 2: http://docs.givewp.com/addon-zapier */
139 __( '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' ),
140 esc_url( 'http://docs.givewp.com/api' ),
141 esc_url( 'http://docs.givewp.com/addon-zapier' )
142 );
143 ?>
144 </span>
145 <?php
146
147 /**
148 * Fires after displaying API keys.
149 *
150 * @since 1.0
151 */
152 do_action( 'give_tools_api_keys_after' );
153 }
154
155
156 /**
157 * Hide char in string
158 *
159 * @param string $str
160 * @param int $show_char_count
161 * @param string $replace
162 *
163 * @return string
164 * @since 2.5.0
165 *
166 */
167 function give_hide_char( $str, $show_char_count, $replace = '*' ) {
168 return str_repeat(
169 $replace,
170 strlen( $str ) - $show_char_count ) . substr( $str, - $show_char_count, $show_char_count
171 );
172 }
173
174
175 /**
176 * Format marKdown formatted string.
177 *
178 * @param string $readme Markdown format string
179 *
180 * @return string
181 * @since 2.5.0
182 *
183 */
184 function give_get_format_md( $readme ) {
185 $readme = preg_replace( '/`(.*?)`/', '<code>\\1</code>', $readme );
186 $readme = preg_replace( '/[\040]\*\*(.*?)\*\*/', ' <strong>\\1</strong>', $readme );
187 $readme = preg_replace( '/[\040]\*(.*?)\*/', ' <em>\\1</em>', $readme );
188 $readme = preg_replace( '/= (.*?) =/', '<h4>\\1</h4>', $readme );
189 $readme = preg_replace( '/\[(.*?)\]\((.*?)\)/', '<a href="\\2">\\1</a>', $readme );
190
191 return $readme;
192 }
193
194 /**
195 * Add-ons Render Feed
196 *
197 * Renders the add-ons page feed.
198 *
199 * @param string $feed_type
200 * @param bool $echo
201 *
202 * @return string
203 * @since 1.0
204 */
205 function give_add_ons_feed( $feed_type = '', $echo = true ) {
206
207 $addons_debug = false; // set to true to debug. NEVER LEAVE TRUE IN PRODUCTION.
208 $cache_key = $feed_type ? "give_add_ons_feed_{$feed_type}" : 'give_add_ons_feed';
209 $cache = Give_Cache::get( $cache_key, true );
210 $feed_url = Give_License::get_website_url() . 'downloads/feed/';
211
212 if ( false === $cache || ( true === $addons_debug && true === WP_DEBUG ) ) {
213 switch ( $feed_type ) {
214 case 'price-bundle':
215 $feed_url = Give_License::get_website_url() . 'downloads/feed/addons-price-bundles.php';
216 break;
217 case 'addons-directory':
218 $feed_url = Give_License::get_website_url() . 'downloads/feed/index.php';
219 break;
220 }
221
222 if ( function_exists( 'vip_safe_wp_remote_get' ) ) {
223 $feed = vip_safe_wp_remote_get( $feed_url, false, 3, 1, 20, array( 'sslverify' => false ) );
224 } else {
225 $feed = wp_remote_get( $feed_url, array( 'sslverify' => false ) );
226 }
227
228 if ( ! is_wp_error( $feed ) ) {
229 if ( ! empty( $feed['body'] ) ) {
230 $cache = wp_remote_retrieve_body( $feed );
231 Give_Cache::set( $cache_key, $cache, DAY_IN_SECONDS, true );
232 }
233 } else {
234 $cache = sprintf(
235 '<div class="error inline"><p>%s</p></div>',
236 esc_html__( 'There was an error retrieving the GiveWP add-ons list from the server. Please try again.', 'give' )
237 );
238 }
239 }
240
241 $cache = wp_kses_post( $cache );
242
243 if ( $echo ) {
244 echo $cache;
245 }
246
247 return $cache;
248 }
249
250
251 /**
252 * Get list of premium add-ons
253 *
254 * @return array
255 * @since 2.5.0
256 */
257 function give_get_premium_add_ons() {
258 $list = wp_extract_urls( give_add_ons_feed( 'addons-directory', false ) );
259 $list = array_values( array_filter( $list, function ( $url ) {
260 return false !== strpos( $url, 'givewp.com/addons' );
261 } ) );
262
263 return array_map( function ( $url ) {
264 $path = wp_parse_url( untrailingslashit( $url ) )['path'];
265
266 return str_replace( '/addons/', '', $path );
267 }, $list );
268 }
269