pods_evaluate_tag

Evaluate tag like magic tag but mapped through pods_v.

Description

(string) pods_evaluate_tag( (string|array) $tag, (bool) $sanitize = false ); 

Returns (string)

Parameters (2)

0. $tag (string|array)
The tag.
1. $sanitize — Optional. (bool) => false
Whether to sanitize tags

Usage

  1. if ( !function_exists( 'pods_evaluate_tag' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'pods-custom-content-types-and-fields/includes/data.php'; 
  3.  
  4. // The tag. 
  5. $tag = null; 
  6.  
  7. // Whether to sanitize tags 
  8. $sanitize = false; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = pods_evaluate_tag($tag, $sanitize); 
  12.  

Defined (1)

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

/includes/data.php  
  1. function pods_evaluate_tag( $tag, $sanitize = false ) { 
  2.  
  3. global $wpdb; 
  4.  
  5. // Handle pods_evaluate_tags 
  6. if ( is_array( $tag ) ) { 
  7. if ( !isset( $tag[ 2 ] ) && strlen( trim( $tag[ 2 ] ) ) < 1 ) { 
  8. return ''; 
  9.  
  10. $tag = $tag[ 2 ]; 
  11.  
  12. $tag = trim( $tag, ' {@}' ); 
  13. $tag = explode( '.', $tag ); 
  14.  
  15. if ( empty( $tag ) || !isset( $tag[ 0 ] ) || strlen( trim( $tag[ 0 ] ) ) < 1 ) { 
  16. return ''; 
  17.  
  18. // Fix formatting that may be after the first . 
  19. if ( 2 < count( $tag ) ) { 
  20. $first_tag = $tag[ 0 ]; 
  21. unset( $tag[ 0 ] ); 
  22.  
  23. $tag = array( 
  24. $first_tag,  
  25. implode( '.', $tag ) 
  26. ); 
  27.  
  28. foreach ( $tag as $k => $v ) { 
  29. $tag[ $k ] = trim( $v ); 
  30.  
  31. $value = ''; 
  32.  
  33. $single_supported = array( 
  34. 'template-url',  
  35. 'stylesheet-url',  
  36. 'site-url',  
  37. 'home-url',  
  38. 'admin-url',  
  39. 'includes-url',  
  40. 'content-url',  
  41. 'plugins-url',  
  42. 'network-site-url',  
  43. 'network-home-url',  
  44. 'network-admin-url',  
  45. 'user-admin-url',  
  46. 'prefix' 
  47. ); 
  48.  
  49. if ( in_array( $tag[ 0 ], $single_supported ) ) { 
  50. $value = pods_v( '', $tag[ 0 ], '', true ); 
  51. elseif ( 1 == count( $tag ) ) { 
  52. $value = pods_v( $tag[ 0 ], 'get', '', true ); 
  53. elseif ( 2 == count( $tag ) ) { 
  54. $value = pods_v( $tag[ 1 ], $tag[ 0 ], '', true ); 
  55.  
  56. $value = apply_filters( 'pods_evaluate_tag', $value, $tag ); 
  57.  
  58. if ( is_array( $value ) && 1 == count( $value ) ) { 
  59. $value = current( $value ); 
  60.  
  61. if ( is_array( $value ) ) { 
  62. $value = pods_serial_comma( $value ); 
  63.  
  64. if ( $sanitize ) { 
  65. $value = pods_sanitize( $value ); 
  66.  
  67. return $value; 
  68.