PluginProbe
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell / 3.13.0
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell v3.13.0
3.13.4 3.13.3 3.13.2 3.13.1 3.13.0 3.12.13 3.12.12 3.12.11 3.12.10 3.12.9 3.12.8 3.12.7 3.12.6 3.12.5 3.12.4 3.12.3 3.12.1 3.12.2 3.12.0 3.11.1 3.11.0 3.10.9 3.10.8 3.10.7 3.10.6 All 262 releases
wpfunnels / admin / modules / automations / class-wpfnl-automations.php

class-wpfnl-automations.php in WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell 3.13.0, at admin/modules/automations/class-wpfnl-automations.php

238 lines 10.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Automations module
4 *
5 * @package
6 */
7
8 namespace WPFunnels\Modules\Admin\Automations;
9
10 use WPFunnels\Admin\Module\Wpfnl_Admin_Module;
11 use WPFunnels\Traits\SingletonTrait;
12 use WPFunnels\Wpfnl_functions;
13
14 class Module extends Wpfnl_Admin_Module
15 {
16 use SingletonTrait;
17
18 public function __construct()
19 {
20 // Enqueue automation-canvas scripts
21 add_action('admin_enqueue_scripts', [$this, 'enqueue_automation_scripts']);
22
23 // Initialize REST API
24 require_once WPFNL_DIR . '/admin/modules/automations/class-wpfnl-automation-rest-api.php';
25 }
26
27 /**
28 * Enqueue automation canvas scripts
29 *
30 * @param string $hook Current admin page hook
31 * @since 3.9.5
32 */
33 public function enqueue_automation_scripts($hook)
34 {
35 // Only load on automation page
36 if ('wpfunnels_page_wpfnl_automations' !== $hook) {
37 return;
38 }
39
40 // Enqueue wp-tinymce for WYSIWYG editor support
41 wp_tinymce_inline_scripts();
42 wp_enqueue_editor();
43
44 // Load automation-canvas script
45 $automation_asset_file = WPFNL_DIR . '/admin/assets/dist/js/automation-canvas.min.asset.php';
46 $automation_dependencies = ['wp-element', 'wp-i18n', 'wp-api-fetch', 'wp-data'];
47 $automation_version = WPFNL_VERSION;
48
49 if (file_exists($automation_asset_file)) {
50 $automation_asset = require $automation_asset_file;
51 $automation_dependencies = isset($automation_asset['dependencies']) ? $automation_asset['dependencies'] : $automation_dependencies;
52 $automation_version = isset($automation_asset['version']) ? $automation_asset['version'] : $automation_version;
53 }
54
55 // The automation-canvas bundle ships its own copy of lodash (pulled in by
56 // easy-email's `import { ... } from "lodash"`). Lodash's UMD wrapper self-registers
57 // as the global `_`, clobbering WP core's Underscore.js that media-views.js relies
58 // on for `_.each(list, iteratee, context)` context-binding — breaking the media
59 // modal ("this.activateMode is not a function") once this script has run.
60 // Force load-order against 'underscore' and snapshot/restore the real global
61 // around it rather than reworking the bundled easy-email/lodash import graph.
62 $automation_dependencies[] = 'underscore';
63 $automation_dependencies = array_unique($automation_dependencies);
64
65 wp_add_inline_script(
66 'underscore',
67 'window.__wpfnlCoreUnderscore = window.__wpfnlCoreUnderscore || window._;',
68 'after'
69 );
70
71 wp_enqueue_script(
72 'wpfnl-automation-canvas',
73 WPFNL_URL . 'admin/assets/dist/js/automation-canvas.min.js',
74 $automation_dependencies,
75 $automation_version,
76 true
77 );
78
79 wp_add_inline_script(
80 'wpfnl-automation-canvas',
81 'if (window.__wpfnlCoreUnderscore) { window._ = window.__wpfnlCoreUnderscore; }',
82 'after'
83 );
84
85 // Enqueue automation-canvas styles extracted by a production build.
86 Wpfnl_functions::enqueue_bundle_style( 'automation-canvas', 'wpfnl-automation-canvas-styles' );
87
88 // The automation editor's own full-screen overlay (.wpfnl-automation-modal, see
89 // admin/src/automation-canvas/AutomationModal.scss) sits at z-index: 999999,
90 // higher than WP core's default .media-modal z-index — pushing the media
91 // library modal behind the editor chrome. Force it back on top.
92 wp_add_inline_style(
93 'media-views',
94 '.media-modal { z-index: 9999999999 !important; } .media-modal-backdrop { z-index: 999999998 !important; }'
95 );
96
97 // Localize script with data
98 wp_localize_script(
99 'wpfnl-automation-canvas',
100 'wpfnlAutomationVars',
101 [
102 'ajaxUrl' => admin_url('admin-ajax.php'),
103 'nonce' => wp_create_nonce('wpfnl_automation_nonce'),
104 'restUrl' => rest_url(),
105 'restNonce' => wp_create_nonce('wp_rest'),
106 ]
107 );
108
109 // Provide MRM_Vars global that automation-canvas components depend on.
110 $current_user = wp_get_current_user();
111 $email_settings = get_option( '_mrm_email_settings', array() );
112 $is_pro_active = defined( 'MAIL_MINT_PRO_VERSION' );
113 $is_pro_lic_active = $is_pro_active && class_exists( 'MRM\\Common\\MrmCommon' ) && \MRM\Common\MrmCommon::is_mailmint_pro_license_active();
114 $mint_trans = class_exists( 'Mint\\MRM\\Utilities\\Helper\\TranslationString\\TransStrings' )
115 ? \Mint\MRM\Utilities\Helper\TranslationString\TransStrings::getStrings()
116 : array();
117 $lists = class_exists( 'Mint\\MRM\\DataBase\\Models\\ContactGroupModel' )
118 ? \Mint\MRM\DataBase\Models\ContactGroupModel::get_all_to_custom_select( 'lists' )
119 : array();
120 $tags = class_exists( 'Mint\\MRM\\DataBase\\Models\\ContactGroupModel' )
121 ? \Mint\MRM\DataBase\Models\ContactGroupModel::get_all_to_custom_select( 'tags' )
122 : array();
123
124 wp_localize_script(
125 'wpfnl-automation-canvas',
126 'MRM_Vars',
127 array(
128 'ajaxurl' => admin_url( 'admin-ajax.php' ),
129 'api_base_url' => get_rest_url(),
130 'nonce' => wp_create_nonce( 'wp_rest' ),
131 'current_userID' => get_current_user_id(),
132 'admin_url' => get_admin_url(),
133 'date_format' => get_option( 'date_format', 'F j, Y' ),
134 'time_format' => get_option( 'time_format', 'H:i' ),
135 'gmt_offset' => get_option( 'gmt_offset' ),
136 'local_time' => date_i18n( 'Y-m-d H:i:s' ),
137 'current_user_email' => $current_user->user_email,
138 'email_settings' => $email_settings,
139 'lists' => $lists,
140 'tags' => $tags,
141 'is_wc_active' => class_exists( 'WooCommerce' ),
142 'is_edd_active' => defined( 'EDD_VERSION' ),
143 'is_mailmint_pro_active' => $is_pro_active,
144 'is_mailmint_pro_license_active' => $is_pro_lic_active,
145 'is_tutor_active' => defined( 'TUTOR_VERSION' ),
146 'is_gform_active' => class_exists( 'GFCommon' ),
147 'is_jetform_active' => class_exists( 'Jet_Form_Builder\\Plugin' ),
148 'is_fluentform_active' => defined( 'FLUENTFORM' ),
149 'is_learndash_active' => defined( 'LEARNDASH_VERSION' ),
150 'is_memberpress_active' => defined( 'MEPR_VERSION' ),
151 'is_contact_form_active' => defined( 'WPCF7_VERSION' ),
152 'is_lifterlms_active' => defined( 'LLMS_VERSION' ),
153 'is_fluent_booking_active' => defined( 'FLUENT_BOOKING_VERSION' ),
154 'is_wp_form_active' => class_exists( 'WPForms' ),
155 'is_bricks_active' => defined( 'BRICKS_VERSION' ),
156 'is_wcs_active' => class_exists( 'WC_Subscriptions' ),
157 'is_wcm_active' => class_exists( 'WC_Memberships' ),
158 'is_wcw_active' => class_exists( 'TInvWishlist' ),
159 'mint_trans' => $mint_trans,
160 'mint_page' => 'automation',
161 'open_ai_key' => array(),
162 'twilio_settings' => array(),
163 'post_types' => array(),
164 'contact_general_fields' => array(),
165 'contact_custom_fields' => array(),
166 'editor_data_source' => $this->get_editor_data_source(),
167 )
168 );
169 }
170
171 /**
172 * Provide the product/post category options the email builder's custom
173 * block panels (e.g. ProductBlock) read from MRM_Vars.editor_data_source.
174 * Without this key present, `options={undefined}` is passed to a Select
175 * field, which throws "Cannot read properties of undefined (reading 'map')"
176 * the moment that panel renders.
177 *
178 * @return array
179 * @since 3.12.10
180 */
181 private function get_editor_data_source()
182 {
183 return array(
184 'product_categories' => $this->get_formatted_categories( 'product_cat' ),
185 'post_categories' => $this->get_formatted_categories( 'category' ),
186 'placeholder_image' => '',
187 );
188 }
189
190 /**
191 * Fetch terms for a taxonomy formatted as {value, label} pairs.
192 *
193 * @param string $taxonomy Taxonomy name.
194 * @return array
195 * @since 3.12.10
196 */
197 private function get_formatted_categories( $taxonomy )
198 {
199 if ( ! taxonomy_exists( $taxonomy ) ) {
200 return array();
201 }
202
203 $terms = get_categories(
204 array(
205 'taxonomy' => $taxonomy,
206 'orderby' => 'name',
207 'hide_empty' => false,
208 )
209 );
210
211 $formatted = array();
212 foreach ( $terms as $term ) {
213 $formatted[] = array(
214 'value' => $term->term_id,
215 'label' => $term->name,
216 );
217 }
218
219 return $formatted;
220 }
221
222 public function get_view()
223 {
224 require_once WPFNL_DIR . '/admin/modules/automations/views/view.php';
225 }
226
227 public function get_name()
228 {
229 return __('automations','wpfnl');
230 }
231
232 public function init_ajax()
233 {
234
235 }
236 }
237
238