← All changes
|
app/src/Support/Scripts/AdminModelEditController.php
+21
-120
4.6.6
→
2.6.1
View file →
| @@ -1,8 +1,9 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace SureCart\Support\Scripts; |
| 4 | 4 | |
| 5 | +use SureCart\Models\Account; | |
| 5 | 6 | use SureCart\Support\Currency; |
| 6 | 7 | |
| 7 | 8 | /** |
| 8 | 9 | * Class for model edit pages to extend. |
| @@ -36,16 +37,8 @@ | ||
| 36 | 37 | */ |
| 37 | 38 | protected $dependencies = [ 'sc-core-data', 'sc-ui-data' ]; |
| 38 | 39 | |
| 39 | 40 | /** |
| 40 | - * Whether this admin screen renders a `@wordpress/dataviews` table and | |
| 41 | - * needs the bundled DataViews stylesheet. | |
| 42 | - * | |
| 43 | - * @var bool | |
| 44 | - */ | |
| 45 | - protected $needs_dataviews_style = false; | |
| 46 | - | |
| 47 | - /** | |
| 48 | 41 | * Data to pass to the page. |
| 49 | 42 | * |
| 50 | 43 | * @var array |
| 51 | 44 | */ |
| @@ -65,16 +58,10 @@ | ||
| 65 | 58 | */ |
| 66 | 59 | public function enqueueScriptDependencies() { |
| 67 | 60 | wp_enqueue_media(); |
| 68 | 61 | wp_enqueue_style( 'wp-components' ); |
| 69 | - wp_enqueue_style( 'wp-editor' ); | |
| 70 | 62 | } |
| 71 | 63 | |
| 72 | - /** | |
| 73 | - * Enqueue components | |
| 74 | - * | |
| 75 | - * @return void | |
| 76 | - */ | |
| 77 | 64 | public function enqueueComponents() { |
| 78 | 65 | wp_enqueue_script( 'surecart-components' ); |
| 79 | 66 | wp_enqueue_style( 'surecart-themes-default' ); |
| 80 | 67 | wp_add_inline_style( |
| @@ -80,39 +67,11 @@ | ||
| 80 | 67 | wp_add_inline_style( |
| 81 | 68 | 'surecart-themes-default', |
| 82 | 69 | ':root { --sc-color-primary-text: #fff; }' // this is important in case the user has a dark primary text. |
| 83 | 70 | ); |
| 84 | - wp_add_inline_style( | |
| 85 | - 'surecart-themes-default', | |
| 86 | - '.sc-dragging { z-index: 1 }' // this is required for dragging. | |
| 87 | - ); | |
| 88 | 71 | } |
| 89 | 72 | |
| 90 | 73 | /** |
| 91 | - * Enqueue the bundled `@wordpress/dataviews` stylesheet copied to | |
| 92 | - * `dist/vendor/` at build time. See `webpack.config.js` for the | |
| 93 | - * CopyPlugin pattern that produces this file. | |
| 94 | - * | |
| 95 | - * Only enqueues when `$needs_dataviews_style` is set on the controller. | |
| 96 | - */ | |
| 97 | - protected function enqueueDataviewsStyle(): void { | |
| 98 | - if ( ! $this->needs_dataviews_style ) { | |
| 99 | - return; | |
| 100 | - } | |
| 101 | - $relative = is_rtl() ? 'dist/vendor/dataviews-rtl.css' : 'dist/vendor/dataviews.css'; | |
| 102 | - $abs_path = plugin_dir_path( SURECART_PLUGIN_FILE ) . $relative; | |
| 103 | - if ( ! file_exists( $abs_path ) ) { | |
| 104 | - return; | |
| 105 | - } | |
| 106 | - wp_enqueue_style( | |
| 107 | - 'sc-dataviews', | |
| 108 | - trailingslashit( \SureCart::core()->assets()->getUrl() ) . $relative, | |
| 109 | - [], | |
| 110 | - defined( 'SURECART_VERSION' ) ? SURECART_VERSION : (string) filemtime( $abs_path ) | |
| 111 | - ); | |
| 112 | - } | |
| 113 | - | |
| 114 | - /** | |
| 115 | 74 | * Enqueue scripts |
| 116 | 75 | * |
| 117 | 76 | * @return void |
| 118 | 77 | */ |
| @@ -122,9 +81,8 @@ | ||
| 122 | 81 | } |
| 123 | 82 | |
| 124 | 83 | // components are also used on index pages. |
| 125 | 84 | $this->enqueueComponents(); |
| 126 | - $this->enqueueDataviewsStyle(); | |
| 127 | 85 | |
| 128 | 86 | // match url query for the scripts. |
| 129 | 87 | if ( ! empty( $this->url_query ) ) { |
| 130 | 88 | foreach ( $this->url_query as $param => $value ) { |
| @@ -137,12 +95,15 @@ | ||
| 137 | 95 | |
| 138 | 96 | // enqueue dependencies. |
| 139 | 97 | $this->enqueueScriptDependencies(); |
| 140 | 98 | |
| 141 | - // Fix Jetpack script key hijacking issues. | |
| 99 | + // remove admin notices. | |
| 100 | + remove_all_actions( 'admin_notices' ); | |
| 101 | + | |
| 102 | + // fix shitty jetpack issues key hijacking issues. | |
| 142 | 103 | add_filter( |
| 143 | 104 | 'admin_head', |
| 144 | - function () { | |
| 105 | + function() { | |
| 145 | 106 | wp_dequeue_script( 'wpcom-notes-common' ); |
| 146 | 107 | wp_dequeue_script( 'wpcom-notes-admin-bar' ); |
| 147 | 108 | wp_dequeue_style( 'wpcom-notes-admin-bar' ); |
| 148 | 109 | wp_dequeue_style( 'noticons' ); |
| @@ -150,86 +111,32 @@ | ||
| 150 | 111 | 200 |
| 151 | 112 | ); |
| 152 | 113 | |
| 153 | 114 | // automatically load dependencies and version. |
| 154 | - $asset_file_path = plugin_dir_path( SURECART_PLUGIN_FILE ) . "dist/$this->path.asset.php"; | |
| 155 | - if ( ! file_exists( $asset_file_path ) ) { | |
| 156 | - // Bundle hasn't been built yet (e.g. fresh install or the entry | |
| 157 | - // was just added without running `yarn build`). Bail rather than | |
| 158 | - // crashing on an `array_merge( null, ... )`. | |
| 159 | - return; | |
| 160 | - } | |
| 161 | - $asset_file = include $asset_file_path; | |
| 115 | + $asset_file = include plugin_dir_path( SURECART_PLUGIN_FILE ) . "dist/$this->path.asset.php"; | |
| 162 | 116 | |
| 163 | - // Fall back to plugin version so we still cache-bust on upgrade if | |
| 164 | - // the asset manifest is missing or malformed. | |
| 165 | - $version = $asset_file['version'] ?? ( defined( 'SURECART_VERSION' ) ? SURECART_VERSION : null ); | |
| 166 | - | |
| 167 | 117 | // Enqueue scripts. |
| 168 | - wp_enqueue_script( | |
| 118 | + \SureCart::core()->assets()->enqueueScript( | |
| 169 | 119 | $this->handle, |
| 170 | 120 | trailingslashit( \SureCart::core()->assets()->getUrl() ) . "dist/$this->path.js", |
| 171 | - array_merge( $asset_file['dependencies'] ?? [], $this->dependencies ), | |
| 172 | - $version, | |
| 173 | - true | |
| 121 | + array_merge( $asset_file['dependencies'], $this->dependencies ), | |
| 122 | + $asset_file['version'] . '-' . \SureCart::plugin()->version() | |
| 174 | 123 | ); |
| 175 | 124 | |
| 176 | - // Enqueue extracted CSS if the build produced a stylesheet for this entry. | |
| 177 | - $style_path = plugin_dir_path( SURECART_PLUGIN_FILE ) . "dist/$this->path.css"; | |
| 178 | - if ( file_exists( $style_path ) ) { | |
| 179 | - wp_enqueue_style( | |
| 180 | - $this->handle, | |
| 181 | - trailingslashit( \SureCart::core()->assets()->getUrl() ) . "dist/$this->path.css", | |
| 182 | - array(), | |
| 183 | - $version | |
| 184 | - ); | |
| 185 | - } | |
| 186 | - | |
| 187 | - // Enqueue the vendor/library stylesheet (style-{entry}.css) produced by splitChunks. | |
| 188 | - $vendor_style_basename = 'style-' . basename( $this->path ); | |
| 189 | - $vendor_style_dir = dirname( $this->path ); | |
| 190 | - $vendor_style_rel = ( '.' === $vendor_style_dir ? '' : $vendor_style_dir . '/' ) . $vendor_style_basename . '.css'; | |
| 191 | - $vendor_style_path = plugin_dir_path( SURECART_PLUGIN_FILE ) . "dist/$vendor_style_rel"; | |
| 192 | - if ( file_exists( $vendor_style_path ) ) { | |
| 193 | - wp_enqueue_style( | |
| 194 | - $this->handle . '-vendor', | |
| 195 | - trailingslashit( \SureCart::core()->assets()->getUrl() ) . "dist/$vendor_style_rel", | |
| 196 | - array(), | |
| 197 | - $version | |
| 198 | - ); | |
| 199 | - } | |
| 200 | - | |
| 201 | - if ( $this->needs_dataviews_style ) { | |
| 202 | - $this->data['enhanced_admin_views_enabled'] = (bool) get_option( 'surecart_enhanced_admin_views', true ); | |
| 203 | - $this->data['modern_view_intro'] = \SureCart\Settings\SettingService::getModernViewIntroData(); | |
| 204 | - } | |
| 205 | - | |
| 206 | 125 | // pass app url. |
| 207 | - $this->data['upgrade_url'] = \SureCart::config()->links->purchase; | |
| 208 | - $this->data['surecart_app_url'] = defined( 'SURECART_APP_URL' ) ? SURECART_APP_URL : ''; | |
| 209 | - $this->data['account_id'] = \SureCart::account()->id ?? ''; | |
| 210 | - $this->data['account_slug'] = \SureCart::account()->slug ?? ''; | |
| 211 | - $this->data['api_url'] = \SureCart::requests()->getBaseUrl(); | |
| 212 | - $this->data['plugin_url'] = \SureCart::core()->assets()->getUrl(); | |
| 213 | - $this->data['locale'] = str_replace( '_', '-', get_locale() ); | |
| 214 | - $this->data['root_url'] = esc_url_raw( get_rest_url() ); | |
| 215 | - $this->data['home_url'] = untrailingslashit( get_home_url() ); | |
| 216 | - $this->data['site_name'] = get_bloginfo( 'name' ); | |
| 217 | - $this->data['site_icon_url'] = get_site_icon_url( 96 ); | |
| 218 | - $this->data['buy_page_slug'] = untrailingslashit( \SureCart::settings()->permalinks()->getBase( 'buy_page' ) ); | |
| 219 | - $this->data['product_page_slug'] = untrailingslashit( \SureCart::settings()->permalinks()->getBase( 'product_page' ) ); | |
| 220 | - $this->data['collection_page_slug'] = untrailingslashit( \SureCart::settings()->permalinks()->getBase( 'collection_page' ) ); | |
| 221 | - $this->data['is_block_theme'] = \SureCart::utility()->blockTemplates()->isFSETheme(); | |
| 222 | - $this->data['claim_url'] = ! \SureCart::account()->claimed ? \SureCart::routeUrl( 'account.claim' ) : ''; | |
| 223 | - $this->data['claim_expired'] = \SureCart::account()->claim_expired ?? false; | |
| 224 | - $this->data['is_woocommerce_active'] = class_exists( 'WooCommerce' ); | |
| 126 | + $this->data['upgrade_url'] = \SureCart::config()->links->purchase; | |
| 127 | + $this->data['surecart_app_url'] = defined( 'SURECART_APP_URL' ) ? SURECART_APP_URL : ''; | |
| 128 | + $this->data['api_url'] = \SureCart::requests()->getBaseUrl(); | |
| 129 | + $this->data['plugin_url'] = \SureCart::core()->assets()->getUrl(); | |
| 130 | + $this->data['home_url'] = untrailingslashit( get_home_url() ); | |
| 131 | + $this->data['buy_page_slug'] = untrailingslashit( \SureCart::settings()->permalinks()->getBase( 'buy_page' ) ); | |
| 132 | + $this->data['product_page_slug'] = untrailingslashit( \SureCart::settings()->permalinks()->getBase( 'product_page' ) ); | |
| 133 | + $this->data['is_block_theme'] = \SureCart::utility()->blockTemplates()->isFSETheme(); | |
| 134 | + $this->data['claim_url'] = ! \SureCart::account()->claimed ? \SureCart::routeUrl( 'account.claim' ) : ''; | |
| 225 | 135 | |
| 226 | 136 | if ( in_array( 'currency', $this->with_data ) ) { |
| 227 | 137 | $this->data['currency_code'] = \SureCart::account()->currency; |
| 228 | 138 | } |
| 229 | - if ( in_array( 'review_protocol', $this->with_data ) ) { | |
| 230 | - $this->data['review_protocol'] = \SureCart::account()->review_protocol; | |
| 231 | - } | |
| 232 | 139 | if ( in_array( 'tax_protocol', $this->with_data ) ) { |
| 233 | 140 | $this->data['tax_protocol'] = \SureCart::account()->tax_protocol; |
| 234 | 141 | } |
| 235 | 142 | if ( in_array( 'shipping_protocol', $this->with_data ) ) { |
| @@ -238,9 +145,9 @@ | ||
| 238 | 145 | if ( in_array( 'checkout_page_url', $this->with_data ) ) { |
| 239 | 146 | $this->data['checkout_page_url'] = \SureCart::getUrl()->checkout(); |
| 240 | 147 | } |
| 241 | 148 | if ( in_array( 'supported_currencies', $this->with_data ) ) { |
| 242 | - $this->data['supported_currencies'] = Currency::list(); | |
| 149 | + $this->data['supported_currencies'] = Currency::getSupportedCurrencies(); | |
| 243 | 150 | } |
| 244 | 151 | if ( in_array( 'links', $this->with_data ) ) { |
| 245 | 152 | $this->data['links'] = []; |
| 246 | 153 | foreach ( array_keys( \SureCart::getAdminPageNames() ) as $name ) { |
| @@ -246,18 +153,12 @@ | ||
| 246 | 153 | foreach ( array_keys( \SureCart::getAdminPageNames() ) as $name ) { |
| 247 | 154 | $this->data['links'][ $name ] = esc_url_raw( add_query_arg( [ 'action' => 'edit' ], \SureCart::getUrl()->index( $name ) ) ); |
| 248 | 155 | } |
| 249 | 156 | } |
| 250 | - if ( in_array( 'google_map_api_key', $this->with_data ) ) { | |
| 251 | - $this->data['google_map_api_key'] = \SureCart::googleMaps()->getApiKey(); | |
| 252 | - } | |
| 253 | 157 | |
| 254 | 158 | // pass entitlements to page. |
| 255 | 159 | $this->data['entitlements'] = \SureCart::account()->entitlements; |
| 256 | - $this->data['get_locale'] = str_replace( '_', '-', determine_locale() ); | |
| 257 | - | |
| 258 | - // pass wp user roles to page. | |
| 259 | - $this->data['wp_user_roles'] = get_editable_roles(); | |
| 160 | + $this->data['get_locale'] = str_replace( '_', '-', get_locale() ); | |
| 260 | 161 | |
| 261 | 162 | wp_set_script_translations( $this->handle, 'surecart' ); |
| 262 | 163 | |
| 263 | 164 | // common localizations. |