0

I am trying to build my first plugin but am receiving the following error:

Warning: Cannot modify header information - headers already sent by (output started at /wp-admin/includes/template.php:1642) in /wp-includes/pluggable.php on line 876

But here's the thing: template.php isn't 1600 lines long and pluggable doesn't have any whitespace at that point.

My plugin code is as follows:

<?php  
/* 
Plugin Name: Test 
Plugin URI: http://www.Test.com
Description: Test
Author: Test
Version: 1.0 
Author URI: http://www.Test.com
*/  

function Test_admin() {  
    include('admin.php');  
}
function Test_admin_actions() { 
    $icon_url = "";
    add_menu_page( "Test", "Test", "switch_themes", "Test", "Test_admin", $icon_url, 58 );
}
add_action('admin_menu', 'Test_admin_actions');
?>

The admin.php file is currently empty.

The plugin adds a Test menu option in the admin page just before the Appearance option. When you click on it, you should theoretically get a white page but instead, you get the error.

So I'm pretty dumbfounded by this. I've disabled, deleted, and reinstalled my plugin to no avail.

Any ideas?

5
  • So the error disappears after the plugin is deactivates? It is definitely a problem with this plugin? Commented Jan 17, 2013 at 4:50
  • Yes. This error happens uniquely when clicking the Test menu option that the plugin adds. Commented Jan 17, 2013 at 4:52
  • It appears that something is trying to use the wp_redirect() function after the admin header has been printed Commented Jan 17, 2013 at 4:55
  • What would that be? My plugin doesn't do anything. My entire code is what is posted. Commented Jan 17, 2013 at 4:57
  • Have you tried changing the names of your functions? Possible conflict? Commented Jan 17, 2013 at 4:58

2 Answers 2

2

I'll guess your include is failing. If it's in the same directory as your main plugin file, try:

include( plugin_dir_path(__FILE__) . '/admin.php' );
2
  • Yes, this could be the reason +1 Commented Jan 17, 2013 at 4:59
  • That did the trick! Commented Jan 17, 2013 at 5:04
0

It's most likely a space after the closing ?> tag. The WordPress Codex recommends that you drop the closing tag completely.

2
  • 1
    Negative. No spaces after the closing tag. Even with the closing tag removed, the error persists. Commented Jan 17, 2013 at 4:41
  • It's a good suggestion all the same, it's good practice to leave out the closing tag to avoid whitespace and headers sent errors more easily. Commented Feb 3, 2014 at 18:38

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.