first commit
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
/**
|
||||
* Plugin Installer Class
|
||||
*
|
||||
* @package YachtBooking
|
||||
*/
|
||||
|
||||
namespace YachtBooking;
|
||||
|
||||
// Exit if accessed directly
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Installer class - handles plugin installation and database setup
|
||||
*/
|
||||
class Installer {
|
||||
|
||||
/**
|
||||
* Run installation
|
||||
*/
|
||||
public function install() {
|
||||
$this->create_tables();
|
||||
$this->create_options();
|
||||
$this->set_version();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create custom database tables
|
||||
*/
|
||||
private function create_tables() {
|
||||
global $wpdb;
|
||||
|
||||
$charset_collate = $wpdb->get_charset_collate();
|
||||
$table_name = $wpdb->prefix . 'yacht_availability';
|
||||
|
||||
$sql = "CREATE TABLE $table_name (
|
||||
id bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
yacht_id bigint(20) UNSIGNED NOT NULL,
|
||||
date date NOT NULL,
|
||||
status varchar(20) NOT NULL DEFAULT 'available',
|
||||
booking_id bigint(20) UNSIGNED NULL,
|
||||
created_at datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE KEY yacht_date (yacht_id, date),
|
||||
KEY yacht_id (yacht_id),
|
||||
KEY date (date),
|
||||
KEY status (status),
|
||||
KEY booking_id (booking_id)
|
||||
) $charset_collate;";
|
||||
|
||||
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
|
||||
dbDelta( $sql );
|
||||
}
|
||||
|
||||
/**
|
||||
* Create default plugin options
|
||||
*/
|
||||
private function create_options() {
|
||||
$options = array(
|
||||
'yacht_booking_default_status' => 'pending',
|
||||
'yacht_booking_email_from_name' => get_bloginfo( 'name' ),
|
||||
'yacht_booking_email_from' => get_bloginfo( 'admin_email' ),
|
||||
'yacht_booking_date_format' => 'Y-m-d',
|
||||
'yacht_booking_currency_symbol' => 'zł',
|
||||
'yacht_booking_terms_page_id' => 0,
|
||||
'yacht_booking_enable_notifications' => 'yes',
|
||||
'yacht_booking_gcal_sync_enabled' => 'no',
|
||||
);
|
||||
|
||||
foreach ( $options as $key => $value ) {
|
||||
if ( false === get_option( $key ) ) {
|
||||
add_option( $key, $value );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set plugin version
|
||||
*/
|
||||
private function set_version() {
|
||||
update_option( 'yacht_booking_version', YACHT_BOOKING_VERSION );
|
||||
update_option( 'yacht_booking_installed_at', current_time( 'mysql' ) );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user