wp_create_nonce( 'wp_subscription_bulk_action_nonce' ), 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) ); } /** * Create Subscriptions Menu. */ public function create_admin_menu() { $parent_slug = 'wp-subscription'; // Determine if the menu is active $is_active = isset($_GET['page']) && strpos($_GET['page'], 'wp-subscription') === 0; $icon_url = $is_active ? WP_SUBSCRIPTION_ASSETS . '/images/icons/subscription-20.png' : WP_SUBSCRIPTION_ASSETS . '/images/icons/subscription-20-gray.png'; // Main menu add_menu_page( __( 'WP Subscription', 'wp_subscription' ), __( 'WP Subscription', 'wp_subscription' ), 'manage_woocommerce', $parent_slug, array( $this, 'render_subscriptions_page' ), $icon_url, 40 ); // Subscriptions List add_submenu_page( $parent_slug, __( 'Subscriptions', 'wp_subscription' ), __( 'Subscriptions', 'wp_subscription' ), 'manage_woocommerce', $parent_slug, array( $this, 'render_subscriptions_page' ) ); // Stats Overview add_submenu_page( $parent_slug, __( 'Reports', 'wp_subscription' ), __( 'Reports', 'wp_subscription' ), 'manage_woocommerce', 'wp-subscription-stats', array( $this, 'render_stats_page' ) ); // Settings add_submenu_page( $parent_slug, __( 'Settings', 'wp_subscription' ), __( 'Settings', 'wp_subscription' ), 'manage_woocommerce', 'wp-subscription-settings', array( $this, 'render_settings_page' ) ); // Support add_submenu_page( $parent_slug, __( 'Support', 'wp_subscription' ), __( 'Support', 'wp_subscription' ), 'manage_woocommerce', 'wp-subscription-support', array( $this, 'render_support_page' ) ); // Add WP Subscription link under WooCommerce menu add_submenu_page( 'woocommerce', __( 'WP Subscription', 'wp_subscription' ), __( 'WP Subscription', 'wp_subscription' ), 'manage_woocommerce', 'wp-subscription', array( $this, 'render_subscriptions_page' ) ); } /** * Render the admin header */ public function render_admin_footer() { ?>
'wp-subscription', 'label' => __('Subscriptions', 'wp_subscription'), 'url' => admin_url('admin.php?page=wp-subscription'), ], [ 'slug' => 'wp-subscription-stats', 'label' => __('Reports', 'wp_subscription'), 'url' => admin_url('admin.php?page=wp-subscription-stats'), ], [ 'slug' => 'wp-subscription-settings', 'label' => __('Settings', 'wp_subscription'), 'url' => admin_url('admin.php?page=wp-subscription-settings'), ] ]; // Allow pro plugin to inject menu items $menu_items = apply_filters('wp_subscription_admin_header_menu_items', $menu_items, $current); $menu_items = array_merge($menu_items, [ [ 'slug' => 'wp-subscription-support', 'label' => __('Support', 'wp_subscription'), 'url' => admin_url('admin.php?page=wp-subscription-support'), ], ]); ?> render_admin_header(); // Handle filters $status = isset($_GET['subscrpt_status']) ? sanitize_text_field($_GET['subscrpt_status']) : ''; $search = isset($_GET['s']) ? sanitize_text_field($_GET['s']) : ''; $date_filter = isset($_GET['date_filter']) ? sanitize_text_field($_GET['date_filter']) : ''; $per_page = isset($_GET['per_page']) ? max(1, intval($_GET['per_page'])) : 20; $paged = isset($_GET['paged']) ? max(1, intval($_GET['paged'])) : 1; // Handle form submissions (both filters and bulk actions) if ($_SERVER['REQUEST_METHOD'] === 'POST') { // Handle bulk actions if (isset($_POST['bulk_action']) || isset($_POST['bulk_action2'])) { $bulk_action = isset($_POST['bulk_action']) ? sanitize_text_field($_POST['bulk_action']) : sanitize_text_field($_POST['bulk_action2']); $action = isset($_POST['action']) ? sanitize_text_field($_POST['action']) : sanitize_text_field($_POST['action2']); if ($bulk_action && $action && $action !== '-1' && isset($_POST['subscription_ids']) && is_array($_POST['subscription_ids'])) { $subscription_ids = array_map('intval', $_POST['subscription_ids']); if ($action === 'trash') { foreach ($subscription_ids as $sub_id) { wp_trash_post($sub_id); } } elseif ($action === 'restore') { foreach ($subscription_ids as $sub_id) { wp_untrash_post($sub_id); } } elseif ($action === 'delete') { foreach ($subscription_ids as $sub_id) { wp_delete_post($sub_id, true); } } wp_safe_redirect(admin_url('admin.php?page=wp-subscription')); exit; } } // Handle filter form submission if (isset($_POST['filter_action'])) { $filter_params = array(); if (!empty($_POST['subscrpt_status'])) { $filter_params['subscrpt_status'] = sanitize_text_field($_POST['subscrpt_status']); } if (!empty($_POST['date_filter'])) { $filter_params['date_filter'] = sanitize_text_field($_POST['date_filter']); } if (!empty($_POST['s'])) { $filter_params['s'] = sanitize_text_field($_POST['s']); } if (!empty($_POST['per_page'])) { $filter_params['per_page'] = intval($_POST['per_page']); } $redirect_url = add_query_arg($filter_params, admin_url('admin.php?page=wp-subscription')); wp_safe_redirect($redirect_url); exit; } } // Handle individual actions if (isset($_GET['action']) && !empty($_GET['sub_id'])) { $sub_id = intval($_GET['sub_id']); $action = sanitize_text_field($_GET['action']); if ($action === 'duplicate') { $post = get_post($sub_id); if ($post && $post->post_type === 'subscrpt_order') { $new_post = [ 'post_title' => $post->post_title . ' (Copy)', 'post_content' => $post->post_content, 'post_status' => 'draft', 'post_type' => 'subscrpt_order', ]; $new_id = wp_insert_post($new_post); if ($new_id) { $meta = get_post_meta($sub_id); foreach ($meta as $key => $values) { foreach ($values as $value) { add_post_meta($new_id, $key, maybe_unserialize($value)); } } } } wp_safe_redirect(admin_url('admin.php?page=wp-subscription')); exit; } elseif ($action === 'trash') { // Move to trash wp_trash_post($sub_id); wp_safe_redirect(admin_url('admin.php?page=wp-subscription')); exit; } elseif ($action === 'restore') { // Restore from trash wp_untrash_post($sub_id); wp_safe_redirect(admin_url('admin.php?page=wp-subscription')); exit; } elseif ($action === 'delete') { // Permanent delete wp_delete_post($sub_id, true); wp_safe_redirect(admin_url('admin.php?page=wp-subscription')); exit; } elseif ($action === 'clean_trash') { // Clean all trash items $trash_posts = get_posts([ 'post_type' => 'subscrpt_order', 'post_status' => 'trash', 'numberposts' => -1, 'fields' => 'ids' ]); foreach ($trash_posts as $trash_id) { wp_delete_post($trash_id, true); } wp_safe_redirect(admin_url('admin.php?page=wp-subscription&subscrpt_status=trash')); exit; } } $args = [ 'post_type' => 'subscrpt_order', 'post_status' => 'any', 'posts_per_page' => $per_page, 'paged' => $paged, 'orderby' => 'date', 'order' => 'DESC', ]; if ($status) { $args['post_status'] = $status; } // Search only by subscription ID if ($search !== '') { if (is_numeric($search)) { $args['p'] = intval($search); } else { // If not numeric, return no results $args['post__in'] = array(0); } } // Dynamic date filter (YYYY-MM) if ($date_filter && preg_match('/^\d{4}-\d{2}$/', $date_filter)) { $year = substr($date_filter, 0, 4); $month = substr($date_filter, 5, 2); $args['date_query'][] = [ 'year' => intval($year), 'month' => intval($month), ]; } $query = new \WP_Query($args); $subscriptions = $query->posts; $total = $query->found_posts; $max_num_pages = $query->max_num_pages; // Get all possible statuses for filter dropdown $all_statuses = get_post_stati(['show_in_admin_all_list' => true], 'objects'); include dirname(__FILE__) . '/views/subscription-list.php'; ?> render_admin_header(); if ( ! class_exists('Sdevs_Wc_Subscription_Pro') ) { ?>WPSubscription helps you to sell products and services on a recurring basis using your existing WooCommerce store. Whether you're offering digital licenses, physical product boxes, or ongoing service plans, this plugin provides the tools to build and manage subscription models.