PluginProbe
CBX Map for Google Map & OpenStreetMap / 1.1.6
CBX Map for Google Map & OpenStreetMap v1.1.6
trunk 1.1.10 1.1.11 1.1.12 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5
cbxgooglemap / includes / cbxgooglemap-functions.php

cbxgooglemap-functions.php in CBX Map for Google Map & OpenStreetMap 1.1.6, at includes/cbxgooglemap-functions.php

109 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 // If this file is called directly, abort.
3 if (!defined('WPINC')) {
4 die;
5 }
6
7
8 /**
9 * Get the template path.
10 *
11 * @return string
12 */
13 function cbxgooglemap_template_path() {
14 return apply_filters( 'cbxgooglemap_template_path', 'cbxgooglemap/' );
15 }//end cbxgooglemap_template_path
16
17 /**
18 * Locate a template and return the path for inclusion.
19 *
20 * This is the load order:
21 *
22 * yourtheme/$template_path/$template_name
23 * yourtheme/$template_name
24 * $default_path/$template_name
25 *
26 * @param string $template_name Template name.
27 * @param string $template_path Template path. (default: '').
28 * @param string $default_path Default path. (default: '').
29 *
30 * @return string
31 */
32 function cbxgooglemap_locate_template( $template_name, $template_path = '', $default_path = '' ) {
33 if ( ! $template_path ) {
34 $template_path = cbxgooglemap_template_path();
35 }
36
37 if ( ! $default_path ) {
38 $default_path = CBXGOOGLEMAP_ROOT_PATH . 'templates/';
39 }
40
41 // Look within passed path within the theme - this is priority.
42 $template = locate_template(
43 array(
44 trailingslashit( $template_path ) . $template_name,
45 $template_name,
46 )
47 );
48
49 // Get default template/.
50 if ( ! $template ) {
51 $template = $default_path . $template_name;
52 }
53
54 // Return what we found.
55 return apply_filters( 'cbxgooglemap_locate_template', $template, $template_name, $template_path );
56 }//end function cbxgooglemap_locate_template
57
58
59 /**
60 * Get other templates (e.g. product attributes) passing attributes and including the file.
61 *
62 * @param string $template_name Template name.
63 * @param array $args Arguments. (default: array).
64 * @param string $template_path Template path. (default: '').
65 * @param string $default_path Default path. (default: '').
66 */
67 function cbxgooglemap_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
68 if ( ! empty( $args ) && is_array( $args ) ) {
69 extract( $args ); // @codingStandardsIgnoreLine
70 }
71
72 $located = cbxgooglemap_locate_template( $template_name, $template_path, $default_path );
73
74 if ( ! file_exists( $located ) ) {
75 /* translators: %s template */
76 wc_doing_it_wrong( __FUNCTION__, sprintf( __( '%s does not exist.', 'cbxgooglemap' ), '<code>' . $located . '</code>' ), '1.0.0' );
77
78 return;
79 }
80
81 // Allow 3rd party plugin filter template file from their plugin.
82 $located = apply_filters( 'cbxgooglemap_get_template', $located, $template_name, $args, $template_path, $default_path );
83
84 do_action( 'cbxgooglemap_before_template_part', $template_name, $template_path, $located, $args );
85
86 include $located;
87
88 do_action( 'cbxgooglemap_after_template_part', $template_name, $template_path, $located, $args );
89 }//end function cbxgooglemap_get_template
90
91 /**
92 * Like wc_get_template, but returns the HTML instead of outputting.
93 *
94 * @see wc_get_template
95 * @since 2.5.0
96 *
97 * @param string $template_name Template name.
98 * @param array $args Arguments. (default: array).
99 * @param string $template_path Template path. (default: '').
100 * @param string $default_path Default path. (default: '').
101 *
102 * @return string
103 */
104 function cbxgooglemap_get_template_html( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
105 ob_start();
106 cbxgooglemap_get_template( $template_name, $args, $template_path, $default_path );
107
108 return ob_get_clean();
109 }//end function cbxgooglemap_get_template_html