Initial plugin setup (v0.0.1)
All checks were successful
Create Release Package / build-release (push) Successful in 1m21s
All checks were successful
Create Release Package / build-release (push) Successful in 1m21s
- Main plugin file with PHP 8.3+ and WordPress 6.0+ version checks - Plugin singleton class with admin menu and settings pages - License Manager integration with SecureLicenseClient - License settings tab with validation and activation - Admin CSS and JavaScript for license management - Gitea CI/CD workflow for automated releases - Documentation: README.md, PLAN.md, CHANGELOG.md, CLAUDE.md - Composer dependencies: Twig 3.0, license client - Git submodule for wc-licensed-product-client library Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
177
wp-bnb.php
Normal file
177
wp-bnb.php
Normal file
@@ -0,0 +1,177 @@
|
||||
<?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' );
|
||||
Reference in New Issue
Block a user