I am using a plugin to display a Terms and Conditions page to my visitors. The visitors would have to agree to the terms and conditions in order to see the actual content of the website.

When this plugin is active and the terms and conditions page is displayed, it does not use the normal theme rendering flow. Instead, the plugin calls get_header(), get_footer(), etc to render the page directly. While doing so, is_admin() would return true, even though we really should consider the terms and conditions page to be the front-end and not the dashboard/admin panel. The theme uses is_admin() to decide whether or not to enqueue certain javascripts, so it enqueues the wrong set of javascript files and I get a whole bunch of javascript errors.

How can I make is_admin() return true in the context of the plugin?

P.S. The exact plugin in question is this: http://wordpress.org/extend/plugins/force-apply-terms-and-conditions/

  • Please show the code. Or is it from the plugin? – kaiser Jun 14 '12 at 10:05
  • It's from the plugin. The plugin defines a plugin_force_apply class, which has a show_confirm() function that does the rendering. And you would need a theme that depends on is_admin() to enqueue CSS or javascript, in order to demonstrate the effect. – Kal Jun 14 '12 at 10:12
  • Afaik, that isn't your problem. The plugin clearly hooks to init, which is present everywhere in WP. Also take a look at the first 2 lines of code in force-apply-terms-and-conditions.php -this tells us, that if we're not in admin, it hooks nicely. – kaiser Jun 14 '12 at 10:39

This is kinda tricky! I'd say use either of the conditional tags or the global $pagenow variable to check your page, and then do that action what you'd otherwise do if is_admin was false.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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