Calling paramenter, get UTF8 null return error in formatting.php

我只是一个虾纸丫 提交于 2019-12-12 02:32:50

问题


I am getting a related Catchable fatal error: Object of class WP_User could not be converted to string in /wp-includes/formatting.php on line 766. I found a thread that relates at https://wordpress.org/support/topic/catchable-fatal-error-object-of-class-wp_error-could-not-be-converted-to-string-11

The php I am using, which I think should be working is:

add_filter('gform_field_value_pm_first', 'populate_pm_first');
function populate_pm_first($value){
    return $user_info = get_userdata(get_current_user_id());
      $first_name = $user_info->first_name;
      echo "$first_name";

}

The error I am getting relates to formatting.php:

/**

 * Checks for invalid UTF8 in a string.
 *
 * @since 2.8.0
 *
 * @param string $string The text which is to be checked.
 * @param boolean $strip Optional. Whether to attempt to strip out invalid UTF8. Default is false.
 * @return string The checked text.
 */
function wp_check_invalid_utf8( $string, $strip = false ) {
    $string = (string) $string;

        if ( 0 === strlen( $string ) ) {
        return '';
    }

回答1:


I think the syntax is:

$first_name = $user_info->user_firstname;

Might be worth a try. Hope this helps :)




回答2:


You need to return user name as string instead of whole user object.

 add_filter('gform_field_value_pm_first', 'populate_pm_first');
 function populate_pm_first($value)
 {
      $user_info = get_userdata(get_current_user_id());
      $first_name = $user_info->first_name;
      return $first_name; // return user name string
      //echo "$first_name";
 }


来源:https://stackoverflow.com/questions/30020237/calling-paramenter-get-utf8-null-return-error-in-formatting-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!