WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

i'm building a widget to login from the sidebar and print errors if any, so everything is working fine except that when i login it returns an error:
Warning: Cannot modify header information - headers already sent.....

the code of the widget:

// Custom Login/Meta Widget
function widget_artdev_meta() { ?>

<?php global $user_ID, $user_identity, $user_level ?>
<?php if ( $user_ID ) : ?>
<div class="widget">
 <h2>Control Panel</h2>
  <li>Identified as <strong><?php echo $user_identity ?></strong>.
   <?php if ( $user_level >= 10 ) : ?>
   <li><a href="<?php bloginfo('url') ?>/wp-admin">Dashboard</a></li>
   <?php endif // $user_level >= 10 ?>

   <?php if ( $user_level >= 1 ) : ?>
   <li><a href="<?php bloginfo('url') ?>/wp-admin/post-new.php">Write an article</a></li>
   <?php endif // $user_level >= 1 ?>

   <li><a href="<?php bloginfo('url') ?>/profile">Profile &amp; personal options</a></li>
   <li><a href="<?php echo wp_logout_url( $_SERVER['REQUEST_URI'] ); ?>" title="Exit">Exit</a></li>

<?php elseif ( get_option('users_can_register') ) : ?>

if ( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) && $_POST['action'] == 'log-in' ) :
 global $error;
 $login = wp_login( $_POST['log'], $_POST['pwd'] );
 $login = wp_signon( array( 'user_login' => $_POST['log'], 'user_password' => $_POST['pwd'], 'remember' => $_POST['rememberme'] ), false );

<div class="widget">

 <?php if ( $error ) : ?>
  <p class="error">
   <?php echo $error; ?>
  </p><!-- .error -->
 <?php endif; ?>

  <form action="<?php the_permalink(); ?>" method="post">
   <label for="log">Customer ID
    <input type="text" name="log" id="log" value="<?php echo wp_specialchars(stripslashes($user_login), 1) ?>" size="22" class="input_text_login alignright" />
   <label for="pwd">Password
    <input type="password" name="pwd" id="pwd" size="22" class="input_text_login alignright" />
    <input type="submit" name="submit" value="Login" class="button" style="margin-right:35px; width:70px;" />
    <input name="rememberme" id="rememberme" type="checkbox" checked="checked" value="forever" /> Remember me
    <input type="hidden" name="action" value="log-in" />
    <input type="hidden" name="redirect_to" value="<?php echo $_SERVER['REQUEST_URI']; ?>"/>
  <li><a href="<?php bloginfo('url') ?>/wp-login.php?action=lostpassword">Recover password</a></li>
  <li><a href="<?php bloginfo('url') ?>/register">Register</a></li>

<?php endif // get_option('users_can_register') ?>
<?php }
if ( function_exists('register_sidebar_widget') )
register_sidebar_widget(__('&rarr; Login/Meta Widget','artdev'), 'widget_artdev_meta');

anyone out there can help? i can't understand where the problem is...!

thanks a lot!

share|improve this question
up vote 2 down vote accepted
  • Don't use both wp_login() and wp_signon(). They do the same thing, but first one is deprecated
  • Use the 2.8 widget API
  • Put wp_signon() inside a function that you hook on the init tag (You can handle the errors in the widget() function)
share|improve this answer
thanks a lot AmbitiousAmoeba, i will take a deep look and i'll come back with the results – Philip Dec 19 '10 at 9:35

Your Answer


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.