PluginProbe
Subscriptions for WooCommerce with Stripe Recurring Payments / 1.9.5
Subscriptions for WooCommerce with Stripe Recurring Payments v1.9.5
2.0.0 1.11.2 1.11.1 1.11.0 1.10.9 1.10.8 1.10.7 1.10.6 1.10.5 1.10.4 1.10.3 1.10.2 1.10.1 1.10.0 1.9.6 1.9.5 trunk 1.3.0 1.3.1 1.3.2 1.4.0 1.4.1 1.4.2 1.5.0 1.5.1 All 61 releases
subscription / includes / Assets.php

Assets.php in Subscriptions for WooCommerce with Stripe Recurring Payments 1.9.5, at includes/Assets.php

129 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace SpringDevs\Subscription;
4
5 /**
6 * Scripts and Styles Class
7 */
8 class Assets {
9
10 /**
11 * Assets constructor.
12 */
13 public function __construct() {
14 if ( is_admin() ) {
15 add_action( 'admin_enqueue_scripts', array( $this, 'register' ), 5 );
16 } else {
17 add_action( 'wp_enqueue_scripts', array( $this, 'register' ), 5 );
18 }
19 }
20
21 /**
22 * Register our app scripts and styles
23 *
24 * @return void
25 */
26 public function register() {
27 $this->register_scripts( $this->get_scripts() );
28 $this->register_styles( $this->get_styles() );
29 }
30
31 /**
32 * Register scripts
33 *
34 * @param array $scripts scripts.
35 *
36 * @return void
37 */
38 private function register_scripts( $scripts ) {
39 foreach ( $scripts as $handle => $script ) {
40 $deps = isset( $script['deps'] ) ? $script['deps'] : false;
41 $in_footer = isset( $script['in_footer'] ) ? $script['in_footer'] : false;
42 $version = isset( $script['version'] ) ? $script['version'] : SUBSCRPT_VERSION;
43
44 wp_register_script( $handle, $script['src'], $deps, $version, $in_footer );
45
46 // Register script translations for scripts that use wp-i18n (e.g., block assets).
47 if ( function_exists( 'wp_set_script_translations' ) && 'sdevs_subscrpt_cart_block' === $handle ) {
48 wp_set_script_translations( $handle, 'subscription', SUBSCRPT_PATH . '/languages' );
49 }
50 }
51 }
52
53 /**
54 * Register styles
55 *
56 * @param array $styles styles.
57 *
58 * @return void
59 */
60 public function register_styles( $styles ) {
61 foreach ( $styles as $handle => $style ) {
62 $deps = isset( $style['deps'] ) ? $style['deps'] : false;
63
64 wp_register_style( $handle, $style['src'], $deps, SUBSCRPT_VERSION );
65 }
66 }
67
68 /**
69 * Get all registered scripts
70 *
71 * @return array
72 */
73 public function get_scripts() {
74 $plugin_js_assets_path = SUBSCRPT_ASSETS . '/js/';
75
76 $block_script_asset_path = SUBSCRPT_PATH . '/build/index.asset.php';
77 $block_script_asset = file_exists( $block_script_asset_path )
78 ? require $block_script_asset_path
79 : array(
80 'dependencies' => false,
81 'version' => SUBSCRPT_VERSION,
82 );
83
84 $scripts = array(
85 'sdevs_subscription_admin' => array(
86 'src' => $plugin_js_assets_path . 'admin.js',
87 'deps' => array( 'jquery' ),
88 'in_footer' => true,
89 ),
90 'sdevs_installer' => array(
91 'src' => $plugin_js_assets_path . 'installer.js',
92 'deps' => array( 'jquery' ),
93 'in_footer' => true,
94 ),
95 'sdevs_subscrpt_cart_block' => array(
96 'src' => SUBSCRPT_URL . '/build/index.js',
97 'deps' => $block_script_asset['dependencies'],
98 'version' => $block_script_asset['version'],
99 'in_footer' => true,
100 ),
101 );
102
103 return $scripts;
104 }
105
106 /**
107 * Get registered styles
108 *
109 * @return array
110 */
111 public function get_styles() {
112 $plugin_css_assets_path = SUBSCRPT_ASSETS . '/css/';
113
114 $styles = array(
115 'subscrpt_admin_css' => array(
116 'src' => $plugin_css_assets_path . 'admin.css',
117 ),
118 'subscrpt_status_css' => array(
119 'src' => $plugin_css_assets_path . 'status.css',
120 ),
121 'sdevs_installer' => array(
122 'src' => $plugin_css_assets_path . 'installer.css',
123 ),
124 );
125
126 return $styles;
127 }
128 }
129