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 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?

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

2 Answers 2

up vote 2 down vote accepted

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' );
share|improve this answer
    
Yes, this could be the reason +1 –  bungeshea_ Jan 17 '13 at 4:59
    
That did the trick! –  Sweepster Jan 17 '13 at 5:04

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

share|improve this answer
1  
Negative. No spaces after the closing tag. Even with the closing tag removed, the error persists. –  Sweepster Jan 17 '13 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. –  t31os Feb 3 at 18:38

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.