PluginProbe
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments / 3.6.1
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments v3.6.1
4.7.2 4.7.1 4.7.0 4.6.6 4.6.5 4.6.4 4.6.3 4.6.2 4.6.1 4.6.0 4.5.1 4.5.0 4.4.2 4.4.1 4.4.0 4.3.3 4.3.2 4.3.1 4.3.0 4.2.3 4.2.2 4.2.1 1.0.3 1.0.4 1.0.5 All 281 releases
surecart / app / src / Support / Scripts / AdminModelEditController.php

AdminModelEditController.php in SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments 3.6.1, at app/src/Support/Scripts/AdminModelEditController.php

189 lines 5.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace SureCart\Support\Scripts;
4
5 use SureCart\Models\Account;
6 use SureCart\Support\Currency;
7
8 /**
9 * Class for model edit pages to extend.
10 */
11 abstract class AdminModelEditController {
12 /**
13 * Script path.
14 *
15 * @var string
16 */
17 protected $path = '';
18
19 /**
20 * Script handle.
21 *
22 * @var string
23 */
24 protected $handle = '';
25
26 /**
27 * What types of data to add the the page.
28 *
29 * @var array
30 */
31 protected $with_data = [ 'links' ];
32
33 /**
34 * Additional dependencies
35 *
36 * @var array
37 */
38 protected $dependencies = [ 'sc-core-data', 'sc-ui-data' ];
39
40 /**
41 * Data to pass to the page.
42 *
43 * @var array
44 */
45 protected $data = [];
46
47 /**
48 * Optional conditionally load.
49 */
50 protected function condition() {
51 return true;
52 }
53
54 /**
55 * Enqueue needed scripts
56 *
57 * @return void
58 */
59 public function enqueueScriptDependencies() {
60 wp_enqueue_media();
61 wp_enqueue_style( 'wp-components' );
62 wp_enqueue_style( 'wp-editor' );
63 }
64
65 public function enqueueComponents() {
66 wp_enqueue_script( 'surecart-components' );
67 wp_enqueue_style( 'surecart-themes-default' );
68 wp_add_inline_style(
69 'surecart-themes-default',
70 ':root { --sc-color-primary-text: #fff; }' // this is important in case the user has a dark primary text.
71 );
72 wp_add_inline_style(
73 'surecart-themes-default',
74 '.sc-dragging { z-index: 1 }' // this is required for dragging.
75 );
76 }
77
78 /**
79 * Enqueue scripts
80 *
81 * @return void
82 */
83 public function enqueue() {
84 if ( ! $this->condition() ) {
85 return;
86 }
87
88 // components are also used on index pages.
89 $this->enqueueComponents();
90
91 // match url query for the scripts.
92 if ( ! empty( $this->url_query ) ) {
93 foreach ( $this->url_query as $param => $value ) {
94 // phpcs:ignore
95 if ( ! isset( $_GET[ $param ] ) || $value !== sanitize_text_field( wp_unslash( $_GET[ $param ] ) ) ) {
96 return;
97 }
98 }
99 }
100
101 // enqueue dependencies.
102 $this->enqueueScriptDependencies();
103
104 // fix shitty jetpack issues key hijacking issues.
105 add_filter(
106 'admin_head',
107 function () {
108 wp_dequeue_script( 'wpcom-notes-common' );
109 wp_dequeue_script( 'wpcom-notes-admin-bar' );
110 wp_dequeue_style( 'wpcom-notes-admin-bar' );
111 wp_dequeue_style( 'noticons' );
112 },
113 200
114 );
115
116 // automatically load dependencies and version.
117 $asset_file = include plugin_dir_path( SURECART_PLUGIN_FILE ) . "dist/$this->path.asset.php";
118
119 // Enqueue scripts.
120 wp_enqueue_script(
121 $this->handle,
122 trailingslashit( \SureCart::core()->assets()->getUrl() ) . "dist/$this->path.js",
123 array_merge( $asset_file['dependencies'], $this->dependencies ),
124 $asset_file['version'],
125 true
126 );
127
128 // pass app url.
129 $this->data['upgrade_url'] = \SureCart::config()->links->purchase;
130 $this->data['surecart_app_url'] = defined( 'SURECART_APP_URL' ) ? SURECART_APP_URL : '';
131 $this->data['account_id'] = \SureCart::account()->id ?? '';
132 $this->data['account_slug'] = \SureCart::account()->slug ?? '';
133 $this->data['api_url'] = \SureCart::requests()->getBaseUrl();
134 $this->data['plugin_url'] = \SureCart::core()->assets()->getUrl();
135 $this->data['home_url'] = untrailingslashit( get_home_url() );
136 $this->data['buy_page_slug'] = untrailingslashit( \SureCart::settings()->permalinks()->getBase( 'buy_page' ) );
137 $this->data['product_page_slug'] = untrailingslashit( \SureCart::settings()->permalinks()->getBase( 'product_page' ) );
138 $this->data['collection_page_slug'] = untrailingslashit( \SureCart::settings()->permalinks()->getBase( 'collection_page' ) );
139 $this->data['is_block_theme'] = \SureCart::utility()->blockTemplates()->isFSETheme();
140 $this->data['claim_url'] = ! \SureCart::account()->claimed ? \SureCart::routeUrl( 'account.claim' ) : '';
141
142 if ( in_array( 'currency', $this->with_data ) ) {
143 $this->data['currency_code'] = \SureCart::account()->currency;
144 }
145 if ( in_array( 'tax_protocol', $this->with_data ) ) {
146 $this->data['tax_protocol'] = \SureCart::account()->tax_protocol;
147 }
148 if ( in_array( 'shipping_protocol', $this->with_data ) ) {
149 $this->data['shipping_protocol'] = \SureCart::account()->shipping_protocol;
150 }
151 if ( in_array( 'checkout_page_url', $this->with_data ) ) {
152 $this->data['checkout_page_url'] = \SureCart::getUrl()->checkout();
153 }
154 if ( in_array( 'supported_currencies', $this->with_data ) ) {
155 $this->data['supported_currencies'] = Currency::list();
156 }
157 if ( in_array( 'links', $this->with_data ) ) {
158 $this->data['links'] = [];
159 foreach ( array_keys( \SureCart::getAdminPageNames() ) as $name ) {
160 $this->data['links'][ $name ] = esc_url_raw( add_query_arg( [ 'action' => 'edit' ], \SureCart::getUrl()->index( $name ) ) );
161 }
162 }
163 if ( in_array( 'i18n', $this->with_data ) ) {
164 $this->data['i18n'] = \SureCart::state()->i18n()->get();
165 }
166
167 // pass entitlements to page.
168 $this->data['entitlements'] = \SureCart::account()->entitlements;
169 $this->data['get_locale'] = str_replace( '_', '-', get_locale() );
170
171 wp_set_script_translations( $this->handle, 'surecart' );
172
173 // common localizations.
174 wp_localize_script(
175 $this->handle,
176 'scData',
177 apply_filters( "$this->handle/data", $this->data )
178 );
179
180 wp_localize_script( $this->handle, 'scIcons', [ 'path' => esc_url_raw( plugin_dir_url( SURECART_PLUGIN_FILE ) . 'dist/icon-assets' ) ] );
181
182 // custom localizations.
183 $this->localize( $this->handle );
184 }
185
186 protected function localize( $handle ) {
187 }
188 }
189