-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsmart-variation-swatches-for-woocommerce.php
252 lines (191 loc) · 6.91 KB
/
smart-variation-swatches-for-woocommerce.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
<?php
/*
Plugin Name: Smart Variation Swatches for WooCommerce
Plugin URI: https://athemeart.com/downloads/smart-variation-swatches-woocommerce-pro/
Description: An extension of WooCommerce that make variable products be more beauty and friendly with customers.
Version: 1.2.3
Author: aThemeArt
Author URI: http://athemeart.com/
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Text Domain: smart-variation-swatches
Domain Path: /languages/
Tested up to: 5.4.9
WC requires at least:3
WC tested up to: 5.4.2
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
/**
* The main plugin class
*/
final class ATA_WC_Variation_Swatches {
/**
* The single instance of the class
*
* @var ATA_WC_Variation_Swatches
*/
protected static $instance = null;
/**
* Extra attribute types
*
* @var array
*/
public $types = array();
/**
* Main instance
*
* @return ATA_WC_Variation_Swatches
*/
public static function instance() {
if ( null == self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Class constructor.
*/
public function __construct() {
$this->types = array(
'color' => esc_html__( 'Color', 'smart-variation-swatches' ),
'image' => esc_html__( 'Image', 'smart-variation-swatches' ),
'label' => esc_html__( 'Label', 'smart-variation-swatches' ),
'select_2' => esc_html__( 'Select box', 'smart-variation-swatches' ),
);
$this->includes();
$this->init_hooks();
}
/**
* Include required core files used in admin and on the frontend.
*/
public function includes() {
require_once 'inc/class-admin.php';
require_once 'inc/class-options.php';
require_once 'inc/default.php';
require_once 'inc/class-frontend.php';
require_once 'inc/class-wc-ex-product-data-tab.php';
require_once 'inc/widgets-helper.php';
require_once 'inc/wc_widget_layered_nav_categories.php';
require_once 'inc/plugins-settings.php';
}
/**
* Initialize hooks
*/
public function init_hooks() {
add_action( 'init', array( $this, 'load_textdomain' ) );
add_filter( 'product_attributes_type_selector', array( $this, 'add_attribute_types' ) );
if ( is_admin() ) {
add_action( 'init', array( 'ATA_WC_Variation_Swatches_Admin', 'instance' ) );
add_action( 'init', array( 'ATA_WC_Variation_Swatches_Options', 'instance' ) );
add_action( 'init', array( 'WC_EX_Product_Data_Tab_Swatches', 'instance' ) );
} else {
add_action( 'init', array( 'ATA_WC_Variation_Swatches_Frontend', 'instance' ) );
//add_action( 'init', array( 'ATA_WC_Variation_Swatches_Frontend_Arachive', 'instance' ) );
}
add_filter( 'plugin_action_links', array( $this, 'swatches_action_links' ), 999, 2 );
add_filter( 'plugin_row_meta', array( $this, 'plugin_row_meta' ), 10, 2 );
add_action( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'swatches_settings_action_links' ) );
}
/**
* Load plugin text domain
*/
public function load_textdomain() {
load_plugin_textdomain( 'smart-variation-swatches', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
}
/**
* Add extra attribute types
* Add color, image and label type
*
* @param array $types
*
* @return array
*/
public function add_attribute_types( $types ) {
$types = array_merge( $types, $this->types );
return $types;
}
/**
* Get attribute's properties
*
* @param string $taxonomy
*
* @return object
*/
public function get_tax_attribute( $taxonomy ) {
global $wpdb;
$attr = substr( $taxonomy, 3 );
$attr = $wpdb->get_row( "SELECT * FROM " . $wpdb->prefix . "woocommerce_attribute_taxonomies WHERE attribute_name = '$attr'" );
return $attr;
}
/**
* Instance of frontend
*
* @return ATA_WC_Variation_Swatches_Frontend
*/
public function frontend() {
return ATA_WC_Variation_Swatches_Frontend::instance();
}
function swatches_settings_action_links( $links ) {
$links = array_merge( array(
'<a href="' . esc_url( admin_url( '/admin.php?page=ata-variation-swatches' ) ) . '">' . __( 'Settings', 'textdomain' ) . '</a>'
), $links );
return $links;
}
public function swatches_action_links( $actions, $file ) {
if ( $file == plugin_basename( __FILE__ )) {
$actions['apsw_go_pro'] = '<a href="https://athemeart.com/downloads/smart-variation-swatches-woocommerce-pro/" target="_blank" style="color: #45b450; font-weight: bold">Go Pro!</a>';
}
return $actions;
}
public function plugin_row_meta( $links, $file ){
if ( $file == plugin_basename( __FILE__ )) {
$report_url = esc_url( add_query_arg( array(
'utm_source' => 'wp-admin-plugins',
'utm_medium' => 'row-meta-link',
'utm_campaign' => 'smart-variation-swatches',
), 'https://athemeart.com/support/' ) );
$documentation_url = esc_url( add_query_arg( array(
'utm_source' => 'wp-admin-plugins',
'utm_medium' => 'row-meta-link',
'utm_campaign' => 'smart-variation-swatches',
), 'https://athemeart.com/blog/docs/smart-variation-swatches-plugins-documentation/installation/' ) );
$links[ 'documentation' ] = '<a target="_blank" href="' . esc_url( $documentation_url ) . '" title="' . esc_attr( esc_html__( 'Read Documentation', 'woo-variation-swatches' ) ) . '">' . esc_html__( 'Read Documentation', 'smart-variation-swatches' ) . '</a>';
$links[ 'issues' ] = sprintf( '%2$s <a target="_blank" href="%1$s">%3$s</a>', esc_url( $report_url ), esc_html__( 'Facing issue?', 'woo-variation-swatches' ), '<span style="color: red">' . esc_html__( 'Please open a ticket.', 'smart-variation-swatches' ) . '</span>' );
}
return $links;
}
}
/**
* Main instance of plugin
*
* @return ATA_WC_Variation_Swatches
*/
function ATA_WCVS() {
return ATA_WC_Variation_Swatches::instance();
}
/**
* Display notice in case of WooCommerce plugin is not activated
*/
function ata_wc_variation_swatches_wc_notice() {
?>
<div class="error">
<p><?php esc_html_e( 'Smart Variation Wwatches for WooCommerce-pro is enabled but not effective. It requires WooCommerce in order to work.', 'smart-variation-swatches' ); ?></p>
</div>
<?php
}
/**
* Construct plugin when plugins loaded in order to make sure WooCommerce API is fully loaded
* Check if WooCommerce is not activated then show an admin notice
* or create the main instance of plugin
*/
function ata_wc_variation_swatches_constructor() {
if ( ! function_exists( 'WC' ) ) {
add_action( 'admin_notices', 'ata_wc_variation_swatches_wc_notice' );
} else {
ATA_WCVS();
}
}
add_action( 'plugins_loaded', 'ata_wc_variation_swatches_constructor' );
require_once 'inc/plugins-settings.php';