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.

I'm creating a plugin version of the Roots Theme function additions - to make it a bit more portable, but have run into a snag.

Part of what Roots does is add htaccess rules based on the current theme information -- like so:

// only use clean urls if the theme isn't a child or an MU (Network) install
if (!is_multisite() && !is_child_theme() && get_option('permalink_structure')) {
  add_action('generate_rewrite_rules', 'roots_add_rewrites');
  add_action('generate_rewrite_rules', 'roots_add_h5bp_htaccess');
  if (!is_admin()) {
    $tags = array(
      'plugins_url',
      'bloginfo',
      'stylesheet_directory_uri',
      'template_directory_uri',
      'script_loader_src',
      'style_loader_src'
    );

    add_filters($tags, 'roots_clean_urls');
  }
}

So, it's basically checking to make sure that the current setup is not a multisite environment, not a child theme and that the permalink structure has been updated from the defaults. It seems like the is_child_theme() is not being called correctly, mainly because I get the following error on the frontend:

Notice: Use of undefined constant TEMPLATEPATH - assumed 'TEMPLATEPATH' in /Users/studio/Sites/base_wp/wp-includes/theme.php on line 17

Notice: Use of undefined constant STYLESHEETPATH - assumed 'STYLESHEETPATH' in /Users/studio/Sites/base_wp/wp-includes/theme.php on line 17

So, from what I can gather, it's the wp-includes/theme.php file that is not included in plugin files (which makes senses).

I've been banging my head against the wall with this one, but am trying to figure out the cleanest way possible to add in those constants to the plugin itself -> should I just include that theme.php file? Thanks.

UPDATE: Looks like I can use functions that are in wp-includes/theme.php (like get_themes()) so I know that's not the issue. hm...

share|improve this question

1 Answer 1

up vote 2 down vote accepted

TEMPLATEPATH and STYLESHEETPATH will be deprecated in the near future. It is not safe to rely on these constants. Use get_template_directory() and get_stylesheet_directory() instead.
And wait until the init hook (or after_setup_theme before you use them to be sure all needed files are loaded.

Example for a plugin:

add_action( 'after_setup_theme', 'wpse_50359_set_plugin_basics' );

function wpse_50359_set_plugin_basics()
{
    if ( is_child_theme() )
    {
        // do something awesome …
    }
}
share|improve this answer
    
Hi @toscho - thanks for the response -- I think what I'm struggling to understand here is that I'm not actually using those constants anywhere -- it looks like is_child_theme references them --> is there a better/different way to check if the active theme is a child theme via a plugin? Thanks. –  Zach Apr 26 '12 at 19:05
    
The function is okay, you just can not call it too early. I'll edit my answer. –  toscho Apr 26 '12 at 19:17
    
Thanks! That leads me to another question about plugin functions in general - but I'll open up another question for that if I can't find it after some research. Thanks! –  Zach Apr 26 '12 at 19:32

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.