0

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:

<?php
// 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>
 <ul>
  <li>Identified as <strong><?php echo $user_identity ?></strong>.
  <ul>
   <?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>
  </ul>
  </li>
 </ul>
</div>

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

<?php
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 );
endif;
?>

<div class="widget">
 <h2>Identification</h2>

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

 <ul>
  <li>
  <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>
   <label for="pwd">Password
    <input type="password" name="pwd" id="pwd" size="22" class="input_text_login alignright" />
   </label>
    <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']; ?>"/>
  </form>
  </li>
  <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>
 </ul>
</div>

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

1 Answer 1

2
  • 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)
1
  • thanks a lot AmbitiousAmoeba, i will take a deep look and i'll come back with the results
    – Philip
    Dec 19, 2010 at 9:35

Your Answer

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

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