PluginProbe ʕ •ᴥ•ʔ
ShopEngine Elementor WooCommerce Builder Addon – All in One WooCommerce Solution / 1.2.1
ShopEngine Elementor WooCommerce Builder Addon – All in One WooCommerce Solution v1.2.1
4.9.2 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 4 years ago admin-product.php 5 years ago attribute-hooks.php 4 years ago frontend.php 5 years ago helper.php 5 years ago swatches.php 5 years ago
swatches.php
143 lines
1 <?php
2
3 namespace ShopEngine\Modules\Swatches;
4
5 use ShopEngine\Traits\Singleton;
6
7 defined('ABSPATH') || exit;
8
9
10 class Swatches
11 {
12
13 const MODULE_VERSION = '1.0.0';
14
15 const PA_COLOR = 'shopengine_color';
16 const PA_IMAGE = 'shopengine_image';
17 const PA_LABEL = 'shopengine_label';
18
19 private $attribute_types = [];
20
21 use Singleton;
22
23
24 public static function get_module_uri() {
25
26 return plugin_dir_url(__FILE__);
27 }
28
29
30 public static function get_module_dir() {
31
32 return plugin_dir_path(__FILE__);
33 }
34
35
36 public static function asset_source($type = 'css', $directory = null) {
37
38 return self::get_module_uri() . 'assets/' . $type . '/' . $directory;
39 }
40
41
42 public function init() {
43
44 $this->set_attribute_types(self::PA_COLOR, esc_html__('Shopengine Color', 'shopengine'));
45 $this->set_attribute_types(self::PA_IMAGE, esc_html__('Shopengine Image', 'shopengine'));
46 $this->set_attribute_types(self::PA_LABEL, esc_html__('Shopengine Label', 'shopengine'));
47
48
49 //Add option to attribute.......................................................
50 add_filter('product_attributes_type_selector', [$this, 'push_attribute_types']);
51
52 if(is_admin()) {
53
54 add_action('admin_init', [$this, 'init_hooks']);
55 add_action('admin_print_scripts', [$this, 'enqueue']);
56 add_action('admin_init', [$this, 'includes_product']);
57 }
58
59
60 if(!is_admin() || (defined('DOING_AJAX') && DOING_AJAX)) {
61
62 add_action('init', [$this, 'init_frontend_hook']);
63 }
64 }
65
66
67 public function push_attribute_types($types) {
68
69 $types = array_merge($types, $this->attribute_types);
70
71 return $types;
72 }
73
74
75 private function set_attribute_types($key, $title) {
76
77 $this->attribute_types[$key] = $title;
78
79 return $this;
80 }
81
82
83 public function includes_product() {
84
85 Admin_Product::instance()->init();
86 }
87
88
89 public function init_hooks() {
90
91 Attribute_Hooks::instance()->init();
92 }
93
94
95 public function init_frontend_hook() {
96
97 Frontend::instance()->init();
98 }
99
100
101 public function enqueue() {
102
103 $screen = get_current_screen();
104 if(empty($screen)) {
105 return;
106 }
107
108 if(strpos($screen->id, 'edit-pa_') === false && strpos($screen->id, 'product') === false) {
109 return;
110 }
111
112 wp_enqueue_media();
113 wp_enqueue_style('shopengine-css-admin', Swatches::asset_source('css', 'admin.css'), ['wp-color-picker'], Swatches::MODULE_VERSION);
114 wp_enqueue_script('shopengine-js-admin', Swatches::asset_source('js', 'admin.js'), ['jquery', 'wp-color-picker', 'wp-util'], Swatches::MODULE_VERSION, true);
115
116 wp_localize_script(
117 'shopengine-js-admin',
118 'swatch_conf',
119 [
120 'i18n' => [
121 'title' => esc_html__('Choose an image', 'shopengine'),
122 'button' => esc_html__('Use image', 'shopengine'),
123 ],
124 'dummy' => Helper::get_dummy(),
125 ]
126 );
127 }
128
129
130 public function get_available_types() {
131
132 return $this->attribute_types;
133 }
134
135
136 public static function is_module_active() {
137
138 // todo - implement the logic later...........
139
140 return true;
141 }
142 }
143