PluginProbe
YayMail – WooCommerce Email Customizer / 4.4.0
YayMail – WooCommerce Email Customizer v4.4.0
4.4.4 4.4.3 4.4.2 4.4.1 trunk 1.9.6 2.1.4 2.1.5 3.2.2 3.2.6 3.2.7.1 3.2.8.1 3.2.9 3.3 3.3.1 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9 3.4 3.4.1 3.4.2 3.4.3 All 55 releases
yaymail / src / SupportedPlugins.php

SupportedPlugins.php in YayMail – WooCommerce Email Customizer 4.4.0, at src/SupportedPlugins.php

418 lines 14.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace YayMail;
3
4 use YayMail\Models\AddonModel;
5 use YayMail\Utils\SingletonTrait;
6 /**
7 * YayMail SupportedPlugins
8 *
9 * @method static SupportedPlugins get_instance()
10 */
11 class SupportedPlugins {
12
13 use SingletonTrait;
14
15 private $wc_emails = [];
16 private $addon_supported_plugins = [];
17 private $pro_supported_plugins = [];
18
19 private function __construct() {
20 $this->addon_supported_plugins = AddonModel::get_3rd_party_addons();
21 $this->init_pro_plugins_list();
22 }
23
24
25 public function get_template_ids_from_core() {
26 return AddonModel::get_template_ids(
27 [
28 'WC_Email_Cancelled_Order',
29 'WC_Email_Customer_Cancelled_Order',
30 'WC_Email_Customer_Completed_Order',
31 'WC_Email_Customer_Invoice',
32 'WC_Email_Customer_New_Account',
33 'WC_Email_Customer_Note',
34 'WC_Email_Customer_On_Hold_Order',
35 'WC_Email_Customer_Processing_Order',
36 'WC_Email_Customer_Refunded_Order',
37 'WC_Email_Customer_Reset_Password',
38 'WC_Email_Failed_Order',
39 'WC_Email_Customer_Failed_Order',
40 'WC_Email_New_Order',
41 ]
42 );
43 }
44
45
46 /**
47 * Determines the source of support for a given template ID.
48 *
49 * This method checks if the template ID is supported by the core, an addon, or neither.
50 *
51 * @param string $template_id The template ID to check.
52 * @return string Returns 'already_supported', 'addon_needed' if supported by an addon, 'pro_needed' if supported by pro, or 'not_supported'.
53 */
54 private function get_support_status( string $template_id ): string {
55 // If the YayMail template data exists, it means the template is supported and ready to be edited
56 if ( ! empty( $this->get_yaymail_template_data( $template_id ) ) ) {
57 return 'already_supported';
58 }
59
60 /**
61 * Check addons
62 */
63 $template_ids_from_addons = [];
64 foreach ( $this->get_addon_supported_plugins() as $third_party ) {
65 if ( ! empty( $third_party['template_ids'] ) && ! empty( $third_party['is_3rd_party_installed'] ) ) {
66 $template_ids_from_addons = array_merge( $template_ids_from_addons, $third_party['template_ids'] );
67 }
68 }
69 if ( in_array( $template_id, $template_ids_from_addons, true ) ) {
70 return 'addon_needed';
71 }
72
73 /**
74 * Check Pro
75 */
76 $template_ids_from_pro = [];
77 foreach ( $this->get_pro_supported_plugins() as $third_party ) {
78 if ( ! empty( $third_party['template_ids'] ) ) {
79 $template_ids_from_pro = array_merge( $template_ids_from_pro, $third_party['template_ids'] );
80 }
81 }
82 if ( in_array( $template_id, $template_ids_from_pro, true ) ) {
83 return 'pro_needed';
84 }
85
86 return 'not_supported';
87 }
88
89 /**
90 * Get the plugin name based on a specific template ID.
91 *
92 * @param string $template_id The template ID to search for.
93 * @return array|null The addon info if the template ID is found, or null if not found.
94 */
95 private function get_addon_info( string $template_id ): ?array {
96
97 foreach ( $this->addon_supported_plugins as $addon ) {
98 // Check if 'template_ids' exists and contains the specified template ID
99 if ( isset( $addon['template_ids'] ) && in_array( $template_id, $addon['template_ids'], true ) ) {
100 return $addon;
101 }
102 }
103
104 return null;
105 }
106
107 /**
108 * Retrieves support information for a given template.
109 *
110 * @param string $template_id Template id.
111 *
112 * @return array An associative array containing:
113 * - 'support_status' (string): 'already_supported', 'addon_needed' if supported by an addon, 'pro_needed' if supported by pro, or 'not_supported'.
114 * - 'addon_info' (array|null): array (object) that has 3 fields: {plugin_name: string, template_ids: array of strings, link_upgrade: string}
115 */
116 public function get_support_info( string $template_id ): array {
117 $support_status = $this->get_support_status( $template_id );
118 $addon_info = $this->get_addon_info( $template_id );
119
120 return [
121 'status' => $support_status,
122 'addon' => $addon_info,
123 ];
124 }
125
126 public function get_yaymail_template_data( $template_id ) {
127 $yaymail_emails = \yaymail_get_emails();
128 return current( array_filter( $yaymail_emails, fn( $email ) => $email->get_id() === $template_id ) );
129 }
130
131 private function init_pro_plugins_list() {
132
133 if ( class_exists( 'FooEvents' ) ) {
134 $this->pro_supported_plugins['foo_events'] = [
135 'plugin_name' => 'FooEvents for WooCommerce',
136 ];
137 }
138
139 if ( class_exists( 'Bright_Plugins_COSW' ) ) {
140 $template_ids = [];
141 $arg = [
142 'numberposts' => -1,
143 'post_type' => 'order_status',
144 ];
145 $order_statuses = get_posts( $arg );
146
147 if ( $order_statuses ) {
148 foreach ( $order_statuses as $order_status ) {
149 $slug = get_post_meta( $order_status->ID, 'status_slug', true );
150 if ( ! empty( $slug ) ) {
151 $slug = 'bvos_custom_' . $slug;
152 }
153 if ( isset( $this->wc_emails[ $slug ] ) ) {
154 $template_ids[] = $slug;
155 }
156 }
157 }
158
159 $this->pro_supported_plugins['cosm_by_bright_plugins'] = [
160 'plugin_name' => 'Custom Order Status Manager for WooCommerce by Bright Plugins',
161 'template_ids' => $template_ids,
162 ];
163 }//end if
164
165 if ( class_exists( 'WC_Order_Status_Manager_Loader' ) ) {
166 $emails = wc_order_status_manager()->get_emails_instance()->get_emails();
167
168 $template_ids = [];
169 foreach ( $emails as $email ) {
170
171 $email_id = 'wc_order_status_email_' . esc_attr( $email->ID );
172
173 if ( isset( $wc_emails[ $email_id ] ) ) {
174 $template_ids[] = $wc_emails[ $email_id ];
175 }
176 }
177 $this->pro_supported_plugins['wodm_by_skyverge'] = [
178 'plugin_name' => 'WooCommerce Order Status Manager by SkyVerge',
179 'template_ids' => $template_ids,
180 ];
181 }
182
183 if ( class_exists( 'Zorem_Woocommerce_Advanced_Shipment_Tracking' )
184 || ( class_exists( 'Ast_Pro' ) ) ) {
185 $this->pro_supported_plugins['ast_by_zorem'] = [
186 'plugin_name' => 'Advanced Shipment Tracking by Zorem',
187 'template_ids' => AddonModel::get_template_ids(
188 [ 'WC_Email_Customer_Partial_Shipped_Order' ]
189 ),
190 ];
191 }
192
193 if ( function_exists( 'yith_ywot_premium_init' ) || function_exists( 'yith_ywot_init' ) ) {
194 $this->pro_supported_plugins['ywot'] = [
195 'plugin_name' => 'YITH WooCommerce Order & Shipment Tracking free/premium',
196 ];
197 }
198
199 if ( class_exists( 'Woocommerce_Local_Pickup' ) ) {
200 $this->pro_supported_plugins['advanced_local_pickup'] = [
201 'plugin_name' => 'Advanced Local Pickup for WooCommerce',
202 ];
203 }
204
205 if ( class_exists( 'CWG_Instock_API' ) ) {
206 $this->pro_supported_plugins['back_in_stock_notifier'] = [
207 'plugin_name' => 'Back In Stock Notifier for WooCommerce',
208 'template_ids' => [
209 'notifier_instock_mail',
210 'notifier_subscribe_mail',
211 ],
212 ];
213 }
214 if ( class_exists( 'ACF' ) ) {
215 $this->pro_supported_plugins['acf'] = [
216 'plugin_name' => 'Advanced Custom Fields ACF by WP Engine',
217 ];
218 }
219
220 if ( class_exists( 'WC_Connect_Loader' ) ) {
221 $this->pro_supported_plugins['wc_shipping_tax'] = [
222 'plugin_name' => 'WC Shipping & Tax',
223 ];
224 }
225
226 if ( class_exists( 'WC_Software' ) ) {
227 $this->pro_supported_plugins['wc_software_addon'] = [
228 'plugin_name' => 'Software Addon by WooCommerce',
229 ];
230 }
231
232 if ( class_exists( 'WC_Shipment_Tracking' ) ) {
233 $this->pro_supported_plugins['wc_shipment_tracking'] = [
234 'plugin_name' => 'Shipment Tracking by WooCommerce',
235 ];
236 }
237
238 if ( class_exists( 'PH_Shipment_Tracking_Common' ) ) {
239 $this->pro_supported_plugins['pluginhive_shipment_tracking'] = [
240 'plugin_name' => 'Shipment Tracking by PluginHive',
241 ];
242 }
243
244 if ( class_exists( '\OneTeamSoftware\WooCommerce\Shipping\Plugin' ) ) {
245 $this->pro_supported_plugins['chitchats_shipping'] = [
246 'plugin_name' => 'Chitchats Shipping Pro',
247 ];
248 }
249
250 if ( class_exists( 'Alg_WC_Custom_Order_Statuses' ) ) {
251 $this->pro_supported_plugins['cos_tychesoftwares'] = [
252 'plugin_name' => 'Custom Order Status by TycheSoftwares',
253 ];
254 }
255
256 if ( class_exists( 'WOOCOS_Email_Manager' ) ) {
257 $template_ids = [];
258 $custom_order_statuses = json_decode( get_option( 'woocos_custom_order_statuses' ) );
259 if ( $custom_order_statuses ) {
260 foreach ( $custom_order_statuses as $order_status ) {
261 $slug = $order_status->slug;
262
263 if ( isset( $this->wc_emails[ $slug ] ) ) {
264 $template_ids[] = $this->wc_emails[ $slug ];
265 }
266 }
267 }
268 $this->pro_supported_plugins['cos_nuggethone'] = [
269 'plugin_name' => 'Custom Order Status by Nuggethone',
270 'template_ids' => $template_ids,
271 ];
272 }
273
274 if ( class_exists( 'WC_Admin_Custom_Order_Fields' ) ) {
275 $this->pro_supported_plugins['cof_skyverge'] = [
276 'plugin_name' => 'WooCommerce Admin Custom Order Fields by SkyVerge',
277 ];
278 }
279
280 if ( class_exists( 'WC_Checkout_Field_Editor' ) ) {
281 $this->pro_supported_plugins['wc_checkout_field_editor'] = [
282 'plugin_name' => 'WooCommerce Checkout Field Editor',
283 ];
284 }
285
286 if ( function_exists( 'AWCFE' ) ) {
287 $this->pro_supported_plugins['checkout-field-editor-and-manager-for-woocommerce'] = [
288 'plugin_name' => 'Checkout Field Editor and Manager for WooCommerce',
289 ];
290 }
291
292 if ( class_exists( 'TrackingMore' ) ) {
293 $this->pro_supported_plugins['trackingmore'] = [
294 'plugin_name' => 'TrackingMore Order Tracking For WooCommerce',
295 ];
296 }
297
298 if ( class_exists( 'GTranslate' ) ) {
299 $this->pro_supported_plugins['gtranslate'] = [
300 'plugin_name' => 'GTranslate',
301 ];
302 }
303
304 if ( class_exists( '\Loco_api_WordPressTranslations' ) ) {
305 $this->pro_supported_plugins['loco'] = [
306 'plugin_name' => 'Loco',
307 ];
308 }
309
310 if ( class_exists( 'Polylang' ) ) {
311 $this->pro_supported_plugins['polylang'] = [
312 'plugin_name' => 'Polylang',
313 ];
314 }
315
316 if ( class_exists( 'TRP_Translate_Press' ) ) {
317 $this->pro_supported_plugins['translatepress'] = [
318 'plugin_name' => 'TranslatePress',
319 ];
320 }
321
322 if ( function_exists( 'weglot_get_service' ) ) {
323 $this->pro_supported_plugins['weglot'] = [
324 'plugin_name' => 'Weglot',
325 ];
326 }
327
328 if ( class_exists( 'SitePress' ) ) {
329 $this->pro_supported_plugins['wpml'] = [
330 'plugin_name' => 'WPML',
331 ];
332 }
333
334 // if ( class_exists( 'AST_PRO_Install' ) ) {
335 // $this->pro_supported_plugins['ast_pro'] = [
336 // 'plugin_name' => 'Advanced Shipment Tracking Pro',
337 // ];
338 // }
339
340 // if ( class_exists( 'PH_Shipment_Tracking_API_Manager' ) ) {
341 // $this->pro_supported_plugins['ph_shipment_tracking'] = [
342 // 'plugin_name' => 'PH Shipment Tracking',
343 // ];
344 // }
345
346 if ( class_exists( 'EventON' ) ) {
347 $this->pro_supported_plugins['event_on'] = [
348 'plugin_name' => 'EventON',
349 ];
350 }
351
352 if ( function_exists( 'woocontracts_maile_ekle' ) ) {
353 $this->pro_supported_plugins['woo_contracts_maile'] = [
354 'plugin_name' => 'WC EmailSozlesmeler',
355 ];
356 }
357
358 if ( class_exists( 'WooCommerce_Show_Attributes' ) ) {
359 $this->pro_supported_plugins['wc_show_attributes'] = [
360 'plugin_name' => 'WC Show Attributes',
361 ];
362 }
363
364 if ( class_exists( 'THWCFD' ) ) {
365 $this->pro_supported_plugins['cfd_themehigh'] = [
366 'plugin_name' => 'Checkout Field Editor by Themehigh',
367 ];
368 }
369 if ( class_exists( 'Flexible_Checkout_Fields_Plugin' ) ) {
370 $this->pro_supported_plugins['flexible_checkout_fields'] = [
371 'plugin_name' => 'Flexible Checkout Fields for WooCommerce',
372 ];
373 }
374 if ( class_exists( '\Woocommerce\Pagarme\Core' ) ) {
375 $this->pro_supported_plugins['pagarme'] = [
376 'plugin_name' => 'Pagarme',
377 ];
378 }
379
380 if ( class_exists( '\Payplug\PayplugWoocommerce' ) ) {
381 $this->pro_supported_plugins['payplug'] = [
382 'plugin_name' => 'Payplug',
383 ];
384 }
385 }
386
387 public function get_addon_supported_plugins() {
388 return $this->addon_supported_plugins;
389 }
390 public function get_pro_supported_plugins() {
391 return $this->pro_supported_plugins;
392 }
393
394 public function get_all_addon_supported_template_ids() {
395 $template_ids = [];
396 foreach ( $this->addon_supported_plugins as $addon_namespace => $addon ) {
397 $template_ids = array_merge( $template_ids, $this->get_addon_supported_template_ids( $addon_namespace ) );
398 }
399 return $template_ids;
400 }
401
402 public function get_addon_supported_template_ids( string $addon_namespace ): array {
403 return $this->addon_supported_plugins[ $addon_namespace ]['template_ids'] ?? [];
404 }
405
406 public function get_slug_name_supported_plugins(): array {
407 return array_map(
408 function( $addon ) {
409 return [
410 'plugin_name' => $addon['plugin_name'] ?? '',
411 'slug_name' => $addon['slug_name'] ?? '',
412 ];
413 },
414 $this->addon_supported_plugins
415 );
416 }
417 }
418