WithoutNamespace
2 weeks ago
AbstractPlugin.php
2 weeks ago
Activateable.php
2 weeks ago
ActivationAware.php
2 weeks ago
ActivationTracker.php
2 weeks ago
Conditional.php
2 weeks ago
Deactivateable.php
2 weeks ago
Hookable.php
2 weeks ago
HookableCollection.php
2 weeks ago
HookableParent.php
2 weeks ago
HookablePluginDependant.php
2 weeks ago
PluginAccess.php
2 weeks ago
SlimPlugin.php
2 weeks ago
TemplateLoad.php
2 weeks ago
TemplateLoad.php
64 lines
| 1 | <?php |
| 2 | |
| 3 | namespace FSVendor\WPDesk\PluginBuilder\Plugin; |
| 4 | |
| 5 | /** |
| 6 | * @deprecated Use wpdesk/wp-view |
| 7 | * |
| 8 | * @package WPDesk\PluginBuilder\Plugin |
| 9 | */ |
| 10 | trait TemplateLoad |
| 11 | { |
| 12 | /** |
| 13 | * Plugin path. |
| 14 | * |
| 15 | * @var string |
| 16 | */ |
| 17 | protected $plugin_path; |
| 18 | /** |
| 19 | * Template path. |
| 20 | * |
| 21 | * @var string |
| 22 | */ |
| 23 | protected $template_path; |
| 24 | /** |
| 25 | * Init base variables for plugin |
| 26 | */ |
| 27 | public function init_template_base_variables() |
| 28 | { |
| 29 | $this->plugin_path = $this->plugin_info->get_plugin_dir(); |
| 30 | $this->template_path = $this->plugin_info->get_text_domain(); |
| 31 | } |
| 32 | /** |
| 33 | * Renders end returns selected template |
| 34 | * |
| 35 | * @param string $name Name of the template. |
| 36 | * @param string $path Additional inner path to the template. |
| 37 | * @param array $args args Accessible from template. |
| 38 | * |
| 39 | * @return string |
| 40 | */ |
| 41 | public function load_template($name, $path = '', $args = array()) |
| 42 | { |
| 43 | $plugin_template_path = trailingslashit($this->plugin_path) . 'templates/'; |
| 44 | // Look within passed path within the theme - this is priority. |
| 45 | $template = locate_template(array(trailingslashit($this->get_template_path()) . trailingslashit($path) . $name . '.php')); |
| 46 | if (!$template) { |
| 47 | $template = $plugin_template_path . trailingslashit($path) . $name . '.php'; |
| 48 | } |
| 49 | extract($args); |
| 50 | ob_start(); |
| 51 | include $template; |
| 52 | return ob_get_clean(); |
| 53 | } |
| 54 | /** |
| 55 | * Get template path. |
| 56 | * |
| 57 | * @return string |
| 58 | */ |
| 59 | public function get_template_path() |
| 60 | { |
| 61 | return trailingslashit($this->template_path); |
| 62 | } |
| 63 | } |
| 64 |