Change wc_safe_dump to wc_print_r

Match print_r arguments, this makes usage obvious.
This commit is contained in:
Jon Surrell 2016-12-16 22:51:20 +01:00
parent 3f4b473a48
commit aee5917440
7 changed files with 24 additions and 15 deletions

View File

@ -325,7 +325,7 @@ class WC_Admin_Report {
if ( $debug ) {
echo '<pre>';
echo wc_safe_dump( $query );
wc_print_r( $query );
echo '</pre>';
}

View File

@ -297,7 +297,7 @@ class WC_Gateway_Paypal extends WC_Payment_Gateway {
return new WP_Error( 'error', $result->get_error_message() );
}
$this->log( 'Refund Result: ' . wc_safe_dump( $result ) );
$this->log( 'Refund Result: ' . wc_print_r( $result, true ) );
switch ( strtolower( $result->ACK ) ) {
case 'success':
@ -328,7 +328,7 @@ class WC_Gateway_Paypal extends WC_Payment_Gateway {
return;
}
$this->log( 'Capture Result: ' . wc_safe_dump( $result ) );
$this->log( 'Capture Result: ' . wc_print_r( $result, true ) );
if ( ! empty( $result->PAYMENTSTATUS ) ) {
switch ( $result->PAYMENTSTATUS ) {

View File

@ -88,7 +88,7 @@ class WC_Gateway_Paypal_API_Handler {
)
);
WC_Gateway_Paypal::log( 'DoCapture Response: ' . wc_safe_dump( $raw_response ) );
WC_Gateway_Paypal::log( 'DoCapture Response: ' . wc_print_r( $raw_response, true ) );
if ( empty( $raw_response['body'] ) ) {
return new WP_Error( 'paypal-api', 'Empty Response' );
@ -120,7 +120,7 @@ class WC_Gateway_Paypal_API_Handler {
)
);
WC_Gateway_Paypal::log( 'Refund Response: ' . wc_safe_dump( $raw_response ) );
WC_Gateway_Paypal::log( 'Refund Response: ' . wc_print_r( $raw_response, true ) );
if ( empty( $raw_response['body'] ) ) {
return new WP_Error( 'paypal-api', 'Empty Response' );

View File

@ -91,8 +91,8 @@ class WC_Gateway_Paypal_IPN_Handler extends WC_Gateway_Paypal_Response {
// Post back to get a response.
$response = wp_safe_remote_post( $this->sandbox ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params );
WC_Gateway_Paypal::log( 'IPN Request: ' . wc_safe_dump( $params ) );
WC_Gateway_Paypal::log( 'IPN Response: ' . wc_safe_dump( $response ) );
WC_Gateway_Paypal::log( 'IPN Request: ' . wc_print_r( $params, true ) );
WC_Gateway_Paypal::log( 'IPN Response: ' . wc_print_r( $response, true ) );
// Check to see if the request was valid.
if ( ! is_wp_error( $response ) && $response['response']['code'] >= 200 && $response['response']['code'] < 300 && strstr( $response['body'], 'VERIFIED' ) ) {

View File

@ -88,7 +88,7 @@ class WC_Gateway_Paypal_PDT_Handler extends WC_Gateway_Paypal_Response {
$transaction_result = $this->validate_transaction( $transaction );
WC_Gateway_Paypal::log( 'PDT Transaction Result: ' . wc_safe_dump( $transaction_result ) );
WC_Gateway_Paypal::log( 'PDT Transaction Result: ' . wc_print_r( $transaction_result, true ) );
update_post_meta( $order->get_id(), '_paypal_status', $status );
update_post_meta( $order->get_id(), '_transaction_id', $transaction );

View File

@ -45,7 +45,7 @@ class WC_Gateway_Paypal_Request {
public function get_request_url( $order, $sandbox = false ) {
$paypal_args = http_build_query( array_filter( $this->get_paypal_args( $order ) ), '', '&' );
WC_Gateway_Paypal::log( 'PayPal Request Args for order ' . $order->get_order_number() . ': ' . wc_safe_dump( $paypal_args ) );
WC_Gateway_Paypal::log( 'PayPal Request Args for order ' . $order->get_order_number() . ': ' . wc_print_r( $paypal_args, true ) );
if ( $sandbox ) {
return 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' . $paypal_args;

View File

@ -1425,16 +1425,19 @@ function wc_get_logger() {
}
/**
* Dump an expression safely.
* Prints human-readable information about a variable.
*
* Some server environments blacklist some debugging functions. This function provides a safe way to
* turn an expression into a printable, readable form while protecting from errors.
* turn an expression into a printable, readable form without calling blacklisted functions.
*
* @since 2.8
*
* @param mixed $expression The expression to be printed.
* @return string|bool Result of printing expression. False if no alternatives are available.
* @param bool $return Optional. Default false. Set to true to return the human-readable string.
* @return string|bool False if expression could not be printed. True if the expression was printed.
* If $return is true, a string representation will be returned.
*/
function wc_safe_dump( $expression ) {
function wc_print_r( $expression, $return = false ) {
$alternatives = array(
array( 'func' => 'print_r', 'args' => array( $expression, true ) ),
array( 'func' => 'var_export', 'args' => array( $expression, true ) ),
@ -1442,11 +1445,17 @@ function wc_safe_dump( $expression ) {
array( 'func' => 'serialize', 'args' => array( $expression ) ),
);
$alternatives = apply_filters( 'woocommerce_safe_dump_alternatives', $alternatives, $expression );
$alternatives = apply_filters( 'woocommerce_print_r_alternatives', $alternatives, $expression );
foreach ( $alternatives as $alternative ) {
if ( function_exists( $alternative['func'] ) ) {
return call_user_func_array( $alternative['func'], $alternative['args'] );
$res = call_user_func_array( $alternative['func'], $alternative['args'] );
if ( $return ) {
return $res;
} else {
echo $res;
return true;
}
}
}