__('Order Export', 'hdwebmobile-order-export'), 'order' => 85, 'render' => array($this, 'render_page'), ); return $tabs; } public function render_page() { ?>

$label) : ?>

sanitize_date(isset($_GET['date_from']) ? sanitize_text_field(wp_unslash($_GET['date_from'])) : ''); $date_to = $this->sanitize_date(isset($_GET['date_to']) ? sanitize_text_field(wp_unslash($_GET['date_to'])) : ''); $submitted_statuses = isset($_GET['status']) && is_array($_GET['status']) ? array_map('sanitize_text_field', wp_unslash($_GET['status'])) : array(); $statuses = array_values(array_intersect($submitted_statuses, array_keys(wc_get_order_statuses()))); $this->ensure_exporter_class_loaded(); $exporter = new HDOE_Exporter(); $exporter->set_filters($date_from, $date_to, $statuses); $exporter->set_filename('orders-export-' . gmdate('Y-m-d') . '.csv'); $exporter->export(); } private function sanitize_date($raw) { return preg_match('/^\d{4}-\d{2}-\d{2}$/', $raw) ? $raw : ''; } /** * WooCommerce only loads WC_CSV_Exporter on-demand (inside WC_Admin_Exporters), not on * every request, so it may not exist yet even though WooCommerce itself is active -- * same class of issue as WC_Email needing WC()->mailer() forced first. Requiring it * explicitly here guarantees the parent class exists before class-hdoe-exporter.php, * which extends it, is parsed. */ private function ensure_exporter_class_loaded() { require_once WC_ABSPATH . 'includes/export/abstract-wc-csv-exporter.php'; require_once HDOE_PLUGIN_DIR . 'includes/class-hdoe-exporter.php'; } }