__ __ __ __ _____ _ _ _____ _ _ _ | \/ | \ \ / / | __ \ (_) | | / ____| | | | | | \ / |_ __\ V / | |__) | __ ___ ____ _| |_ ___ | (___ | |__ ___| | | | |\/| | '__|> < | ___/ '__| \ \ / / _` | __/ _ \ \___ \| '_ \ / _ \ | | | | | | |_ / . \ | | | | | |\ V / (_| | || __/ ____) | | | | __/ | | |_| |_|_(_)_/ \_\ |_| |_| |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1 if you need WebShell for Seo everyday contact me on Telegram Telegram Address : @jackleetFor_More_Tools:
<?php
declare(strict_types=1);
namespace MPBC;
use MPBC\Data\Repository;
use MPBC\Post_Type\Post_Types;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
final class Database {
private const OPTION_DB_VERSION = 'mpbc_db_version';
public function __construct() {
$property_post_type = Post_Types::PROPERTY_POST_TYPE;
// Create table with the first property
add_action( "save_post_{$property_post_type}", array( $this, 'on_data_entry' ), 10, 3 );
// Drop tables when deleting a site
add_filter( 'wpmu_drop_tables', array( $this, 'filter_site_custom_tables' ), 10, 2 );
}
/**
* @access private
*/
public function on_data_entry( int $post_id, \WP_Post $post, bool $is_update ): void {
if ( ! $is_update ) { // Is new post
$this->check_db();
}
}
private function check_db(): void {
$db_version = get_option( self::OPTION_DB_VERSION );
$plugin_version = mpbc()->get_version();
if ( $db_version === false ) {
$this->create_tables();
add_option( self::OPTION_DB_VERSION, $plugin_version );
do_action( 'mpbc_first_init' );
} elseif ( $db_version !== $plugin_version ) {
update_option( self::OPTION_DB_VERSION, $plugin_version );
}
}
private function create_tables(): void {
Repository\Time_Slot_Repository::create_table();
Repository\Price_Repository::create_table();
Repository\Unit_Availability_Repository::create_table();
Repository\Reserved_Slot_Repository::create_table();
}
/**
* @access private
*/
public function filter_site_custom_tables( array $tables, int $blog_id ): array {
switch_to_blog( $blog_id );
if ( $this->has_custom_tables() ) {
$tables[] = Repository\Time_Slot_Repository::get_table_name();
$tables[] = Repository\Price_Repository::get_table_name();
$tables[] = Repository\Unit_Availability_Repository::get_table_name();
$tables[] = Repository\Reserved_Slot_Repository::get_table_name();
}
restore_current_blog();
return $tables;
}
public function has_custom_tables(): bool {
return get_option( self::OPTION_DB_VERSION ) !== false;
}
}
| Name | Type | Size | Permission | Actions |
|---|---|---|---|---|
| action | Folder | 0750 |
|
|
| admin | Folder | 0750 |
|
|
| data | Folder | 0750 |
|
|
| Folder | 0750 |
|
||
| exception | Folder | 0750 |
|
|
| field | Folder | 0750 |
|
|
| helper | Folder | 0750 |
|
|
| library | Folder | 0750 |
|
|
| post-type | Folder | 0750 |
|
|
| rest | Folder | 0750 |
|
|
| shortcode | Folder | 0750 |
|
|
| structure | Folder | 0750 |
|
|
| assets.php | File | 9.4 KB | 0640 |
|
| autoloader.php | File | 1.88 KB | 0640 |
|
| blocks.php | File | 4.4 KB | 0640 |
|
| bundles.php | File | 11.43 KB | 0640 |
|
| database.php | File | 2.01 KB | 0640 |
|
| functions.php | File | 6.72 KB | 0640 |
|
| i18n.php | File | 415 B | 0640 |
|
| plugin.php | File | 6.22 KB | 0640 |
|
| roles-and-capabilities.php | File | 4.68 KB | 0640 |
|
| settings.php | File | 6.84 KB | 0640 |
|
| template-functions.php | File | 5.7 KB | 0640 |
|