1

I have a wordpress plugin that is interfering with the function of another plugin. But, I believe the interference only occurs on the admin side.

I've found the lines within the code that are interfering, and they appear to be loading html code on the header and footer of ALL admin pages.

I would like to restrict these lines of code so that they only display on the post/page edit pages of the admin.

Not exactly sure how to do that. I know I'll need some sort of conditional statement, but not sure EXACTLY how the code should read or what the best condition would be to use.

Any help would be greatly appreciated.

1
  • There's a $current_screen global variable which you can use to find what's the current admin page Commented Apr 21, 2012 at 16:11

2 Answers 2

1

Using @One Trick Pony's method, this should do what you want:

global $current_screen;  // Makes the $current_screen object available
if ($current_screen && $current_screen->base == "edit") {
    // Edit-page/post-only code here    
}

If you want it on the add OR edit screens, then:

global $current_screen;  // Makes the $current_screen object available           
if ($current_screen && ($current_screen->base == "edit" || $current_screen->base == "post")) {
    // Add-or-edit-page/post-only code       
 }
3
  • Thanks for the input. However, this did not work. Although enclosing the code with your code did solve the plugin conflict, it apparently does not load the code properly on the add/edit pages because the plugin is not working properly on these pages.
    – Michael
    Commented Apr 22, 2012 at 4:32
  • So it did work as the question was put, but you have not included enough code or info for us to completely troubleshoot the problem. Commented Apr 22, 2012 at 14:40
  • Understood, and probably correct. It turned out that your suggestion would have worked except the code I wanted to conditionally load is code that must have already loaded for your "global $current_screen" to work - namely admin_init and admin_head. I made it work by doing it more "manually" with php using basename($_SERVER['PHP_SELF']) and $_GET['action'] in my conditional statement.
    – Michael
    Commented Apr 22, 2012 at 18:36
0

After trying cale_b's suggestion and finding that his code would only work if admin_init and admin_head had already loaded (but that's the very code I was trying to conditionally load), I needed to go another way.

Thanks to Cale_b for giving me a little head-start from which I was able to come up with the following conditional. Also, apologies to Cale_b for not providing him enough info to know that his code would not work.

The working code was this:

if (basename($_SERVER['PHP_SELF']) == "post-new.php" || (basename($_SERVER['PHP_SELF']) == "post.php" && $_GET['action'] == "edit")) {
    add_action( 'admin_init', array(&$this,'enqueue_assets') );
    add_action( 'admin_head', array(&$this,'jquery_ui_dialog') );
    add_action( 'admin_footer', array(&$this,'add_jquery_ui_dialog') );     }

This allowed me to only "run" those add_action statements on the post edit and new post pages within the admin, eliminating the conflict with my other plugin.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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