178 lines
4.2 KiB
PHP
178 lines
4.2 KiB
PHP
|
|
<?php
|
||
|
|
/**
|
||
|
|
* Plugin Name: WP BnB Management
|
||
|
|
* Plugin URI: https://src.bundespruefstelle.ch/magdev/wp-bnb
|
||
|
|
* Description: A comprehensive Bed & Breakfast management system for WordPress. Manage buildings, rooms, bookings, and guests.
|
||
|
|
* Version: 0.0.1
|
||
|
|
* Requires at least: 6.0
|
||
|
|
* Requires PHP: 8.3
|
||
|
|
* Author: Marco Graetsch
|
||
|
|
* Author URI: https://src.bundespruefstelle.ch/magdev
|
||
|
|
* License: GPL-2.0-or-later
|
||
|
|
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
|
||
|
|
* Text Domain: wp-bnb
|
||
|
|
* Domain Path: /languages
|
||
|
|
*
|
||
|
|
* @package Magdev\WpBnb
|
||
|
|
*/
|
||
|
|
|
||
|
|
declare( strict_types=1 );
|
||
|
|
|
||
|
|
// Prevent direct file access.
|
||
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
||
|
|
exit;
|
||
|
|
}
|
||
|
|
|
||
|
|
// Plugin version constant - MUST match Version in header above.
|
||
|
|
define( 'WP_BNB_VERSION', '0.0.1' );
|
||
|
|
|
||
|
|
// Plugin path constants.
|
||
|
|
define( 'WP_BNB_PATH', plugin_dir_path( __FILE__ ) );
|
||
|
|
define( 'WP_BNB_URL', plugin_dir_url( __FILE__ ) );
|
||
|
|
define( 'WP_BNB_BASENAME', plugin_basename( __FILE__ ) );
|
||
|
|
|
||
|
|
// Minimum requirements.
|
||
|
|
define( 'WP_BNB_MIN_PHP_VERSION', '8.3.0' );
|
||
|
|
define( 'WP_BNB_MIN_WP_VERSION', '6.0' );
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Check PHP version requirements.
|
||
|
|
*
|
||
|
|
* @return bool
|
||
|
|
*/
|
||
|
|
function wp_bnb_check_php_version(): bool {
|
||
|
|
return version_compare( PHP_VERSION, WP_BNB_MIN_PHP_VERSION, '>=' );
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Check WordPress version requirements.
|
||
|
|
*
|
||
|
|
* @return bool
|
||
|
|
*/
|
||
|
|
function wp_bnb_check_wp_version(): bool {
|
||
|
|
return version_compare( get_bloginfo( 'version' ), WP_BNB_MIN_WP_VERSION, '>=' );
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Display admin notice for PHP version requirement.
|
||
|
|
*
|
||
|
|
* @return void
|
||
|
|
*/
|
||
|
|
function wp_bnb_php_version_notice(): void {
|
||
|
|
?>
|
||
|
|
<div class="notice notice-error">
|
||
|
|
<p>
|
||
|
|
<?php
|
||
|
|
printf(
|
||
|
|
/* translators: 1: Required PHP version, 2: Current PHP version */
|
||
|
|
esc_html__( 'WP BnB Management requires PHP version %1$s or higher. You are running PHP %2$s.', 'wp-bnb' ),
|
||
|
|
esc_html( WP_BNB_MIN_PHP_VERSION ),
|
||
|
|
esc_html( PHP_VERSION )
|
||
|
|
);
|
||
|
|
?>
|
||
|
|
</p>
|
||
|
|
</div>
|
||
|
|
<?php
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Display admin notice for WordPress version requirement.
|
||
|
|
*
|
||
|
|
* @return void
|
||
|
|
*/
|
||
|
|
function wp_bnb_wp_version_notice(): void {
|
||
|
|
?>
|
||
|
|
<div class="notice notice-error">
|
||
|
|
<p>
|
||
|
|
<?php
|
||
|
|
printf(
|
||
|
|
/* translators: 1: Required WordPress version, 2: Current WordPress version */
|
||
|
|
esc_html__( 'WP BnB Management requires WordPress version %1$s or higher. You are running WordPress %2$s.', 'wp-bnb' ),
|
||
|
|
esc_html( WP_BNB_MIN_WP_VERSION ),
|
||
|
|
esc_html( get_bloginfo( 'version' ) )
|
||
|
|
);
|
||
|
|
?>
|
||
|
|
</p>
|
||
|
|
</div>
|
||
|
|
<?php
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Initialize the plugin.
|
||
|
|
*
|
||
|
|
* @return void
|
||
|
|
*/
|
||
|
|
function wp_bnb_init(): void {
|
||
|
|
// Check PHP version.
|
||
|
|
if ( ! wp_bnb_check_php_version() ) {
|
||
|
|
add_action( 'admin_notices', 'wp_bnb_php_version_notice' );
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
// Check WordPress version.
|
||
|
|
if ( ! wp_bnb_check_wp_version() ) {
|
||
|
|
add_action( 'admin_notices', 'wp_bnb_wp_version_notice' );
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
// Load Composer autoloader.
|
||
|
|
$autoloader = WP_BNB_PATH . 'vendor/autoload.php';
|
||
|
|
if ( ! file_exists( $autoloader ) ) {
|
||
|
|
add_action( 'admin_notices', function (): void {
|
||
|
|
?>
|
||
|
|
<div class="notice notice-error">
|
||
|
|
<p>
|
||
|
|
<?php esc_html_e( 'WP BnB Management: Composer autoloader not found. Please run "composer install" in the plugin directory.', 'wp-bnb' ); ?>
|
||
|
|
</p>
|
||
|
|
</div>
|
||
|
|
<?php
|
||
|
|
} );
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
require_once $autoloader;
|
||
|
|
|
||
|
|
// Initialize the plugin.
|
||
|
|
\Magdev\WpBnb\Plugin::get_instance();
|
||
|
|
}
|
||
|
|
|
||
|
|
// Hook initialization to plugins_loaded.
|
||
|
|
add_action( 'plugins_loaded', 'wp_bnb_init' );
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Plugin activation hook.
|
||
|
|
*
|
||
|
|
* @return void
|
||
|
|
*/
|
||
|
|
function wp_bnb_activate(): void {
|
||
|
|
// Check requirements before activation.
|
||
|
|
if ( ! wp_bnb_check_php_version() || ! wp_bnb_check_wp_version() ) {
|
||
|
|
deactivate_plugins( plugin_basename( __FILE__ ) );
|
||
|
|
wp_die(
|
||
|
|
esc_html__( 'WP BnB Management requires PHP 8.3+ and WordPress 6.0+.', 'wp-bnb' ),
|
||
|
|
esc_html__( 'Plugin Activation Error', 'wp-bnb' ),
|
||
|
|
array( 'back_link' => true )
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
// Set default options.
|
||
|
|
add_option( 'wp_bnb_version', WP_BNB_VERSION );
|
||
|
|
|
||
|
|
// Flush rewrite rules for custom post types.
|
||
|
|
flush_rewrite_rules();
|
||
|
|
}
|
||
|
|
|
||
|
|
register_activation_hook( __FILE__, 'wp_bnb_activate' );
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Plugin deactivation hook.
|
||
|
|
*
|
||
|
|
* @return void
|
||
|
|
*/
|
||
|
|
function wp_bnb_deactivate(): void {
|
||
|
|
// Flush rewrite rules.
|
||
|
|
flush_rewrite_rules();
|
||
|
|
}
|
||
|
|
|
||
|
|
register_deactivation_hook( __FILE__, 'wp_bnb_deactivate' );
|