Skip to content
Snippets Groups Projects
Select Git revision
  • 58a8ee24ae805b49a39b8763872ece812392012a
  • 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

AbstractBuilder.php

Blame
  • TemplateLoad.php 2.06 KiB
    <?php
    
    namespace WPDesk\PluginBuilder\Plugin;
    
    trait TemplateLoad {
    
    	/**
    	 * Plugin path.
    	 *
    	 * @var string
    	 */
    	protected $plugin_path;
    
    	/**
    	 * Template path.
    	 *
    	 * @var string
    	 */
    	protected $template_path;
    
    	/**
    	 * Init base variables for plugin
    	 *
    	 * @param \WPDesk_Plugin_Info $plugin_info Plugin info.
    	 */
    	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();
    	}
    
    	/**
    	 * 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() {