PluginProbe
Ever Compare – Products Compare Plugin for WooCommerce / 1.3.5
Ever Compare – Products Compare Plugin for WooCommerce v1.3.5
1.3.7 1.1.7 1.1.8 1.1.9 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 trunk 1.0.0 1.0.1 1.0.2 All 31 releases
ever-compare / ever-compare.php

ever-compare.php in Ever Compare – Products Compare Plugin for WooCommerce 1.3.5, at ever-compare.php

214 lines 6.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: Ever Compare
4 * Description: WooCommerce Product compare plugin
5 * Plugin URI: https://hasthemes.com/plugins/
6 * Author: HasTheme
7 * Author URI: https://hasthemes.com/
8 * Version: 1.3.5
9 * License: GPL2 or later
10 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
11 * Text Domain: ever-compare
12 * Domain Path: /languages
13 * WC tested up to: 10.0.2
14 */
15
16 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
17
18 /**
19 * Plugin Main Class
20 */
21 final class Ever_Compare{
22
23 /**
24 * Plugin version
25 *
26 * @var string
27 */
28 const version = '1.3.5';
29
30 /**
31 * [$_instance]
32 * @var null
33 */
34 private static $_instance = null;
35
36 /**
37 * [instance] Initializes a singleton instance
38 * @return [Base]
39 */
40 public static function instance() {
41 if ( is_null( self::$_instance ) ) {
42 self::$_instance = new self();
43 }
44 return self::$_instance;
45 }
46
47 /**
48 * [__construct] Class Constructor
49 */
50 private function __construct(){
51
52 $this->define_constants();
53 add_action( 'plugins_loaded', [ $this, 'includes' ] );
54
55 register_activation_hook( EVERCOMPARE_FILE, [ $this, 'activate' ] );
56
57 add_action( 'init', [ $this, 'i18n' ] );
58 add_action( 'plugins_loaded', [ $this, 'init_plugin' ] );
59
60 // Compatible With WooCommerce Features
61 add_action( 'before_woocommerce_init', function() {
62 if ( class_exists( '\Automattic\WooCommerce\Utilities\FeaturesUtil' ) ) {
63 \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', EVERCOMPARE_FILE, true );
64 \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'cart_checkout_blocks', EVERCOMPARE_FILE, true );
65 \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'product_block_editor', EVERCOMPARE_FILE, true );
66 }
67 } );
68 }
69
70 /**
71 * Define the required plugin constants
72 *
73 * @return void
74 */
75 public function define_constants() {
76 define( 'EVERCOMPARE_VERSION', self::version );
77 define( 'EVERCOMPARE_FILE', __FILE__ );
78 define( 'EVERCOMPARE_PATH', __DIR__ );
79 define( 'EVERCOMPARE_DIR', plugin_dir_path( EVERCOMPARE_FILE ) );
80 define( 'EVERCOMPARE_URL', plugins_url( '', EVERCOMPARE_FILE ) );
81 define( 'EVERCOMPARE_ASSETS', EVERCOMPARE_URL . '/assets' );
82 define( 'EVERCOMPARE_BASE', plugin_basename( EVERCOMPARE_FILE ) );
83 }
84
85 /**
86 * [includes] Load file
87 * @return [void]
88 */
89 public function includes(){
90 require_once EVERCOMPARE_PATH . '/vendor/autoload.php';
91 if ( ! function_exists('is_plugin_active') ){ include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); }
92 }
93
94 /**
95 * [i18n] Load text domain
96 * @return [void]
97 */
98 public function i18n() {
99 load_plugin_textdomain( 'ever-compare', false, dirname( plugin_basename( EVERCOMPARE_FILE ) ) . '/languages/' );
100 }
101
102 /**
103 * Initialize the plugin
104 *
105 * @return void
106 */
107 public function init_plugin() {
108
109 EverCompare\Assets::instance();
110
111 if ( is_admin() ) {
112 $this->admin_notices();
113 EverCompare\Admin::instance();
114 }
115
116 if ( ! ever_compare_woocommerce_installed() ) {
117 return;
118 }
119
120 if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
121 EverCompare\Ajax::instance();
122 }
123
124 EverCompare\Frontend::instance();
125
126 // add image size
127 $this->set_image_size();
128
129 // let's filter the woocommerce image size
130 add_filter( 'woocommerce_get_image_size_ever-compare-image', [ $this, 'wc_image_filter_size' ], 10, 1 );
131
132 // let's filter the speculation rules
133 add_filter( 'wp_speculation_rules_href_exclude_paths', function( $exclude_paths ) {
134 $compare_page_id = ever_compare_get_option( 'compare_page', 'ever_compare_table_settings_tabs' );
135 if ( $compare_page_id ) {
136 $compare_page_url = get_permalink( $compare_page_id );
137 $compare_path = parse_url( $compare_page_url, PHP_URL_PATH );
138 if ( $compare_path ) {
139 $compare_path = trailingslashit( $compare_path );
140 $exclude_paths[] = "{$compare_path}*";
141 }
142 }
143 return $exclude_paths;
144 });
145 }
146
147 /**
148 * Do stuff upon plugin activation
149 *
150 * @return void
151 */
152 public function activate() {
153 $this->includes();
154 $installer = new EverCompare\Installer();
155 $installer->run();
156 }
157
158 /**
159 * Admin Notices
160 * @return void
161 */
162 public function admin_notices() {
163 $notice = new EverCompare\Admin\Notices();
164 $notice->notice();
165 }
166
167 /**
168 * [set_image_size] Set Image Size
169 */
170 public function set_image_size(){
171
172 $image_dimention = ever_compare_get_option( 'image_size', 'ever_compare_table_settings_tabs', array( 'width'=>300, 'height'=>300 ) );
173 if( isset( $image_dimention ) && is_array( $image_dimention ) ){
174 $hard_crop = !empty( ever_compare_get_option( 'hard_crop', 'ever_compare_table_settings_tabs' ) ) ? true : false;
175 add_image_size( 'ever-compare-image', $image_dimention['width'], $image_dimention['height'], $hard_crop );
176 }
177
178 }
179
180 /**
181 * [wc_image_filter_size]
182 * @return [array]
183 */
184 public function wc_image_filter_size(){
185
186 $image_dimention = ever_compare_get_option( 'image_size', 'ever_compare_table_settings_tabs', array('width'=>300,'height'=>300) );
187 $hard_crop = !empty( ever_compare_get_option( 'hard_crop', 'ever_compare_table_settings_tabs' ) ) ? true : false;
188
189 if( isset( $image_dimention ) && is_array( $image_dimention ) ){
190 return array(
191 'width' => isset( $image_dimention['width'] ) ? absint( $image_dimention['width'] ) : 300,
192 'height' => isset( $image_dimention['height'] ) ? absint( $image_dimention['height'] ) : 300,
193 'crop' => isset( $hard_crop ) ? 1 : 0,
194 );
195 }
196
197 }
198
199 }
200
201 /**
202 * Initializes the main plugin
203 *
204 * @return ever_compare
205 */
206 function ever_compare() {
207 if( ! class_exists('Woolentor_Ever_Compare') ){
208 return Ever_Compare::instance();
209 }
210 }
211
212 // Start Our journey
213 ever_compare();
214