调用paramenter,在formatting.php中获取UTF8空返回错误 [英] Calling paramenter, get UTF8 null return error in formatting.php
本文介绍了调用paramenter,在formatting.php中获取UTF8空返回错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我遇到一个相关的可捕获的致命错误:无法在766行的/wp-includes/formatting.php中将类WP_User的对象转换为字符串.我在
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
我正在使用的php,我认为应该是:
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";
}
我遇到的错误与formatting.php有关:
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 '';
}
推荐答案
您需要以字符串形式返回用户名,而不是整个用户object
.
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";
}
这篇关于调用paramenter,在formatting.php中获取UTF8空返回错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文