| 1 |
<?php |
| 2 |
|
| 3 |
// Exit if accessed directly |
| 4 |
if ( ! defined( 'ABSPATH' ) ) { |
| 5 |
exit; |
| 6 |
} |
| 7 |
|
| 8 |
if ( ! function_exists( 'wc_print_r' ) ) { |
| 9 |
/** |
| 10 |
* Prints human-readable information about a variable. |
| 11 |
* |
| 12 |
* Some server environments blacklist some debugging functions. This function provides a safe way to |
| 13 |
* turn an expression into a printable, readable form without calling blacklisted functions. |
| 14 |
* |
| 15 |
* @since 3.0 |
| 16 |
* |
| 17 |
* @param mixed $expression The expression to be printed. |
| 18 |
* @param bool $return Optional. Default false. Set to true to return the human-readable string. |
| 19 |
* |
| 20 |
* @return string|bool False if expression could not be printed. True if the expression was printed. |
| 21 |
* If $return is true, a string representation will be returned. |
| 22 |
*/ |
| 23 |
function wc_print_r( $expression, $return = false ) { |
| 24 |
$alternatives = array( |
| 25 |
array( |
| 26 |
'func' => 'print_r', |
| 27 |
'args' => array( $expression, true ), |
| 28 |
), |
| 29 |
array( |
| 30 |
'func' => 'var_export', |
| 31 |
'args' => array( $expression, true ), |
| 32 |
), |
| 33 |
array( |
| 34 |
'func' => 'json_encode', |
| 35 |
'args' => array( $expression ), |
| 36 |
), |
| 37 |
array( |
| 38 |
'func' => 'serialize', |
| 39 |
'args' => array( $expression ), |
| 40 |
), |
| 41 |
); |
| 42 |
|
| 43 |
$alternatives = apply_filters( 'woocommerce_print_r_alternatives', $alternatives, $expression ); |
| 44 |
|
| 45 |
foreach ( $alternatives as $alternative ) { |
| 46 |
if ( function_exists( $alternative['func'] ) ) { |
| 47 |
$res = call_user_func_array( $alternative['func'], $alternative['args'] ); |
| 48 |
if ( $return ) { |
| 49 |
return $res; |
| 50 |
} else { |
| 51 |
echo $res; // WPCS: XSS ok. |
| 52 |
|
| 53 |
return true; |
| 54 |
} |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
return false; |
| 59 |
} |
| 60 |
} |