admin管理员组文章数量:1122846
I am getting the following error in the code snippet below and pointing to the line that references the $result[ 'body' ]
assignment. The is_wp_error
should have caught the error?
Fatal error: Cannot use object of type WP_Error as array
$result = wp_remote_post( ..... ) );
if ( is_wp_error( $result ) ):
$display = 'Error Message';
else:
$display = $result[ 'body' ];
endif;
I am getting the following error in the code snippet below and pointing to the line that references the $result[ 'body' ]
assignment. The is_wp_error
should have caught the error?
Fatal error: Cannot use object of type WP_Error as array
$result = wp_remote_post( ..... ) );
if ( is_wp_error( $result ) ):
$display = 'Error Message';
else:
$display = $result[ 'body' ];
endif;
Share
Improve this question
edited Sep 4, 2024 at 11:03
bueltge
17.1k7 gold badges61 silver badges97 bronze badges
asked May 29, 2017 at 3:40
user1941464user1941464
213 bronze badges
1 Answer
Reset to default 0Both wp_remote_post
and wp_remote_get
return WP_Error
object if there is an error. You could use the get_error_message
function of WP_Error
class to receive the error and show it.
$request = wp_remote_post( $url );
if ( is_wp_error( $request ) ) {
// If the request has failed, show the error message
echo $request->get_error_message();
} else {
$content = wp_remote_retrieve_body( $request );
// Do stuff with $content
}
For more details, go ahead Here
本文标签: iswperror is missing error
版权声明:本文标题:is_wp_error is missing error 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736283313a1926928.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论