Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

First of all, I'm completely sure I'm being an idiot on this one - but an hour of scratching my head and searching this site has still left me perplexed.

I'm trying to access a constant that's defined within the constructor of my plugin in an included file. The file is included in a function that's hooked to the wp_footer action:

class className {
function className () {
    $this->__construct();
}

function __construct() {
    DEFINE('IMPACTMENU_IMAGES', WP_PLUGIN_URL . '/impactmenu/images'); 
    DEFINE('IMPACTMENU_TEMPLATES', WP_PLUGIN_URL . '/impactmenu/templates');

    add_action('wp_footer', array($this, 'impact_menu_html'));
} 

function impact_menu_html() {
    ob_start();
    include(IMPACTMENU_TEMPLATES . '/template.php');
    $im_footer = ob_get_contents();
    ob_end_clean();
    echo $im_footer;
   }
}

And in the template.php file:

echo IMPACTMENU_IMAGES;

I'm expecting the output to be the path to the images directory, but the output is actually simply "IMPACTMENU_IMAGES".

Any help on this would be greatly appreciated!

share|improve this question
add comment

1 Answer

The Problem here is that the Template Files get processed before the wp_footer action, so your constant is not defined at that stage.

Just to be sure, try hooking your constructor of the class to an action that is called earlier, I don't really know how early you need it, but try init. You could also construct your class when the Plugin is loaded, then you should be on the safe side.

share|improve this answer
    
Thanks! I must be getting a bit confused with this because I thought that the loading order must have been the problem so moved the constant definitions to another function and hooked that to init, yet the same result. –  Paul McCarthy Jan 23 '13 at 17:02
    
I'm a bit confused by this - why does the IMPACTMENU_TEMPLATES constant work whereas the constant that's included after this point doesn't work? At what point are includes processed? –  Paul McCarthy Jan 23 '13 at 20:51
    
Can you post the code of your Plugin please? –  fischi Jan 24 '13 at 5:21
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.