PluginProbe ʕ •ᴥ•ʔ
WooCommerce Square / 2.3.2
WooCommerce Square v2.3.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 5 years ago Admin 5 years ago Emails 5 years ago Gateway 5 years ago Handlers 5 years ago Sync 5 years ago Utilities 5 years ago AJAX.php 5 years ago API.php 5 years ago Admin.php 5 years ago Functions.php 5 years ago Gateway.php 5 years ago Lifecycle.php 5 years ago Plugin.php 5 years ago Settings.php 5 years ago
Admin.php
264 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
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' ) || 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 if ( version_compare( WC_VERSION, '3.4', '>=' ) ) {
75 $this->privacy_handler = new Admin\Privacy();
76 }
77
78 $this->add_hooks();
79 }
80
81
82 /**
83 * Adds the action & filter hooks.
84 *
85 * @since 2.0.0
86 */
87 private function add_hooks() {
88
89 // add the settings page.
90 add_filter(
91 'woocommerce_get_settings_pages',
92 function ( $pages ) {
93
94 $pages[] = new Admin\Settings_Page( $this->get_plugin()->get_settings_handler() );
95
96 return $pages;
97 }
98 );
99
100 // load admin scripts.
101 add_action(
102 'admin_enqueue_scripts',
103 function() {
104 $this->load_scripts_styles();
105 }
106 );
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 } elseif ( $this->get_plugin()->is_plugin_settings() ) {
151
152 wp_enqueue_style(
153 'wc-square-admin',
154 $this->get_plugin()->get_plugin_url() . '/assets/css/admin/wc-square-admin.min.css',
155 array(),
156 Plugin::VERSION
157 );
158
159 wp_enqueue_script(
160 'wc-square-admin-settings',
161 $this->get_plugin()->get_plugin_url() . '/assets/js/admin/wc-square-admin-settings.min.js',
162 array( 'jquery', 'jquery-blockui', 'backbone', 'wc-backbone-modal' ),
163 Plugin::VERSION,
164 true
165 );
166
167 $sync_job = $this->get_plugin()->get_sync_handler()->get_job_in_progress();
168
169 if ( $sync_job ) {
170 $existing_sync_id = $sync_job->id;
171 } else {
172 $existing_sync_id = false;
173 }
174
175 wp_localize_script(
176 'wc-square-admin-settings',
177 'wc_square_admin_settings',
178 array(
179 'ajax_url' => admin_url( 'admin-ajax.php' ),
180 'is_product_sync_enabled' => $this->get_plugin()->get_settings_handler()->is_product_sync_enabled(),
181 'is_woocommerce_sor' => $this->get_plugin()->get_settings_handler()->is_system_of_record_woocommerce(),
182 'is_square_sor' => $this->get_plugin()->get_settings_handler()->is_system_of_record_square(),
183 'is_inventory_sync_enabled' => $this->get_plugin()->get_settings_handler()->is_inventory_sync_enabled(),
184 'is_sandbox' => $this->get_plugin()->get_settings_handler()->is_sandbox(),
185 'existing_sync_job_id' => $existing_sync_id,
186 'sync_in_background' => $this->get_plugin()->get_sync_handler()->should_sync_in_background(),
187 'import_products_from_square' => wp_create_nonce( 'import-products-from-square' ),
188 'sync_products_with_square' => wp_create_nonce( 'sync-products-with-square' ),
189 'get_sync_with_square_status_nonce' => wp_create_nonce( 'get-sync-with-square-status' ),
190 'handle_sync_with_square_records' => wp_create_nonce( 'handle-sync-with-square-records' ),
191 'i18n' => array(
192 'resolved' => __( 'Resolved', 'woocommerce-square' ),
193 'no_records_found' => __( 'No records found', 'woocommerce-square' ),
194 'skipped' => __( 'Skipped', 'woocommerce-square' ),
195 'updated' => __( 'Updated', 'woocommerce-square' ),
196 'imported' => __( 'Imported', 'woocommerce-square' ),
197 'sync_inventory_label' => array(
198 'square' => __( 'Enable to fetch inventory changes from Square', 'woocommerce-square' ),
199 'woocommerce' => __( 'Enable to push inventory changes to Square', 'woocommerce-square' ),
200 ),
201 'sync_inventory_description' => array(
202 'square' => __( 'Inventory is fetched from Square periodically and updated in WooCommerce', 'woocommerce-square' ),
203 'woocommerce' => sprintf(
204 /* translators: Placeholders: %1$s - <strong> tag, %2$s - </strong> tag */
205 __( 'Inventory is %1$salways fetched from Square%2$s periodically to account for sales from other channels.', 'woocommerce-square' ),
206 '<strong>',
207 '</strong>'
208 ),
209 ),
210 ),
211 )
212 );
213 }
214 }
215
216
217 /**
218 * Gets a list of variable product types.
219 *
220 * @since 2.0.0
221 *
222 * @return string[]
223 */
224 private function get_variable_product_types() {
225
226 /**
227 * Filters the variable product types.
228 *
229 * @since 2.0.0
230 *
231 * @param string[] array of product types
232 */
233 return (array) apply_filters( 'wc_square_variable_product_types', array( 'variable', 'variable-subscription' ) );
234 }
235
236
237 /**
238 * Gets the products handler.
239 *
240 * @since 2.0.0
241 *
242 * @return Admin\Products
243 */
244 public function get_products_handler() {
245
246 return $this->products_handler;
247 }
248
249
250 /**
251 * Gets the plugin instance.
252 *
253 * @since 2.0.0
254 *
255 * @return Plugin
256 */
257 protected function get_plugin() {
258
259 return $this->plugin;
260 }
261
262
263 }
264