diff --git a/src/BuildDirector/LegacyBuildDirector.php b/src/BuildDirector/LegacyBuildDirector.php index 90e01620403535ff1d204cb9222cbc4be5e97177..ba28304546322942fcbe143581d1f80a8da7d710 100644 --- a/src/BuildDirector/LegacyBuildDirector.php +++ b/src/BuildDirector/LegacyBuildDirector.php @@ -27,7 +27,7 @@ class LegacyBuildDirector { } /** - * Returns built plugin + * Returns built pluginPluginAccess.php * * @return AbstractPlugin */ diff --git a/src/Plugin/Template.php b/src/Plugin/Template.php new file mode 100644 index 0000000000000000000000000000000000000000..9e1ca9bb1a0b54cbe3ca694e35abfc40256be2d3 --- /dev/null +++ b/src/Plugin/Template.php @@ -0,0 +1,61 @@ +<?php + +namespace WPDesk\PluginBuilder\Plugin; + +trait Template { + + /** + * Plugin path. + * + * @var string + */ + public $plugin_path; + + /** + * Template path. + * + * @var string + */ + public $template_path; + + /** + * Init base variables for plugin + */ + public function init_template_base_variables() { + $this->plugin_path = $this->plugin_info->get_plugin_dir(); + $this->template_path = $this->plugin_info->get_text_domain(); + } + + /** + * Renders end returns selected template + * + * @param string $name Name of the template. + * @param string $path Additional inner path to the template. + * @param array $args args Accessible from template. + * + * @return string + */ + public function load_template( $name, $path = '', $args = array() ) { + $plugin_template_path = trailingslashit( $this->plugin_path ) . 'templates/'; + + // Look within passed path within the theme - this is priority. + $template = locate_template( + array( + trailingslashit( $this->get_template_path() ) . trailingslashit( $path ) . $name . '.php', + ) + ); + + if ( ! $template ) { + $template = $plugin_template_path . trailingslashit( $path ) . $name . '.php'; + } + + extract( $args ); + ob_start(); + include( $template ); + + return ob_get_clean(); + } + + + +} \ No newline at end of file