PluginProbe ʕ •ᴥ•ʔ
WooCommerce Square / 4.8.0
WooCommerce Square v4.8.0
5.5.0 5.4.3 5.4.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 2 years ago Admin 1 year ago Emails 2 years ago Framework 1 year ago Gateway 2 years ago Handlers 1 year ago Sync 1 year ago Utilities 2 years ago AJAX.php 2 years ago API.php 2 years ago Admin.php 2 years ago Functions.php 3 years ago Gateway.php 2 years ago Lifecycle.php 2 years ago Plugin.php 2 years ago Settings.php 2 years ago WC_Order_Square.php 2 years ago WC_Payments_Compatibility.php 2 years ago
Admin.php
350 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\Admin\Analytics\Revenue;
29 use WooCommerce\Square\Handlers\Product;
30
31 /**
32 * The base admin handler class.
33 *
34 * @since 2.0.0
35 */
36 class Admin {
37
38
39 /**
40 * Product handler.
41 *
42 * @var Handlers\Products
43 */
44 private $products_handler;
45
46 /**
47 * Privacy handler.
48 *
49 * @var Admin\Privacy
50 */
51 private $privacy_handler;
52
53 /**
54 * Plugin
55 *
56 * @var Plugin plugin instance
57 */
58 private $plugin;
59
60
61 /**
62 * Constructs the class.
63 *
64 * @since 2.0.0
65 *
66 * @param Plugin $plugin plugin instance.
67 */
68 public function __construct( Plugin $plugin ) {
69
70 $this->plugin = $plugin;
71
72 $this->products_handler = $this->plugin->get_products_handler();
73
74 // privacy
75 $this->privacy_handler = new Admin\Privacy();
76
77 new Revenue();
78
79 $this->add_hooks();
80 }
81
82
83 /**
84 * Adds the action & filter hooks.
85 *
86 * @since 2.0.0
87 */
88 private function add_hooks() {
89
90 // add the settings page.
91 add_filter(
92 'woocommerce_get_settings_pages',
93 function ( $pages ) {
94
95 $pages[] = new Admin\Settings_Page( $this->get_plugin()->get_settings_handler() );
96
97 return $pages;
98 }
99 );
100
101 // load admin scripts.
102 add_action(
103 'admin_enqueue_scripts',
104 function ( $hook ) {
105 $this->load_scripts_styles( $hook );
106 }
107 );
108 }
109
110
111 /**
112 * Loads and enqueues admin scripts and styles.
113 *
114 * @param string $hook The current admin page.
115 *
116 * @since 2.0.0
117 */
118 private function load_scripts_styles( $hook ) {
119 global $typenow;
120
121 if ( 'product' === $typenow ) {
122
123 wp_enqueue_script(
124 'wc-square-admin-products',
125 $this->get_plugin()->get_plugin_url() . '/build/assets/admin/wc-square-admin-products.js',
126 array( 'jquery' ),
127 Plugin::VERSION,
128 true
129 );
130
131 wp_localize_script(
132 'wc-square-admin-products',
133 'wc_square_admin_products',
134 array(
135 'ajax_url' => admin_url( 'admin-ajax.php' ),
136 'settings_url' => esc_url( $this->get_plugin()->get_settings_url() ),
137 'variable_product_types' => $this->get_variable_product_types(),
138 'synced_with_square_taxonomy' => Product::SYNCED_WITH_SQUARE_TAXONOMY,
139 'is_product_sync_enabled' => $this->get_plugin()->get_settings_handler()->is_product_sync_enabled(),
140 'is_woocommerce_sor' => $this->get_plugin()->get_settings_handler()->is_system_of_record_woocommerce(),
141 'is_square_sor' => $this->get_plugin()->get_settings_handler()->is_system_of_record_square(),
142 'is_inventory_sync_enabled' => $this->get_plugin()->get_settings_handler()->is_inventory_sync_enabled(),
143 'get_quick_edit_product_details_nonce' => wp_create_nonce( 'get-quick-edit-product-details' ),
144 'fetch_product_stock_with_square_nonce' => wp_create_nonce( 'fetch-product-stock-with-square' ),
145 'supported_products_for_sync' => array( 'simple', 'variable' ),
146 'i18n' => array(
147 'inventory_tracking_disabled' => __( 'Inventory tracking is disabled for this product', 'woocommerce-square' ),
148 'synced_with_square' => __( 'Synced with Square', 'woocommerce-square' ),
149 'managed_by_square' => __( 'Managed by Square', 'woocommerce-square' ),
150 'fetch_stock_with_square' => __( 'Fetch stock from Square', 'woocommerce-square' ),
151 'sync_inventory' => __( 'Sync inventory', 'woocommerce-square' ),
152 'sync_stock_from_square' => __( 'Sync stock from Square', 'woocommerce-square' ),
153 ),
154 )
155 );
156 } elseif ( $this->get_plugin()->is_plugin_settings() ) {
157 wp_enqueue_style(
158 'wc-square-admin',
159 $this->get_plugin()->get_plugin_url() . '/build/assets/admin/wc-square-admin.css',
160 array(),
161 Plugin::VERSION
162 );
163
164 wp_enqueue_script(
165 'wc-square-admin-settings',
166 $this->get_plugin()->get_plugin_url() . '/build/assets/admin/wc-square-admin-settings.js',
167 array( 'jquery', 'jquery-blockui', 'backbone', 'wc-backbone-modal' ),
168 Plugin::VERSION,
169 true
170 );
171
172 $sync_job = $this->get_plugin()->get_sync_handler()->get_job_in_progress();
173
174 if ( $sync_job ) {
175 $existing_sync_id = $sync_job->id;
176 } else {
177 $existing_sync_id = false;
178 }
179
180 wp_localize_script(
181 'wc-square-admin-settings',
182 'wc_square_admin_settings',
183 array(
184 'ajax_url' => admin_url( 'admin-ajax.php' ),
185 'is_product_sync_enabled' => $this->get_plugin()->get_settings_handler()->is_product_sync_enabled(),
186 'is_woocommerce_sor' => $this->get_plugin()->get_settings_handler()->is_system_of_record_woocommerce(),
187 'is_square_sor' => $this->get_plugin()->get_settings_handler()->is_system_of_record_square(),
188 'is_inventory_sync_enabled' => $this->get_plugin()->get_settings_handler()->is_inventory_sync_enabled(),
189 'is_sandbox' => $this->get_plugin()->get_settings_handler()->is_sandbox(),
190 'existing_sync_job_id' => $existing_sync_id,
191 'import_products_from_square' => wp_create_nonce( 'import-products-from-square' ),
192 'sync_products_with_square' => wp_create_nonce( 'sync-products-with-square' ),
193 'get_sync_with_square_status_nonce' => wp_create_nonce( 'get-sync-with-square-status' ),
194 'handle_sync_with_square_records' => wp_create_nonce( 'handle-sync-with-square-records' ),
195 'i18n' => array(
196 'resolved' => __( 'Resolved', 'woocommerce-square' ),
197 'no_records_found' => __( 'No records found', 'woocommerce-square' ),
198 'skipped' => __( 'Skipped', 'woocommerce-square' ),
199 'updated' => __( 'Updated', 'woocommerce-square' ),
200 'imported' => __( 'Imported', 'woocommerce-square' ),
201 'sync_inventory_label' => array(
202 'square' => __( 'Enable to fetch inventory changes from Square', 'woocommerce-square' ),
203 'woocommerce' => __( 'Enable to push inventory changes to Square', 'woocommerce-square' ),
204 ),
205 'sync_inventory_description' => array(
206 'square' => __( 'Inventory is fetched from Square periodically and updated in WooCommerce', 'woocommerce-square' ),
207 'woocommerce' => sprintf(
208 /* translators: Placeholders: %1$s - <strong> tag, %2$s - </strong> tag */
209 __( 'Inventory is %1$salways fetched from Square%2$s periodically to account for sales from other channels.', 'woocommerce-square' ),
210 '<strong>',
211 '</strong>'
212 ),
213 ),
214 ),
215 )
216 );
217
218 $asset_file = WC_SQUARE_PLUGIN_PATH . 'build/settings.asset.php';
219
220 if ( ! file_exists( $asset_file ) ) {
221 return;
222 }
223
224 $asset = include $asset_file;
225
226 wp_enqueue_script(
227 'woocommerce-square-settings-js',
228 WC_SQUARE_PLUGIN_URL . 'build/settings.js',
229 $asset['dependencies'],
230 $asset['version'],
231 array(
232 'in_footer' => true,
233 )
234 );
235
236 wp_localize_script(
237 'woocommerce-square-settings-js',
238 'wcSquareSettings',
239 array(
240 'nonce' => wp_create_nonce( 'wc_square_settings' ),
241 'homeUrl' => home_url(),
242 'adminUrl' => admin_url(),
243 'ajaxUrl' => admin_url( 'admin-ajax.php' ),
244 'depsCheck' => $this->get_plugin()->get_dependency_handler()->meets_php_dependencies(),
245 )
246 );
247
248 wp_enqueue_style(
249 'woocommerce-square-settings-css',
250 WC_SQUARE_PLUGIN_URL . 'build/settings.css',
251 array(),
252 $asset['version'],
253 );
254 } elseif ( 'woocommerce_page_woocommerce-square-onboarding' === $hook ) {
255 $asset_file = WC_SQUARE_PLUGIN_PATH . 'build/onboarding.asset.php';
256
257 if ( ! file_exists( $asset_file ) ) {
258 return;
259 }
260
261 $asset = include $asset_file;
262
263 wp_enqueue_script(
264 'woocommerce-square-onboarding-js',
265 WC_SQUARE_PLUGIN_URL . 'build/onboarding.js',
266 $asset['dependencies'],
267 $asset['version'],
268 array(
269 'in_footer' => true,
270 )
271 );
272
273 wp_localize_script(
274 'woocommerce-square-onboarding-js',
275 'wcSquareSettings',
276 array(
277 'nonce' => wp_create_nonce( 'wc_square_settings' ),
278 'homeUrl' => home_url(),
279 'adminUrl' => admin_url(),
280 'ajaxUrl' => admin_url( 'admin-ajax.php' ),
281 )
282 );
283
284 wp_enqueue_style(
285 'woocommerce-square-onboarding-css',
286 WC_SQUARE_PLUGIN_URL . 'build/onboarding.css',
287 array(),
288 $asset['version'],
289 );
290
291 wp_localize_script(
292 'woocommerce-square-onboarding-js',
293 'wcSquareOnboarding',
294 array(
295 'plugin_version' => WC_SQUARE_PLUGIN_VERSION,
296 'is_mobile' => wp_is_mobile(),
297 )
298 );
299 }
300
301 wp_enqueue_style( 'wp-components' );
302 }
303
304
305 /**
306 * Gets a list of variable product types.
307 *
308 * @since 2.0.0
309 *
310 * @return string[]
311 */
312 private function get_variable_product_types() {
313
314 /**
315 * Filters the variable product types.
316 *
317 * @since 2.0.0
318 *
319 * @param string[] array of product types
320 */
321 return (array) apply_filters( 'wc_square_variable_product_types', array( 'variable', 'variable-subscription' ) );
322 }
323
324
325 /**
326 * Gets the products handler.
327 *
328 * @since 2.0.0
329 *
330 * @return Admin\Products
331 */
332 public function get_products_handler() {
333
334 return $this->products_handler;
335 }
336
337
338 /**
339 * Gets the plugin instance.
340 *
341 * @since 2.0.0
342 *
343 * @return Plugin
344 */
345 protected function get_plugin() {
346
347 return $this->plugin;
348 }
349 }
350