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