' . sprintf( esc_html__( 'ChatGPT Product Feed for WooCommerce requires WooCommerce to be installed and active. You can download %s here.', 'agentic-commerce-protocol-chatgpt-product-feed-ovena-acp-for-woocommerce' ), 'WooCommerce' ) . '

'; } register_activation_hook( __FILE__, 'ovena_acp_activate' ); register_deactivation_hook( __FILE__, 'ovena_acp_deactivate' ); /** * Plugin activation hook. * * Runs when the plugin is activated. Sets up the cron job for * automatic product synchronization based on user settings. * * @since 1.0.0 * @return void */ function ovena_acp_activate() { if ( ! class_exists( 'WooCommerce' ) ) { add_action( 'admin_notices', 'ovena_acp_missing_wc_notice' ); return; } // Schedule cron job for syncing with custom interval if ( ! wp_next_scheduled( 'ovena_acp_sync' ) ) { // Only schedule if auto-sync is enabled (default is true) $auto_sync = get_option( 'ovena_acp_auto_sync', true ); if ( $auto_sync ) { wp_schedule_event( time(), 'ovena_custom_interval', 'ovena_acp_sync' ); } } } /** * Plugin deactivation hook. * * Runs when the plugin is deactivated. Clears all scheduled * cron jobs to prevent them from running while the plugin is inactive. * * @since 1.0.0 * @return void */ function ovena_acp_deactivate() { wp_clear_scheduled_hook( 'ovena_acp_sync' ); } if ( ! class_exists( 'Ovena_ACP' ) ) : /** * Main Ovena ACP class. * * This is the main plugin class that initializes all plugin functionality. * It uses a singleton pattern to ensure only one instance exists. * * @since 1.0.0 * @package OvenaCommerceFeed */ class Ovena_ACP { /** * Single instance of this class. * * @since 1.0.0 * @var Ovena_ACP|null */ private static $instance; /** * Constructor. * * Initializes the plugin by setting up all necessary hooks. * * @since 1.0.0 */ public function __construct() { $this->init_hooks(); } /** * Initialize WordPress hooks. * * Sets up all actions and filters required for the plugin to function. * * @since 1.0.0 * @return void */ private function init_hooks() { // Initialize admin interface if ( is_admin() ) { new Ovena_ACP_Admin(); } // Hook sync functionality add_action( 'ovena_acp_sync', array( $this, 'run_sync' ) ); // Add custom cron schedule add_filter( 'cron_schedules', array( $this, 'add_custom_cron_intervals' ) ); } /** * Add custom cron intervals. * * Registers a custom dynamic cron interval based on user settings. * * @since 1.0.0 * @param array $schedules Existing cron schedules. * @return array Modified cron schedules array. */ public function add_custom_cron_intervals( $schedules ) { $interval = absint( get_option( 'ovena_acp_sync_interval', 15 ) ); // Ensure interval is between 15 and 1440 minutes if ( $interval < 15 ) { $interval = 15; } elseif ( $interval > 1440 ) { $interval = 1440; } $schedules['ovena_custom_interval'] = array( 'interval' => $interval * 60, // Convert minutes to seconds /* translators: %d: number of minutes for the sync interval */ 'display' => sprintf( __( 'Every %d Minutes', 'agentic-commerce-protocol-chatgpt-product-feed-ovena-acp-for-woocommerce' ), $interval ), ); return $schedules; } /** * Run the product sync process. * * Called by the cron job to synchronize products with the Ovena API. * Only runs if auto-sync is enabled in settings. * * @since 1.0.0 * @return void */ public function run_sync() { // Check if auto-sync is enabled $auto_sync = get_option( 'ovena_acp_auto_sync', true ); if ( ! $auto_sync ) { return; // Skip sync if auto-sync is disabled } $sync = new Ovena_ACP_Sync(); $sync->sync_products(); } /** * Get the singleton instance of this class. * * Ensures only one instance can be loaded, following the singleton pattern. * * @since 1.0.0 * @return Ovena_ACP The single instance of the class. */ public static function instance() { if ( null === self::$instance ) { self::$instance = new self(); } return self::$instance; } } endif; add_action( 'plugins_loaded', 'ovena_acp_init', 10 ); /** * Initialize the plugin. * * Loads the plugin text domain for translations and initializes the main * plugin class if WooCommerce is active. If WooCommerce is not active, * shows an admin notice. * * @since 1.0.0 * @return void */ function ovena_acp_init() { // WordPress.org automatically loads translations for plugins // No need to manually call load_plugin_textdomain() since WP 4.6 if ( ! class_exists( 'WooCommerce' ) ) { add_action( 'admin_notices', 'ovena_acp_missing_wc_notice' ); return; } // Declare compatibility with WooCommerce HPOS (High-Performance Order Storage) add_action( 'before_woocommerce_init', 'ovena_acp_declare_hpos_compatibility' ); Ovena_ACP::instance(); } /** * Declare compatibility with WooCommerce HPOS. * * Declares that this plugin is compatible with WooCommerce High-Performance Order Storage. * * @since 1.1.0 * @return void */ function ovena_acp_declare_hpos_compatibility() { if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) { \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', OVENA_ACP_FILE, true ); } }