PluginProbe
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI / 6.0.2
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI v6.0.2
6.0.2 6.0.1 6.0.0 5.8.6 5.8.5 5.8.4 5.8.3 5.8.2 5.8.1 5.8.0 5.7.9.2 5.7.9.1 5.7.8 5.7.9 5.7.6 5.7.7 5.7.5 5.7.4 5.7.3 5.7.2 5.7.1 trunk 5.6.0 5.6.1 5.6.2 All 33 releases
automatorwp / integrations / jetformbuilder / includes / functions.php

functions.php in AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI 6.0.2, at integrations/jetformbuilder/includes/functions.php

130 lines 3.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Functions
4 *
5 * @package AutomatorWP\JetFormBuilder\Functions
6 * @author AutomatorWP <contact@automatorwp.com>, Ruben Garcia <rubengcdev@gmail.com>
7 * @since 1.0.0
8 */
9 // Exit if accessed directly
10 if( !defined( 'ABSPATH' ) ) exit;
11
12 /**
13 * Get form fields values
14 *
15 * @since 1.0.0
16 *
17 * @param Jet_Form_Builder\Form_Handler $form_handler
18 *
19 * @return array
20 */
21 function automatorwp_jetformbuilder_get_form_fields_values( $form_handler ) {
22
23 $form_fields = array();
24
25 $all_fields = $form_handler->action_handler->request_data;
26
27 foreach ( $all_fields as $field_key => $field_value ) {
28 if ( empty( $field_value ) ) {
29 continue;
30 }
31
32 if ( substr( $field_key, 0, 2 ) === '__' ) {
33 continue;
34 }
35
36 $form_fields[$field_key] = $field_value;
37 }
38
39 return $form_fields;
40
41 }
42
43 /**
44 * Custom tags replacements
45 *
46 * @since 1.0.0
47 *
48 * @param string $parsed_content Content parsed
49 * @param array $replacements Automation replacements
50 * @param int $automation_id The automation ID
51 * @param int $user_id The user ID
52 * @param string $content The content to parse
53 *
54 * @return string
55 */
56 function automatorwp_jetformbuilder_parse_automation_tags( $parsed_content, $replacements, $automation_id, $user_id, $content ) {
57
58 $new_replacements = array();
59
60 // Get automation triggers to pass their tags
61 $triggers = automatorwp_get_automation_triggers( $automation_id );
62
63 foreach( $triggers as $trigger ) {
64
65 $trigger_args = automatorwp_get_trigger( $trigger->type );
66
67 // Skip if trigger is not from this integration
68 if( $trigger_args['integration'] !== 'jetformbuilder' ) {
69 continue;
70 }
71
72 // Get the last trigger log (where data for tags replacement will be get
73 $log = automatorwp_get_user_last_completion( $trigger->id, $user_id, 'trigger' );
74
75 if( ! $log ) {
76 continue;
77 }
78
79 ct_setup_table( 'automatorwp_logs' );
80 $form_fields = ct_get_object_meta( $log->id, 'form_fields', true );
81 ct_reset_setup_table();
82
83 // Skip if not form fields
84 if( ! is_array( $form_fields ) ) {
85 continue;
86 }
87
88 // Look for form field tags
89 preg_match_all( "/\{t:" . $trigger->id . ":form_field:\s*(.*?)\s*\}/", $parsed_content, $matches );
90
91 if( is_array( $matches ) && isset( $matches[1] ) ) {
92
93 foreach( $matches[1] as $field_name ) {
94 // Replace {t:ID:form_field:NAME} by the field value
95 if( isset( $form_fields[$field_name] ) ) {
96 $new_replacements['{t:' . $trigger->id . ':form_field:' . $field_name . '}'] = $form_fields[$field_name];
97 }
98 }
99
100 }
101
102 // Look for form field tags
103 preg_match_all( "/\{" . $trigger->id . ":form_field:\s*(.*?)\s*\}/", $parsed_content, $matches );
104
105 if( is_array( $matches ) && isset( $matches[1] ) ) {
106
107 foreach( $matches[1] as $field_name ) {
108 // Replace {ID:form_field:NAME} by the field value
109 if( isset( $form_fields[$field_name] ) ) {
110 $new_replacements['{' . $trigger->id . ':form_field:' . $field_name . '}'] = $form_fields[$field_name];
111 }
112 }
113
114 }
115
116 }
117
118 if( count( $new_replacements ) ) {
119
120 $tags = array_keys( $new_replacements );
121
122 // Replace all tags by their replacements
123 $parsed_content = str_replace( $tags, $new_replacements, $parsed_content );
124
125 }
126
127 return $parsed_content;
128
129 }
130 add_filter( 'automatorwp_parse_automation_tags', 'automatorwp_jetformbuilder_parse_automation_tags', 10, 5 );