/** * Coponix Premium functions and definitions */ if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } /** * Theme Setup */ function coponix_setup() { // Add support for title tag add_theme_support( 'title-tag' ); // Add support for post thumbnails add_theme_support( 'post-thumbnails' ); // Register navigation menus register_nav_menus( array( 'primary' => __( 'Primary Menu', 'coponix' ), 'footer' => __( 'Footer Menu', 'coponix' ), ) ); // Switch default core markup for search form, comment form, and comments to output valid HTML5. add_theme_support( 'html5', array( 'search-form', 'comment-form', 'comment-list', 'gallery', 'caption', ) ); } add_action( 'after_setup_theme', 'coponix_setup' ); /** * Enqueue scripts and styles */ function coponix_scripts() { // Main Stylesheet wp_enqueue_style( 'coponix-style', get_stylesheet_uri(), array(), '1.0.0' ); // Custom Main CSS wp_enqueue_style( 'coponix-main', get_template_directory_uri() . '/assets/css/main.css', array(), '1.0.0' ); // Custom Main JS wp_enqueue_script( 'coponix-app', get_template_directory_uri() . '/assets/js/app.js', array(), '1.0.0', true ); // Localize script for AJAX (if needed later) wp_localize_script( 'coponix-app', 'coponix_data', array( 'ajax_url' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'coponix_nonce' ), ) ); } add_action( 'wp_enqueue_scripts', 'coponix_scripts' ); /** * Register Custom Post Types (Coupons & Stores) */ function coponix_register_cpts() { if ( ! post_type_exists( 'coupon' ) ) { register_post_type( 'coupon', array( 'labels' => array( 'name' => 'الكوبونات', 'singular_name' => 'كوبون', ), 'public' => true, 'has_archive' => true, 'menu_icon' => 'dashicons-tickets-alt', 'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt', 'custom-fields' ), 'rewrite' => array( 'slug' => 'coupons' ), 'show_in_rest' => true, )); } if ( ! taxonomy_exists( 'store' ) ) { register_taxonomy( 'store', 'coupon', array( 'labels' => array( 'name' => 'المتاجر', 'singular_name' => 'متجر', ), 'hierarchical' => true, 'show_admin_column' => true, 'show_in_rest' => true, )); } } add_action( 'init', 'coponix_register_cpts' ); /** * Data Import Function */ function coponix_do_import() { $csv_url = 'https://docs.google.com/spreadsheets/d/e/2PACX-1vTaPmGBKx7Mqt77YeaUJN88_77XCqvLHM33uT4-WjomIAXnU-PU5X4II5gaeXAitw/pub?output=csv'; $response = wp_remote_get($csv_url, ['timeout' => 45]); if (is_wp_error($response)) return "Error: " . $response->get_error_message(); $body = wp_remote_retrieve_body($response); $rows = explode("\n", $body); array_shift($rows); // Remove header $count = 0; foreach ($rows as $row_str) { $row = str_getcsv($row_str); if (count($row) < 5) continue; $store_name = trim($row[0]); $geo = trim($row[1]); $category = trim($row[2]); $website = trim($row[3]); $code = trim($row[4]); if (empty($store_name)) continue; $title = "كود خصم " . $store_name . " فعال لعام 2026"; $existing_post = get_page_by_title($title, OBJECT, 'coupon'); if (!$existing_post) { $post_id = wp_insert_post([ 'post_title' => $title, 'post_type' => 'coupon', 'post_status' => 'publish', 'post_excerpt' => "كود خصم " . $store_name . " " . $category . " بقيمة توفير ممتازة لعام 2026", ]); if ($post_id) { update_post_meta($post_id, 'coupon_geo', $geo); update_post_meta($post_id, 'coupon_category', $category); update_post_meta($post_id, 'store_url', $website); update_post_meta($post_id, 'coupon_code', $code); wp_set_object_terms($post_id, $store_name, 'store'); $count++; } } } return "Imported/Synced $count new coupons successfully."; } add_action('init', function() { if (isset($_GET['run_import']) && current_user_can('manage_options')) { $result = coponix_do_import(); wp_die($result . '

Return to Dashboard'); } });