PluginProbe
EasyTest – Simplify A/B Testing / trunk
EasyTest – Simplify A/B Testing vtrunk
1.0.4 1.0.3 trunk 1.0.1 1.0.2
convertpro / includes / Assets.php

Assets.php in EasyTest – Simplify A/B Testing trunk, at includes/Assets.php

141 lines 3.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace ConvertPro;
4 if (!defined('ABSPATH')) {
5 exit; // Called directly, nothing to do here.
6 }
7
8
9 /**
10 * Scripts and Styles Class
11 */
12 class Assets
13 {
14
15 function __construct()
16 {
17
18 if (is_admin()) {
19 add_action('admin_enqueue_scripts', [$this, 'register'], 5);
20 } else {
21 add_action('wp_enqueue_scripts', [$this, 'register'], 5);
22 }
23 }
24
25 /**
26 * Register our app scripts and styles
27 *
28 * @return void
29 */
30 public function register()
31 {
32 $this->register_scripts($this->get_scripts());
33 $this->register_styles($this->get_styles());
34 }
35
36 /**
37 * Register scripts
38 *
39 * @param array $scripts
40 *
41 * @return void
42 */
43 private function register_scripts($scripts)
44 {
45 foreach ($scripts as $handle => $script) {
46 $deps = isset($script['deps']) ? $script['deps'] : false;
47 $in_footer = isset($script['in_footer']) ? $script['in_footer'] : false;
48 $version = isset($script['version']) ? $script['version'] : CONVERTPRO_VERSION;
49
50 wp_register_script($handle, $script['src'], $deps, $version, $in_footer);
51 }
52 }
53
54 /**
55 * Register styles
56 *
57 * @param array $styles
58 *
59 * @return void
60 */
61 public function register_styles($styles)
62 {
63 foreach ($styles as $handle => $style) {
64 $deps = isset($style['deps']) ? $style['deps'] : false;
65
66 wp_register_style($handle, $style['src'], $deps, CONVERTPRO_VERSION);
67 }
68 }
69
70 /**
71 * Get all registered scripts
72 *
73 * @return array
74 */
75 public function get_scripts()
76 {
77 $prefix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '.min' : '';
78
79 $scripts = [
80
81 'test-variations-admin' => [
82 'src' => CONVERTPRO_ASSETS . '/js/test-variation.js',
83 'deps' => ['jquery'],
84 'version' => CONVERTPRO_VERSION,
85 'in_footer' => true
86 ],
87 // Bundled rather than loaded from a CDN: WordPress.org requires
88 // plugins to ship their own assets, and a remote script would also
89 // break the report on sites without outside network access.
90 'chart' => [
91 'src' => CONVERTPRO_ASSETS . '/vendor/chartjs/chart.umd.js',
92 'deps' => [],
93 'version' => '4.5.1',
94 'in_footer' => true
95 ],
96 'convertpro-click-goal' => [
97 'src' => CONVERTPRO_ASSETS . '/js/click-goal.js',
98 'deps' => [],
99 'version' => CONVERTPRO_VERSION,
100 'in_footer' => true
101 ],
102 'ab-tester-select2' => [
103 'src' => CONVERTPRO_ASSETS . '/js/select2.min.js',
104 'deps' => ['jquery'],
105 'version' => '4.1.0',
106 'in_footer' => true
107 ],
108
109
110 ];
111
112 return $scripts;
113 }
114
115 /**
116 * Get registered styles
117 *
118 * @return array
119 */
120 public function get_styles()
121 {
122
123 $styles = [
124 'convertpro-style' => [
125 'src' => CONVERTPRO_ASSETS . '/css/style.css'
126 ],
127 'convertpro-frontend' => [
128 'src' => CONVERTPRO_ASSETS . '/css/frontend.css'
129 ],
130 'convertpro-admin' => [
131 'src' => CONVERTPRO_ASSETS . '/css/admin.css'
132 ],
133 'select2-style' => [
134 'src' => CONVERTPRO_ASSETS . '/css/select2.min.css'
135 ],
136 ];
137
138 return $styles;
139 }
140 }
141