PluginProbe
WooCommerce Square / 2.0.7
WooCommerce Square v2.0.7
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 All 132 releases
woocommerce-square / includes / Admin.php

Admin.php in WooCommerce Square 2.0.7, at includes/Admin.php

217 lines 7.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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
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
22 */
23
24 namespace WooCommerce\Square;
25
26 defined( 'ABSPATH' ) or exit;
27
28 use SkyVerge\WooCommerce\PluginFramework\v5_4_0 as Framework;
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 /** @var Admin\Products */
40 private $products_handler;
41
42 /** @var Admin\Privacy */
43 private $privacy_handler;
44
45 /** @var Plugin plugin instance */
46 private $plugin;
47
48
49 /**
50 * Constructs the class.
51 *
52 * @since 2.0.0
53 *
54 * @param Plugin $plugin plugin instance
55 */
56 public function __construct( Plugin $plugin ) {
57
58 $this->plugin = $plugin;
59
60 $this->products_handler = new Admin\Products();
61 $this->privacy_handler = new Admin\Privacy();
62
63 $this->add_hooks();
64 }
65
66
67 /**
68 * Adds the action & filter hooks.
69 *
70 * @since 2.0.0
71 */
72 private function add_hooks() {
73
74 // add the settings page
75 add_filter( 'woocommerce_get_settings_pages', function ( $pages ) {
76
77 $pages[] = new Admin\Settings_Page( $this->get_plugin()->get_settings_handler() );
78
79 return $pages;
80 } );
81
82 // load admin scripts
83 add_action( 'admin_enqueue_scripts', function() { $this->load_scripts_styles(); } );
84 }
85
86
87 /**
88 * Loads and enqueues admin scripts and styles.
89 *
90 * @since 2.0.0
91 */
92 private function load_scripts_styles() {
93 global $typenow;
94
95 if ( 'product' === $typenow ) {
96
97 wp_enqueue_script( 'wc-square-admin-products', $this->get_plugin()->get_plugin_url() . '/assets/js/admin/wc-square-admin-products.min.js', [ 'jquery' ], Plugin::VERSION, true );
98
99 wp_localize_script( 'wc-square-admin-products', 'wc_square_admin_products', [
100
101 'ajax_url' => admin_url( 'admin-ajax.php' ),
102 'settings_url' => esc_url( $this->get_plugin()->get_settings_url() ),
103 'variable_product_types' => $this->get_variable_product_types(),
104 'synced_with_square_taxonomy' => Product::SYNCED_WITH_SQUARE_TAXONOMY,
105 'is_product_sync_enabled' => $this->get_plugin()->get_settings_handler()->is_product_sync_enabled(),
106 'is_woocommerce_sor' => $this->get_plugin()->get_settings_handler()->is_system_of_record_woocommerce(),
107 'is_square_sor' => $this->get_plugin()->get_settings_handler()->is_system_of_record_square(),
108 'is_inventory_sync_enabled' => $this->get_plugin()->get_settings_handler()->is_inventory_sync_enabled(),
109 'is_product_synced_with_square_nonce' => wp_create_nonce( 'is-product-synced-with-square' ),
110 'fetch_product_stock_with_square_nonce' => wp_create_nonce( 'fetch-product-stock-with-square' ),
111
112 'i18n' => [
113 'synced_with_square' => __( 'Synced with Square', 'woocommerce-square' ),
114 'managed_by_square' => __( 'Managed by Square', 'woocommerce-square' ),
115 'fetch_stock_with_square' => __( 'Fetch stock from Square', 'woocommerce-square' ),
116 ],
117
118 ] );
119
120 } elseif ( $this->get_plugin()->is_plugin_settings() ) {
121
122 wp_enqueue_style( 'wc-square-admin', $this->get_plugin()->get_plugin_url() . '/assets/css/admin/wc-square-admin.min.css', [], Plugin::VERSION );
123
124 wp_enqueue_script( 'wc-square-admin-settings', $this->get_plugin()->get_plugin_url() . '/assets/js/admin/wc-square-admin-settings.min.js', [ 'jquery', 'jquery-blockui', 'backbone', 'wc-backbone-modal' ], Plugin::VERSION, true );
125
126 if ( $sync_job = $this->get_plugin()->get_sync_handler()->get_job_in_progress() ) {
127 $existing_sync_id = $sync_job->id;
128 } else {
129 $existing_sync_id = false;
130 }
131
132 wp_localize_script( 'wc-square-admin-settings', 'wc_square_admin_settings', [
133
134 'ajax_url' => admin_url( 'admin-ajax.php' ),
135 'is_product_sync_enabled' => $this->get_plugin()->get_settings_handler()->is_product_sync_enabled(),
136 'is_woocommerce_sor' => $this->get_plugin()->get_settings_handler()->is_system_of_record_woocommerce(),
137 'is_square_sor' => $this->get_plugin()->get_settings_handler()->is_system_of_record_square(),
138 'is_inventory_sync_enabled' => $this->get_plugin()->get_settings_handler()->is_inventory_sync_enabled(),
139 'existing_sync_job_id' => $existing_sync_id,
140 'sync_in_background' => $this->get_plugin()->get_sync_handler()->should_sync_in_background(),
141 'import_products_from_square' => wp_create_nonce( 'import-products-from-square' ),
142 'sync_products_with_square' => wp_create_nonce( 'sync-products-with-square' ),
143 'get_sync_with_square_status_nonce' => wp_create_nonce( 'get-sync-with-square-status' ),
144 'handle_sync_with_square_records' => wp_create_nonce( 'handle-sync-with-square-records' ),
145
146 'i18n' => [
147 'resolved' => __( 'Resolved', 'woocommerce-square' ),
148 'no_records_found' => __( 'No records found', 'woocommerce-square' ),
149 'skipped' => __( 'Skipped', 'woocommerce-square' ),
150 'imported' => __( 'Imported', 'woocommerce-square' ),
151 'sync_inventory_label' => [
152 'square' => __( 'Enable to fetch inventory changes from Square', 'woocommerce-square' ),
153 'woocommerce' => __( 'Enable to push inventory changes to Square', 'woocommerce-square' ),
154 ],
155 'sync_inventory_description' => [
156 'square' => __( 'Inventory is fetched from Square periodically and updated in WooCommerce', 'woocommerce-square' ),
157 'woocommerce' => sprintf(
158 /* translators: Placeholders: %1$s - <strong> tag, %2$s - </strong> tag */
159 __( 'Inventory is %1$salways fetched from Square%2$s periodically to account for sales from other channels.', 'woocommerce-square' ),
160 '<strong>', '</strong>'
161 ),
162 ],
163 ],
164
165 ] );
166 }
167 }
168
169
170 /**
171 * Gets a list of variable product types.
172 *
173 * @since 2.0.0
174 *
175 * @return string[]
176 */
177 private function get_variable_product_types() {
178
179 /**
180 * Filters the variable product types.
181 *
182 * @since 2.0.0
183 *
184 * @param string[] array of product types
185 */
186 return (array) apply_filters( 'wc_square_variable_product_types', [ 'variable', 'variable-subscription' ] );
187 }
188
189
190 /**
191 * Gets the products handler.
192 *
193 * @since 2.0.0
194 *
195 * @return Admin\Products
196 */
197 public function get_products_handler() {
198
199 return $this->products_handler;
200 }
201
202
203 /**
204 * Gets the plugin instance.
205 *
206 * @since 2.0.0
207 *
208 * @return Plugin
209 */
210 protected function get_plugin() {
211
212 return $this->plugin;
213 }
214
215
216 }
217