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 am creating a shortcode plugin for Bootstrap framework that will go along with my theme. However since this would be released to the plugin, if a users's theme already has Bootstrap.css included, is there a way for me to check this from a plugin?

share|improve this question
add comment

2 Answers

up vote 4 down vote accepted

You might be able to use wp_style_is() to do this:

$style = 'bootstrap';
if( ( ! wp_style_is( $style, 'queue' ) ) && ( ! wp_style_is( $style, 'done' ) ) ) {
    //queue up your bootstrap
    wp_enqueue_style( $style, $path_to_bootstrap, $deps, $ver, $media );
}

This comes with all the same caveats as @Milo's solution -- it'll only work if the copy of bootstrap.css was registered or enqueued with a handle of bootstrap.

References

share|improve this answer
    
Thanks Pat. This does the job. As @Milo suggested will have to show some warning/notice too. But this is great. –  Harish Chouhan Jun 28 '13 at 7:14
add comment

There's no bulletproof way of doing this, as a theme developer could add the bootstrap.css file directly to a theme file, or enqueue it under any number of handles, or rename the css file to something else.

You could check the $wp_styles global for bootstrap in a handle or filename, but this may fail (as noted above) or give you a false positive if bootstrap happens to be in a handle or file unrelated to your bootstrap. It's also possible to build custom versions of bootstrap, so even if you did locate it, it may not contain all of the styles it's assumed to contain.

Here's a quick example of peeking into the enqueued styles:

function wpa_inspect_styles(){
    global $wp_styles;
    var_dump( $wp_styles );
}
add_action( 'wp_enqueue_scripts', 'wpa_inspect_styles', 9999 );

Probably the best option, in my opinion, is to do some cursory checking and inform the user that you may have detected bootstrap in their theme, enqueue the file by default, and provide an option to disable the stylesheet.

share|improve this answer
    
Thanks Mila. Showing a user a message as you suggested seems to be a great way to be sure. –  Harish Chouhan Jun 28 '13 at 7:13
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.