PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.0.2
GiveWP – Donation Plugin and Fundraising Platform v2.0.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 / template-functions.php
give / includes Last commit date
admin 8 years ago api 8 years ago deprecated 8 years ago donors 8 years ago emails 8 years ago forms 8 years ago gateways 8 years ago libraries 8 years ago payments 8 years ago actions.php 8 years ago ajax-functions.php 8 years ago class-give-async-process.php 8 years ago class-give-background-updater.php 8 years ago class-give-cache.php 8 years ago class-give-cli-commands.php 8 years ago class-give-cron.php 8 years ago class-give-db-donor-meta.php 8 years ago class-give-db-donors.php 8 years ago class-give-db-form-meta.php 8 years ago class-give-db-logs-meta.php 8 years ago class-give-db-logs.php 8 years ago class-give-db-meta.php 8 years ago class-give-db-payment-meta.php 8 years ago class-give-db.php 8 years ago class-give-donate-form.php 8 years ago class-give-donor.php 8 years ago class-give-email-access.php 8 years ago class-give-gravatars.php 8 years ago class-give-html-elements.php 8 years ago class-give-license-handler.php 8 years ago class-give-logging.php 8 years ago class-give-roles.php 8 years ago class-give-session.php 8 years ago class-give-stats.php 8 years ago class-give-template-loader.php 9 years ago class-give-tooltips.php 8 years ago class-give-translation.php 8 years ago class-notices.php 8 years ago country-functions.php 8 years ago currency-functions.php 8 years ago error-tracking.php 8 years ago filters.php 8 years ago formatting.php 8 years ago import-functions.php 8 years ago install.php 8 years ago login-register.php 8 years ago misc-functions.php 8 years ago plugin-compatibility.php 8 years ago post-types.php 8 years ago price-functions.php 8 years ago process-donation.php 8 years ago scripts.php 8 years ago shortcodes.php 8 years ago template-functions.php 8 years ago user-functions.php 8 years ago
template-functions.php
496 lines
1 <?php
2 /**
3 * Template Functions
4 *
5 * @package Give
6 * @subpackage Functions/Templates
7 * @copyright Copyright (c) 2016, WordImpress
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 * Returns the path to the Give templates directory
19 *
20 * @since 1.0
21 * @return string
22 */
23 function give_get_templates_dir() {
24 return GIVE_PLUGIN_DIR . 'templates';
25 }
26
27 /**
28 * Returns the URL to the Give templates directory
29 *
30 * @since 1.0
31 * @return string
32 */
33 function give_get_templates_url() {
34 return GIVE_PLUGIN_URL . 'templates';
35 }
36
37 /**
38 * Get other templates, passing attributes and including the file.
39 *
40 * @since 1.6
41 *
42 * @param string $template_name Template file name.
43 * @param array $args Passed arguments. Default is empty array().
44 * @param string $template_path Template file path. Default is empty.
45 * @param string $default_path Default path. Default is empty.
46 */
47 function give_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
48 if ( ! empty( $args ) && is_array( $args ) ) {
49 extract( $args );
50 }
51
52 $template_names = array( $template_name . '.php' );
53
54 $located = give_locate_template( $template_names, $template_path, $default_path );
55
56 if ( ! file_exists( $located ) ) {
57 /* translators: %s: the template */
58 Give()->notices->print_frontend_notice( sprintf( __( 'The %s template was not found.', 'give' ), $located ), true );
59
60 return;
61 }
62
63 // Allow 3rd party plugin filter template file from their plugin.
64 $located = apply_filters( 'give_get_template', $located, $template_name, $args, $template_path, $default_path );
65
66 /**
67 * Fires in give template, before the file is included.
68 *
69 * Allows you to execute code before the file is included.
70 *
71 * @since 1.6
72 *
73 * @param string $template_name Template file name.
74 * @param string $template_path Template file path.
75 * @param string $located Template file filter by 3rd party plugin.
76 * @param array $args Passed arguments.
77 */
78 do_action( 'give_before_template_part', $template_name, $template_path, $located, $args );
79
80 include( $located );
81
82 /**
83 * Fires in give template, after the file is included.
84 *
85 * Allows you to execute code after the file is included.
86 *
87 * @since 1.6
88 *
89 * @param string $template_name Template file name.
90 * @param string $template_path Template file path.
91 * @param string $located Template file filter by 3rd party plugin.
92 * @param array $args Passed arguments.
93 */
94 do_action( 'give_after_template_part', $template_name, $template_path, $located, $args );
95 }
96
97 /**
98 * Retrieves a template part
99 *
100 * Taken from bbPress.
101 *
102 * @since 1.0
103 *
104 * @param string $slug Template part file slug {slug}.php.
105 * @param string $name Optional. Template part file name {slug}-{name}.php. Default is null.
106 * @param bool $load If true the template file will be loaded, if it is found.
107 *
108 * @return string
109 */
110 function give_get_template_part( $slug, $name = null, $load = true ) {
111
112 /**
113 * Fires in give template part, before the template part is retrieved.
114 *
115 * Allows you to execute code before retrieving the template part.
116 *
117 * @since 1.0
118 *
119 * @param string $slug Template part file slug {slug}.php.
120 * @param string $name Template part file name {slug}-{name}.php.
121 */
122 do_action( "get_template_part_{$slug}", $slug, $name );
123
124 // Setup possible parts
125 $templates = array();
126 if ( isset( $name ) ) {
127 $templates[] = $slug . '-' . $name . '.php';
128 }
129 $templates[] = $slug . '.php';
130
131 // Allow template parts to be filtered
132 $templates = apply_filters( 'give_get_template_part', $templates, $slug, $name );
133
134 // Return the part that is found
135 return give_locate_template( $templates, $load, false );
136 }
137
138 /**
139 * Retrieve the name of the highest priority template file that exists.
140 *
141 * Searches in the STYLESHEETPATH before TEMPLATEPATH so that themes which
142 * inherit from a parent theme can just overload one file. If the template is
143 * not found in either of those, it looks in the theme-compat folder last.
144 *
145 * Forked from bbPress
146 *
147 * @since 1.0
148 *
149 * @param string|array $template_names Template file(s) to search for, in order.
150 * @param bool $load If true the template file will be loaded if it is found.
151 * @param bool $require_once Whether to require_once or require. Default true.
152 * Has no effect if $load is false.
153 *
154 * @return string The template filename if one is located.
155 */
156 function give_locate_template( $template_names, $load = false, $require_once = true ) {
157 // No file found yet
158 $located = false;
159
160 // Try to find a template file
161 foreach ( (array) $template_names as $template_name ) {
162
163 // Continue if template is empty
164 if ( empty( $template_name ) ) {
165 continue;
166 }
167
168 // Trim off any slashes from the template name
169 $template_name = ltrim( $template_name, '/' );
170
171 // try locating this template file by looping through the template paths
172 foreach ( give_get_theme_template_paths() as $template_path ) {
173
174 if ( file_exists( $template_path . $template_name ) ) {
175 $located = $template_path . $template_name;
176 break;
177 }
178 }
179
180 if ( $located ) {
181 break;
182 }
183 }
184
185 if ( ( true == $load ) && ! empty( $located ) ) {
186 load_template( $located, $require_once );
187 }
188
189 return $located;
190 }
191
192 /**
193 * Returns a list of paths to check for template locations
194 *
195 * @since 1.0
196 * @return array
197 */
198 function give_get_theme_template_paths() {
199
200 $template_dir = give_get_theme_template_dir_name();
201
202 $file_paths = array(
203 1 => trailingslashit( get_stylesheet_directory() ) . $template_dir,
204 10 => trailingslashit( get_template_directory() ) . $template_dir,
205 100 => give_get_templates_dir(),
206 );
207
208 $file_paths = apply_filters( 'give_template_paths', $file_paths );
209
210 // sort the file paths based on priority
211 ksort( $file_paths, SORT_NUMERIC );
212
213 return array_map( 'trailingslashit', $file_paths );
214 }
215
216 /**
217 * Returns the template directory name.
218 *
219 * Themes can filter this by using the give_templates_dir filter.
220 *
221 * @since 1.0
222 * @return string
223 */
224 function give_get_theme_template_dir_name() {
225 return trailingslashit( apply_filters( 'give_templates_dir', 'give' ) );
226 }
227
228 /**
229 * Adds Give Version to the <head> tag
230 *
231 * @since 1.0
232 * @return void
233 */
234 function give_version_in_header() {
235 echo '<meta name="generator" content="Give v' . GIVE_VERSION . '" />' . "\n";
236 }
237
238 add_action( 'wp_head', 'give_version_in_header' );
239
240 /**
241 * Determines if we're currently on the Donations History page.
242 *
243 * @since 1.0
244 * @return bool True if on the Donations History page, false otherwise.
245 */
246 function give_is_donation_history_page() {
247
248 $ret = is_page( give_get_option( 'history_page' ) );
249
250 return apply_filters( 'give_is_donation_history_page', $ret );
251 }
252
253 /**
254 * Adds body classes for Give pages
255 *
256 * @since 1.0
257 *
258 * @param array $class current classes
259 *
260 * @return array Modified array of classes
261 */
262 function give_add_body_classes( $class ) {
263 $classes = (array) $class;
264
265 if ( give_is_success_page() ) {
266 $classes[] = 'give-success';
267 $classes[] = 'give-page';
268 }
269
270 if ( give_is_failed_transaction_page() ) {
271 $classes[] = 'give-failed-transaction';
272 $classes[] = 'give-page';
273 }
274
275 if ( give_is_donation_history_page() ) {
276 $classes[] = 'give-donation-history';
277 $classes[] = 'give-page';
278 }
279
280 if ( give_is_test_mode() ) {
281 $classes[] = 'give-test-mode';
282 $classes[] = 'give-page';
283 }
284
285 // Theme-specific Classes used to prevent conflicts via CSS
286 /* @var WP_Theme $current_theme */
287 $current_theme = wp_get_theme();
288
289 switch ( $current_theme->get_template() ) {
290
291 case 'Divi':
292 $classes[] = 'give-divi';
293 break;
294 case 'Avada':
295 $classes[] = 'give-avada';
296 break;
297 case 'twentysixteen':
298 $classes[] = 'give-twentysixteen';
299 break;
300 case 'twentyseventeen':
301 $classes[] = 'give-twentyseventeen';
302 break;
303
304 }
305
306 return array_unique( $classes );
307 }
308
309 add_filter( 'body_class', 'give_add_body_classes' );
310
311
312 /**
313 * Add Post Class Filter
314 *
315 * Adds extra post classes for forms
316 *
317 * @since 1.0
318 *
319 * @param array $classes
320 * @param string|array $class
321 * @param int|string $post_id
322 *
323 * @return array
324 */
325 function give_add_post_class( $classes, $class = '', $post_id = '' ) {
326 if ( ! $post_id || 'give_forms' !== get_post_type( $post_id ) ) {
327 return $classes;
328 }
329
330 //@TODO: Add classes for custom taxonomy and form configurations (multi vs single donations, etc).
331
332 if ( false !== ( $key = array_search( 'hentry', $classes ) ) ) {
333 unset( $classes[ $key ] );
334 }
335
336 return $classes;
337 }
338
339
340 add_filter( 'post_class', 'give_add_post_class', 20, 3 );
341
342 /**
343 * Get the placeholder image URL for forms etc
344 *
345 * @access public
346 * @return string
347 */
348 function give_get_placeholder_img_src() {
349
350 $placeholder_url = '//placehold.it/600x600&text=' . urlencode( esc_attr__( 'Give Placeholder Image', 'give' ) );
351
352 return apply_filters( 'give_placeholder_img_src', $placeholder_url );
353 }
354
355
356 /**
357 * Global
358 */
359 if ( ! function_exists( 'give_output_content_wrapper' ) ) {
360
361 /**
362 * Output the start of the page wrapper.
363 */
364 function give_output_content_wrapper() {
365 give_get_template_part( 'global/wrapper-start' );
366 }
367 }
368 if ( ! function_exists( 'give_output_content_wrapper_end' ) ) {
369
370 /**
371 * Output the end of the page wrapper.
372 */
373 function give_output_content_wrapper_end() {
374 give_get_template_part( 'global/wrapper-end' );
375 }
376 }
377
378 /**
379 * Single Give Form
380 */
381 if ( ! function_exists( 'give_left_sidebar_pre_wrap' ) ) {
382 function give_left_sidebar_pre_wrap() {
383 echo apply_filters( 'give_left_sidebar_pre_wrap', '<div id="give-sidebar-left" class="give-sidebar give-single-form-sidebar-left">' );
384 }
385 }
386
387 if ( ! function_exists( 'give_left_sidebar_post_wrap' ) ) {
388 function give_left_sidebar_post_wrap() {
389 echo apply_filters( 'give_left_sidebar_post_wrap', '</div>' );
390 }
391 }
392
393 if ( ! function_exists( 'give_get_forms_sidebar' ) ) {
394 function give_get_forms_sidebar() {
395 give_get_template_part( 'single-give-form/sidebar' );
396 }
397 }
398
399 if ( ! function_exists( 'give_show_form_images' ) ) {
400
401 /**
402 * Output the donation form featured image.
403 */
404 function give_show_form_images() {
405 if ( give_is_setting_enabled( give_get_option( 'form_featured_img' ) ) ) {
406 give_get_template_part( 'single-give-form/featured-image' );
407 }
408 }
409 }
410
411 if ( ! function_exists( 'give_template_single_title' ) ) {
412
413 /**
414 * Output the form title.
415 */
416 function give_template_single_title() {
417 give_get_template_part( 'single-give-form/title' );
418 }
419 }
420
421 /**
422 * Conditional Functions
423 */
424
425 if ( ! function_exists( 'is_give_form' ) ) {
426
427 /**
428 * is_give_form
429 *
430 * Returns true when viewing a single form.
431 *
432 * @since 1.6
433 *
434 * @return bool
435 */
436 function is_give_form() {
437 return is_singular( array( 'give_form' ) );
438 }
439 }
440
441 if ( ! function_exists( 'is_give_category' ) ) {
442
443 /**
444 * is_give_category
445 *
446 * Returns true when viewing give form category archive.
447 *
448 * @since 1.6
449 *
450 * @param string $term The term slug your checking for.
451 * Leave blank to return true on any.
452 * Default is blank.
453 *
454 * @return bool
455 */
456 function is_give_category( $term = '' ) {
457 return is_tax( 'give_forms_category', $term );
458 }
459 }
460
461 if ( ! function_exists( 'is_give_tag' ) ) {
462
463 /**
464 * is_give_tag
465 *
466 * Returns true when viewing give form tag archive.
467 *
468 * @since 1.6
469 *
470 * @param string $term The term slug your checking for.
471 * Leave blank to return true on any.
472 * Default is blank.
473 *
474 * @return bool
475 */
476 function is_give_tag( $term = '' ) {
477 return is_tax( 'give_forms_tag', $term );
478 }
479 }
480
481 if ( ! function_exists( 'is_give_taxonomy' ) ) {
482
483 /**
484 * is_give_taxonomy
485 *
486 * Returns true when viewing a give form taxonomy archive.
487 *
488 * @since 1.6
489 *
490 * @return bool
491 */
492 function is_give_taxonomy() {
493 return is_tax( get_object_taxonomies( 'give_form' ) );
494 }
495 }
496