Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // MAKE SURE YOU READ THE COMMENT AT BOTTOM OF THIS PAGE REGARDING UPDATING THE TEMPLATE FILE
- // TO OUTPUT THE NEW DATE_END FIELD!!!
- // Admin Area
- add_filter( 'resume_manager_resume_experience_fields', 'smyles_custom_repeatable_fields_admin_experience' );
- add_filter( 'resume_manager_resume_education_fields', 'smyles_custom_repeatable_fields_admin_education' );
- // Frontend
- add_filter( 'submit_resume_form_fields', 'smyles_custom_repeatable_fields', 1 );
- /**
- * Customize Education Repeatable Fields (Admin Area)
- *
- * @param $fields
- *
- * @return array
- */
- function smyles_custom_repeatable_fields_admin_education( $fields ) {
- $fields['date'] = array(
- 'label' => __( 'Start Date' ),
- 'name' => 'resume_education_date[]',
- 'placeholder' => '',
- 'description' => '',
- 'required' => true,
- 'type' => 'fpdate'
- );
- $fields['date_end'] = array(
- 'label' => __( 'End Date' ),
- 'name' => 'resume_education_date_end[]',
- 'placeholder' => '',
- 'description' => '',
- 'required' => true,
- 'type' => 'fpdate'
- );
- return $fields;
- }
- /**
- * Customize Experience Repeatable Fields (Admin Area)
- *
- * @param $fields
- *
- * @return array
- */
- function smyles_custom_repeatable_fields_admin_experience( $fields ) {
- $fields['date'] = array(
- 'label' => __( 'Start Date' ),
- 'name' => 'resume_experience_date[]',
- 'placeholder' => '',
- 'description' => '',
- 'required' => true,
- 'type' => 'fpdate'
- );
- $fields['date_end'] = array(
- 'label' => __( 'End Date' ),
- 'name' => 'resume_experience_date_end[]',
- 'placeholder' => '',
- 'description' => '',
- 'required' => true,
- 'type' => 'fpdate'
- );
- return $fields;
- }
- /**
- * Frontend Repeatable Fields Customizations
- *
- * These are the customizations for the frontend of the site. If you update something here, make sure to update
- * it in the admin fields above as frontend and admin use different configurations.
- *
- * @param $fields
- *
- * @return array
- */
- function smyles_custom_repeatable_fields( $fields ) {
- if ( ! isset( $fields['resume_fields'], $fields['resume_fields']['candidate_education'], $fields['resume_fields']['candidate_experience'] ) ) {
- return $fields;
- }
- // Remove notes and store temporarily so fields are in order (priority does not work on repeatable fields)
- $edu_notes = $fields['resume_fields']['candidate_education']['fields']['notes'];
- unset( $fields['resume_fields']['candidate_education']['fields']['notes'] );
- // Customize default 'date' field
- $fields['resume_fields']['candidate_education']['fields']['date'] = array(
- 'label' => __( 'Start Date' ),
- 'placeholder' => '',
- 'description' => '',
- 'required' => true,
- 'type' => 'fpdate',
- 'priority' => 3
- );
- // Add new custom 'date_end' field
- $fields['resume_fields']['candidate_education']['fields']['date_end'] = array(
- 'label' => __( 'End Date' ),
- 'placeholder' => '',
- 'description' => '',
- 'required' => true,
- 'type' => 'fpdate',
- 'priority' => 4
- );
- // Add notes field back to be at end of array
- $fields['resume_fields']['candidate_education']['fields']['notes'] = $edu_notes;
- // Remove notes and store temporarily so fields are in order (priority does not work on repeatable fields)
- $exp_notes = $fields['resume_fields']['candidate_experience']['fields']['notes'];
- unset( $fields['resume_fields']['candidate_experience']['fields']['notes'] );
- // Customize default 'date' field
- $fields['resume_fields']['candidate_experience']['fields']['date'] = array(
- 'label' => __( 'Start Date' ),
- 'placeholder' => '',
- 'description' => '',
- 'required' => true,
- 'type' => 'fpdate',
- 'priority' => 3
- );
- // Add new custom 'date_end' field
- $fields['resume_fields']['candidate_experience']['fields']['date_end'] = array(
- 'label' => __( 'End Date' ),
- 'placeholder' => '',
- 'description' => '',
- 'required' => true,
- 'type' => 'fpdate',
- 'priority' => 4
- );
- // Add notes field back to be at end of array
- $fields['resume_fields']['candidate_experience']['fields']['notes'] = $exp_notes;
- return $fields;
- }
- // Output custom JS in FRONTEND to initialize form fields in repeatable experience fields
- add_action( 'submit_resume_form_start', 'smyles_resume_subfields_frontend_js_init' );
- /**
- * Custom Resume Form jQuery for Date Pickers Output
- */
- function smyles_resume_subfields_frontend_js_init() {
- wp_enqueue_script( 'jmfe-fpdate-field' );
- wp_enqueue_style( 'jmfe-flatpickr-style' );
- // Flatpickr Custom Theme
- if ( wp_style_is( 'jmfe-flatpickr-theme', 'registered' ) && ! wp_style_is( 'jmfe-flatpickr-theme', 'enqueued' ) ) {
- wp_enqueue_style( 'jmfe-flatpickr-theme' );
- }
- echo "<script>jQuery( function( $ ){
- $( '.resume-manager-add-row' ).click( function(){
- // Outside to maintain this reference
- var dataParent = $(this).parent();
- setTimeout( function(){
- // After 500ms search for newly added repeatable
- var dataRow = dataParent.find( '.resume-manager-data-row:last' );
- jmfe_fpdate_field.mode = 'single';
- dataRow.find( '.jmfe-fpdate-picker' ).flatpickr( jmfe_fpdate_field );
- }, 500 );
- });
- });</script>";
- }
- // Output custom JS in ADMIN to initialize form fields in repeatable experience fields
- add_action( 'admin_print_footer_scripts', 'smyles_resume_subfields_admin_js_init' );
- /**
- * Custom Resume Form jQuery for Date Pickers Output (Admin Area)
- */
- function smyles_resume_subfields_admin_js_init() {
- // Only load JS on resume post type!!
- if ( get_post_type() !== 'resume' ) {
- return;
- }
- wp_enqueue_script( 'jmfe-fpdate-field' );
- wp_enqueue_style( 'jmfe-flatpickr-style' );
- // Flatpickr Custom Theme
- if ( wp_style_is( 'jmfe-flatpickr-theme', 'registered' ) && ! wp_style_is( 'jmfe-flatpickr-theme', 'enqueued' ) ) {
- wp_enqueue_style( 'jmfe-flatpickr-theme' );
- }
- echo "<script>
- jQuery( function( $ ){
- // Init on add
- $( 'input.resume_manager_add_row' ).click( function(){
- // Outside to maintain this reference
- var dataParent = $(this).closest( 'table' );
- setTimeout( function(){
- dataParent.find( 'tr:last .jmfe-fpdate-picker' ).flatpickr( jmfe_fpdate_field );
- }, 500 );
- });
- //$( '.jmfe-fpdate-picker' ).flatpickr( jmfe_fpdate_field );
- });
- </script>";
- }
Add Comment
Please, Sign In to add comment