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.

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

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改