template_include filter does not render the custom template

Question

I created a plugin that will render a shortcode that is entered to a page.

This Shortcode shall override the theme’s page template and use the one that I included on the plugin

Here’s my code:

api.php

   class Api{

    public static $logger = null;

    function Api() {
        add_shortcode('my_shortcode', array(&$this, 'my_shortcode_function'));
    }

    function my_shortcode_function($atts,$content = null)   
    {
        add_filter( 'template_include', 'custom_view');         
    }

    function custom_view()
    {
        $template = plugin_dir_path( __FILE__ ) . 'custom-page.php';

        return $template;

    }
}

    add_action('init', 'apiInit', 10);
    function apiInit() {

    global $api; 

  if (class_exists('Api')){
    $api = new Api();
  }
    }

and here’s my custom-page.php (which I am 100% sure that is in the correct path / directory that I am pointing in the code)

   <?php
   /**
    * Response View Template
    * File: custom-page.php
    *
    */
   echo 'I am here!';
  <?

Tried to debug each function it goes through my_shortcode_function() but does not go through custom view function.

Cheers!

0
, user37449 10 years 2013-09-01T19:44:03-05:00 0 Answers 89 views 0

Leave an answer

Browse
Browse