| @@ -1,60 +1,61 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | // Exit if accessed directly |
| 4 | -if ( ! defined( 'ABSPATH' ) ) { | |
| 5 | - exit; | |
| 4 | +if (!defined('ABSPATH')) { | |
| 5 | + exit; | |
| 6 | 6 | } |
| 7 | 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 | - ); | |
| 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 | + { | |
| 25 | + $alternatives = [ | |
| 26 | + [ | |
| 27 | + 'func' => 'print_r', | |
| 28 | + 'args' => [$expression, true], | |
| 29 | + ], | |
| 30 | + [ | |
| 31 | + 'func' => 'var_export', | |
| 32 | + 'args' => [$expression, true], | |
| 33 | + ], | |
| 34 | + [ | |
| 35 | + 'func' => 'json_encode', | |
| 36 | + 'args' => [$expression], | |
| 37 | + ], | |
| 38 | + [ | |
| 39 | + 'func' => 'serialize', | |
| 40 | + 'args' => [$expression], | |
| 41 | + ], | |
| 42 | + ]; | |
| 42 | 43 | |
| 43 | - $alternatives = apply_filters( 'woocommerce_print_r_alternatives', $alternatives, $expression ); | |
| 44 | + $alternatives = apply_filters('woocommerce_print_r_alternatives', $alternatives, $expression); | |
| 44 | 45 | |
| 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. | |
| 46 | + foreach ($alternatives as $alternative) { | |
| 47 | + if (function_exists($alternative['func'])) { | |
| 48 | + $res = call_user_func_array($alternative['func'], $alternative['args']); | |
| 49 | + if ($return) { | |
| 50 | + return $res; | |
| 51 | + } else { | |
| 52 | + echo $res; // WPCS: XSS ok. | |
| 52 | 53 | |
| 53 | - return true; | |
| 54 | - } | |
| 55 | - } | |
| 56 | - } | |
| 54 | + return true; | |
| 55 | + } | |
| 56 | + } | |
| 57 | + } | |
| 57 | 58 | |
| 58 | - return false; | |
| 59 | - } | |
| 60 | -} | |
| 59 | + return false; | |
| 60 | + } | |
| 61 | +} | |