wc_print_r

Prints human-readable information about a variable.

Description

(string|bool) wc_print_r( (mixed) $expression, (bool) $return = false ); 

Some server environments blacklist some debugging functions. This function provides a safe way to turn an expression into a printable, readable form without calling blacklisted functions.

Returns (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.

Parameters (2)

0. $expression (mixed)
The expression to be printed.
1. $return — Optional. (bool) => false
Default false. Set to true to return the human-readable string.

Usage

  1. if ( !function_exists( 'wc_print_r' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-core-functions.php'; 
  3.  
  4. // The expression to be printed. 
  5. $expression = null; 
  6.  
  7. // Optional. Default false. Set to true to return the human-readable string. 
  8. $return = false; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = wc_print_r($expression, $return); 
  12.  

Defined (1)

The function is defined in the following location(s).

/includes/wc-core-functions.php  
  1. function wc_print_r( $expression, $return = false ) { 
  2. $alternatives = array( 
  3. array( 'func' => 'print_r', 'args' => array( $expression, true ) ),  
  4. array( 'func' => 'var_export', 'args' => array( $expression, true ) ),  
  5. array( 'func' => 'json_encode', 'args' => array( $expression ) ),  
  6. array( 'func' => 'serialize', 'args' => array( $expression ) ),  
  7. ); 
  8.  
  9. $alternatives = apply_filters( 'woocommerce_print_r_alternatives', $alternatives, $expression ); 
  10.  
  11. foreach ( $alternatives as $alternative ) { 
  12. if ( function_exists( $alternative['func'] ) ) { 
  13. $res = call_user_func_array( $alternative['func'], $alternative['args'] ); 
  14. if ( $return ) { 
  15. return $res; 
  16. } else { 
  17. echo $res; 
  18. return true; 
  19.  
  20. return false;