PluginProbe ʕ •ᴥ•ʔ
CommerceBird – AI Command Center, ERP Integrations & B2B for WooCommerce (Zoho, Exact Online). / 2.2.15
CommerceBird – AI Command Center, ERP Integrations & B2B for WooCommerce (Zoho, Exact Online). v2.2.15
3.0.3 3.0.2 3.0.1 trunk 2.2.14 2.2.15 2.2.16 2.2.17 2.2.18 2.2.19 2.3.0 2.3.1 2.3.10 2.3.11 2.3.12 2.3.13 2.3.14 2.3.2 2.3.3 2.3.4 2.3.5 2.3.6 2.3.7 2.3.8 2.3.9 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.5.0 2.5.1 2.5.2 2.6.0 2.6.1 2.6.2 2.6.3 2.6.4 2.6.5 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 2.7.9 2.7.91 2.7.92 2.7.93 2.8.0 2.8.1 2.8.2 2.8.3 2.8.4 2.8.5 2.9.0 2.9.1 2.9.2 2.9.3 3.0.0
commercebird / admin / includes / Template.php
commercebird / admin / includes Last commit date
Actions 1 year ago Connectors 1 year ago Traits 1 year ago Cmbird_Acf.php 1 year ago Cors.php 1 year ago Template.php 1 year ago
Template.php
119 lines
1 <?php
2
3 namespace CommerceBird\Admin;
4
5 use CommerceBird\Admin\Traits\Singleton;
6 use CommerceBird\API\CreateOrderWebhook;
7 use CommerceBird\API\ProductWebhook;
8 use CommerceBird\API\ShippingWebhook;
9
10 if ( ! defined( 'ABSPATH' ) ) {
11 exit;
12 }
13
14 final class Template {
15 use Singleton;
16
17 const NAME = 'commercebird-app';
18
19 public function __construct() {
20 add_action( 'admin_menu', array( $this, 'menu' ) );
21 add_action( 'admin_enqueue_scripts', array( $this, 'scripts' ) );
22 }
23
24 public function menu(): void {
25 $svg = CMBIRD_URL . 'admin/commercebird-icon.svg';
26 add_menu_page(
27 __( 'CommerceBird', 'commercebird' ),
28 __( 'CommerceBird', 'commercebird' ),
29 'manage_woocommerce',
30 self::NAME,
31 function () {
32 wp_enqueue_style( self::NAME );
33 wp_enqueue_style( self::NAME . '-notify', CMBIRD_URL . 'admin/css/notyf.min.css', array(), CMBIRD_VERSION );
34 // Pass version number to the Vue script
35 wp_localize_script(
36 self::NAME,
37 'cmbirdData',
38 array(
39 'version' => CMBIRD_VERSION,
40 )
41 );
42 wp_enqueue_script( self::NAME );
43 add_filter( 'script_loader_tag', array( $this, 'add_module' ), 10, 3 );
44 printf( '<div id="%s">Loading...</div>', esc_attr( self::NAME ) );
45 },
46 $svg,
47 29
48 );
49 }
50
51 /**
52 * It will add module attribute to script tag.
53 *
54 * @param string $tag of script.
55 * @param string $id of script.
56 *
57 * @return string
58 */
59 public function add_module( string $tag, string $id ): string {
60 if ( self::NAME === $id ) {
61 $tag = str_replace( '<script ', '<script type="module" ', $tag );
62 }
63
64 return $tag;
65 }
66
67 /**
68 * It loads scripts based on plugin's mode, dev or prod.
69 *
70 * @return void
71 */
72 public function scripts(): void {
73 global $wp_roles;
74 // comment on production
75 wp_register_style( self::NAME, 'http://localhost:5000/src/main.css', array(), CMBIRD_VERSION );
76 wp_register_script( self::NAME, 'http://localhost:5000/src/main.js', array(), CMBIRD_VERSION, true );
77 // comment on production
78 wp_register_style( self::NAME, CMBIRD_URL . 'admin/assets/dist/index.css', array(), CMBIRD_VERSION );
79 wp_register_script( self::NAME, CMBIRD_URL . 'admin/assets/dist/index.js', array(), CMBIRD_VERSION, true );
80 wp_add_inline_style( self::NAME, '#wpcontent, .auto-fold #wpcontent{padding-left: 0px} #wpcontent .notice, #wpcontent #message{display: none} input[type=checkbox]:checked::before{content:unset}' );
81 $active_plugins = apply_filters( 'active_plugins', get_option( 'active_plugins' ) );
82 wp_localize_script(
83 self::NAME,
84 'commercebird_admin',
85 array(
86 'security_token' => wp_create_nonce( self::NAME ),
87 'api_token' => get_option( 'cmbird_zi_webhook_password', false ),
88 'webhooks' => array(
89 'Items' => ProductWebhook::endpoint(),
90 'Order Create' => CreateOrderWebhook::endpoint(),
91 'Shipping Status' => ShippingWebhook::endpoint(),
92 ),
93 'redirect_uri' => admin_url( 'admin.php?page=commercebird-app' ),
94 'url' => admin_url( 'admin-ajax.php' ),
95 'wc_tax_enabled' => is_plugin_active( 'woocommerce/woocommerce.php' ) ? wc_tax_enabled() : false,
96 'roles' => $wp_roles->get_names(),
97 'b2b_enabled' => class_exists( 'Addify_B2B_Plugin' ),
98 'fileinfo_enabled' => extension_loaded( 'fileinfo' ),
99 'acf_enabled' => class_exists( 'ACF' ),
100 'cosw_enabled' => self::is_wc_shipped_status_exists(),
101 'wcb2b_enabled' => class_exists( 'WooCommerceB2B' ),
102 'wcb2b_groups' => get_transient( 'wc_b2b_groups' ),
103 'site_url' => site_url(),
104 'eo_sync' => get_option( 'cmbird_exact_online_sync_orders' ),
105 ),
106 );
107 }
108
109 /**
110 * Check if the status "shipped" exists in WooCommerce statuses.
111 *
112 * @return bool
113 */
114 public static function is_wc_shipped_status_exists(): bool {
115 $shipped_status = wc_get_order_statuses();
116 return isset( $shipped_status['wc-shipped'] );
117 }
118 }
119