PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.6.3
GiveWP – Donation Plugin and Fundraising Platform v2.6.3
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 6 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 6 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 6 years ago class-blank-slate.php 6 years ago class-give-admin.php 6 years ago class-give-html-elements.php 6 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 6 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
280 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,
22 array(
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 = array();
57 $get_sizes = get_intermediate_image_sizes();
58 $core_image_sizes = array( 'thumbnail', 'medium', 'medium_large', 'large' );
59
60 // This will help us to filter special characters from a string
61 $filter_slug_items = array( '_', '-' );
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 = array() ) {
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, array( 'sslverify' => false ) );
227 } else {
228 $feed = wp_remote_get( $feed_url, array( '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 /**
255 * Get list of premium add-ons
256 *
257 * @return array
258 * @since 2.5.0
259 */
260 function give_get_premium_add_ons() {
261 $list = wp_extract_urls( give_add_ons_feed( 'addons-directory', false ) );
262 $list = array_values(
263 array_filter(
264 $list,
265 function ( $url ) {
266 return false !== strpos( $url, 'givewp.com/addons' );
267 }
268 )
269 );
270
271 return array_map(
272 function ( $url ) {
273 $path = wp_parse_url( untrailingslashit( $url ) )['path'];
274
275 return str_replace( '/addons/', '', $path );
276 },
277 $list
278 );
279 }
280