admin管理员组文章数量:1318156
I using remote payment system of 2 WordPress site, 1st WordPress site to 2nd WordPress site. 1st is main website & 2nd website work like merchant website that process payment of paypal. We fetch user order details of 1st website to 2nd website for process paypal payment. But on fetching web page of 2nd website getting error, but remember it solved if reload it once
Fatal error: Uncaught Error: Cannot use object of type WP_Error as array in /../plugins/rm-payment.php:on line 231
$response = wp_remote_post( $remote_url, $request );
if(strlen($response["body"]) > 0) {
$insert = $wpdb->insert( $table_name, array(
'user_email' => $query['user'],
'reference' => $query['ref'],
'token_ref' => $token_ref,
'point_type' => $query['ctype'],
'amount' => $query['amount'],
'cost' => $total_price,
'ref_id' => $timestamp,
'payment_date' => current_time( 'mysql' ),
'created_at' => current_time( 'mysql' )
));
$insert2 = $A_wpdb->insert( $A_table_name, array(
'user_email' => $query['user'],
'reference' => $query['ref'],
'amount' => $query['amount'],
'ref_id' => $timestamp,
'payment_date' => current_time( 'mysql' ),
'created_at' => current_time( 'mysql' )
));
if($insert) {
$payment_id = $wpdb->insert_id;
} else {
echo "Error!"; exit();
}
} else {
wp_redirect( $query['url'] . '?message=user-not-exist' ); exit();
}
'''
I using remote payment system of 2 WordPress site, 1st WordPress site to 2nd WordPress site. 1st is main website & 2nd website work like merchant website that process payment of paypal. We fetch user order details of 1st website to 2nd website for process paypal payment. But on fetching web page of 2nd website getting error, but remember it solved if reload it once
Fatal error: Uncaught Error: Cannot use object of type WP_Error as array in /../plugins/rm-payment.php:on line 231
$response = wp_remote_post( $remote_url, $request );
if(strlen($response["body"]) > 0) {
$insert = $wpdb->insert( $table_name, array(
'user_email' => $query['user'],
'reference' => $query['ref'],
'token_ref' => $token_ref,
'point_type' => $query['ctype'],
'amount' => $query['amount'],
'cost' => $total_price,
'ref_id' => $timestamp,
'payment_date' => current_time( 'mysql' ),
'created_at' => current_time( 'mysql' )
));
$insert2 = $A_wpdb->insert( $A_table_name, array(
'user_email' => $query['user'],
'reference' => $query['ref'],
'amount' => $query['amount'],
'ref_id' => $timestamp,
'payment_date' => current_time( 'mysql' ),
'created_at' => current_time( 'mysql' )
));
if($insert) {
$payment_id = $wpdb->insert_id;
} else {
echo "Error!"; exit();
}
} else {
wp_redirect( $query['url'] . '?message=user-not-exist' ); exit();
}
'''
Share Improve this question asked Oct 28, 2020 at 13:50 MidasMidas 1 1- 1 In the given code, which line is 231? The provided error tells us that on line 231 we have a WP_Error Object instead of an array. – Howdy_McGee ♦ Commented Oct 28, 2020 at 14:11
1 Answer
Reset to default 0My guess is that you're accessing $response
as an array when it's a \WP_Error
. Check out the possible return values of wp_remote_post
:
(array|WP_Error) The response or WP_Error on failure.
You should modify your code in a couple of ways:
$response = wp_remote_post( $remote_url, $request );
if ( is_wp_error( $response ) ) {
// handle the error response here.
}
$body = wp_remote_retrieve_body( $response );
if( false !== strlen( $body ) ) {
This ensures you catch any \WP_Error
returns and gets the body data using wp_remote_retrieve_body
. You can also use wp_remote_retrieve_response_code( $response )
to get the HTTP status code (e.g. 200
, 401
, etc.)
本文标签: wp queryFatal error Uncaught Error Cannot use object of type WPError as array in pluginsrmpaymentphp
版权声明:本文标题:wp query - Fatal error: Uncaught Error: Cannot use object of type WP_Error as array in ..pluginsrm-payment.php 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742031406a2416511.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论