Init(Core): create and add project
This commit is contained in:
100
sodino.php
Normal file
100
sodino.php
Normal file
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
/**
|
||||
* Plugin Name: Sodino (سودینو)
|
||||
* Plugin URI: https://example.com/sodino
|
||||
* Description: افزونه هوشمند قیمتگذاری و بهینهسازی درآمد برای ووکامرس. قیمت محصولات را بر اساس رفتار کاربر و قوانین تعریفشده به صورت پویا تنظیم میکند.
|
||||
* Version: 1.0.0
|
||||
* Author: Your Name
|
||||
* License: GPL v2 or later
|
||||
* Text Domain: sodino
|
||||
* Requires at least: 5.0
|
||||
* Tested up to: 6.0
|
||||
* Requires PHP: 7.4
|
||||
* WC requires at least: 5.0
|
||||
* WC tested up to: 6.0
|
||||
*/
|
||||
|
||||
// Prevent direct access
|
||||
if (!defined('ABSPATH')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
// Define plugin constants
|
||||
define('SODINO_VERSION', '1.0.0');
|
||||
define('SODINO_PLUGIN_DIR', plugin_dir_path(__FILE__));
|
||||
define('SODINO_PLUGIN_URL', plugin_dir_url(__FILE__));
|
||||
define('SODINO_PLUGIN_BASENAME', plugin_basename(__FILE__));
|
||||
|
||||
// Autoloader for PSR-4
|
||||
spl_autoload_register(function ($class) {
|
||||
// Namespace prefix
|
||||
$prefix = 'Sodino\\';
|
||||
|
||||
// Base directory for the namespace prefix
|
||||
$base_dir = SODINO_PLUGIN_DIR . 'app/';
|
||||
|
||||
// Does the class use the namespace prefix?
|
||||
$len = strlen($prefix);
|
||||
if (strncmp($prefix, $class, $len) !== 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the relative class name
|
||||
$relative_class = substr($class, $len);
|
||||
|
||||
// Replace namespace separators with directory separators
|
||||
$file = $base_dir . str_replace('\\', '/', $relative_class) . '.php';
|
||||
|
||||
// If the file exists, require it
|
||||
if (file_exists($file)) {
|
||||
require $file;
|
||||
}
|
||||
});
|
||||
|
||||
// Activation hook
|
||||
register_activation_hook(__FILE__, 'sodino_activate');
|
||||
function sodino_activate() {
|
||||
// Include database migration
|
||||
require_once SODINO_PLUGIN_DIR . 'database/migrations.php';
|
||||
sodino_create_tables();
|
||||
|
||||
// Flush rewrite rules if needed
|
||||
flush_rewrite_rules();
|
||||
}
|
||||
|
||||
// Deactivation hook
|
||||
register_deactivation_hook(__FILE__, 'sodino_deactivate');
|
||||
function sodino_deactivate() {
|
||||
// Flush rewrite rules
|
||||
flush_rewrite_rules();
|
||||
}
|
||||
|
||||
// Bootstrap the plugin
|
||||
function sodino_init() {
|
||||
// Check if WooCommerce is active
|
||||
if (!class_exists('WooCommerce')) {
|
||||
add_action('admin_notices', 'sodino_woocommerce_missing_notice');
|
||||
return;
|
||||
}
|
||||
|
||||
// Initialize admin
|
||||
if (is_admin()) {
|
||||
require_once SODINO_PLUGIN_DIR . 'admin/admin.php';
|
||||
}
|
||||
|
||||
// Initialize public hooks
|
||||
require_once SODINO_PLUGIN_DIR . 'public/hooks/pricing-hooks.php';
|
||||
|
||||
// Load text domain
|
||||
load_plugin_textdomain('sodino', false, dirname(SODINO_PLUGIN_BASENAME) . '/languages/');
|
||||
}
|
||||
add_action('plugins_loaded', 'sodino_init');
|
||||
|
||||
// WooCommerce missing notice
|
||||
function sodino_woocommerce_missing_notice() {
|
||||
?>
|
||||
<div class="error">
|
||||
<p><?php _e('Sodino requires WooCommerce to be installed and active.', 'sodino'); ?></p>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
Reference in New Issue
Block a user