| 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.0.0 |
| 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: 4.9.1 |
| 14 |
*/ |
| 15 |
|
| 16 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 17 |
require_once __DIR__ . '/vendor/autoload.php'; |
| 18 |
|
| 19 |
/** |
| 20 |
* Plugin Main Class |
| 21 |
*/ |
| 22 |
final class Ever_Compare{ |
| 23 |
|
| 24 |
/** |
| 25 |
* Plugin version |
| 26 |
* |
| 27 |
* @var string |
| 28 |
*/ |
| 29 |
const version = '1.0.0'; |
| 30 |
|
| 31 |
/** |
| 32 |
* [$_instance] |
| 33 |
* @var null |
| 34 |
*/ |
| 35 |
private static $_instance = null; |
| 36 |
|
| 37 |
/** |
| 38 |
* [instance] Initializes a singleton instance |
| 39 |
* @return [Base] |
| 40 |
*/ |
| 41 |
public static function instance() { |
| 42 |
if ( is_null( self::$_instance ) ) { |
| 43 |
self::$_instance = new self(); |
| 44 |
} |
| 45 |
return self::$_instance; |
| 46 |
} |
| 47 |
|
| 48 |
/** |
| 49 |
* [__construct] Class Constructor |
| 50 |
*/ |
| 51 |
private function __construct(){ |
| 52 |
|
| 53 |
$this->define_constants(); |
| 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 |
} |
| 61 |
|
| 62 |
/** |
| 63 |
* Define the required plugin constants |
| 64 |
* |
| 65 |
* @return void |
| 66 |
*/ |
| 67 |
public function define_constants() { |
| 68 |
define( 'EVERCOMPARE_VERSION', self::version ); |
| 69 |
define( 'EVERCOMPARE_FILE', __FILE__ ); |
| 70 |
define( 'EVERCOMPARE_PATH', __DIR__ ); |
| 71 |
define( 'EVERCOMPARE_URL', plugins_url( '', EVERCOMPARE_FILE ) ); |
| 72 |
define( 'EVERCOMPARE_ASSETS', EVERCOMPARE_URL . '/assets' ); |
| 73 |
define( 'EVERCOMPARE_BASE', plugin_basename( EVERCOMPARE_FILE ) ); |
| 74 |
} |
| 75 |
|
| 76 |
/** |
| 77 |
* [i18n] Load text domain |
| 78 |
* @return [void] |
| 79 |
*/ |
| 80 |
public function i18n() { |
| 81 |
load_plugin_textdomain( 'ever-compare', false, dirname( plugin_basename( EVERCOMPARE_FILE ) ) . '/languages/' ); |
| 82 |
} |
| 83 |
|
| 84 |
/** |
| 85 |
* Initialize the plugin |
| 86 |
* |
| 87 |
* @return void |
| 88 |
*/ |
| 89 |
public function init_plugin() { |
| 90 |
if ( ! function_exists('is_plugin_active') ){ include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); } |
| 91 |
|
| 92 |
EverCompare\Assets::instance(); |
| 93 |
|
| 94 |
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { |
| 95 |
EverCompare\Frontend\Manage_Compare::instance()->ajax_init(); |
| 96 |
} |
| 97 |
|
| 98 |
if ( is_admin() ) { |
| 99 |
$this->admin_notices(); |
| 100 |
EverCompare\Admin::instance(); |
| 101 |
} else { |
| 102 |
EverCompare\Frontend::instance(); |
| 103 |
} |
| 104 |
|
| 105 |
// add image size |
| 106 |
$this->set_image_size(); |
| 107 |
|
| 108 |
// let's filter the woocommerce image size |
| 109 |
add_filter( 'woocommerce_get_image_size_ever-compare-image', [ $this, 'wc_image_filter_size' ], 10, 1 ); |
| 110 |
|
| 111 |
} |
| 112 |
|
| 113 |
/** |
| 114 |
* Do stuff upon plugin activation |
| 115 |
* |
| 116 |
* @return void |
| 117 |
*/ |
| 118 |
public function activate() { |
| 119 |
$installer = new EverCompare\Installer(); |
| 120 |
$installer->run(); |
| 121 |
} |
| 122 |
|
| 123 |
/** |
| 124 |
* Admin Notices |
| 125 |
* @return void |
| 126 |
*/ |
| 127 |
public function admin_notices() { |
| 128 |
$notice = new EverCompare\Admin\Notices(); |
| 129 |
$notice->notice(); |
| 130 |
} |
| 131 |
|
| 132 |
/** |
| 133 |
* [set_image_size] Set Image Size |
| 134 |
*/ |
| 135 |
public function set_image_size(){ |
| 136 |
|
| 137 |
$image_dimention = ever_compare_get_option( 'image_size', 'ever_compare_table_settings_tabs' ); |
| 138 |
if( isset( $image_dimention ) && is_array( $image_dimention ) ){ |
| 139 |
$hard_crop = !empty( ever_compare_get_option( 'hard_crop', 'ever_compare_table_settings_tabs' ) ) ? true : false; |
| 140 |
add_image_size( 'ever-compare-image', $image_dimention['width'], $image_dimention['height'], $hard_crop ); |
| 141 |
} |
| 142 |
|
| 143 |
} |
| 144 |
|
| 145 |
/** |
| 146 |
* [wc_image_filter_size] |
| 147 |
* @return [array] |
| 148 |
*/ |
| 149 |
public function wc_image_filter_size(){ |
| 150 |
|
| 151 |
$image_dimention = ever_compare_get_option( 'image_size', 'ever_compare_table_settings_tabs' ); |
| 152 |
$hard_crop = !empty( ever_compare_get_option( 'hard_crop', 'ever_compare_table_settings_tabs' ) ) ? true : false; |
| 153 |
|
| 154 |
if( isset( $image_dimention ) && is_array( $image_dimention ) ){ |
| 155 |
return array( |
| 156 |
'width' => isset( $image_dimention['width'] ) ? absint( $image_dimention['width'] ) : 600, |
| 157 |
'height' => isset( $image_dimention['height'] ) ? absint( $image_dimention['height'] ) : 600, |
| 158 |
'crop' => isset( $hard_crop ) ? 1 : 0, |
| 159 |
); |
| 160 |
} |
| 161 |
|
| 162 |
} |
| 163 |
|
| 164 |
} |
| 165 |
|
| 166 |
/** |
| 167 |
* Initializes the main plugin |
| 168 |
* |
| 169 |
* @return ever_compare |
| 170 |
*/ |
| 171 |
function ever_compare() { |
| 172 |
return Ever_Compare::instance(); |
| 173 |
} |
| 174 |
|
| 175 |
// Start Our journey |
| 176 |
ever_compare(); |