Guest User

Untitled

a guest
Dec 7th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.20 KB | None | 0 0
  1. <?php
  2.  
  3. // MAKE SURE YOU READ THE COMMENT AT BOTTOM OF THIS PAGE REGARDING UPDATING THE TEMPLATE FILE
  4. // TO OUTPUT THE NEW DATE_END FIELD!!!
  5.  
  6. // Admin Area
  7. add_filter( 'resume_manager_resume_experience_fields', 'smyles_custom_repeatable_fields_admin_experience' );
  8. add_filter( 'resume_manager_resume_education_fields', 'smyles_custom_repeatable_fields_admin_education' );
  9.  
  10. // Frontend
  11. add_filter( 'submit_resume_form_fields', 'smyles_custom_repeatable_fields', 1 );
  12.  
  13. /**
  14. * Customize Education Repeatable Fields (Admin Area)
  15. *
  16. * @param $fields
  17. *
  18. * @return array
  19. */
  20. function smyles_custom_repeatable_fields_admin_education( $fields ) {
  21.  
  22. $fields['date'] = array(
  23. 'label' => __( 'Start Date' ),
  24. 'name' => 'resume_education_date[]',
  25. 'placeholder' => '',
  26. 'description' => '',
  27. 'required' => true,
  28. 'type' => 'fpdate'
  29. );
  30.  
  31. $fields['date_end'] = array(
  32. 'label' => __( 'End Date' ),
  33. 'name' => 'resume_education_date_end[]',
  34. 'placeholder' => '',
  35. 'description' => '',
  36. 'required' => true,
  37. 'type' => 'fpdate'
  38. );
  39.  
  40. return $fields;
  41. }
  42.  
  43. /**
  44. * Customize Experience Repeatable Fields (Admin Area)
  45. *
  46. * @param $fields
  47. *
  48. * @return array
  49. */
  50. function smyles_custom_repeatable_fields_admin_experience( $fields ) {
  51.  
  52. $fields['date'] = array(
  53. 'label' => __( 'Start Date' ),
  54. 'name' => 'resume_experience_date[]',
  55. 'placeholder' => '',
  56. 'description' => '',
  57. 'required' => true,
  58. 'type' => 'fpdate'
  59. );
  60.  
  61. $fields['date_end'] = array(
  62. 'label' => __( 'End Date' ),
  63. 'name' => 'resume_experience_date_end[]',
  64. 'placeholder' => '',
  65. 'description' => '',
  66. 'required' => true,
  67. 'type' => 'fpdate'
  68. );
  69.  
  70. return $fields;
  71. }
  72.  
  73. /**
  74. * Frontend Repeatable Fields Customizations
  75. *
  76. * These are the customizations for the frontend of the site. If you update something here, make sure to update
  77. * it in the admin fields above as frontend and admin use different configurations.
  78. *
  79. * @param $fields
  80. *
  81. * @return array
  82. */
  83. function smyles_custom_repeatable_fields( $fields ) {
  84.  
  85. if ( ! isset( $fields['resume_fields'], $fields['resume_fields']['candidate_education'], $fields['resume_fields']['candidate_experience'] ) ) {
  86. return $fields;
  87. }
  88.  
  89. // Remove notes and store temporarily so fields are in order (priority does not work on repeatable fields)
  90. $edu_notes = $fields['resume_fields']['candidate_education']['fields']['notes'];
  91. unset( $fields['resume_fields']['candidate_education']['fields']['notes'] );
  92.  
  93. // Customize default 'date' field
  94. $fields['resume_fields']['candidate_education']['fields']['date'] = array(
  95. 'label' => __( 'Start Date' ),
  96. 'placeholder' => '',
  97. 'description' => '',
  98. 'required' => true,
  99. 'type' => 'fpdate',
  100. 'priority' => 3
  101. );
  102.  
  103. // Add new custom 'date_end' field
  104. $fields['resume_fields']['candidate_education']['fields']['date_end'] = array(
  105. 'label' => __( 'End Date' ),
  106. 'placeholder' => '',
  107. 'description' => '',
  108. 'required' => true,
  109. 'type' => 'fpdate',
  110. 'priority' => 4
  111. );
  112.  
  113. // Add notes field back to be at end of array
  114. $fields['resume_fields']['candidate_education']['fields']['notes'] = $edu_notes;
  115.  
  116. // Remove notes and store temporarily so fields are in order (priority does not work on repeatable fields)
  117. $exp_notes = $fields['resume_fields']['candidate_experience']['fields']['notes'];
  118. unset( $fields['resume_fields']['candidate_experience']['fields']['notes'] );
  119.  
  120. // Customize default 'date' field
  121. $fields['resume_fields']['candidate_experience']['fields']['date'] = array(
  122. 'label' => __( 'Start Date' ),
  123. 'placeholder' => '',
  124. 'description' => '',
  125. 'required' => true,
  126. 'type' => 'fpdate',
  127. 'priority' => 3
  128. );
  129.  
  130. // Add new custom 'date_end' field
  131. $fields['resume_fields']['candidate_experience']['fields']['date_end'] = array(
  132. 'label' => __( 'End Date' ),
  133. 'placeholder' => '',
  134. 'description' => '',
  135. 'required' => true,
  136. 'type' => 'fpdate',
  137. 'priority' => 4
  138. );
  139.  
  140. // Add notes field back to be at end of array
  141. $fields['resume_fields']['candidate_experience']['fields']['notes'] = $exp_notes;
  142.  
  143. return $fields;
  144. }
  145.  
  146. // Output custom JS in FRONTEND to initialize form fields in repeatable experience fields
  147. add_action( 'submit_resume_form_start', 'smyles_resume_subfields_frontend_js_init' );
  148.  
  149. /**
  150. * Custom Resume Form jQuery for Date Pickers Output
  151. */
  152. function smyles_resume_subfields_frontend_js_init() {
  153.  
  154. wp_enqueue_script( 'jmfe-fpdate-field' );
  155. wp_enqueue_style( 'jmfe-flatpickr-style' );
  156.  
  157. // Flatpickr Custom Theme
  158. if ( wp_style_is( 'jmfe-flatpickr-theme', 'registered' ) && ! wp_style_is( 'jmfe-flatpickr-theme', 'enqueued' ) ) {
  159. wp_enqueue_style( 'jmfe-flatpickr-theme' );
  160. }
  161.  
  162. echo "<script>jQuery( function( $ ){
  163.  
  164. $( '.resume-manager-add-row' ).click( function(){
  165. // Outside to maintain this reference
  166. var dataParent = $(this).parent();
  167.  
  168. setTimeout( function(){
  169. // After 500ms search for newly added repeatable
  170. var dataRow = dataParent.find( '.resume-manager-data-row:last' );
  171. jmfe_fpdate_field.mode = 'single';
  172. dataRow.find( '.jmfe-fpdate-picker' ).flatpickr( jmfe_fpdate_field );
  173. }, 500 );
  174. });
  175.  
  176. });</script>";
  177. }
  178.  
  179. // Output custom JS in ADMIN to initialize form fields in repeatable experience fields
  180. add_action( 'admin_print_footer_scripts', 'smyles_resume_subfields_admin_js_init' );
  181.  
  182. /**
  183. * Custom Resume Form jQuery for Date Pickers Output (Admin Area)
  184. */
  185. function smyles_resume_subfields_admin_js_init() {
  186.  
  187. // Only load JS on resume post type!!
  188. if ( get_post_type() !== 'resume' ) {
  189. return;
  190. }
  191.  
  192. wp_enqueue_script( 'jmfe-fpdate-field' );
  193. wp_enqueue_style( 'jmfe-flatpickr-style' );
  194. // Flatpickr Custom Theme
  195. if ( wp_style_is( 'jmfe-flatpickr-theme', 'registered' ) && ! wp_style_is( 'jmfe-flatpickr-theme', 'enqueued' ) ) {
  196. wp_enqueue_style( 'jmfe-flatpickr-theme' );
  197. }
  198.  
  199. echo "<script>
  200. jQuery( function( $ ){
  201.  
  202. // Init on add
  203. $( 'input.resume_manager_add_row' ).click( function(){
  204.  
  205. // Outside to maintain this reference
  206. var dataParent = $(this).closest( 'table' );
  207.  
  208. setTimeout( function(){
  209. dataParent.find( 'tr:last .jmfe-fpdate-picker' ).flatpickr( jmfe_fpdate_field );
  210. }, 500 );
  211. });
  212.  
  213. //$( '.jmfe-fpdate-picker' ).flatpickr( jmfe_fpdate_field );
  214. });
  215. </script>";
  216. }
Add Comment
Please, Sign In to add comment