/core/fields/date_picker/date_picker.php

  1. <?php 
  2.  
  3. class acf_field_date_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 = 'date_picker'; 
  17. $this->label = __("Date Picker", 'acf'); 
  18. $this->category = __("jQuery", 'acf'); 
  19. $this->defaults = array( 
  20. 'date_format' => 'yymmdd',  
  21. 'display_format' => 'dd/mm/yy',  
  22. 'first_day' => 1, // monday 
  23. ); 
  24.  
  25.  
  26. // actions 
  27. add_action('init', array($this, 'init')); 
  28.  
  29.  
  30. // do not delete! 
  31. parent::__construct(); 
  32.  
  33.  
  34. /** 
  35. * init 
  36. * 
  37. * This function is run on the 'init' action to set the field's $l10n data. Before the init action,  
  38. * access to the $wp_locale variable is not possible. 
  39. * 
  40. * @type action (init) 
  41. * @date 3/09/13 
  42. * 
  43. * @param N/A 
  44. * @return N/A 
  45. */ 
  46.  
  47. function init() 
  48. global $wp_locale; 
  49.  
  50. $this->l10n = array( 
  51. 'closeText' => __( 'Done', 'acf' ),  
  52. 'currentText' => __( 'Today', 'acf' ),  
  53. 'monthNames' => array_values( $wp_locale->month ),  
  54. 'monthNamesShort' => array_values( $wp_locale->month_abbrev ),  
  55. 'monthStatus' => __( 'Show a different month', 'acf' ),  
  56. 'dayNames' => array_values( $wp_locale->weekday ),  
  57. 'dayNamesShort' => array_values( $wp_locale->weekday_abbrev ),  
  58. 'dayNamesMin' => array_values( $wp_locale->weekday_initial ),  
  59. 'isRTL' => isset($wp_locale->is_rtl) ? $wp_locale->is_rtl : false,  
  60. ); 
  61.  
  62.  
  63. /** 
  64. * create_field() 
  65. * 
  66. * Create the HTML interface for your field 
  67. * 
  68. * @param $field - an array holding all the field's data 
  69. * 
  70. * @type action 
  71. * @since 3.6 
  72. * @date 23/01/13 
  73. */ 
  74.  
  75. function create_field( $field ) 
  76. // make sure it's not blank 
  77. if( !$field['date_format'] ) 
  78. $field['date_format'] = 'yymmdd'; 
  79. if( !$field['display_format'] ) 
  80. $field['display_format'] = 'dd/mm/yy'; 
  81.  
  82.  
  83. // html 
  84. echo '<div class="acf-date_picker" data-save_format="' . $field['date_format'] . '" data-display_format="' . $field['display_format'] . '" data-first_day="' . $field['first_day'] . '">'; 
  85. echo '<input type="hidden" value="' . $field['value'] . '" name="' . $field['name'] . '" class="input-alt" />'; 
  86. echo '<input type="text" value="" class="input" />'; 
  87. echo '</div>'; 
  88.  
  89.  
  90. /** 
  91. * create_options() 
  92. * 
  93. * Create extra options for your field. This is rendered when editing a field. 
  94. * The value of $field['name'] can be used (like bellow) to save extra data to the $field 
  95. * 
  96. * @type action 
  97. * @since 3.6 
  98. * @date 23/01/13 
  99. * 
  100. * @param $field - an array holding all the field's data 
  101. */ 
  102.  
  103. function create_options( $field ) 
  104. // global 
  105. global $wp_locale; 
  106.  
  107.  
  108. // vars 
  109. $key = $field['name']; 
  110.  
  111. ?> 
  112. <tr class="field_option field_option_<?php echo $this->name; ?>"> 
  113. <td class="label"> 
  114. <label><?php _e("Save format", 'acf'); ?></label> 
  115. <p class="description"><?php _e("This format will determine the value saved to the database and returned via the API", 'acf'); ?></p> 
  116. <p><?php _e("\"yymmdd\" is the most versatile save format. Read more about", 'acf'); ?> <a href="http://docs.jquery.com/UI/Datepicker/formatDate"><?php _e("jQuery date formats", 'acf'); ?></a></p> 
  117. </td> 
  118. <td> 
  119. <?php  
  120. do_action('acf/create_field', array( 
  121. 'type' => 'text',  
  122. 'name' => 'fields[' .$key.'][date_format]',  
  123. 'value' => $field['date_format'],  
  124. )); 
  125. ?> 
  126. </td> 
  127. </tr> 
  128. <tr class="field_option field_option_<?php echo $this->name; ?>"> 
  129. <td class="label"> 
  130. <label><?php _e("Display format", 'acf'); ?></label> 
  131. <p class="description"><?php _e("This format will be seen by the user when entering a value", 'acf'); ?></p> 
  132. <p><?php _e("\"dd/mm/yy\" or \"mm/dd/yy\" are the most used display formats. Read more about", 'acf'); ?> <a href="http://docs.jquery.com/UI/Datepicker/formatDate" target="_blank"><?php _e("jQuery date formats", 'acf'); ?></a></p> 
  133. </td> 
  134. <td> 
  135. <?php  
  136. do_action('acf/create_field', array( 
  137. 'type' => 'text',  
  138. 'name' => 'fields[' .$key.'][display_format]',  
  139. 'value' => $field['display_format'],  
  140. )); 
  141. ?> 
  142. </td> 
  143. </tr> 
  144. <tr class="field_option field_option_<?php echo $this->name; ?>"> 
  145. <td class="label"> 
  146. <label for=""><?php _e("Week Starts On", 'acf'); ?></label> 
  147. </td> 
  148. <td> 
  149. <?php  
  150.  
  151. $choices = array_values( $wp_locale->weekday ); 
  152.  
  153. do_action('acf/create_field', array( 
  154. 'type' => 'select',  
  155. 'name' => 'fields['.$key.'][first_day]',  
  156. 'value' => $field['first_day'],  
  157. 'choices' => $choices,  
  158. )); 
  159.  
  160. ?> 
  161. </td> 
  162. </tr> 
  163. <?php 
  164.  
  165.  
  166.  
  167. new acf_field_date_picker(); 
  168.  
  169. ?> 
.