| 1 |
<?php |
| 2 |
|
| 3 |
if ( ! defined( 'ABSPATH' ) ) { |
| 4 |
exit; |
| 5 |
} |
| 6 |
|
| 7 |
class Pektsekye_Ymm_Setup_Install { |
| 8 |
|
| 9 |
|
| 10 |
public static function init() { |
| 11 |
|
| 12 |
} |
| 13 |
|
| 14 |
|
| 15 |
public static function install() { |
| 16 |
|
| 17 |
if ( !class_exists( 'WooCommerce' ) ) { |
| 18 |
deactivate_plugins('ymm'); |
| 19 |
wp_die( __( 'YMM requires WooCommerce to run. Please install WooCommerce and activate.', 'ymm-search' ) ); |
| 20 |
} |
| 21 |
|
| 22 |
if ( version_compare( WC()->version, '3.0', "<" ) ) { |
| 23 |
wp_die(sprintf(__( 'WooCommerce %s or higher is required (You are running %s)', 'ymm-search' ), '3.0', WC()->version)); |
| 24 |
} |
| 25 |
|
| 26 |
self::create_tables(); |
| 27 |
|
| 28 |
add_option('ymm_display_vehicle_fitment', 'yes'); |
| 29 |
add_option('ymm_enable_category_dropdowns', 'yes'); |
| 30 |
add_option('ymm_enable_search_field', 'yes'); |
| 31 |
} |
| 32 |
|
| 33 |
|
| 34 |
private static function create_tables() { |
| 35 |
global $wpdb; |
| 36 |
|
| 37 |
$wpdb->hide_errors(); |
| 38 |
|
| 39 |
require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
| 40 |
|
| 41 |
dbDelta( self::get_schema() ); |
| 42 |
} |
| 43 |
|
| 44 |
|
| 45 |
private static function get_schema() { |
| 46 |
global $wpdb; |
| 47 |
|
| 48 |
return " |
| 49 |
CREATE TABLE {$wpdb->base_prefix}ymm ( |
| 50 |
id int(11) unsigned NOT NULL auto_increment, |
| 51 |
product_id int(11) unsigned NOT NULL, |
| 52 |
make varchar(100) NOT NULL, |
| 53 |
model varchar(100) NOT NULL, |
| 54 |
year_from int(4) unsigned NOT NULL default 0, |
| 55 |
year_to int(4) unsigned NOT NULL default 0, |
| 56 |
PRIMARY KEY (id), |
| 57 |
UNIQUE KEY uk_ymm_product_id (product_id, make, model, year_from, year_to) |
| 58 |
) ENGINE=MyISAM DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; |
| 59 |
"; |
| 60 |
|
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
public static function wpmu_drop_tables( $tables ) { |
| 65 |
global $wpdb; |
| 66 |
$tables[] = $wpdb->base_prefix . 'ymm'; |
| 67 |
return $tables; |
| 68 |
} |
| 69 |
} |
| 70 |
|