plugin_name = $plugin_name; $this->version = $version; } /** * Helper method for cached database queries. * * @param string $cache_key The cache key. * @param callable $query_func The query function to execute if cache miss. * @param int $cache_expire Cache expiration time in seconds (default: 300). * @return mixed The query result. */ private function cached_query( $cache_key, $query_func, $cache_expire = 300 ) { $result = wp_cache_get( $cache_key, 'dp_aicoso_admin' ); if ( false === $result ) { // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Query is cached $result = call_user_func( $query_func ); wp_cache_set( $cache_key, $result, 'dp_aicoso_admin', $cache_expire ); } return $result; } /** * Get safe table name for SQL queries. * * @param string $table Base table name. * @return string Full table name with prefix. */ private function get_table_name( $table ) { global $wpdb; return $wpdb->prefix . $table; } /** * Register the stylesheets for the admin area. * * @param string $hook The current admin page hook. */ public function enqueue_styles( $hook ) { if ( false === strpos( $hook, 'dp-aicoso' ) && false === strpos( $hook, 'dynamic-pricing' ) ) { return; } wp_enqueue_style( $this->plugin_name, DP_AICOSO_PLUGIN_URL . 'admin/css/dp-aicoso-admin.css', array(), $this->version, 'all' ); wp_enqueue_style( 'wp-color-picker' ); // Use WordPress built-in jQuery UI styles. wp_enqueue_style( 'jquery-ui-style', includes_url( 'css/jquery-ui-dialog.min.css' ), array(), $this->version, 'all' ); } /** * Register the JavaScript for the admin area. * * @param string $hook The current admin page hook. */ public function enqueue_scripts( $hook ) { if ( false === strpos( $hook, 'dp-aicoso' ) && false === strpos( $hook, 'dynamic-pricing' ) ) { return; } wp_enqueue_script( 'wc-enhanced-select' ); wp_enqueue_script( 'selectWoo' ); wp_enqueue_style( 'woocommerce_admin_styles' ); wp_enqueue_script( $this->plugin_name, DP_AICOSO_PLUGIN_URL . 'admin/js/dp-aicoso-admin.js', array( 'jquery', 'wp-color-picker', 'jquery-ui-datepicker', 'selectWoo' ), $this->version, true ); // Get available roles for JavaScript. $available_roles = array(); if ( class_exists( 'DP_AICOSO_Role_Rule' ) ) { $available_roles = DP_AICOSO_Role_Rule::get_available_roles(); } wp_localize_script( $this->plugin_name, 'dp_aicoso_admin', array( 'ajax_url' => admin_url( 'admin-ajax.php' ), 'admin_url' => admin_url( 'admin.php' ), 'plugin_url' => DP_AICOSO_PLUGIN_URL, 'nonce' => wp_create_nonce( 'dp_aicoso_admin' ), 'search_products_nonce' => wp_create_nonce( 'dp_aicoso_admin' ), 'export_nonce' => wp_create_nonce( 'dp_aicoso_export' ), 'available_roles' => $available_roles, 'strings' => array( 'confirm_delete' => __( 'Are you sure you want to delete this rule?', 'aicoso-dynamic-pricing-for-woocommerce' ), 'saving' => __( 'Saving...', 'aicoso-dynamic-pricing-for-woocommerce' ), 'dates_cleared' => __( 'Dates Cleared!', 'aicoso-dynamic-pricing-for-woocommerce' ), 'saved' => __( 'Rule saved successfully', 'aicoso-dynamic-pricing-for-woocommerce' ), 'error' => __( 'An error occurred', 'aicoso-dynamic-pricing-for-woocommerce' ), 'cache_cleared' => __( 'Cache cleared successfully!', 'aicoso-dynamic-pricing-for-woocommerce' ), 'cache_clear_error' => __( 'Error clearing cache.', 'aicoso-dynamic-pricing-for-woocommerce' ), ), ) ); wp_add_inline_script( $this->plugin_name, 'var dp_aicoso_plugin_url = "' . esc_js( DP_AICOSO_PLUGIN_URL ) . '";', 'before' ); // Export button handler (replaces inline