refactor(Core): refactor and optimize code
This commit is contained in:
64
sodino.php
64
sodino.php
@@ -3,7 +3,7 @@
|
||||
* Plugin Name: Sodino (سودینو)
|
||||
* Plugin URI: https://example.com/sodino
|
||||
* Description: افزونه هوشمند قیمتگذاری و بهینهسازی درآمد برای ووکامرس. قیمت محصولات را بر اساس رفتار کاربر و قوانین تعریفشده به صورت پویا تنظیم میکند.
|
||||
* Version: 1.0.0
|
||||
* Version: 2.0.0
|
||||
* Author: Your Name
|
||||
* License: GPL v2 or later
|
||||
* Text Domain: sodino
|
||||
@@ -20,7 +20,7 @@ if (!defined('ABSPATH')) {
|
||||
}
|
||||
|
||||
// Define plugin constants
|
||||
define('SODINO_VERSION', '1.0.0');
|
||||
define('SODINO_VERSION', '2.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__));
|
||||
@@ -60,6 +60,18 @@ function sodino_activate() {
|
||||
|
||||
// Flush rewrite rules if needed
|
||||
flush_rewrite_rules();
|
||||
|
||||
// Set default settings
|
||||
if (!get_option('sodino_settings')) {
|
||||
update_option('sodino_settings', [
|
||||
'plugin_enabled' => 1,
|
||||
'pricing_enabled' => 1,
|
||||
'upsell_enabled' => 1,
|
||||
'banner_enabled' => 1,
|
||||
'cache_enabled' => 1,
|
||||
'cache_duration' => 3600,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
// Deactivation hook
|
||||
@@ -70,6 +82,10 @@ function sodino_deactivate() {
|
||||
|
||||
// Clear analytics cron
|
||||
wp_clear_scheduled_hook('sodino_hourly_analytics');
|
||||
|
||||
// Clear all cache
|
||||
$cache = \Sodino\Core\Cache::getInstance();
|
||||
$cache->clearAll();
|
||||
}
|
||||
|
||||
// Bootstrap the plugin
|
||||
@@ -79,6 +95,9 @@ function sodino_init() {
|
||||
add_action('admin_notices', 'sodino_woocommerce_missing_notice');
|
||||
return;
|
||||
}
|
||||
|
||||
// Load text domain
|
||||
load_plugin_textdomain('sodino', false, dirname(SODINO_PLUGIN_BASENAME) . '/languages/');
|
||||
|
||||
// Initialize admin
|
||||
if (is_admin()) {
|
||||
@@ -86,19 +105,35 @@ function sodino_init() {
|
||||
}
|
||||
|
||||
// Initialize public hooks
|
||||
require_once SODINO_PLUGIN_DIR . 'public/hooks/pricing-hooks.php';
|
||||
require_once SODINO_PLUGIN_DIR . 'public/hooks/analytics-hooks.php';
|
||||
require_once SODINO_PLUGIN_DIR . 'public/hooks/upsell-hooks.php';
|
||||
require_once SODINO_PLUGIN_DIR . 'public/hooks/banner-hooks.php';
|
||||
sodino_init_public_hooks();
|
||||
|
||||
// Schedule analytics aggregation if needed
|
||||
sodino_schedule_analytics();
|
||||
|
||||
// Load text domain
|
||||
load_plugin_textdomain('sodino', false, dirname(SODINO_PLUGIN_BASENAME) . '/languages/');
|
||||
}
|
||||
add_action('plugins_loaded', 'sodino_init');
|
||||
|
||||
/**
|
||||
* Initialize public hooks
|
||||
*/
|
||||
function sodino_init_public_hooks() {
|
||||
$settings = \Sodino\Core\Settings::getInstance();
|
||||
|
||||
if ($settings->isPricingEnabled()) {
|
||||
require_once SODINO_PLUGIN_DIR . 'public/hooks/pricing-hooks.php';
|
||||
}
|
||||
|
||||
if ($settings->isUpsellEnabled()) {
|
||||
require_once SODINO_PLUGIN_DIR . 'public/hooks/upsell-hooks.php';
|
||||
}
|
||||
|
||||
if ($settings->isBannerEnabled()) {
|
||||
require_once SODINO_PLUGIN_DIR . 'public/hooks/banner-hooks.php';
|
||||
}
|
||||
|
||||
// Always load analytics
|
||||
require_once SODINO_PLUGIN_DIR . 'public/hooks/analytics-hooks.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule analytics cron job
|
||||
*/
|
||||
@@ -130,4 +165,13 @@ function sodino_woocommerce_missing_notice() {
|
||||
<p><?php _e('Sodino requires WooCommerce to be installed and active.', 'sodino'); ?></p>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add settings link on plugin page
|
||||
*/
|
||||
add_filter('plugin_action_links_' . SODINO_PLUGIN_BASENAME, function($links) {
|
||||
$settings_link = '<a href="' . admin_url('admin.php?page=sodino-settings') . '">' . __('تنظیمات', 'sodino') . '</a>';
|
||||
array_unshift($links, $settings_link);
|
||||
return $links;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user