PluginProbe ʕ •ᴥ•ʔ
CommerceBird – AI Command Center, ERP Integrations & B2B for WooCommerce (Zoho, Exact Online). / 2.7.0
CommerceBird – AI Command Center, ERP Integrations & B2B for WooCommerce (Zoho, Exact Online). v2.7.0
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 5 months ago Connectors 6 months ago Security 6 months ago Traits 6 months ago Cmbird_Acf.php 6 months ago Template.php 6 months ago index.php 1 year ago
Template.php
193 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 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Using WordPress core filter.
80 $active_plugins = apply_filters( 'active_plugins', get_option( 'active_plugins' ) );
81 wp_localize_script(
82 self::NAME,
83 'commercebird_admin',
84 array(
85 'security_token' => wp_create_nonce( self::NAME ),
86 'api_token' => get_option( 'cmbird_zi_webhook_password', false ),
87 'webhooks' => array(
88 'Items' => ProductWebhook::endpoint(),
89 'Order Create' => CreateOrderWebhook::endpoint(),
90 'Shipping Status' => ShippingWebhook::endpoint(),
91 ),
92 'redirect_uri' => admin_url( 'admin.php?page=commercebird-app' ),
93 'url' => admin_url( 'admin-ajax.php' ),
94 'wc_tax_enabled' => is_plugin_active( 'woocommerce/woocommerce.php' ) ? wc_tax_enabled() : false,
95 'roles' => $wp_roles->get_names(),
96 'b2b_enabled' => class_exists( 'Addify_B2B_Plugin' ),
97 'fileinfo_enabled' => extension_loaded( 'fileinfo' ),
98 'acf_enabled' => class_exists( 'ACF' ),
99 'wcb2b_enabled' => class_exists( 'WooCommerceB2B' ),
100 'wcb2b_groups' => get_transient( 'wc_b2b_groups' ),
101 'site_url' => site_url(),
102 'eo_sync' => get_option( 'cmbird_exact_online_sync_orders' ),
103 ),
104 );
105 }
106
107 /**
108 * Add custom styles for admin notices
109 *
110 * @return void
111 */
112 public function admin_notice_styles(): void {
113 ?>
114 <style>
115 .cmbird-notice h3 {
116 color: # d63638;
117 margin: .75em 0 0 0;
118 }
119
120 .cmbird-notice p {
121 margin: 0.5em 0;
122 }
123
124 .cmbird-license-notice {
125 border-left-color: # d63638;
126 }
127 </style>
128 <?php
129 }
130
131 /**
132 * Display subscription expired/on-hold notice in wp-admin
133 *
134 * @return void
135 */
136 public function subscription_expired_notice(): void {
137 // Only show on admin pages and to users who can manage woocommerce.
138 if ( ! current_user_can( 'manage_woocommerce' ) ) {
139 return;
140 }
141
142 // Get subscription ID from options.
143 $subscription_id = get_option( 'commercebird-subscription-id', 0 );
144 if ( empty( $subscription_id ) ) {
145 return;
146 }
147
148 // Check subscription status.
149 $subscription_data = $this->get_subscription_status();
150
151 if ( isset( $subscription_data['status'] ) && in_array( $subscription_data['status'], array( 'on-hold', 'expired', 'cancelled' ) ) ) {
152 $class = 'notice notice-error cmbird-notice cmbird-license-notice';
153 $exclamation_icon_url = CMBIRD_URL . 'admin/exclamation-triangle.svg';
154 $renew_url = "https://commercebird.com/my-account/view-subscription/{$subscription_id}";
155
156 $message = sprintf(
157 '<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>',
158 esc_url( $exclamation_icon_url ),
159 esc_html__( 'Heads up! Your CommerceBird license has expired.', 'commercebird' ),
160 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' ),
161 esc_url( $renew_url ),
162 esc_html__( 'Renew Now', 'commercebird' ),
163 esc_url( 'https://support.commercebird.com' ),
164 esc_html__( 'Learn More', 'commercebird' )
165 );
166
167 printf( '<div class="%1$s" id="cmbird-notice-license-expired">%2$s</div>', esc_attr( $class ), wp_kses_post( $message ) );
168 }
169 }
170
171 /**
172 * Get subscription status data
173 *
174 * @return array
175 */
176 private function get_subscription_status(): array {
177 // Check transient first to avoid excessive API calls.
178 $transient = get_transient( 'subscription_details' );
179 if ( ! empty( $transient ) && isset( $transient['status'] ) ) {
180 return $transient;
181 }
182
183 // Fallback: try to get from a stored option or return empty.
184 // This will need to be populated by the subscription check process.
185 $stored_status = get_option( 'commercebird-subscription-status', '' );
186 if ( ! empty( $stored_status ) ) {
187 return array( 'status' => $stored_status );
188 }
189
190 return array();
191 }
192 }
193