Last active
October 6, 2017 20:34
-
-
Save MWDelaney/d571d8ff1738d85dd1734c03124bb6c2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace App; | |
| /** | |
| * WP Job Manager application form using Formidable or Formidable Pro | |
| * Version: 1.0 | |
| * Requires: WP Job Manager, Formidable, Advanced Custom Fields Pro | |
| * Author: Michael W. Delaney | |
| */ | |
| /** | |
| * Add Formidable Options Page in WP Job Manager Menu | |
| * @var [type] | |
| */ | |
| if( function_exists('acf_add_options_page') ) { | |
| // add sub page | |
| acf_add_options_sub_page(array( | |
| 'page_title' => 'WP Job Manager Formidable Pro Integration', | |
| 'menu_title' => 'Formidable', | |
| 'parent_slug' => 'edit.php?post_type=job_listing', | |
| )); | |
| } | |
| /** | |
| * Populate an ACF field with all Formidable forms | |
| * @return [type] [description] | |
| */ | |
| function get_forms(){ | |
| $results = array(); | |
| foreach (\FrmForm::get_published_forms() as $published_form) { | |
| $results[$published_form->id] = $published_form->name; | |
| } | |
| return $results; | |
| } | |
| /* auto populate acf field with form IDs */ | |
| add_filter('acf/load_field/name=choose_form', function( $field ) { | |
| $result = get_forms(); | |
| if( is_array($result) ){ | |
| $field['choices'] = array(); | |
| foreach( $result as $key=>$match ){ | |
| $field['choices'][ $key ] = $match; | |
| } | |
| } | |
| return $field; | |
| }); | |
| /** | |
| * Put our Formidable form into the Appy accordion. | |
| * @var [type] | |
| */ | |
| add_action( 'init', function() { | |
| global $job_manager; | |
| // Remove "Apply via email" action | |
| remove_action('job_manager_application_details_email', array( $job_manager->post_types, 'application_details_email')); | |
| // Add our shortcode | |
| add_action('job_manager_application_details_email', function() { | |
| echo \FrmFormsController::get_form_shortcode( | |
| array( | |
| 'id' => get_field("choose_form", 'option') | |
| ) | |
| ); | |
| }); | |
| }); | |
| /** | |
| * ACF Fields | |
| */ | |
| if( function_exists('acf_add_local_field_group') ): | |
| acf_add_local_field_group(array ( | |
| 'key' => 'group_59d7e1c8d9eda', | |
| 'title' => 'Application Form', | |
| 'fields' => array ( | |
| array ( | |
| 'key' => 'field_59d7e1d0201f4', | |
| 'label' => 'Choose Form', | |
| 'name' => 'choose_form', | |
| 'type' => 'select', | |
| 'instructions' => '', | |
| 'required' => 0, | |
| 'conditional_logic' => 0, | |
| 'wrapper' => array ( | |
| 'width' => '', | |
| 'class' => '', | |
| 'id' => '', | |
| ), | |
| 'choices' => array ( | |
| 2 => 'Test Form', | |
| ), | |
| 'default_value' => array ( | |
| ), | |
| 'allow_null' => 0, | |
| 'multiple' => 0, | |
| 'ui' => 1, | |
| 'ajax' => 0, | |
| 'return_format' => 'value', | |
| 'placeholder' => '', | |
| ), | |
| ), | |
| 'location' => array ( | |
| array ( | |
| array ( | |
| 'param' => 'options_page', | |
| 'operator' => '==', | |
| 'value' => 'acf-options-formidable', | |
| ), | |
| ), | |
| ), | |
| 'menu_order' => 0, | |
| 'position' => 'normal', | |
| 'style' => 'default', | |
| 'label_placement' => 'top', | |
| 'instruction_placement' => 'label', | |
| 'hide_on_screen' => '', | |
| 'active' => 1, | |
| 'description' => '', | |
| )); | |
| endif; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment