PluginProbe
WooCommerce Square / 3.4.2
WooCommerce Square v3.4.2
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
263 lines 7.7 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' ) || 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 'import_products_from_square' => wp_create_nonce( 'import-products-from-square' ),
187 'sync_products_with_square' => wp_create_nonce( 'sync-products-with-square' ),
188 'get_sync_with_square_status_nonce' => wp_create_nonce( 'get-sync-with-square-status' ),
189 'handle_sync_with_square_records' => wp_create_nonce( 'handle-sync-with-square-records' ),
190 'i18n' => array(
191 'resolved' => __( 'Resolved', 'woocommerce-square' ),
192 'no_records_found' => __( 'No records found', 'woocommerce-square' ),
193 'skipped' => __( 'Skipped', 'woocommerce-square' ),
194 'updated' => __( 'Updated', 'woocommerce-square' ),
195 'imported' => __( 'Imported', 'woocommerce-square' ),
196 'sync_inventory_label' => array(
197 'square' => __( 'Enable to fetch inventory changes from Square', 'woocommerce-square' ),
198 'woocommerce' => __( 'Enable to push inventory changes to Square', 'woocommerce-square' ),
199 ),
200 'sync_inventory_description' => array(
201 'square' => __( 'Inventory is fetched from Square periodically and updated in WooCommerce', 'woocommerce-square' ),
202 'woocommerce' => sprintf(
203 /* translators: Placeholders: %1$s - <strong> tag, %2$s - </strong> tag */
204 __( 'Inventory is %1$salways fetched from Square%2$s periodically to account for sales from other channels.', 'woocommerce-square' ),
205 '<strong>',
206 '</strong>'
207 ),
208 ),
209 ),
210 )
211 );
212 }
213 }
214
215
216 /**
217 * Gets a list of variable product types.
218 *
219 * @since 2.0.0
220 *
221 * @return string[]
222 */
223 private function get_variable_product_types() {
224
225 /**
226 * Filters the variable product types.
227 *
228 * @since 2.0.0
229 *
230 * @param string[] array of product types
231 */
232 return (array) apply_filters( 'wc_square_variable_product_types', array( 'variable', 'variable-subscription' ) );
233 }
234
235
236 /**
237 * Gets the products handler.
238 *
239 * @since 2.0.0
240 *
241 * @return Admin\Products
242 */
243 public function get_products_handler() {
244
245 return $this->products_handler;
246 }
247
248
249 /**
250 * Gets the plugin instance.
251 *
252 * @since 2.0.0
253 *
254 * @return Plugin
255 */
256 protected function get_plugin() {
257
258 return $this->plugin;
259 }
260
261
262 }
263