function woo_ce_trigger_new_order_export( $order_id = 0 ) { global $export; if( !empty( $order_id ) ) { $export_format = woo_ce_get_option( 'trigger_new_order_format', 'csv' ); $export_fields = woo_ce_get_option( 'trigger_new_order_fields', 'all' ); $gui = woo_ce_get_option( 'trigger_new_order_method', 'archive' ); set_transient( WOO_CD_PREFIX . '_single_export_format', sanitize_text_field( $export_format ), MINUTE_IN_SECONDS ); set_transient( WOO_CD_PREFIX . '_single_export_order_ids', absint( $order_id ), MINUTE_IN_SECONDS ); set_transient( WOO_CD_PREFIX . '_single_export_fields', sanitize_text_field( $export_fields ), MINUTE_IN_SECONDS ); $export_type = 'order'; if( woo_ce_cron_export( $gui, $export_type ) ) { error_log( sprintf( '[store-exporter-deluxe] %s: Success: %s', $export->filename, sprintf( __( 'New Order #%d export saved to WordPress Media', 'woo_ce' ), $order_id ) ) ); } delete_transient( WOO_CD_PREFIX . '_single_export_format' ); delete_transient( WOO_CD_PREFIX . '_single_export_order_ids' ); delete_transient( WOO_CD_PREFIX . '_single_export_fields' ); unset( $gui, $export_type ); } }
function woo_ce_cron() { $action = woo_get_action(); // This is where the CRON export magic happens if( $action == 'woo_ce-cron' ) { // Check that Store Exporter is installed and activated or jump out if( !function_exists( 'woo_ce_get_option' ) ) return; // Return silent response and record to error log if CRON support is disabled or bad secret key provided if( woo_ce_get_option( 'enable_cron', 0 ) == 0 ) { error_log( '[store-exporter-deluxe] Error: Failed CRON access, CRON is disabled' ); return; } $key = ( isset( $_GET['key'] ) ? sanitize_text_field( $_GET['key'] ) : '' ); if( $key <> woo_ce_get_option( 'secret_key', '' ) ) { $ip_address = woo_ce_get_visitor_ip_address(); error_log( sprintf( '[store-exporter-deluxe] Error: Failed CRON attempt from %s, incorrect secret key' ), $ip_address ); return; } $gui = ( isset( $_GET['gui'] ) ? absint( $_GET['gui'] ) : 0 ); $response = ( isset( $_GET['response'] ) ? sanitize_text_field( $_GET['response'] ) : '' ); // Output to screen in friendly design with on-screen error responses if( $gui == 1 ) { woo_ce_cron_export( 'gui' ); // Return export download to browser in different expected formats, uses error_log for error responses } else if( $gui == 0 && in_array( $response, array( 'download', 'raw', 'url', 'file', 'email', 'post', 'ftp' ) ) ) { switch( $response ) { // Return export download to browser case 'download': echo woo_ce_cron_export( 'download' ); break; // Return raw download to browser case 'raw': echo woo_ce_cron_export( 'raw' ); break; // Return the URI to the saved export case 'url': echo woo_ce_cron_export( 'url' ); break; // Return the system path to the saved export case 'file': echo woo_ce_cron_export( 'file' ); break; case 'email': echo woo_ce_cron_export( 'email' ); break; case 'post': echo woo_ce_cron_export( 'post' ); break; case 'ftp': echo woo_ce_cron_export( 'ftp' ); break; } } else { // Return simple binary response echo absint( woo_ce_cron_export() ); } exit(); } }
function woo_ce_admin_order_single_export_xlsx( $order = false ) { if( $order !== false ) { // Set the export format type $export_type = 'xlsx'; // Set up our export set_transient( WOO_CD_PREFIX . '_single_export_format', $export_type, MINUTE_IN_SECONDS ); set_transient( WOO_CD_PREFIX . '_single_export_order_ids', $order->id, MINUTE_IN_SECONDS ); // Run the export $gui = 'download'; $export_type = 'order'; woo_ce_cron_export( $gui, $export_type ); // Clean up delete_transient( WOO_CD_PREFIX . '_single_export_format' ); delete_transient( WOO_CD_PREFIX . '_single_export_order_ids' ); exit(); } }