acf_field_true_false

The Advanced Custom Fields acf field true false class.

Defined (1)

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

/core/fields/true_false.php  
  1. class acf_field_true_false extends acf_field 
  2.  
  3. /** 
  4. * __construct 
  5. * Set name / label needed for actions / filters 
  6. * @since 3.6 
  7. * @date 23/01/13 
  8. */ 
  9.  
  10. function __construct() 
  11. // vars 
  12. $this->name = 'true_false'; 
  13. $this->label = __("True / False", 'acf'); 
  14. $this->category = __("Choice", 'acf'); 
  15. $this->defaults = array( 
  16. 'default_value' => 0,  
  17. 'message' => '',  
  18. ); 
  19.  
  20.  
  21. // do not delete! 
  22. parent::__construct(); 
  23.  
  24.  
  25.  
  26. /** 
  27. * create_field() 
  28. * Create the HTML interface for your field 
  29. * @param $field - an array holding all the field's data 
  30. * @type action 
  31. * @since 3.6 
  32. * @date 23/01/13 
  33. */ 
  34.  
  35. function create_field( $field ) 
  36. // html 
  37. echo '<ul class="acf-checkbox-list ' . $field['class'] . '">'; 
  38. echo '<input type="hidden" name="'.$field['name'].'" value="0" />'; 
  39. $selected = ($field['value'] == 1) ? 'checked="yes"' : ''; 
  40. echo '<li><label><input id="' . $field['id'] . '-1" type="checkbox" name="'.$field['name'].'" value="1" ' . $selected . ' />' . $field['message'] . '</label></li>'; 
  41.  
  42. echo '</ul>'; 
  43.  
  44.  
  45. /** 
  46. * create_options() 
  47. * Create extra options for your field. This is rendered when editing a field. 
  48. * The value of $field['name'] can be used (like bellow) to save extra data to the $field 
  49. * @type action 
  50. * @since 3.6 
  51. * @date 23/01/13 
  52. * @param $field - an array holding all the field's data 
  53. */ 
  54.  
  55. function create_options( $field ) 
  56. // vars 
  57. $key = $field['name']; 
  58.  
  59.  
  60. ?> 
  61. <tr class="field_option field_option_<?php echo $this->name; ?>"> 
  62. <td class="label"> 
  63. <label><?php _e("Message", 'acf'); ?></label> 
  64. <p class="description"><?php _e("eg. Show extra content", 'acf'); ?></a></p> 
  65. </td> 
  66. <td> 
  67. <?php  
  68. do_action('acf/create_field', array( 
  69. 'type' => 'text',  
  70. 'name' => 'fields['.$key.'][message]',  
  71. 'value' => $field['message'],  
  72. )); 
  73. ?> 
  74. </td> 
  75. </tr> 
  76. <tr class="field_option field_option_<?php echo $this->name; ?>"> 
  77. <td class="label"> 
  78. <label><?php _e("Default Value", 'acf'); ?></label> 
  79. </td> 
  80. <td> 
  81. <?php 
  82.  
  83. do_action('acf/create_field', array( 
  84. 'type' => 'true_false',  
  85. 'name' => 'fields['.$key.'][default_value]',  
  86. 'value' => $field['default_value'],  
  87. )); 
  88.  
  89. ?> 
  90. </td> 
  91. </tr> 
  92. <?php 
  93.  
  94.  
  95.  
  96. /** 
  97. * format_value_for_api() 
  98. * This filter is appied to the $value after it is loaded from the db and before it is passed back to the api functions such as the_field 
  99. * @type filter 
  100. * @since 3.6 
  101. * @date 23/01/13 
  102. * @param $value - the value which was loaded from the database 
  103. * @param $post_id - the $post_id from which the value was loaded 
  104. * @param $field - the field array holding all the field options 
  105. * @return $value - the modified value 
  106. */ 
  107.  
  108. function format_value_for_api( $value, $post_id, $field ) 
  109. $value = ($value == 1) ? true : false; 
  110.  
  111. return $value; 
  112.