PluginProbe ʕ •ᴥ•ʔ
WooCommerce Square / 3.8.2
WooCommerce Square v3.8.2
5.4.1 5.4.0 trunk 1.0.25 1.0.26 1.0.27 1.0.28 1.0.29 1.0.30 1.0.31 1.0.32 1.0.33 1.0.34 1.0.35 1.0.36 1.0.37 1.0.38 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 2.4.0 2.4.1 2.5.0 2.5.1 2.5.2 2.5.3 2.6.0 2.7.0 2.8.0 2.9.0 2.9.1 3.0.0 3.0.1 3.0.2 3.0.3 3.1.0 3.2.0 3.3.0 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.6.1 3.7.0 3.7.1 3.8.0 3.8.1 3.8.2 3.8.3 3.9.0 4.0.0 4.1.0 4.2.0 4.2.1 4.2.2 4.2.3 4.3.0 4.3.1 4.3.2 4.4.0 4.4.1 4.4.2 4.5.0 4.5.1 4.5.2 4.6.0 4.6.1 4.6.2 4.6.3 4.6.4 4.7.0 4.7.1 4.7.2 4.7.3 4.7.4 4.8.0 4.8.1 4.8.2 4.8.3 4.8.4 4.8.5 4.8.6 4.8.7 4.8.8 4.9.0 4.9.1 4.9.2 4.9.3 4.9.4 4.9.5 4.9.6 4.9.7 4.9.8 4.9.9 5.0.0 5.0.1 5.1.0 5.1.1 5.1.2 5.2.0 5.3.0 5.3.1 5.3.2 5.3.3
woocommerce-square / includes / Admin.php
woocommerce-square / includes Last commit date
API 3 years ago Admin 3 years ago Emails 3 years ago Framework 3 years ago Gateway 3 years ago Handlers 3 years ago Sync 3 years ago Utilities 3 years ago AJAX.php 3 years ago API.php 3 years ago Admin.php 3 years ago Functions.php 3 years ago Gateway.php 3 years ago Lifecycle.php 3 years ago Plugin.php 3 years ago Settings.php 3 years ago
Admin.php
292 lines
1 <?php
2 /**
3 * WooCommerce Square
4 *
5 * This source file is subject to the GNU General Public License v3.0
6 * that is bundled with this package in the file license.txt.
7 * It is also available through the world-wide-web at this URL:
8 * http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0 or later
9 * If you did not receive a copy of the license and are unable to
10 * obtain it through the world-wide-web, please send an email
11 * to license@woocommerce.com so we can send you a copy immediately.
12 *
13 * DISCLAIMER
14 *
15 * Do not edit or add to this file if you wish to upgrade WooCommerce Square to newer
16 * versions in the future. If you wish to customize WooCommerce Square for your
17 * needs please refer to https://docs.woocommerce.com/document/woocommerce-square/
18 *
19 * @author WooCommerce
20 * @copyright Copyright: (c) 2019, Automattic, Inc.
21 * @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0 or later
22 */
23
24 namespace WooCommerce\Square;
25
26 defined( 'ABSPATH' ) || exit;
27
28 use WooCommerce\Square\Handlers\Product;
29
30 /**
31 * The base admin handler class.
32 *
33 * @since 2.0.0
34 */
35 class Admin {
36
37
38 /**
39 * Product handler.
40 *
41 * @var Handlers\Products
42 */
43 private $products_handler;
44
45 /**
46 * Privacy handler.
47 *
48 * @var Admin\Privacy
49 */
50 private $privacy_handler;
51
52 /**
53 * Plugin
54 *
55 * @var Plugin plugin instance
56 */
57 private $plugin;
58
59
60 /**
61 * Constructs the class.
62 *
63 * @since 2.0.0
64 *
65 * @param Plugin $plugin plugin instance.
66 */
67 public function __construct( Plugin $plugin ) {
68
69 $this->plugin = $plugin;
70
71 $this->products_handler = $this->plugin->get_products_handler();
72
73 // privacy
74 $this->privacy_handler = new Admin\Privacy();
75
76 $this->add_hooks();
77 }
78
79
80 /**
81 * Adds the action & filter hooks.
82 *
83 * @since 2.0.0
84 */
85 private function add_hooks() {
86
87 // add the settings page.
88 add_filter(
89 'woocommerce_get_settings_pages',
90 function ( $pages ) {
91
92 $pages[] = new Admin\Settings_Page( $this->get_plugin()->get_settings_handler() );
93
94 return $pages;
95 }
96 );
97
98 // load admin scripts.
99 add_action(
100 'admin_enqueue_scripts',
101 function() {
102 $this->load_scripts_styles();
103 }
104 );
105
106 add_action( 'wc_square_dismiss_notice', array( $this, 'dismiss_gift_cards_disabled_notice' ) );
107 }
108
109
110 /**
111 * Loads and enqueues admin scripts and styles.
112 *
113 * @since 2.0.0
114 */
115 private function load_scripts_styles() {
116 global $typenow;
117
118 if ( 'product' === $typenow ) {
119
120 wp_enqueue_script(
121 'wc-square-admin-products',
122 $this->get_plugin()->get_plugin_url() . '/assets/js/admin/wc-square-admin-products.min.js',
123 array( 'jquery' ),
124 Plugin::VERSION,
125 true
126 );
127
128 wp_localize_script(
129 'wc-square-admin-products',
130 'wc_square_admin_products',
131 array(
132 'ajax_url' => admin_url( 'admin-ajax.php' ),
133 'settings_url' => esc_url( $this->get_plugin()->get_settings_url() ),
134 'variable_product_types' => $this->get_variable_product_types(),
135 'synced_with_square_taxonomy' => Product::SYNCED_WITH_SQUARE_TAXONOMY,
136 'is_product_sync_enabled' => $this->get_plugin()->get_settings_handler()->is_product_sync_enabled(),
137 'is_woocommerce_sor' => $this->get_plugin()->get_settings_handler()->is_system_of_record_woocommerce(),
138 'is_square_sor' => $this->get_plugin()->get_settings_handler()->is_system_of_record_square(),
139 'is_inventory_sync_enabled' => $this->get_plugin()->get_settings_handler()->is_inventory_sync_enabled(),
140 'get_quick_edit_product_details_nonce' => wp_create_nonce( 'get-quick-edit-product-details' ),
141 'fetch_product_stock_with_square_nonce' => wp_create_nonce( 'fetch-product-stock-with-square' ),
142 'i18n' => array(
143 'synced_with_square' => __( 'Synced with Square', 'woocommerce-square' ),
144 'managed_by_square' => __( 'Managed by Square', 'woocommerce-square' ),
145 'fetch_stock_with_square' => __( 'Fetch stock from Square', 'woocommerce-square' ),
146 ),
147 )
148 );
149
150 return;
151 }
152
153 // Temporary - this can be removed when Gift Cards is out of beta. 2023-04-20
154 // The admin stylesheet is needed to provide notice-like styling for the Gift Cards beta notice.
155 if ( $this->get_plugin()->is_gateway_settings() ) {
156 wp_enqueue_style(
157 'wc-square-admin',
158 $this->get_plugin()->get_plugin_url() . '/assets/css/admin/wc-square-admin.min.css',
159 array(),
160 Plugin::VERSION
161 );
162
163 return;
164 }
165
166 if ( $this->get_plugin()->is_plugin_settings() ) {
167 wp_enqueue_style(
168 'wc-square-admin',
169 $this->get_plugin()->get_plugin_url() . '/assets/css/admin/wc-square-admin.min.css',
170 array(),
171 Plugin::VERSION
172 );
173
174 wp_enqueue_script(
175 'wc-square-admin-settings',
176 $this->get_plugin()->get_plugin_url() . '/assets/js/admin/wc-square-admin-settings.min.js',
177 array( 'jquery', 'jquery-blockui', 'backbone', 'wc-backbone-modal' ),
178 Plugin::VERSION,
179 true
180 );
181
182 $sync_job = $this->get_plugin()->get_sync_handler()->get_job_in_progress();
183
184 if ( $sync_job ) {
185 $existing_sync_id = $sync_job->id;
186 } else {
187 $existing_sync_id = false;
188 }
189
190 wp_localize_script(
191 'wc-square-admin-settings',
192 'wc_square_admin_settings',
193 array(
194 'ajax_url' => admin_url( 'admin-ajax.php' ),
195 'is_product_sync_enabled' => $this->get_plugin()->get_settings_handler()->is_product_sync_enabled(),
196 'is_woocommerce_sor' => $this->get_plugin()->get_settings_handler()->is_system_of_record_woocommerce(),
197 'is_square_sor' => $this->get_plugin()->get_settings_handler()->is_system_of_record_square(),
198 'is_inventory_sync_enabled' => $this->get_plugin()->get_settings_handler()->is_inventory_sync_enabled(),
199 'is_sandbox' => $this->get_plugin()->get_settings_handler()->is_sandbox(),
200 'existing_sync_job_id' => $existing_sync_id,
201 'import_products_from_square' => wp_create_nonce( 'import-products-from-square' ),
202 'sync_products_with_square' => wp_create_nonce( 'sync-products-with-square' ),
203 'get_sync_with_square_status_nonce' => wp_create_nonce( 'get-sync-with-square-status' ),
204 'handle_sync_with_square_records' => wp_create_nonce( 'handle-sync-with-square-records' ),
205 'i18n' => array(
206 'resolved' => __( 'Resolved', 'woocommerce-square' ),
207 'no_records_found' => __( 'No records found', 'woocommerce-square' ),
208 'skipped' => __( 'Skipped', 'woocommerce-square' ),
209 'updated' => __( 'Updated', 'woocommerce-square' ),
210 'imported' => __( 'Imported', 'woocommerce-square' ),
211 'sync_inventory_label' => array(
212 'square' => __( 'Enable to fetch inventory changes from Square', 'woocommerce-square' ),
213 'woocommerce' => __( 'Enable to push inventory changes to Square', 'woocommerce-square' ),
214 ),
215 'sync_inventory_description' => array(
216 'square' => __( 'Inventory is fetched from Square periodically and updated in WooCommerce', 'woocommerce-square' ),
217 'woocommerce' => sprintf(
218 /* translators: Placeholders: %1$s - <strong> tag, %2$s - </strong> tag */
219 __( 'Inventory is %1$salways fetched from Square%2$s periodically to account for sales from other channels.', 'woocommerce-square' ),
220 '<strong>',
221 '</strong>'
222 ),
223 ),
224 ),
225 )
226 );
227 }
228 }
229
230
231 /**
232 * Gets a list of variable product types.
233 *
234 * @since 2.0.0
235 *
236 * @return string[]
237 */
238 private function get_variable_product_types() {
239
240 /**
241 * Filters the variable product types.
242 *
243 * @since 2.0.0
244 *
245 * @param string[] array of product types
246 */
247 return (array) apply_filters( 'wc_square_variable_product_types', array( 'variable', 'variable-subscription' ) );
248 }
249
250
251 /**
252 * Gets the products handler.
253 *
254 * @since 2.0.0
255 *
256 * @return Admin\Products
257 */
258 public function get_products_handler() {
259
260 return $this->products_handler;
261 }
262
263
264 /**
265 * Gets the plugin instance.
266 *
267 * @since 2.0.0
268 *
269 * @return Plugin
270 */
271 protected function get_plugin() {
272
273 return $this->plugin;
274 }
275
276
277 /**
278 * Don't show the gift cards disabled notice for every WP Admin once it has been dismissed.
279 *
280 * @since 3.7.1
281 *
282 * @param string $notice_id
283 */
284 public function dismiss_gift_cards_disabled_notice( $notice_id ) {
285 if ( 'gift-cards-disabled' === $notice_id ) {
286 delete_option( 'woocommerce_square_3_7_1_gift_cards_force_disable_notice' );
287 }
288 }
289
290
291 }
292