duancong7573 2015-05-03 12:17
浏览 69
已采纳

不能使用wp_signon()

When I try this code

$creds = array( 'user_login' =>  $_POST['benutzername'], 'user_password' => $_POST['passwort'], 'remember' => true );
$user = wp_signon( $creds, false );
if ( is_wp_error($user) ): echo $user->get_error_message(); endif;
wp_set_current_user($user->ID);
return $user;

I get this message:

Warning: Cannot modify header information - headers already sent by (output started at /home/httpd/vhosts/your-click.ch/httpdocs/wp-includes/formatting.php:4179) in /home/httpd/vhosts/your-click.ch/httpdocs/wp-includes/pluggable.php on line 925 Warning: Cannot modify header information - headers already sent by (output started at /home/httpd/vhosts/your-click.ch/httpdocs/wp-includes/formatting.php:4179) in /home/httpd/vhosts/your-click.ch/httpdocs/wp-includes/pluggable.php on line 926 Warning: Cannot modify header information - headers already sent by (output started at /home/httpd/vhosts/your-click.ch/httpdocs/wp-includes/formatting.php:4179) in /home/httpd/vhosts/your-click.ch/httpdocs/wp-includes/pluggable.php on line 927 Catchable fatal error: Object of class WP_User could not be converted to string in /home/httpd/vhosts/your-click.ch/httpdocs/wp-includes/shortcodes.php on line 286

I am using that code in shortcode.php. What's wrong with my code?

  • 写回答

1条回答 默认 最新

  • doudao1369 2015-05-03 12:27
    关注

    According to the WP Manual for the wp_signon function:

    This function sends headers to the page. It must be run before any content is returned.

    According to the error you get, it seems that you're using this function after some content has being returned already.

    Further more, it seems that WP team advise to use that function in the hook after_setup_theme which:

    will make it run before the headers and cookies are sent, so it can set the needed cookie for login.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line