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 / divi / includes / functions.php

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

122 lines 3.6 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\Divi\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 array $fields_values
18 *
19 * @return array
20 */
21 function automatorwp_divi_get_form_fields_values( $fields_values ) {
22
23 $form_fields = array();
24
25 foreach ( $fields_values as $field_id => $field ) {
26 $form_fields[$field_id] = $field['value'];
27 }
28
29 $form_fields = automatorwp_utilities_pull_array_values( $form_fields );
30
31 return $form_fields;
32
33 }
34
35 /**
36 * Custom tags replacements
37 *
38 * @since 1.0.0
39 *
40 * @param string $parsed_content Content parsed
41 * @param array $replacements Automation replacements
42 * @param int $automation_id The automation ID
43 * @param int $user_id The user ID
44 * @param string $content The content to parse
45 *
46 * @return string
47 */
48 function automatorwp_divi_parse_automation_tags( $parsed_content, $replacements, $automation_id, $user_id, $content ) {
49
50 $new_replacements = array();
51
52 // Get automation triggers to pass their tags
53 $triggers = automatorwp_get_automation_triggers( $automation_id );
54
55 foreach( $triggers as $trigger ) {
56
57 $trigger_args = automatorwp_get_trigger( $trigger->type );
58
59 // Skip if trigger is not from this integration
60 if( $trigger_args['integration'] !== 'divi' ) {
61 continue;
62 }
63
64 // Get the last trigger log (where data for tags replacement will be get
65 $log = automatorwp_get_user_last_completion( $trigger->id, $user_id, 'trigger' );
66
67 if( ! $log ) {
68 continue;
69 }
70
71 ct_setup_table( 'automatorwp_logs' );
72 $form_fields = ct_get_object_meta( $log->id, 'form_fields', true );
73 ct_reset_setup_table();
74
75 // Skip if not form fields
76 if( ! is_array( $form_fields ) ) {
77 continue;
78 }
79
80 // Look for form field tags
81 preg_match_all( "/\{t:" . $trigger->id . ":form_field:\s*(.*?)\s*\}/", $parsed_content, $matches );
82
83 if( is_array( $matches ) && isset( $matches[1] ) ) {
84
85 foreach( $matches[1] as $field_name ) {
86 // Replace {t:ID:form_field:NAME} by the field value
87 if( isset( $form_fields[$field_name] ) ) {
88 $new_replacements['{t:' . $trigger->id . ':form_field:' . $field_name . '}'] = $form_fields[$field_name];
89 }
90 }
91
92 }
93
94 // Look for form field tags
95 preg_match_all( "/\{" . $trigger->id . ":form_field:\s*(.*?)\s*\}/", $parsed_content, $matches );
96
97 if( is_array( $matches ) && isset( $matches[1] ) ) {
98
99 foreach( $matches[1] as $field_name ) {
100 // Replace {ID:form_field:NAME} by the field value
101 if( isset( $form_fields[$field_name] ) ) {
102 $new_replacements['{' . $trigger->id . ':form_field:' . $field_name . '}'] = $form_fields[$field_name];
103 }
104 }
105
106 }
107
108 }
109
110 if( count( $new_replacements ) ) {
111
112 $tags = array_keys( $new_replacements );
113
114 // Replace all tags by their replacements
115 $parsed_content = str_replace( $tags, $new_replacements, $parsed_content );
116
117 }
118
119 return $parsed_content;
120
121 }
122 add_filter( 'automatorwp_parse_automation_tags', 'automatorwp_divi_parse_automation_tags', 10, 5 );