Skip to content
Snippets Groups Projects
Commit 27f8c40c authored by Grzegorz Rola's avatar Grzegorz Rola
Browse files

Added Template trait.

parent 57f32a5f
No related branches found
No related tags found
1 merge request!12Feature/plugin activation
Pipeline #7286 failed
......@@ -27,7 +27,7 @@ class LegacyBuildDirector {
}
/**
* Returns built plugin
* Returns built pluginPluginAccess.php
*
* @return AbstractPlugin
*/
......
<?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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment