Cannot modify header information - headers already

2019-09-21 18:49发布

问题:

Possible Duplicate:
Headers already sent by PHP

When I go into wp-admin on www.newswars.org, I see the following error:

Warning: Cannot modify header information - headers already sent by (output started at /home/newswars/public_html/wp-content/themes/videoplus/functions.php:38) in /home/newswars/public_html/wp-includes/option.php on line 563

Warning: Cannot modify header information - headers already sent by (output started at /home/newswars/public_html/wp-content/themes/videoplus/functions.php:38) in /home/newswars/public_html/wp-includes/option.php on line 564

Can you please help?

EDIT: Ok its this that is causing me the problem.

$user_ej = wp_get_current_user();
if ($user_ej->roles[0] == 'contributor')
{ ?>

This is 36-38 lines. For some reason its getting all messed up. Still I'm not quite sure what the problem is. I tried removing ?> but that gave me a syntax error. I'm at a loss. It is definitely the problem area as it only comes up when someone logs in a 'contributor'.

 <?php
// Translations can be filed in the /lang/ directory
load_theme_textdomain( 'themejunkie', TEMPLATEPATH . '/lang' );


require_once(TEMPLATEPATH . '/includes/sidebar-init.php');
require_once(TEMPLATEPATH . '/includes/custom-functions.php');
require_once(TEMPLATEPATH . '/includes/post-thumbnails.php');

require_once(TEMPLATEPATH . '/includes/theme-postmeta.php');

require_once(TEMPLATEPATH . '/includes/theme-options.php');
require_once(TEMPLATEPATH . '/includes/theme-widgets.php');

require_once(TEMPLATEPATH . '/functions/theme_functions.php'); 
require_once(TEMPLATEPATH . '/functions/admin_functions.php');
function wpr_snap($atts, $content = null) {
        extract(shortcode_atts(array(
            "snap" => 'http://s.wordpress.com/mshots/v1/',
            "url" => 'http://www.catswhocode.com',
            "alt" => 'My image',
            "w" => '400', // width
            "h" => '300' // height
        ), $atts));

    $img = '<img src="' . $snap . '' . urlencode($url) . '?w=' . $w . '&h=' . $h . '" alt="' . $alt . '"/>';
        return $img;
}




add_shortcode("snap", "wpr_snap");

$user_ej = wp_get_current_user();
if ($user_ej->roles[0] == 'contributor')
{ ?>
    <style type="text/css">
        #menu-dashboard, #toplevel_page_wpcf7, #menu-tools 
        {
            display:none;
        }
  </style>





<?php }

add_filter(  'gettext',  'change_post_to_portfolio'  );
add_filter(  'ngettext',  'change_post_to_portfolio'  );

function change_post_to_portfolio( $translated ) {
  $translated = str_ireplace(  'Posts',  'VIDEOS',  $translated );  // ireplace is PHP5 only
  return $translated;
}

// Uncomment this to test your localization, make sure to enter the right language code.
// function test_localization( $locale ) {
//  return "nl_NL";
// }
// add_filter('locale','test_localization');

// Adds categories to pages
add_action('admin_init', 'reg_tax');
function reg_tax() {
register_taxonomy_for_object_type('category', 'page');
add_post_type_support('page', 'category');
}

add_action('admin_footer', 'my_admin_footer');
function my_admin_footer()
{
    $uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : NULL ;

    $message = NULL;

    if ($uri AND strpos($uri,'edit.php'))
    {
        if (strpos($uri,'post_type=page'))
        {
            $message = '1.In the ‘Video Embed Code section,’ enter the video embed code. 2.Enter the title and text in the main panel below. 3.Choose which continent and category is most fitting for your video. 4.Press ‘Publish’';
        }
        else
        {
            $message = 'ALL VIDEOS';
        }
    }

    elseif ($uri AND strpos($uri,'post-new.php'))
    {
        if (strpos($uri,'post_type=page'))
        {
            $message = 'Add pages here';
        }
        else
        {
            $message = '1.In the ‘Video Embed Code section,’ enter the video embed code. 2.Enter the title and text in the main panel below. 3.Choose which continent and category is most fitting for your video. 4.Press ‘Publish’';
        }
    }

    elseif ($uri AND strpos($uri,'post.php'))
    {
        $message = 'THREE';
    }

    if ($message)
    {
        ?><script>
            jQuery(function($)
            {
                $('<div style="margin-bottom:15px; color:#FF0000;"></div>').text('<?php echo $message; ?>').insertAfter('#wpbody-content .wrap h2:eq(0)');
            });
        </script><?php
    }
}
?>

回答1:

add_shortcode("snap", "wpr_snap");
$user_ej = wp_get_current_user();
if ($user_ej->roles[0] == 'contributor')
{ ?>
  <style type="text/css">
    #menu-dashboard, #toplevel_page_wpcf7, #menu-tools 
    {
        display:none;
    }
</style>
<?php }
add_filter(  'gettext',  'change_post_to_portfolio'  );
add_filter(  'ngettext',  'change_post_to_portfolio'  );

isn't inside a function. So it's being called as soon as the file loads. This means all output is sent to the screen immediately This stuff should be inside a function which is then called at the right time (like the other bits).