PluginProbe ʕ •ᴥ•ʔ
CommerceBird – AI Command Center, ERP Integrations & B2B for WooCommerce (Zoho, Exact Online). / 2.5.2
CommerceBird – AI Command Center, ERP Integrations & B2B for WooCommerce (Zoho, Exact Online). v2.5.2
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 8 months ago Connectors 9 months ago Security 9 months ago Traits 9 months ago Cmbird_Acf.php 9 months ago Template.php 8 months ago index.php 1 year ago
Template.php
192 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 add_action( 'admin_notices', array( $this, 'subscription_expired_notice' ) );
23 add_action( 'admin_head', array( $this, 'admin_notice_styles' ) );
24 }
25
26 public function menu(): void {
27 $svg = CMBIRD_URL . 'admin/commercebird-icon.svg';
28 add_menu_page(
29 __( 'CommerceBird', 'commercebird' ),
30 __( 'CommerceBird', 'commercebird' ),
31 'manage_woocommerce',
32 self::NAME,
33 function () {
34 wp_enqueue_style( self::NAME );
35 wp_enqueue_style( self::NAME . '-notify', CMBIRD_URL . 'admin/css/notyf.min.css', array(), CMBIRD_VERSION );
36 // Pass version number to the Vue script.
37 wp_localize_script(
38 self::NAME,
39 'cmbirdData',
40 array(
41 'version' => CMBIRD_VERSION,
42 )
43 );
44 wp_enqueue_script( self::NAME );
45 add_filter( 'script_loader_tag', array( $this, 'add_module' ), 10, 2 );
46 printf( '<div id="%s">Loading...</div>', esc_attr( self::NAME ) );
47 },
48 $svg,
49 29
50 );
51 }
52
53 /**
54 * It will add module attribute to script tag.
55 *
56 * @param string $tag of script.
57 * @param string $id of script.
58 *
59 * @return string
60 */
61 public function add_module( string $tag, string $id ): string {
62 if ( self::NAME === $id ) {
63 $tag = str_replace( '<script ', '<script type="module" ', $tag );
64 }
65
66 return $tag;
67 }
68
69 /**
70 * It loads scripts based on plugin's mode, dev or prod.
71 *
72 * @return void
73 */
74 public function scripts(): void {
75 global $wp_roles;
76 wp_register_style( self::NAME, CMBIRD_URL . 'admin/assets/dist/index.css', array(), CMBIRD_VERSION );
77 wp_register_script( self::NAME, CMBIRD_URL . 'admin/assets/dist/index.js', array(), CMBIRD_VERSION, true );
78 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}' );
79 $active_plugins = apply_filters( 'active_plugins', get_option( 'active_plugins' ) );
80 wp_localize_script(
81 self::NAME,
82 'commercebird_admin',
83 array(
84 'security_token' => wp_create_nonce( self::NAME ),
85 'api_token' => get_option( 'cmbird_zi_webhook_password', false ),
86 'webhooks' => array(
87 'Items' => ProductWebhook::endpoint(),
88 'Order Create' => CreateOrderWebhook::endpoint(),
89 'Shipping Status' => ShippingWebhook::endpoint(),
90 ),
91 'redirect_uri' => admin_url( 'admin.php?page=commercebird-app' ),
92 'url' => admin_url( 'admin-ajax.php' ),
93 'wc_tax_enabled' => is_plugin_active( 'woocommerce/woocommerce.php' ) ? wc_tax_enabled() : false,
94 'roles' => $wp_roles->get_names(),
95 'b2b_enabled' => class_exists( 'Addify_B2B_Plugin' ),
96 'fileinfo_enabled' => extension_loaded( 'fileinfo' ),
97 'acf_enabled' => class_exists( 'ACF' ),
98 'wcb2b_enabled' => class_exists( 'WooCommerceB2B' ),
99 'wcb2b_groups' => get_transient( 'wc_b2b_groups' ),
100 'site_url' => site_url(),
101 'eo_sync' => get_option( 'cmbird_exact_online_sync_orders' ),
102 ),
103 );
104 }
105
106 /**
107 * Add custom styles for admin notices
108 *
109 * @return void
110 */
111 public function admin_notice_styles(): void {
112 ?>
113 <style>
114 .cmbird-notice h3 {
115 color: # d63638;
116 margin: .75em 0 0 0;
117 }
118
119 .cmbird-notice p {
120 margin: 0.5em 0;
121 }
122
123 .cmbird-license-notice {
124 border-left-color: # d63638;
125 }
126 </style>
127 <?php
128 }
129
130 /**
131 * Display subscription expired/on-hold notice in wp-admin
132 *
133 * @return void
134 */
135 public function subscription_expired_notice(): void {
136 // Only show on admin pages and to users who can manage woocommerce.
137 if ( ! current_user_can( 'manage_woocommerce' ) ) {
138 return;
139 }
140
141 // Get subscription ID from options.
142 $subscription_id = get_option( 'commercebird-subscription-id', 0 );
143 if ( empty( $subscription_id ) ) {
144 return;
145 }
146
147 // Check subscription status.
148 $subscription_data = $this->get_subscription_status();
149
150 if ( isset( $subscription_data['status'] ) && in_array( $subscription_data['status'], array( 'on-hold', 'expired', 'cancelled' ) ) ) {
151 $class = 'notice notice-error cmbird-notice cmbird-license-notice';
152 $exclamation_icon_url = CMBIRD_URL . 'admin/exclamation-triangle.svg';
153 $renew_url = "https://commercebird.com/my-account/view-subscription/{$subscription_id}";
154
155 $message = sprintf(
156 '<h3 style="margin: .75em 0 0 0;"><img src="%s" style="vertical-align: text-top; width: 20px; margin-right: 7px;">%s</h3><p>%s</p><p><a href="%s" class="button-primary">%s</a> &nbsp;<a href="%s" class="button-secondary">%s</a></p>',
157 esc_url( $exclamation_icon_url ),
158 esc_html__( 'Heads up! Your CommerceBird license has expired.', 'commercebird' ),
159 esc_html__( 'An active license is needed to use the Zoho & Exact Online integrations. It also provides access to new features, plugin updates (including security improvements), and our world class support!', 'commercebird' ),
160 esc_url( $renew_url ),
161 esc_html__( 'Renew Now', 'commercebird' ),
162 esc_url( 'https://support.commercebird.com' ),
163 esc_html__( 'Learn More', 'commercebird' )
164 );
165
166 printf( '<div class="%1$s" id="cmbird-notice-license-expired">%2$s</div>', esc_attr( $class ), $message );
167 }
168 }
169
170 /**
171 * Get subscription status data
172 *
173 * @return array
174 */
175 private function get_subscription_status(): array {
176 // Check transient first to avoid excessive API calls.
177 $transient = get_transient( 'subscription_details' );
178 if ( ! empty( $transient ) && isset( $transient['status'] ) ) {
179 return $transient;
180 }
181
182 // Fallback: try to get from a stored option or return empty.
183 // This will need to be populated by the subscription check process.
184 $stored_status = get_option( 'commercebird-subscription-status', '' );
185 if ( ! empty( $stored_status ) ) {
186 return array( 'status' => $stored_status );
187 }
188
189 return array();
190 }
191 }
192