Changeset 3313297
- Timestamp:
- 06/17/2025 02:03:06 PM (8 months ago)
- Location:
- sync-forms-with-brilliant-directories/trunk
- Files:
-
- 8 edited
-
assets/js/brildirformsync-script.js (modified) (8 diffs)
-
includes/class-brildirformsync-activator.php (modified) (1 diff)
-
includes/class-brildirformsync-api.php (modified) (5 diffs)
-
includes/class-brildirformsync-display.php (modified) (1 diff)
-
includes/class-brildirformsync-errorlog.php (modified) (1 diff)
-
includes/class-brildirformsync-menu.php (modified) (12 diffs)
-
readme.txt (modified) (2 diffs)
-
sync-forms-with-brilliant-directories.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
sync-forms-with-brilliant-directories/trunk/assets/js/brildirformsync-script.js
r3310605 r3313297 87 87 { id: 'brillforms_select_plugin_label', content: 'Choose the form plugin to use for this sync. Only active plugins on your WordPress site will appear.' }, 88 88 { id: 'brillforms_select_form_label', content: 'Choose the form from the selected plugin to sync. Only forms from the selected plugin will appear.' }, 89 { id: 'brillforms_select_wpforms_label', content: 'Choose the form from the selected plugin to sync. Only forms from the selected plugin will appear.' }, 89 90 { id: 'brillforms_create_option_label', content: 'Select the type of record you want to create (e.g., Member, Lead). The same action for the same form cannot be created more than once.'}, 90 91 { id: 'brillforms_allow_lead_label', content: 'Select whether to allow multiple lead submissions from the same email address. If disabled, only one lead per email is allowed.' }, … … 113 114 114 115 116 function brillhideformwrap(brillselectPlugin) { 117 $('#brillforms_cf7_forms_wrap, #brillforms_wpforms_wrap').hide(); 118 $('#brillforms_cf7_forms, #brillforms_wpforms_forms').prop('disabled', true); 119 120 if (brillselectPlugin === 'contact_form_7') { 121 $('#brillforms_cf7_forms_wrap').show(); 122 $('#brillforms_cf7_forms').prop('disabled', false); 123 } else if (brillselectPlugin === 'wpforms') { 124 $('#brillforms_wpforms_wrap').show(); 125 $('#brillforms_wpforms_forms').prop('disabled', false); 126 } 127 } 128 115 129 $('#brillforms_form_plugin').on('change', function () { 116 if ($(this).val() === 'contact_form_7') { 117 $('#brillforms_cf7_forms_wrap').show(); 118 } else { 119 $('#brillforms_cf7_forms_wrap').hide(); 120 $('#brillforms_fields_wrap').html(''); 121 } 122 }); 130 $('#brillforms_cf7_forms, #brillforms_wpforms_forms').val(''); 131 const brillselectedPlugin = $(this).val(); 132 brillhideformwrap(brillselectedPlugin); 133 }); 134 135 const brillinitialcheckPlugin = $('#brillforms_form_plugin').val(); 136 brillhideformwrap(brillinitialcheckPlugin); 137 123 138 124 139 var brillforms_create_option = $('#brillforms_create_option').val(); … … 132 147 133 148 $('#brillforms_cf7_forms').on('change', function () { 149 $('#brillforms_create_option').val(''); 150 $('#brillforms_fields_wrap').html(''); 151 $('#brill_plan_id').hide(); 152 153 }); 154 $('#brillforms_wpforms_forms').on('change', function () { 134 155 $('#brillforms_create_option').val(''); 135 156 $('#brillforms_fields_wrap').html(''); … … 147 168 $('#brill_plan_id').hide(); 148 169 } 149 var formId = $('#brillforms_cf7_forms').val(); 170 var brill_plugin = $('#brillforms_form_plugin').val(); 171 if(brill_plugin === 'contact_form_7'){ 172 var formId = $('#brillforms_cf7_forms').val(); 173 } else if(brill_plugin === 'wpforms'){ 174 var formId = $('#brillforms_wpforms_forms').val(); 175 } 150 176 var createOption = $('#brillforms_create_option').val(); 151 177 … … 155 181 data: { 156 182 action: 'brildir_sfwbd_load_cf7_form_fields', 183 brill_plugin : brill_plugin, 157 184 form_id: formId, 158 185 post_id: $('#post_ID').val(), … … 175 202 }); 176 203 }); 204 177 205 const selectedPlugin = $('#brillforms_form_plugin').val(); 178 const selectedForm = $('#brillforms_cf7_forms').val();179 180 206 if (selectedPlugin === 'contact_form_7') { 207 $('#brillforms_wpforms_wrap').hide(); 181 208 $('#brillforms_cf7_forms_wrap').show(); 182 183 if (selectedForm) { 184 $('#brillforms_create_option').trigger('change'); 185 } 209 $('#brillforms_create_option').trigger('change'); 210 } else if (selectedPlugin === 'wpforms') { 211 $('#brillforms_cf7_forms_wrap').hide(); 212 $('#brillforms_wpforms_wrap').show(); 213 $('#brillforms_create_option').trigger('change'); 186 214 } else { 187 215 $('#brillforms_cf7_forms_wrap').hide(); … … 562 590 // $('.brillforms_lead_fields').trigger('change.select2'); 563 591 564 565 const $ formSelect = $('#brillforms_cf7_forms');592 const $cfformSelect = $('#brillforms_cf7_forms'); 593 const $wpformSelect = $('#brillforms_wpforms_forms'); 566 594 const $actionSelect = $('#brillforms_create_option'); 567 595 var post_id = brildirformsyncSettings.post_id; … … 610 638 611 639 // Initial check 612 if ($ formSelect.val()) {613 fetchUsedActions($ formSelect.val());640 if ($cfformSelect.val()) { 641 fetchUsedActions($cfformSelect.val()); 614 642 } 615 643 616 644 // Re-check on form change 617 $formSelect.on('change', function () { 645 $cfformSelect.on('change', function () { 646 const formId = $(this).val(); 647 if (formId) { 648 fetchUsedActions(formId); 649 } 650 }); 651 652 // Initial check 653 if ($wpformSelect.val()) { 654 fetchUsedActions($wpformSelect.val()); 655 } 656 657 // Re-check on form change 658 $wpformSelect.on('change', function () { 618 659 const formId = $(this).val(); 619 660 if (formId) { -
sync-forms-with-brilliant-directories/trunk/includes/class-brildirformsync-activator.php
r3310605 r3313297 9 9 { 10 10 11 update_option('brildir_sfwbd_allow_lead', ' no');11 update_option('brildir_sfwbd_allow_lead', 'yes'); 12 12 13 13 global $wpdb; -
sync-forms-with-brilliant-directories/trunk/includes/class-brildirformsync-api.php
r3310605 r3313297 7 7 8 8 add_action('wpcf7_before_send_mail', 'Brildir_Sfwbd_Handle_Cf7_submission'); 9 10 9 function Brildir_Sfwbd_Handle_Cf7_submission($contact_form) 11 10 { … … 103 102 } 104 103 104 add_action('wpforms_process_complete', 'Brildir_Sfwbd_Handle_WPForms_Submission', 10, 4); 105 function Brildir_Sfwbd_Handle_WPForms_Submission($fields, $entry, $form_data, $entry_id) 106 { 107 $form_id = absint($form_data['id']); 108 109 // Get all synced brillforms posts for WPForms 110 $query = new WP_Query([ 111 'post_type' => 'brildir-sfwbd', 112 'posts_per_page' => -1, 113 'post_status' => 'publish', 114 'meta_query' => [ 115 [ 116 'key' => '_brildir_sfwbd_form_plugin', 117 'value' => 'wpforms', 118 ], 119 [ 120 'key' => '_brildir_sfwbd_form_id', 121 'value' => $form_id, 122 ], 123 ], 124 'no_found_rows' => true, 125 'fields' => 'all', 126 ]); 127 128 if (!$query->have_posts()) { 129 return; 130 } 131 132 foreach ($query->posts as $brillsync_form) { 133 $post_id = $brillsync_form->ID; 134 135 $brill_create_option = get_post_meta($post_id, '_brildir_sfwbd_create_option', true); 136 $brill_field_map = get_post_meta($post_id, '_brildir_sfwbd_field_map', true); 137 $brill_custom_field_map = get_post_meta($post_id, '_brildir_sfwbd_field_map_custom', true); 138 $brill_form_plugin = get_post_meta($post_id, '_brildir_sfwbd_form_plugin', true); 139 $brill_form_id = get_post_meta($post_id, '_brildir_sfwbd_form_id', true); 140 $brillsync_form_post = get_post($brill_form_id); 141 $brill_form_name = $brillsync_form_post ? $brillsync_form_post->post_title : 'WPForm'; 142 143 // Get the specific form mapping 144 $brill_form_mapping = $brill_field_map[$form_id] ?? []; 145 146 $brill_map_data = []; 147 148 // Process mapped fields 149 foreach ($brill_form_mapping as $form_field => $bd_field) { 150 foreach ($fields as $field_id => $field_data) { 151 if ((string) $field_id === (string) $form_field) { 152 $brill_map_data[$bd_field] = sanitize_text_field($field_data['value']); 153 } 154 } 155 } 156 157 // Add custom fields 158 if (!is_array($brill_custom_field_map)) { 159 $brill_custom_field_map = []; 160 } 161 162 foreach ($brill_custom_field_map as $brill_field_key => $brill_field_value) { 163 foreach ($brill_field_value as $brill_cus_key => $brill_cus_value) { 164 $brill_map_data[$brill_cus_key] = $brill_cus_value; 165 } 166 } 167 168 // Add subscription ID or status 169 if ($brill_create_option === 'user') { 170 $brill_subscription_id = get_post_meta($post_id, '_brildir_sfwbd_subscription_id', true); 171 if (!empty($brill_subscription_id)) { 172 $brill_map_data['subscription_id'] = sanitize_text_field($brill_subscription_id); 173 } 174 } elseif ($brill_create_option === 'leads') { 175 $brill_map_data['status'] = '1'; 176 } 177 178 // Send to BD API 179 $Brillforms_api_req = Brildir_Sfwbd_Send_To_Bd_api($brill_create_option, $brill_map_data, $brill_form_plugin, $brill_form_name); 180 181 if ($Brillforms_api_req === "success") { 182 // Sync count 183 $current_count = (int) get_post_meta($post_id, '_brildir_sfwbd_sync_count', true); 184 update_post_meta($post_id, '_brildir_sfwbd_sync_count', $current_count + 1); 185 186 // Last sync timestamp 187 update_post_meta($post_id, '_brildir_sfwbd_last_sync_date', current_time('mysql')); 188 } 189 } 190 191 wp_reset_postdata(); 192 } 105 193 106 194 function Brildir_Sfwbd_Send_To_Bd_api($brill_create_type, $brill_map_data, $brill_form_plugin, $brill_form_name) … … 120 208 if ($brill_create_type === 'user') { 121 209 $bd_customer_email = $brill_map_data['email']; 122 } else {210 } elseif ($brill_create_type === 'leads') { 123 211 $bd_customer_email = $brill_map_data['lead_email']; 124 212 } … … 144 232 $search_url 145 233 ); 146 } else {234 } elseif ($brill_create_type === 'leads') { 147 235 $search_url = add_query_arg( 148 236 array( … … 154 242 ); 155 243 } 156 157 244 158 245 $search_args = array( -
sync-forms-with-brilliant-directories/trunk/includes/class-brildirformsync-display.php
r3310605 r3313297 28 28 case 'brildir_sfwbd_form_plugin': 29 29 $brillsync_form_plugin = get_post_meta($post_id, '_brildir_sfwbd_form_plugin', true); 30 $brill_form_plugin = get_post_meta($post_id, '_brildir_sfwbd_plugin_name', true); 31 if ($brill_form_plugin) { 30 31 $brill_form_plugin = ''; 32 if($brillsync_form_plugin === 'contact_form_7'){ 32 33 if (is_plugin_active('contact-form-7/wp-contact-form-7.php')) { 33 update_post_meta($post_id, '_brildir_sfwbd_plugin_name', 'Contact Form 7');34 echo esc_html ($brill_form_plugin);34 $brill_form_plugin = 'Contact form 7'; 35 echo esc_html__('Contact form 7', 'sync-forms-with-brilliant-directories'); 35 36 } else { 37 $brill_form_plugin = 'Contact Form 7 Plugin Not Found'; 36 38 echo esc_html__('Contact Form 7 Plugin Not Found', 'sync-forms-with-brilliant-directories'); 37 update_post_meta($post_id, '_brildir_sfwbd_plugin_name', 'Contact Form 7 Plugin Not Found');38 39 } 39 } 40 } elseif($brillsync_form_plugin === 'wpforms'){ 41 if (is_plugin_active('wpforms-lite/wpforms.php')) { 42 $brill_form_plugin = 'wpforms'; 43 echo esc_html__('wpforms', 'sync-forms-with-brilliant-directories'); 44 } else { 45 $brill_form_plugin = 'wpforms Plugin Not Found'; 46 echo esc_html__('wpforms Plugin Not Found', 'sync-forms-with-brilliant-directories'); 47 } 48 } 49 update_post_meta($post_id, '_brildir_sfwbd_plugin_name', $brill_form_plugin); 40 50 break; 41 51 -
sync-forms-with-brilliant-directories/trunk/includes/class-brildirformsync-errorlog.php
r3310605 r3313297 69 69 foreach ($results as $row) { 70 70 echo '<tr>'; 71 $brill_form_plugin = ucfirst(str_replace('_', ' ', $row->form_plugin)); 71 72 if ($row->form_plugin === 'contact_form_7') { 72 73 $brill_form_plugin = 'Contact Form 7'; -
sync-forms-with-brilliant-directories/trunk/includes/class-brildirformsync-menu.php
r3310605 r3313297 18 18 $brillforms_create_option = get_post_meta($post->ID, '_brildir_sfwbd_create_option', true); 19 19 $brillforms_subscription_id = get_post_meta($post->ID, '_brildir_sfwbd_subscription_id', true); 20 21 // Detect active form plugins22 $form_plugins = [];23 24 if (is_plugin_active('contact-form-7/wp-contact-form-7.php')) {25 $form_plugins['contact_form_7'] = esc_html__('Contact Form 7', 'sync-forms-with-brilliant-directories');26 }27 28 if (is_plugin_active('gravityforms/gravityforms.php')) {29 $form_plugins['gravity_forms'] = esc_html__('Gravity Forms', 'sync-forms-with-brilliant-directories');30 }31 32 if (is_plugin_active('ninja-forms/ninja-forms.php')) {33 $form_plugins['ninja_forms'] = esc_html__('Ninja Forms', 'sync-forms-with-brilliant-directories');34 }35 36 if (is_plugin_active('wpforms-lite/wpforms.php')) {37 $form_plugins['wpforms'] = esc_html__('WPForms Lite', 'sync-forms-with-brilliant-directories');38 }39 20 40 21 // Get CF7 forms … … 54 35 } 55 36 37 $brillforms_wpforms = []; 38 if (post_type_exists('wpforms')) { 39 $wpforms_query = new WP_Query([ 40 'post_type' => 'wpforms', 41 'posts_per_page' => -1, 42 'orderby' => 'title', 43 'order' => 'ASC', 44 ]); 45 46 foreach ($wpforms_query->posts as $form) { 47 $brillforms_wpforms[$form->ID] = esc_html($form->post_title); 48 } 49 } 56 50 ?> 57 <?php /*58 <div class="brill-field-wrap">59 <label for="brillforms_form_plugin"><?php echo esc_html__('Select Form Plugin', 'sync-forms-with-brilliant-directories'); ?></label>60 <select name="brillforms_form_plugin" id="brillforms_form_plugin">61 <option value=""><?php echo esc_html__('-- Select a Form Plugin --', 'sync-forms-with-brilliant-directories'); ?></option>62 <?php foreach ($form_plugins as $key => $label): ?>63 <option value="<?php echo esc_attr($key); ?>" <?php selected($brillforms_selected_plugin, $key); ?>>64 <?php echo esc_html($label); ?>65 </option>66 <?php endforeach; ?>67 </select>68 </div>69 */ ?>70 51 <div class="brillforms-add-sync-wrap"> 71 52 <div class="brill-field-wrap brill-single-select"> … … 82 63 echo '<option value="contact_form_7" disabled>' . esc_html__('Contact Form 7 (Plugin not available)', 'sync-forms-with-brilliant-directories') . '</option>'; 83 64 } 65 if (is_plugin_active('wpforms-lite/wpforms.php')) { 66 echo '<option value="wpforms" ' . selected($brillforms_selected_plugin, 'wpforms', false) . '>' . esc_html__('WPForms', 'sync-forms-with-brilliant-directories') . '</option>'; 67 } else { 68 echo '<option value="wpforms" disabled>' . esc_html__('wpforms (Plugin not available)', 'sync-forms-with-brilliant-directories') . '</option>'; 69 } 84 70 ?> 85 86 71 <option value="gform" disabled> 87 72 <?php echo esc_html__('Gravity Forms (Coming Soon)', 'sync-forms-with-brilliant-directories'); ?> … … 91 76 <?php echo esc_html__('Ninja Forms (Coming Soon)', 'sync-forms-with-brilliant-directories'); ?> 92 77 </option> 93 94 <option value="wpforms" disabled>95 <?php echo esc_html__('WPForms Lite (Coming Soon)', 'sync-forms-with-brilliant-directories'); ?>96 </option>97 78 </select> 98 79 </div> … … 100 81 <div class="brill-field-wrap brill-single-select" id="brillforms_cf7_forms_wrap" style="<?php echo ($brillforms_selected_plugin === 'contact_form_7') ? '' : 'display:none;'; ?>"> 101 82 <label for="brillforms_cf7_forms" id="brillforms_select_form_label"><?php echo esc_html__('Select Form', 'sync-forms-with-brilliant-directories'); ?></label> 102 <select name="brildir_sfwbd_ form_id" id="brillforms_cf7_forms" required>83 <select name="brildir_sfwbd_cf7_form_id" id="brillforms_cf7_forms" required> 103 84 <option value=""><?php echo esc_html__('Select Form', 'sync-forms-with-brilliant-directories'); ?></option> 104 85 <?php foreach ($brillforms_cf7_forms as $id => $title): ?> 86 <option value="<?php echo esc_attr($id); ?>" <?php selected($brillforms_selected_form_id, $id); ?>> 87 <?php echo esc_html($title); ?> 88 </option> 89 <?php endforeach; ?> 90 </select> 91 </div> 92 93 <div class="brill-field-wrap brill-single-select" id="brillforms_wpforms_wrap" style="<?php echo ($brillforms_selected_plugin === 'wpforms') ? '' : 'display:none;'; ?>"> 94 <label for="brillforms_wpforms_forms" id="brillforms_select_wpforms_label"><?php echo esc_html__('Select Form', 'sync-forms-with-brilliant-directories'); ?></label> 95 <select name="brildir_sfwbd_wpforms_form_id" id="brillforms_wpforms_forms" required> 96 <option value=""><?php echo esc_html__('Select Form', 'sync-forms-with-brilliant-directories'); ?></option> 97 <?php foreach ($brillforms_wpforms as $id => $title): ?> 105 98 <option value="<?php echo esc_attr($id); ?>" <?php selected($brillforms_selected_form_id, $id); ?>> 106 99 <?php echo esc_html($title); ?> … … 247 240 } 248 241 242 $brill_selected_plugin = isset($_POST['brildir_sfwbd_form_plugin']) ? sanitize_text_field(wp_unslash($_POST['brildir_sfwbd_form_plugin'])) : ''; 243 $form_id = 0; 244 if ($brill_selected_plugin === 'contact_form_7' && isset($_POST['brildir_sfwbd_cf7_form_id'])) { 245 $form_id = intval(wp_unslash($_POST['brildir_sfwbd_cf7_form_id'])); 246 } elseif ($brill_selected_plugin === 'wpforms' && isset($_POST['brildir_sfwbd_wpforms_form_id'])) { 247 $form_id = intval(wp_unslash($_POST['brildir_sfwbd_wpforms_form_id'])); 248 } 249 249 250 if (isset($_POST['brildir_sfwbd_form_plugin'])) { 250 if (sanitize_text_field(wp_unslash($_POST['brildir_sfwbd_form_plugin'])) === 'contact_form_7' ) { 251 $brillsfwbd_selected_plugin = sanitize_text_field(wp_unslash($_POST['brildir_sfwbd_form_plugin'])); 252 update_post_meta($post_id, '_brildir_sfwbd_form_plugin', $brillsfwbd_selected_plugin); 253 254 if ($brillsfwbd_selected_plugin === 'contact_form_7') { 251 255 update_post_meta($post_id, '_brildir_sfwbd_plugin_name', 'Contact Form 7'); 252 } 253 update_post_meta($post_id, '_brildir_sfwbd_form_plugin', sanitize_text_field(wp_unslash($_POST['brildir_sfwbd_form_plugin']))); 254 } 255 256 if (isset($_POST['brildir_sfwbd_form_id'])) { 257 update_post_meta($post_id, '_brildir_sfwbd_form_id', intval(wp_unslash($_POST['brildir_sfwbd_form_id']))); 258 259 $brillsync_form = get_post(intval(wp_unslash($_POST['brildir_sfwbd_form_id']))); 260 $brill_form_title = $brillsync_form->post_title; 261 update_post_meta($post_id, '_brildir_sfwbd_form_title', $brill_form_title); 256 } elseif ($brillsfwbd_selected_plugin === 'wpforms') { 257 update_post_meta($post_id, '_brildir_sfwbd_plugin_name', 'WPForms'); 258 } 259 260 if ($form_id) { 261 update_post_meta($post_id, '_brildir_sfwbd_form_id', $form_id); 262 $form_post = get_post($form_id); 263 if ($form_post) { 264 update_post_meta($post_id, '_brildir_sfwbd_form_title', $form_post->post_title); 265 } 266 } 262 267 } 263 268 … … 275 280 } 276 281 277 if (isset($_POST['brildir_sfwbd_create_option'], $_POST['brildir_sfwbd_form_id'])) { 278 $form_id = intval(wp_unslash($_POST['brildir_sfwbd_form_id'])); 282 283 if (isset($_POST['brildir_sfwbd_create_option'], $form_id)) { 284 $form_id = $form_id; 279 285 $brill_create_option = sanitize_text_field(wp_unslash($_POST['brildir_sfwbd_create_option'])); 280 286 … … 293 299 // Save form field mappings 294 300 if (isset($_POST['brildir_sfwbd_field_map']) && is_array($_POST['brildir_sfwbd_field_map'])) { 295 $form_id = isset($_POST['brildir_sfwbd_form_id']) ? intval($_POST['brildir_sfwbd_form_id']) : 0;301 $form_id = $form_id; 296 302 if ($form_id) { 297 303 // Get existing mappings or initialize an empty array if none exist … … 328 334 // Save additional custom field mappings 329 335 if (isset($_POST['brildir_sfwbd_field_map_custom']) && is_array($_POST['brildir_sfwbd_field_map_custom'])) { 330 $form_id = isset($_POST['brildir_sfwbd_form_id']) ? intval($_POST['brildir_sfwbd_form_id']) : 0;336 $form_id = $form_id; 331 337 if ($form_id) { 332 338 $custom_fields_raw = wp_unslash($_POST['brildir_sfwbd_field_map_custom']); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized … … 411 417 $post_id = isset($_POST['post_id']) ? intval(wp_unslash($_POST['post_id'])) : 0; 412 418 $create_sub = isset($_POST['create_option']) ? sanitize_text_field(wp_unslash($_POST['create_option'])) : ''; 419 $brill_form_plugin = isset($_POST['brill_plugin']) ? sanitize_text_field(wp_unslash($_POST['brill_plugin'])) : ''; 413 420 414 421 if (!$form_id) { … … 488 495 ), 489 496 'em' => array(), 490 ); 491 echo wp_kses(Brildir_Sfwbd_Get_Cf7_fields($form_id, $create_sub, $saved_mapping, $brill_get_custom_mapping), $brill_allowed_html); 497 ); 498 499 if ($brill_form_plugin === 'contact_form_7'){ 500 echo wp_kses(Brildir_Sfwbd_Get_Cf7_fields($form_id, $create_sub, $saved_mapping, $brill_get_custom_mapping), $brill_allowed_html); 501 } elseif ($brill_form_plugin === 'wpforms'){ 502 echo wp_kses(Brildir_Sfwbd_Get_WPForms_fields($form_id, $create_sub, $saved_mapping, $brill_get_custom_mapping), $brill_allowed_html); 503 } 492 504 493 505 wp_die(); … … 820 832 } 821 833 834 835 function Brildir_Sfwbd_Get_WPForms_fields($form_id, $create_sub, $saved_mapping = [], $brill_get_custom_mapping = []) 836 { 837 ob_start(); 838 $form_post = get_post($form_id); 839 if (!$form_post) { 840 return '<p><em>' . esc_html__('Form not found.', 'sync-forms-with-brilliant-directories') . '</em></p>'; 841 } 842 843 $form_content = json_decode($form_post->post_content, true); 844 if (!isset($form_content['fields']) || !is_array($form_content['fields'])) { 845 return '<p><em>' . esc_html__('No fields found in this WPForm.', 'sync-forms-with-brilliant-directories') . '</em></p>'; 846 } 847 848 // Allowed standard WPForms field types 849 $Wpforms_allowed_types = ['text', 'textarea', 'email', 'name', 'phone', 'address', 'number', 'checkbox', 'radio', 'select', 'date', 'time']; 850 851 $wpfields = []; 852 853 foreach ($form_content['fields'] as $field) { 854 $type = $field['type'] ?? 'text'; 855 $id = $field['id'] ?? ''; 856 $label = $field['label'] ?? $id; 857 858 // Skip non-standard or disallowed field types 859 if ($id && in_array($type, $Wpforms_allowed_types, true)) { 860 $wpfields[] = [ 861 'type' => $type, 862 'name' => $id, // WPForms uses field ID, not "name" 863 'label' => $label 864 ]; 865 } 866 } 867 868 if ($create_sub == 'leads') { 869 $required_fields = [ 870 'lead_email' => 'lead_email (string, email)', 871 ]; 872 $additional_fields = [ 873 'adm_lvl_1_sn' => 'adm_lvl_1_sn (string)', 874 'auto_geocode' => 'auto_geocode (integer)', 875 'auto_match' => 'auto_match (integer)', 876 'country_sn' => 'country_sn (string)', 877 'date_added' => 'date_added (string, datetime)', 878 'flow_source' => 'flow_source (string)', 879 'formname' => 'formname (string)', 880 'lat' => 'lat (number)', 881 'lead_location' => 'lead_location (string)', 882 'lead_message' => 'lead_message (string)', 883 'lead_name' => 'lead_name (string)', 884 'lead_notes' => 'lead_notes (string)', 885 'lead_phone' => 'lead_phone (string)', 886 'lead_price' => 'lead_price (number)', 887 'lng' => 'lng (number)', 888 'location_type' => 'location_type (string)', 889 'nelat' => 'nelat (number)', 890 'nelng' => 'nelng (number)', 891 'origin_ip' => 'origin_ip (string)', 892 'revision_timestamp' => 'revision_timestamp (string, datetime)', 893 'send_lead_email_notification' => 'send_lead_email_notification (integer)', 894 'sub_category_name' => 'sub_category_name(string)', 895 'sub_id' => 'sub_id (integer)', 896 'sub_sub_category_name' => 'sub_sub_category_name (string)', 897 'sub_sub_id' => 'sub_sub_id (integer)', 898 'swlat' => 'swlat (number)', 899 'swlng' => 'swlng (number)', 900 'top_category_name' => 'top_category_name (string)', 901 'top_id' => 'top_id (integer)', 902 'url_from' => 'url_from (string)', 903 ]; 904 } elseif ($create_sub == 'user') { 905 $required_fields = [ 906 'active' => 'Account Status (2 is active, 1 is deactive)', 907 'email' => 'email (string, email)', 908 ]; 909 $additional_fields = [ 910 'about_me' => 'about_me (string)', 911 'address1' => 'address1 (string)', 912 'address2' => 'address2 (string)', 913 'affiliation' => 'affiliation (string)', 914 'auto_geocode' => 'auto_geocode (integer)', 915 'auto_image_import' => 'auto_image_import (integer)', 916 'awards' => 'awards (string)', 917 'blog' => 'blog (string, uri)', 918 'city' => 'city (string)', 919 'company' => 'company (string)', 920 'country_code' => 'country_code (string)', 921 'country_ln' => 'country_ln (string)', 922 'cover_photo' => 'cover_photo (string)', 923 'credentials' => 'credentials (string)', 924 'cv' => 'cv (string)', 925 'experience' => 'experience (integer)', 926 'facebook' => 'facebook (string, uri)', 927 'facebook_id' => 'facebook_id (string)', 928 'featured' => 'featured (integer)', 929 'first_name' => 'first_name (string)', 930 'google_id' => 'google_id (string)', 931 'instagram' => 'instagram (string, uri)', 932 'last_login' => 'last_login (string, datetime)', 933 'last_name' => 'last_name (string)', 934 'lat' => 'lat (number)', 935 'linkedin' => 'linkedin (string, uri)', 936 'listing_type' => 'listing_type (string)', 937 'logo' => 'logo (string)', 938 'lon' => 'lon (number)', 939 'member_tags' => 'member_tags (string)', 940 'modtime' => 'modtime (string, datetime)', 941 'nationwide' => 'nationwide (integer)', 942 'phone_number' => 'phone_number (string)', 943 'pinterest' => 'pinterest (string, uri)', 944 'position' => 'position (string)', 945 'profession_id' => 'profession_id (integer)', 946 'profile_photo' => 'profile_photo (string)', 947 'quote' => 'quote (string)', 948 'rep_matters' => 'rep_matters (string)', 949 'search_description' => 'search_description (string)', 950 'send_email_notifications' => 'send_email_notifications (integer)', 951 'services' => 'services (string)', 952 'signup_date' => 'signup_date (string, datetime)', 953 'snapchat' => 'snapchat (string)', 954 'state_code' => 'state_code (string)', 955 'state_ln' => 'state_ln (string)', 956 'twitter' => 'twitter (string, uri)', 957 'verified' => 'verified (integer)', 958 'website' => 'website (string, uri)', 959 'whatsapp' => 'whatsapp (string)', 960 'youtube' => 'youtube (string, uri)', 961 'zip_code' => 'zip_code (string)', 962 ]; 963 } else { 964 $required_fields = []; 965 $additional_fields = []; 966 } 967 968 // Combine both required and additional fields for the lead fields 969 $lead_fields = array_merge($required_fields, $additional_fields); 970 971 if (!empty($saved_mapping)) { 972 foreach ($saved_mapping as $form_field => $mapped_lead_field) { 973 // Check if it's a custom field not present in $lead_fields already 974 if (!isset($lead_fields[$mapped_lead_field])) { 975 // If it's not already a predefined lead field, add it as a custom field 976 $lead_fields[$mapped_lead_field] = $mapped_lead_field; 977 } 978 } 979 } 980 981 982 $brill_custom_combined = []; 983 // Collect and structure custom_variables 984 foreach ($lead_fields as $value => $label) { 985 if (!in_array($value, array_keys($required_fields)) && 986 !in_array($value, array_keys($additional_fields)) && 987 $value !== 'skip') { 988 $brill_custom_combined[$value] = $label; 989 } 990 } 991 992 if (!is_array($brill_get_custom_mapping)) { 993 $brill_get_custom_mapping = []; 994 } 995 // Collect and structure custom_variable_options 996 foreach($brill_get_custom_mapping as $form_field => $mapped_field) { 997 foreach($mapped_field as $brill_cus_key => $brill_cus_value) { 998 if (!isset($required_fields[$brill_cus_key]) && 999 !isset($additional_fields[$brill_cus_key]) && 1000 $brill_cus_key !== 'skip') { 1001 $brill_custom_combined[$brill_cus_key] = $brill_cus_key; 1002 } 1003 } 1004 } 1005 1006 // Sort by label 1007 asort($brill_custom_combined); 1008 1009 if (!empty($wpfields)) { 1010 ob_start(); 1011 ?> 1012 <div class="brillforms-mapping-wrap"> 1013 <div class="brill-label-wrap"> 1014 <label class="brill-label" id="brillforms_fieldmap_label"><?php echo esc_html__('Map WP Form Fields to Brilliant Directories', 'sync-forms-with-brilliant-directories'); ?></label> 1015 </div> 1016 <table class="widefat brillforms-field-map-table"> 1017 <thead> 1018 <tr> 1019 <th class="brill-form-datas"><?php echo esc_html__('Field Type', 'sync-forms-with-brilliant-directories'); ?></th> 1020 <th class="brill-form-datas"><?php echo esc_html__('Field Label', 'sync-forms-with-brilliant-directories'); ?></th> 1021 <th class="brill-mapping-datas"><div class="brill-mapping-data-wrap"><?php echo esc_html__('Map to Field ', 'sync-forms-with-brilliant-directories'); ?> <span id="requiredFieldsCount"></span></div></th> 1022 </tr> 1023 </thead> 1024 <tbody> 1025 <?php foreach ($wpfields as $field): 1026 $selected_value = $saved_mapping[$field['name']] ?? 'skip'; 1027 ?> 1028 <tr> 1029 <td><?php echo esc_html($field['type']); ?></td> 1030 <td><?php echo esc_html($field['label']); ?></td> 1031 <td> 1032 <?php 1033 // Default to "skip" if nothing is mapped yet 1034 if (empty($selected_value)) { 1035 $selected_value = 'skip'; 1036 } 1037 ?> 1038 <select class="brillforms_lead_fields brill-lead-fields" name="brildir_sfwbd_field_map[<?php echo esc_attr($field['name']); ?>]" > 1039 <option value=""><?php esc_html_e('-- Select --', 'sync-forms-with-brilliant-directories'); ?></option> 1040 <option value="skip" <?php selected($selected_value, 'skip'); ?>> 1041 <?php esc_html_e('Skip Field - Do Not Map', 'sync-forms-with-brilliant-directories'); ?> 1042 </option> 1043 <?php if (!empty($brill_custom_combined)): ?> 1044 <optgroup label="Custom Variable"> 1045 <?php foreach ($brill_custom_combined as $value => $label): ?> 1046 <option value="<?php echo esc_attr($value); ?>" <?php selected($selected_value ?? '', $value); ?>> 1047 <?php echo esc_html($label); ?> 1048 </option> 1049 <?php endforeach; ?> 1050 </optgroup> 1051 <?php endif; ?> 1052 </optgroup> 1053 <!-- Grouped options by required and additional fields --> 1054 <?php if (!empty($required_fields)) : ?> 1055 <optgroup label="Required Mapping Fields"> 1056 <?php foreach ($required_fields as $value => $label): ?> 1057 <option value="<?php echo esc_attr($value); ?>" <?php selected($selected_value, $value); ?>> 1058 <?php echo esc_html($label); ?> 1059 </option> 1060 <?php endforeach; ?> 1061 </optgroup> 1062 <?php endif; ?> 1063 <?php if (!empty($additional_fields)) : ?> 1064 <optgroup label="Additional Fields"> 1065 <?php foreach ($additional_fields as $value => $label): ?> 1066 <option value="<?php echo esc_attr($value); ?>" <?php selected($selected_value, $value); ?>> 1067 <?php echo esc_html($label); ?> 1068 </option> 1069 <?php endforeach; ?> 1070 </optgroup> 1071 <?php endif; ?> 1072 </select> 1073 </td> 1074 </tr> 1075 <?php endforeach; ?> 1076 </tbody> 1077 </table> 1078 </div> 1079 1080 <div class="brill-label-wrap"> 1081 <span class="brill-label" id="brillforms_custom_fields_label"><?php echo esc_html__('Additional Data Sent with Every Form Submission', 'sync-forms-with-brilliant-directories'); ?></span> 1082 </div> 1083 1084 <?php if (!empty($brill_get_custom_mapping)) : 1085 ?> 1086 <div id="additional-mapping-fields-container"> 1087 <?php foreach ($brill_get_custom_mapping as $form_field => $mapped_field) : 1088 foreach ($mapped_field as $brill_cus_key => $brill_cus_value) : 1089 ?> 1090 <div class="brill-additional-field-row" data-index="<?php echo esc_attr($brill_cus_key); ?>"> 1091 <div class="brill-additional-field-delete"> 1092 <span class="brill-del-custom-field" data-index="<?php echo esc_attr($brill_cus_key); ?>"><span aria-hidden="true" class="dashicons dashicons-trash"></span></span> 1093 </div> 1094 <div class="brill-additional-field-select"> 1095 <select class="brillforms_lead_fields" name="brildir_sfwbd_field_map_custom[<?php echo esc_attr($brill_cus_key); ?>][map_to]" style="width: 250px;"> 1096 <option value=""><?php esc_html_e('Select Variable to Map', 'sync-forms-with-brilliant-directories'); ?></option> 1097 <!-- Custom Fields Optgroup --> 1098 // Check if there are custom variables to display 1099 <?php if (!empty($brill_custom_combined)): ?> 1100 <optgroup label="Custom Variable"> 1101 <?php foreach ($brill_custom_combined as $value => $label): ?> 1102 <option value="<?php echo esc_attr($value); ?>" <?php selected($brill_cus_key ?? '', $value); ?>> 1103 <?php echo esc_html($label); ?> 1104 </option> 1105 <?php endforeach; ?> 1106 </optgroup> 1107 <?php endif; ?> 1108 <!-- Required Fields Optgroup --> 1109 <optgroup label="Required Mapping Fields"> 1110 <?php foreach ($required_fields as $value => $label): ?> 1111 <option value="<?php echo esc_attr($value); ?>" <?php selected($brill_cus_key, $value); ?>> 1112 <?php echo esc_html($label); ?> 1113 </option> 1114 <?php endforeach; ?> 1115 </optgroup> 1116 1117 <!-- Additional Fields Optgroup --> 1118 <optgroup label="Additional Fields"> 1119 <?php foreach ($additional_fields as $value => $label): ?> 1120 <option value="<?php echo esc_attr($value); ?>" <?php selected($brill_cus_key, $value); ?>> 1121 <?php echo esc_html($label); ?> 1122 </option> 1123 <?php endforeach; ?> 1124 </optgroup> 1125 </select> 1126 </div> 1127 <div class="brill-additional-field-input"> 1128 <input type="text" name="brildir_sfwbd_field_map_custom[<?php echo esc_attr($brill_cus_key); ?>][name]" value="<?php echo esc_attr($brill_cus_value); ?>" placeholder="Enter Value to Pass" required /> 1129 </div> 1130 </div> 1131 <?php endforeach; 1132 endforeach; 1133 ?> 1134 </div> 1135 <?php else : ?> 1136 <div id="additional-mapping-fields-container"></div> 1137 <?php endif; ?> 1138 <!-- Button to add new mapping --> 1139 <button type="button" id="add-additional-mapping-field" class="button button-secondary" style="margin-top: 10px;"> 1140 <?php esc_html_e('+ Add Data Field', 'sync-forms-with-brilliant-directories'); ?> 1141 </button> 1142 <?php 1143 return ob_get_clean(); 1144 } else { 1145 return wp_kses_post('<p><em>' . esc_html__('No supported fields found in this form.', 'sync-forms-with-brilliant-directories') . '</em></p>'); 1146 } 1147 } -
sync-forms-with-brilliant-directories/trunk/readme.txt
r3310605 r3313297 4 4 Requires at least: 5.6 5 5 Tested up to: 6.8 6 Stable tag: 1.0. 06 Stable tag: 1.0.1 7 7 License: GPL2 8 8 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 100 100 == Changelog == 101 101 102 = 1.0.1 = 103 Integrated the WPForms to the Form syncs. 104 102 105 = 1.0.0 = 103 106 * Initial release of the plugin. -
sync-forms-with-brilliant-directories/trunk/sync-forms-with-brilliant-directories.php
r3310605 r3313297 3 3 * Plugin Name: Sync Forms with Brilliant Directories 4 4 * Description: Easily sync WordPress form submissions to Brilliant Directories with the ‘Sync Forms with Brilliant Directories’ plugin. Automatically create Members and Leads using Contact Form 7, with more plugin support coming soon. Just install, connect your BD account, and start syncing. 5 * Version: 1.0. 05 * Version: 1.0.1 6 6 * Author: Brilliant Directories 7 7 * Text Domain: sync-forms-with-brilliant-directories … … 14 14 exit; 15 15 } 16 17 // Define the plugin version 18 define('BRILDIR_SFWBD_VERSION', '1.0.1'); 16 19 17 20 // Define plugin constants … … 109 112 wp_enqueue_script('jquery'); 110 113 111 wp_register_style('brildir_sfwbd_css', BRILDIR_SFWBD_PLUGIN_URL . 'assets/css/brildirformsync-style.css', array(), '1.0.18');114 wp_register_style('brildir_sfwbd_css', BRILDIR_SFWBD_PLUGIN_URL . 'assets/css/brildirformsync-style.css', array(), BRILDIR_SFWBD_VERSION); 112 115 wp_enqueue_style('brildir_sfwbd_css'); 113 116 114 wp_register_script('brildir_sfwbd_js', BRILDIR_SFWBD_PLUGIN_URL . 'assets/js/brildirformsync-script.js', array('jquery'), '1.0.18', true);117 wp_register_script('brildir_sfwbd_js', BRILDIR_SFWBD_PLUGIN_URL . 'assets/js/brildirformsync-script.js', array('jquery'), BRILDIR_SFWBD_VERSION, true); 115 118 wp_enqueue_script('brildir_sfwbd_js'); 116 119 … … 138 141 139 142 if ($hook === 'post-new.php' || $hook === 'post.php') { 140 wp_register_style('brildir-sfwbd-admin-style', plugin_dir_url(__FILE__) . 'assets/css/admin-style.css', array(), '1.0.6');143 wp_register_style('brildir-sfwbd-admin-style', plugin_dir_url(__FILE__) . 'assets/css/admin-style.css', array(), BRILDIR_SFWBD_VERSION); 141 144 wp_enqueue_style('brildir-sfwbd-admin-style'); 142 145 143 wp_register_script('brildir-sfwbd-admin-script', plugin_dir_url(__FILE__) . 'assets/js/admin-script.js', array('jquery'), '1.0.6', true);146 wp_register_script('brildir-sfwbd-admin-script', plugin_dir_url(__FILE__) . 'assets/js/admin-script.js', array('jquery'), BRILDIR_SFWBD_VERSION, true); 144 147 wp_enqueue_script('brildir-sfwbd-admin-script'); 145 148 }
Note: See TracChangeset
for help on using the changeset viewer.