PluginProbe ʕ •ᴥ•ʔ
ShopEngine Elementor WooCommerce Builder Addon – All in One WooCommerce Solution / 4.6.9
ShopEngine Elementor WooCommerce Builder Addon – All in One WooCommerce Solution v4.6.9
4.9.1 4.9.0 2.0.0 2.1.0 2.2.0 2.2.1 2.2.2 2.3.0 2.4.0 2.5.0 2.5.1 3.0.0 3.1.0 3.1.1 4.0.0 4.0.1 4.1.0 4.1.1 4.2.0 4.2.1 4.3.0 4.3.1 4.4.0 4.5.0 4.5.1 4.6.0 4.6.1 4.6.2 4.6.3 4.6.4 4.6.5 4.6.6 4.6.7 4.6.8 4.6.9 4.7.0 4.7.1 4.7.2 4.7.3 4.7.4 4.7.5 4.7.6 4.7.7 4.7.8 4.7.9 4.8.0 4.8.1 4.8.2 4.8.3 4.8.4 4.8.5 4.8.6 4.8.7 4.8.8 4.8.9 trunk 0.1.2-beta 0.1.3-beta 0.1.4-beta 1.0.0 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.2.1 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.4.0 1.4.1 1.5.0 1.5.1 1.6.0 1.6.1 1.7.0 1.8.0 1.8.1 1.9.0
shopengine / modules / swatches / swatches.php
shopengine / modules / swatches Last commit date
assets 3 years ago loop-product-support 3 years ago admin-product.php 3 years ago attribute-hooks.php 3 years ago frontend.php 3 years ago helper.php 3 years ago swatches.php 3 years ago
swatches.php
147 lines
1 <?php
2
3 namespace ShopEngine\Modules\Swatches;
4
5 use ShopEngine;
6 use ShopEngine\Modules\Swatches\Loop_Product_Support\Shopengine_Swatches;
7 use ShopEngine\Traits\Singleton;
8
9 defined('ABSPATH') || exit;
10
11
12 class Swatches
13 {
14 const PA_COLOR = 'shopengine_color';
15 const PA_IMAGE = 'shopengine_image';
16 const PA_LABEL = 'shopengine_label';
17
18 private $attribute_types = [];
19
20 use Singleton;
21
22
23 public static function get_module_uri() {
24
25 return plugin_dir_url(__FILE__);
26 }
27
28
29 public static function get_module_dir() {
30
31 return plugin_dir_path(__FILE__);
32 }
33
34
35 public static function asset_source($type = 'css', $directory = null) {
36
37 return self::get_module_uri() . 'assets/' . $type . '/' . $directory;
38 }
39
40
41 public function init() {
42
43 $this->set_attribute_types(self::PA_COLOR, esc_html__('Shopengine Color', 'shopengine'));
44 $this->set_attribute_types(self::PA_IMAGE, esc_html__('Shopengine Image', 'shopengine'));
45 $this->set_attribute_types(self::PA_LABEL, esc_html__('Shopengine Label', 'shopengine'));
46
47
48 //Add option to attribute.......................................................
49 add_filter('product_attributes_type_selector', [$this, 'push_attribute_types']);
50
51 if(is_admin()) {
52
53 add_action('admin_init', [$this, 'init_hooks']);
54 add_action('admin_print_scripts', [$this, 'enqueue']);
55 add_action('admin_init', [$this, 'includes_product']);
56 }
57
58
59 if(!is_admin() || (defined('DOING_AJAX') && DOING_AJAX)) {
60
61 add_action('init', [$this, 'init_frontend_hook']);
62 }
63
64 /**
65 * add swatches to product loop
66 */
67 Shopengine_Swatches::getInstance();
68 }
69
70
71 public function push_attribute_types($types) {
72
73 $types = array_merge($types, $this->attribute_types);
74
75 return $types;
76 }
77
78
79 private function set_attribute_types($key, $title) {
80
81 $this->attribute_types[$key] = $title;
82
83 return $this;
84 }
85
86
87 public function includes_product() {
88
89 Admin_Product::instance()->init();
90 }
91
92
93 public function init_hooks() {
94
95 Attribute_Hooks::instance()->init();
96 }
97
98
99 public function init_frontend_hook() {
100
101 Frontend::instance()->init();
102 }
103
104
105 public function enqueue() {
106
107 $screen = get_current_screen();
108 if(empty($screen)) {
109 return;
110 }
111
112 if(strpos($screen->id, 'edit-pa_') === false && strpos($screen->id, 'product') === false) {
113 return;
114 }
115
116 wp_enqueue_media();
117 wp_enqueue_style('shopengine-css-admin', Swatches::asset_source('css', 'admin.css'), ['wp-color-picker'], ShopEngine::version());
118 wp_enqueue_script('shopengine-js-admin', Swatches::asset_source('js', 'admin.js'), ['jquery', 'wp-color-picker', 'wp-util'], ShopEngine::version(), true);
119
120 wp_localize_script(
121 'shopengine-js-admin',
122 'swatch_conf',
123 [
124 'i18n' => [
125 'title' => esc_html__('Choose an image', 'shopengine'),
126 'button' => esc_html__('Use image', 'shopengine'),
127 ],
128 'dummy' => Helper::get_dummy(),
129 ]
130 );
131 }
132
133
134 public function get_available_types() {
135
136 return $this->attribute_types;
137 }
138
139
140 public static function is_module_active() {
141
142 // todo - implement the logic later...........
143
144 return true;
145 }
146 }
147