Skip to content
Snippets Groups Projects
Select Git revision
  • 7823c89d1713af06e37d6e4bfb89c9600986230d
  • master default protected
  • fix/deprecated_functions
  • devel
  • feat/translations
  • feat/upgrade_to_pro_url
  • feat/lang
  • bugfix/require-interface
  • bugfix/require-once-error
  • feature/activation-hooks
  • feature/template-loader
  • feature/template-renderer
  • feature/plugin-activation
  • feature/hookable-object
  • feature/builder-pattern
  • 2.1.2
  • 2.1.1
  • 2.1.0
  • 2.0.0
  • 2.0.0-beta1
  • 1.4.4
  • 1.4.3
  • 1.4.2
  • 1.4.1
  • 1.4
  • 1.3.3
  • 1.3.2
  • 1.3.1
  • 1.3.0
  • 1.2.0
  • 1.1
  • 1.0
32 results

TemplateLoad.php

Blame
  • TemplateLoad.php 1.45 KiB
    <?php
    
    namespace WPDesk\PluginBuilder\Plugin;
    
    /**
     * @deprecated Use wpdesk/wp-view
     *
     * @package WPDesk\PluginBuilder\Plugin
     */
    trait TemplateLoad {
    
    	/**
    	 * Plugin path.
    	 *
    	 * @var string
    	 */
    	protected $plugin_path;
    
    	/**
    	 * Template path.
    	 *
    	 * @var string
    	 */
    	protected $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();
    	}
    
    	/**
    	 * Get template path.
    	 *
    	 * @return string
    	 */
    	public function get_template_path() {
    		return trailingslashit( $this->template_path );