PluginProbe
Maps Plugin using Google Maps for WordPress – WP Google Map / trunk
Maps Plugin using Google Maps for WordPress – WP Google Map vtrunk
1.9.7 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.5.0 1.5.1 1.5.2 1.5.3 All 96 releases
gmap-embed / includes / traits / TemplateRenderer.php

TemplateRenderer.php in Maps Plugin using Google Maps for WordPress – WP Google Map trunk, at includes/traits/TemplateRenderer.php

42 lines 895 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace WGMSRM\Traits;
4
5 if (!defined('ABSPATH')) {
6 exit;
7 }
8
9 trait TemplateRenderer
10 {
11 /**
12 * Render a template file with data.
13 *
14 * @param string $template_name Relative path to template inside 'templates' dir.
15 * @param array $data Associative array of data to extract.
16 * @param bool $echo Whether to echo or return the content.
17 * @return string|void
18 */
19 public function render($template_name, $data = [], $echo = false)
20 {
21 $template_path = WGM_PLUGIN_PATH . 'templates/' . $template_name . '.php';
22
23 if (!file_exists($template_path)) {
24 return '';
25 }
26
27 if (!empty($data)) {
28 extract($data);
29 }
30
31 ob_start();
32 include $template_path;
33 $output = ob_get_clean();
34
35 if ($echo) {
36 echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
37 } else {
38 return $output;
39 }
40 }
41 }
42