abstracts
3 months ago
admin
3 months ago
frontend
1 month ago
integrations
1 month ago
v3
3 months ago
vendor
6 days ago
views
8 months ago
class-simplesalestax.php
6 days ago
class-sst-addresses.php
1 month ago
class-sst-ajax.php
3 months ago
class-sst-assets.php
6 months ago
class-sst-blocks-integration.php
1 month ago
class-sst-blocks.php
1 year ago
class-sst-certificates.php
6 days ago
class-sst-install.php
6 months ago
class-sst-logger.php
5 months ago
class-sst-marketplaces.php
6 months ago
class-sst-order-controller.php
3 months ago
class-sst-order.php
1 month ago
class-sst-origin-address.php
8 months ago
class-sst-product.php
3 months ago
class-sst-rate-limit.php
5 months ago
class-sst-settings.php
3 months ago
class-sst-shipping.php
3 years ago
class-sst-taxcloud-v3-api.php
3 months ago
class-sst-taxcloud-v3.php
3 months ago
class-sst-tic.php
2 years ago
class-sst-updater.php
3 years ago
sst-compatibility-functions.php
4 months ago
sst-functions.php
6 days ago
sst-message-functions.php
3 years ago
sst-update-functions.php
11 months ago
class-sst-assets.php
319 lines
| 1 | <?php |
| 2 | |
| 3 | if ( ! defined( 'ABSPATH' ) ) { |
| 4 | exit; |
| 5 | } |
| 6 | |
| 7 | /** |
| 8 | * Class SST_Assets |
| 9 | * |
| 10 | * Registers common assets. |
| 11 | */ |
| 12 | class SST_Assets { |
| 13 | |
| 14 | /** |
| 15 | * Plugin assets. |
| 16 | * |
| 17 | * @var array |
| 18 | */ |
| 19 | protected $assets = array(); |
| 20 | |
| 21 | /** |
| 22 | * Constructor. |
| 23 | */ |
| 24 | public function __construct() { |
| 25 | add_action( 'init', array( $this, 'init_assets' ) ); |
| 26 | add_action( 'wp_enqueue_scripts', array( $this, 'register_assets' ) ); |
| 27 | add_action( 'admin_enqueue_scripts', array( $this, 'register_admin_assets' ) ); |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * Initializes the assets array. |
| 32 | */ |
| 33 | public function init_assets() { |
| 34 | $this->assets = array( |
| 35 | 'sst-hideseek' => array( |
| 36 | 'type' => 'script', |
| 37 | 'file' => 'jquery.hideseek.min.js', |
| 38 | 'context' => 'both', |
| 39 | 'compressed' => true, |
| 40 | 'options' => array( |
| 41 | 'deps' => array( 'jquery' ), |
| 42 | 'ver' => '0.7.1', |
| 43 | ), |
| 44 | ), |
| 45 | 'sst-backbone-modal' => array( |
| 46 | 'type' => 'script', |
| 47 | 'file' => 'backbone-modal.js', |
| 48 | 'context' => 'both', |
| 49 | 'options' => array( 'deps' => array( 'underscore', 'backbone', 'wp-util' ) ), |
| 50 | ), |
| 51 | 'sst-tic-select' => array( |
| 52 | 'type' => 'script', |
| 53 | 'file' => 'tic-select.js', |
| 54 | 'context' => 'both', |
| 55 | 'options' => array( |
| 56 | 'deps' => array( |
| 57 | 'jquery', |
| 58 | 'sst-hideseek', |
| 59 | 'sst-backbone-modal', |
| 60 | ), |
| 61 | ), |
| 62 | ), |
| 63 | 'sst-wcv-tic-select' => array( |
| 64 | 'type' => 'script', |
| 65 | 'file' => 'wcv-tic-select.js', |
| 66 | 'context' => 'frontend', |
| 67 | 'options' => array( |
| 68 | 'deps' => array( |
| 69 | 'jquery', |
| 70 | ), |
| 71 | ), |
| 72 | ), |
| 73 | 'sst-wcfm-tic-select' => array( |
| 74 | 'type' => 'script', |
| 75 | 'file' => 'wcfm-tic-select.js', |
| 76 | 'context' => 'frontend', |
| 77 | 'options' => array( |
| 78 | 'deps' => array( |
| 79 | 'jquery', |
| 80 | ), |
| 81 | ), |
| 82 | ), |
| 83 | 'sst-tic-select-css' => array( |
| 84 | 'type' => 'style', |
| 85 | 'file' => 'tic-select.css', |
| 86 | 'context' => 'both', |
| 87 | 'options' => array( |
| 88 | 'deps' => array( 'sst-modal-css' ), |
| 89 | ), |
| 90 | ), |
| 91 | 'sst-admin-js' => array( |
| 92 | 'type' => 'script', |
| 93 | 'file' => 'admin.js', |
| 94 | 'context' => 'admin', |
| 95 | 'options' => array( |
| 96 | 'deps' => array( 'jquery' ), |
| 97 | 'localize' => array( |
| 98 | 'SST' => array( |
| 99 | 'strings' => array( |
| 100 | 'enter_id_and_key' => __( |
| 101 | 'Please enter your API Login ID and API Key.', |
| 102 | 'simple-sales-tax' |
| 103 | ), |
| 104 | 'settings_valid' => __( |
| 105 | 'Success! Your TaxCloud settings are valid.', |
| 106 | 'simple-sales-tax' |
| 107 | ), |
| 108 | 'verify_failed' => __( 'Connection to TaxCloud failed.', 'simple-sales-tax' ), |
| 109 | 'verify_btn' => __( 'Verify Settings', 'simple-sales-tax' ), |
| 110 | 'verifying' => __( 'Verifying...', 'simple-sales-tax' ), |
| 111 | 'went_wrong' => __( 'Something went wrong.', 'simple-sales-tax' ), |
| 112 | 'mode_refreshed' => __( 'Success! Your integration mode is now ', 'simple-sales-tax' ), |
| 113 | ), |
| 114 | ), |
| 115 | ), |
| 116 | ), |
| 117 | ), |
| 118 | 'sst-admin-css' => array( |
| 119 | 'type' => 'style', |
| 120 | 'file' => 'admin.css', |
| 121 | 'context' => 'admin', |
| 122 | ), |
| 123 | 'sst-certificate-form' => array( |
| 124 | 'type' => 'script', |
| 125 | 'file' => 'certificate-form.js', |
| 126 | 'context' => 'both', |
| 127 | 'options' => array( |
| 128 | 'deps' => array( |
| 129 | 'jquery', |
| 130 | 'selectWoo', |
| 131 | ), |
| 132 | ), |
| 133 | ), |
| 134 | 'sst-add-certificate-modal' => array( |
| 135 | 'type' => 'script', |
| 136 | 'file' => 'add-certificate-modal.js', |
| 137 | 'context' => 'both', |
| 138 | 'options' => array( |
| 139 | 'deps' => array( |
| 140 | 'jquery', |
| 141 | 'jquery-blockui', |
| 142 | 'sst-backbone-modal', |
| 143 | 'sst-certificate-form', |
| 144 | ), |
| 145 | 'localize' => array( |
| 146 | 'SST_Add_Certificate_Data' => array( |
| 147 | 'nonce' => wp_create_nonce( 'sst_add_certificate' ), |
| 148 | 'strings' => array( |
| 149 | 'please_add_address' => __( |
| 150 | 'Please enter a complete billing address first.', |
| 151 | 'simple-sales-tax' |
| 152 | ), |
| 153 | 'invalid_country' => __( |
| 154 | 'Billing address must be in the United States to add an exemption certificate.', |
| 155 | 'simple-sales-tax' |
| 156 | ), |
| 157 | ), |
| 158 | ), |
| 159 | ), |
| 160 | ) |
| 161 | ), |
| 162 | 'sst-certificate-table' => array( |
| 163 | 'type' => 'script', |
| 164 | 'file' => 'certificate-table.js', |
| 165 | 'context' => 'both', |
| 166 | 'options' => array( |
| 167 | 'deps' => array( |
| 168 | 'jquery', |
| 169 | 'wp-util', |
| 170 | 'wp-hooks', |
| 171 | 'underscore', |
| 172 | 'backbone', |
| 173 | 'sst-backbone-modal', |
| 174 | 'jquery-blockui', |
| 175 | 'sst-add-certificate-modal', |
| 176 | ), |
| 177 | ), |
| 178 | ), |
| 179 | 'sst-checkout' => array( |
| 180 | 'type' => 'script', |
| 181 | 'file' => 'checkout.js', |
| 182 | 'context' => 'frontend', |
| 183 | 'options' => array( |
| 184 | 'deps' => array( |
| 185 | 'jquery', |
| 186 | 'sst-certificate-form', |
| 187 | ), |
| 188 | ), |
| 189 | ), |
| 190 | 'sst-checkout-css' => array( |
| 191 | 'type' => 'style', |
| 192 | 'file' => 'checkout.css', |
| 193 | 'context' => 'frontend', |
| 194 | ), |
| 195 | 'sst-modal-css' => array( |
| 196 | 'type' => 'style', |
| 197 | 'file' => 'modal.css', |
| 198 | 'context' => 'both', |
| 199 | ), |
| 200 | 'sst-certificate-form-css' => array( |
| 201 | 'type' => 'style', |
| 202 | 'file' => 'certificate-form.css', |
| 203 | ), |
| 204 | 'sst-certificate-modal-css' => array( |
| 205 | 'type' => 'style', |
| 206 | 'file' => 'certificate-modal.css', |
| 207 | 'context' => 'both', |
| 208 | 'options' => array( |
| 209 | 'deps' => array( |
| 210 | 'sst-modal-css', |
| 211 | 'sst-certificate-form-css', |
| 212 | ), |
| 213 | ), |
| 214 | ), |
| 215 | 'sst-meta-box' => array( |
| 216 | 'type' => 'script', |
| 217 | 'file' => 'meta-box.js', |
| 218 | 'context' => 'admin', |
| 219 | 'options' => array( |
| 220 | 'deps' => array( |
| 221 | 'jquery', |
| 222 | 'backbone', |
| 223 | 'wp-util', |
| 224 | 'wc-enhanced-select', |
| 225 | 'sst-backbone-modal', |
| 226 | 'sst-add-certificate-modal', |
| 227 | ), |
| 228 | ), |
| 229 | ), |
| 230 | 'sst-address-table' => array( |
| 231 | 'type' => 'script', |
| 232 | 'file' => 'address-table.js', |
| 233 | 'context' => 'admin', |
| 234 | 'options' => array( |
| 235 | 'deps' => array( |
| 236 | 'jquery', |
| 237 | 'wp-util', |
| 238 | 'underscore', |
| 239 | 'backbone', |
| 240 | ), |
| 241 | ), |
| 242 | ), |
| 243 | ); |
| 244 | } |
| 245 | |
| 246 | /** |
| 247 | * Registers frontend assets. |
| 248 | */ |
| 249 | public function register_assets() { |
| 250 | $this->register_assets_for_context( 'frontend' ); |
| 251 | } |
| 252 | |
| 253 | /** |
| 254 | * Registers admin assets. |
| 255 | */ |
| 256 | public function register_admin_assets() { |
| 257 | $this->register_assets_for_context( 'admin' ); |
| 258 | } |
| 259 | |
| 260 | /** |
| 261 | * Helper for registering assets. |
| 262 | * |
| 263 | * @param string $context Context to register assets for. Can be 'admin' or 'frontend'. |
| 264 | */ |
| 265 | private function register_assets_for_context( $context ) { |
| 266 | $js_base_url = SST()->url( 'assets/js/' ); |
| 267 | $css_base_url = SST()->url( 'assets/css/' ); |
| 268 | $plugin_version = SST()->version; |
| 269 | $load_minified = ! defined( 'SCRIPT_DEBUG' ) || ! SCRIPT_DEBUG; |
| 270 | $defaults = array( |
| 271 | 'type' => '', |
| 272 | 'file' => '', |
| 273 | 'compressed' => false, |
| 274 | 'context' => 'both', |
| 275 | 'options' => array(), |
| 276 | ); |
| 277 | |
| 278 | foreach ( $this->assets as $handle => $asset ) { |
| 279 | $asset = wp_parse_args( $asset, $defaults ); |
| 280 | $options = $asset['options']; |
| 281 | $ver = $options['ver'] ?? $plugin_version; |
| 282 | $deps = array(); |
| 283 | |
| 284 | if ( isset( $options['deps'] ) ) { |
| 285 | $deps = $options['deps']; |
| 286 | } |
| 287 | |
| 288 | if ( 'both' === $asset['context'] || $context === $asset['context'] ) { |
| 289 | if ( 'script' === $asset['type'] ) { |
| 290 | $src = $js_base_url . $asset['file']; |
| 291 | |
| 292 | if ( ! $asset['compressed'] && $load_minified ) { |
| 293 | $src = str_replace( '.js', '.min.js', $src ); |
| 294 | } |
| 295 | |
| 296 | wp_register_script( $handle, $src, $deps, $ver, true ); |
| 297 | |
| 298 | if ( isset( $options['localize'] ) ) { |
| 299 | foreach ( $options['localize'] as $object_name => $data ) { |
| 300 | wp_localize_script( $handle, $object_name, $data ); |
| 301 | } |
| 302 | } |
| 303 | } else { |
| 304 | $src = $css_base_url . $asset['file']; |
| 305 | |
| 306 | if ( ! $asset['compressed'] && $load_minified ) { |
| 307 | $src = str_replace( '.css', '.min.css', $src ); |
| 308 | } |
| 309 | |
| 310 | wp_register_style( $handle, $src, $deps, $ver ); |
| 311 | } |
| 312 | } |
| 313 | } |
| 314 | } |
| 315 | |
| 316 | } |
| 317 | |
| 318 | new SST_Assets(); |
| 319 |