Skip to content
Snippets Groups Projects
Select Git revision
  • 679dcfd9f7ca197004d2f9da0f0183126442f55d
  • master default protected
  • devel
  • feature/add-escaping-to-templates
  • feature/add-priority-sorting
  • 3.3.0
  • 3.2.1
  • 3.2.0
  • 3.1.0
  • 3.0.0
  • 2.4.12
  • 2.4.11
  • 2.4.10
  • 2.4.9
  • 2.4.8
  • 2.4.7
  • 2.4.6
  • 2.4.5
  • 2.4.4
  • 2.4.2
  • 2.4.1
  • 2.4.0
  • 2.3.2
  • 2.3.1
  • 2.3
25 results

input-image.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() {