From f9cd6fd429677e6d71171c34abc7e08a090c598e Mon Sep 17 00:00:00 2001 From: Grzegorz Rola <grola@seostudio.pl> Date: Tue, 20 Nov 2018 13:07:33 +0100 Subject: [PATCH] Template loader. --- .gitignore | 3 +- src/Plugin/BasicTemplateLoader.php | 13 +++++++ src/Plugin/TemplateLoad.php | 40 +++++++++++++++++++--- src/Plugin/TemplateLoader.php | 54 ++++++++++++++++++++++++++++++ 4 files changed, 105 insertions(+), 5 deletions(-) create mode 100644 src/Plugin/BasicTemplateLoader.php create mode 100644 src/Plugin/TemplateLoader.php diff --git a/.gitignore b/.gitignore index ccef056..76e3973 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /vendor/ -.idea \ No newline at end of file +.git +.idea diff --git a/src/Plugin/BasicTemplateLoader.php b/src/Plugin/BasicTemplateLoader.php new file mode 100644 index 0000000..4d3fd62 --- /dev/null +++ b/src/Plugin/BasicTemplateLoader.php @@ -0,0 +1,13 @@ +<?php + +namespace WPDesk\PluginBuilder\Plugin; + +/** + * Class BasicTemplateLoader + */ +class BasicTemplateLoader implements TemplateLoader +{ + + use TemplateLoad; + +} diff --git a/src/Plugin/TemplateLoad.php b/src/Plugin/TemplateLoad.php index c3a0098..4061505 100644 --- a/src/Plugin/TemplateLoad.php +++ b/src/Plugin/TemplateLoad.php @@ -20,10 +20,16 @@ trait TemplateLoad { /** * Init base variables for plugin + * + * @param \WPDesk_Plugin_Info $plugin_info Plugin info. */ - public function init_template_base_variables() { - $this->plugin_path = $this->plugin_info->get_plugin_dir(); - $this->template_path = $this->plugin_info->get_text_domain(); + public function init_template_base_variables( \WPDesk_Plugin_Info $plugin_info = null ) { + if ( null === $plugin_info ) { + // Backward compatibility! Do not remove. + $plugin_info = $this->plugin_info; + } + $this->plugin_path = $plugin_info->get_plugin_dir(); + $this->template_path = $plugin_info->get_text_domain(); } /** @@ -65,5 +71,31 @@ trait TemplateLoad { return trailingslashit( $this->template_path ); } + /** + * Set template path. + * + * @param string $template_path Template path. + */ + public function set_template_path( $template_path ) { + $this->template_path = $template_path; + } + + /** + * Get plugin path. + * + * @return string + */ + public function get_plugin_path() { + return trailingslashit( $this->plugin_path ); + } + + /** + * Set plugin path. + * + * @param string $plugin_path Template path. + */ + public function set_plugon_path( $plugin_path ) { + $this->plugin_path = $plugin_path; + } -} \ No newline at end of file +} diff --git a/src/Plugin/TemplateLoader.php b/src/Plugin/TemplateLoader.php new file mode 100644 index 0000000..4b8e472 --- /dev/null +++ b/src/Plugin/TemplateLoader.php @@ -0,0 +1,54 @@ +<?php + +namespace WPDesk\PluginBuilder\Plugin; + +interface TemplateLoader { + + /** + * Init base variables for template loader. + * + * @param \WPDesk_Plugin_Info $plugin_info Plugin info. + */ + public function init_template_base_variables( \WPDesk_Plugin_Info $plugin_info = null ); + + /** + * 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() ); + + /** + * Get template path. + * + * @return string + */ + public function get_template_path(); + + /** + * Set template path. + * + * @param string $template_path Template path. + */ + public function set_template_path( $template_path ); + + /** + * Get plugin path. + * + * @return string + */ + public function get_plugin_path(); + + /** + * Set plugin path. + * + * @param string $plugin_path Template path. + */ + public function set_plugon_path( $plugin_path ); + +} + -- GitLab