frontier_if_block

Processes if condition within a template.

Description

(string) frontier_if_block( (array) $atts, (string) $code ); 

Returns (string)

Parameters (2)

0. $atts (array)
Attributes from template
1. $code (string)
Encoded template to be decoded

Usage

  1. if ( !function_exists( 'frontier_if_block' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'pods-custom-content-types-and-fields/components/Templates/includes/functions-view_template.php'; 
  3.  
  4. // attributes from template 
  5. $atts = array(); 
  6.  
  7. // encoded template to be decoded 
  8. $code = ''; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = frontier_if_block($atts, $code); 
  12.  

Defined (1)

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

/components/Templates/includes/functions-view_template.php  
  1. function frontier_if_block( $atts, $code ) { 
  2.  
  3. $pod =pods $atts[ pod ], $atts[ 'id' ] ); 
  4. $code = explode( '[else]', frontier_decode_template( $code, $atts ) ); 
  5.  
  6. $template = pods_do_shortcode( $pod->do_magic_tags( $code[ 0 ] ), array( 'each', 'pod_sub_template', 'once', 'pod_once_template', 'before', 'pod_before_template', 'after', 'pod_after_template', 'if', 'pod_if_field' ) ); 
  7.  
  8. // sysvals 
  9. $system_values = array( 
  10. '_index',  
  11. ); 
  12.  
  13. // field data 
  14. $field_data = null; 
  15.  
  16. if ( in_array( $atts[ 'field' ], $system_values) ) { 
  17. switch ( $atts[ 'field' ] ) { 
  18. case '_index': 
  19. $field_data = $atts['index']; 
  20. break; 
  21. else{ 
  22.  
  23. $field_data = $pod->field( $atts[ 'field' ] ); 
  24.  
  25.  
  26. if ( ! empty( $field_data ) || isset( $atts[ 'value' ] ) ) { 
  27. // theres a field - let go deeper 
  28. if ( isset( $atts[ 'value' ] ) ) { 
  29.  
  30. // check if + or - are present 
  31. if( substr( $atts[ 'value' ], 0, 1) === '+' ) { 
  32. // is greater 
  33. $atts[ 'value' ] = (float) substr( $atts[ 'value' ], 1) + 1; 
  34. if( (float) $field_data > $atts[ 'value' ] ) { 
  35. // is greater - set it the same to allow 
  36. $atts[ 'value' ] = $field_data; 
  37.  
  38. }elseif( substr( $atts[ 'value' ], 0, 1) === '-' ) { 
  39. // is smaller 
  40. $atts[ 'value' ] = (float) substr( $atts[ 'value' ], 1) - 1; 
  41. if( (float) $field_data < $atts[ 'value' ] ) { 
  42. // is greater - set it the same to allow 
  43. $atts[ 'value' ] = $field_data; 
  44.  
  45.  
  46. if ( $field_data == $atts[ 'value' ] ) { 
  47. return pods_do_shortcode( $template, array( 'each', 'pod_sub_template', 'once', 'pod_once_template', 'before', 'pod_before_template', 'after', 'pod_after_template', 'if', 'pod_if_field' ) ); 
  48. } else { 
  49. if ( isset( $code[ 1 ] ) ) { 
  50. $template = pods_do_shortcode( $pod->do_magic_tags( $code[ 1 ] ), array( 'each', 'pod_sub_template', 'once', 'pod_once_template', 'before', 'pod_before_template', 'after', 'pod_after_template', 'if', 'pod_if_field' ) ); 
  51.  
  52. return pods_do_shortcode( $template, array( 'each', 'pod_sub_template', 'once', 'pod_once_template', 'before', 'pod_before_template', 'after', 'pod_after_template', 'if', 'pod_if_field' ) ); 
  53. } else { 
  54. // Value did not match, nothing should be displayed 
  55. return ''; 
  56.  
  57. return pods_do_shortcode( $template, array( 'each', 'pod_sub_template', 'once', 'pod_once_template', 'before', 'pod_before_template', 'after', 'pod_after_template', 'if', 'pod_if_field' ) ); 
  58. else { 
  59. if ( isset( $code[ 1 ] ) ) { 
  60. $template = pods_do_shortcode( $pod->do_magic_tags( $code[ 1 ] ), array( 'each', 'pod_sub_template', 'once', 'pod_once_template', 'before', 'pod_before_template', 'after', 'pod_after_template', 'if', 'pod_if_field' ) ); 
  61.  
  62. return $template; 
  63.