/core/fields/color_picker.php

  1. <?php 
  2.  
  3. class acf_field_color_picker extends acf_field 
  4.  
  5. /** 
  6. * __construct 
  7. * 
  8. * Set name / label needed for actions / filters 
  9. * 
  10. * @since 3.6 
  11. * @date 23/01/13 
  12. */ 
  13.  
  14. function __construct() 
  15. // vars 
  16. $this->name = 'color_picker'; 
  17. $this->label = __("Color Picker", 'acf'); 
  18. $this->category = __("jQuery", 'acf'); 
  19. $this->defaults = array( 
  20. 'default_value' => '',  
  21. ); 
  22.  
  23.  
  24. // do not delete! 
  25. parent::__construct(); 
  26.  
  27.  
  28.  
  29. /** 
  30. * create_field() 
  31. * 
  32. * Create the HTML interface for your field 
  33. * 
  34. * @param $field - an array holding all the field's data 
  35. * 
  36. * @type action 
  37. * @since 3.6 
  38. * @date 23/01/13 
  39. */ 
  40.  
  41. function create_field( $field ) 
  42. // vars 
  43. $o = array( 'id', 'class', 'name', 'value' ); 
  44. $e = ''; 
  45.  
  46.  
  47. $e .= '<div class="acf-color_picker">'; 
  48. $e .= '<input type="text"'; 
  49.  
  50. foreach( $o as $k ) 
  51. $e .= ' ' . $k . '="' . esc_attr( $field[ $k ] ) . '"';  
  52.  
  53. $e .= ' />'; 
  54. $e .= '</div>'; 
  55.  
  56.  
  57. // return 
  58. echo $e; 
  59.  
  60.  
  61. /** 
  62. * create_options() 
  63. * 
  64. * Create extra options for your field. This is rendered when editing a field. 
  65. * The value of $field['name'] can be used (like bellow) to save extra data to the $field 
  66. * 
  67. * @type action 
  68. * @since 3.6 
  69. * @date 23/01/13 
  70. * 
  71. * @param $field - an array holding all the field's data 
  72. */ 
  73.  
  74. function create_options( $field ) 
  75. // vars 
  76. $key = $field['name']; 
  77.  
  78. ?> 
  79. <tr class="field_option field_option_<?php echo $this->name; ?>"> 
  80. <td class="label"> 
  81. <label><?php _e("Default Value", 'acf'); ?></label> 
  82. </td> 
  83. <td> 
  84. <?php  
  85. do_action('acf/create_field', array( 
  86. 'type' => 'text',  
  87. 'name' => 'fields[' .$key.'][default_value]',  
  88. 'value' => $field['default_value'],  
  89. 'placeholder' => '#ffffff' 
  90. )); 
  91. ?> 
  92. </td> 
  93. </tr> 
  94. <?php 
  95.  
  96.  
  97.  
  98. new acf_field_color_picker(); 
  99.  
  100. ?> 
.