function woo_ce_init() { // Check that Store Exporter Deluxe is installed and activated or jump out if( !function_exists( 'woo_ce_get_option' ) ) return; // Check if scheduled exports is enabled if( woo_ce_get_option( 'enable_auto', 0 ) == 1 ) { // Add custom schedule for automated exports add_filter( 'cron_schedules', 'woo_ce_cron_schedules' ); woo_ce_cron_activation(); } // Check if trigger export on New Order is enabled if( woo_ce_get_option( 'enable_trigger_new_order', 0 ) == 1 ) { // There are other WordPress Actions (woocommerce_new_order, woocommerce_api_create_order) we can hook into but woocommerce_checkout_update_order_meta is the only one where we can access the Order Items add_action( 'woocommerce_checkout_update_order_meta', 'woo_ce_trigger_new_order_export', 10, 1 ); } // Once every x minutes WP-CRON will run the automated export add_action( 'woo_ce_auto_export_schedule', 'woo_ce_auto_export' ); }
function woo_ce_admin_save_settings() { // Strip file extension from export filename $export_filename = strip_tags( $_POST['export_filename'] ); if( ( strpos( $export_filename, '.csv' ) !== false ) || ( strpos( $export_filename, '.xml' ) !== false ) || ( strpos( $export_filename, '.xls' ) !== false ) ) $export_filename = str_replace( array( '.csv', '.xml', '.xls' ), '', $export_filename ); woo_ce_update_option( 'export_filename', $export_filename ); woo_ce_update_option( 'delete_file', absint( $_POST['delete_file'] ) ); woo_ce_update_option( 'encoding', sanitize_text_field( $_POST['encoding'] ) ); woo_ce_update_option( 'delimiter', sanitize_text_field( $_POST['delimiter'] ) ); woo_ce_update_option( 'category_separator', sanitize_text_field( $_POST['category_separator'] ) ); woo_ce_update_option( 'bom', absint( $_POST['bom'] ) ); woo_ce_update_option( 'escape_formatting', sanitize_text_field( $_POST['escape_formatting'] ) ); woo_ce_update_option( 'header_formatting', absint( $_POST['header_formatting'] ) ); if( $_POST['date_format'] == 'custom' && !empty( $_POST['date_format_custom'] ) ) woo_ce_update_option( 'date_format', sanitize_text_field( $_POST['date_format_custom'] ) ); else woo_ce_update_option( 'date_format', sanitize_text_field( $_POST['date_format'] ) ); woo_ce_update_option( 'email_to', sanitize_text_field( $_POST['email_to'] ) ); woo_ce_update_option( 'email_subject', sanitize_text_field( $_POST['email_subject'] ) ); woo_ce_update_option( 'post_to', sanitize_text_field( $_POST['post_to'] ) ); // XML settings woo_ce_update_option( 'xml_attribute_url', ( isset( $_POST['xml_attribute_url'] ) ? absint( $_POST['xml_attribute_url'] ) : 0 ) ); woo_ce_update_option( 'xml_attribute_title', ( isset( $_POST['xml_attribute_title'] ) ? absint( $_POST['xml_attribute_title'] ) : 0 ) ); woo_ce_update_option( 'xml_attribute_date', ( isset( $_POST['xml_attribute_date'] ) ? absint( $_POST['xml_attribute_date'] ) : 0 ) ); woo_ce_update_option( 'xml_attribute_time', ( isset( $_POST['xml_attribute_time'] ) ? absint( $_POST['xml_attribute_time'] ) : 0 ) ); woo_ce_update_option( 'xml_attribute_export', ( isset( $_POST['xml_attribute_export'] ) ? absint( $_POST['xml_attribute_export'] ) : 0 ) ); woo_ce_update_option( 'xml_attribute_orderby', ( isset( $_POST['xml_attribute_orderby'] ) ? absint( $_POST['xml_attribute_orderby'] ) : 0 ) ); woo_ce_update_option( 'xml_attribute_order', ( isset( $_POST['xml_attribute_order'] ) ? absint( $_POST['xml_attribute_order'] ) : 0 ) ); woo_ce_update_option( 'xml_attribute_limit', ( isset( $_POST['xml_attribute_limit'] ) ? absint( $_POST['xml_attribute_limit'] ) : 0 ) ); woo_ce_update_option( 'xml_attribute_offset', ( isset( $_POST['xml_attribute_offset'] ) ? absint( $_POST['xml_attribute_offset'] ) : 0 ) ); // RSS settings woo_ce_update_option( 'rss_title', ( isset( $_POST['rss_title'] ) ? sanitize_text_field( $_POST['rss_title'] ) : '' ) ); woo_ce_update_option( 'rss_link', ( isset( $_POST['rss_link'] ) ? esc_url_raw( $_POST['rss_link'] ) : '' ) ); woo_ce_update_option( 'rss_description', ( isset( $_POST['rss_description'] ) ? sanitize_text_field( $_POST['rss_description'] ) : '' ) ); // Scheduled export settings $enable_auto = absint( $_POST['enable_auto'] ); $auto_schedule = sanitize_text_field( $_POST['auto_schedule'] ); $auto_interval = absint( $_POST['auto_interval'] ); $auto_commence = sanitize_text_field( $_POST['auto_commence'] ); $auto_commence_date = sanitize_text_field( $_POST['auto_commence_date'] ); $site_hash = md5( get_option( 'siteurl' ) ); // Display additional notice if Enabled Scheduled Exports is enabled/disabled or scheduling options are modified if( woo_ce_get_option( 'enable_auto', 0 ) <> $enable_auto || woo_ce_get_option( 'auto_schedule', 'custom' ) <> $auto_schedule || woo_ce_get_option( 'auto_interval', 1440 ) <> $auto_interval || woo_ce_get_option( 'auto_commence', 'now' ) <> $auto_commence || woo_ce_get_option( 'auto_commence_date', date( 'd/m/Y H:i' ) ) <> $auto_commence_date ) { // Save these fields before we re-load the WP-CRON schedule woo_ce_update_option( 'enable_auto', $enable_auto ); // Remove from WP-CRON schedule if disabled if( $enable_auto == 0 ) { woo_ce_cron_activation(); // Re-load the WP-CRON schedule with our new scheduling options } else if( woo_ce_get_option( 'auto_schedule', 'custom' ) <> $auto_schedule || woo_ce_get_option( 'auto_interval', 1440 ) <> $auto_interval || woo_ce_get_option( 'auto_commence', 'now' ) <> $auto_commence || woo_ce_get_option( 'auto_commence_date', date( 'd/m/Y H:i' ) ) <> $auto_commence_date || woo_ce_get_option( 'site_hash', '' ) <> $site_hash ) { // Save these fields before we re-load the WP-CRON schedule woo_ce_update_option( 'auto_commence', $auto_commence ); woo_ce_update_option( 'auto_commence_date', $auto_commence_date ); woo_ce_update_option( 'auto_schedule', $auto_schedule ); woo_ce_update_option( 'auto_interval', $auto_interval ); // Update the Site URL hash we use for live vs. staging checks woo_ce_update_option( 'site_hash', $site_hash ); woo_ce_cron_activation( true ); } switch( $auto_schedule ) { case 'daily': case 'weekly': case 'monthly': $interval = $auto_schedule; break; case 'custom': $interval = sprintf( __( 'in %d minute(s)', 'woo_ce' ), $auto_interval ); break; } switch( $auto_commence ) { case 'now': $commence = __( ' from now' ); break; case 'future': $commence = sprintf( __( ' starting %s' ), $auto_commence_date ); break; } $message = sprintf( __( 'Scheduled exports has been %s.', 'woo_ce' ), ( ( $enable_auto == 1 ) ? sprintf( __( 'activated, next scheduled export will run %s%s', 'woo_ce' ), $interval, $commence ) : __( 'de-activated, no further automated exports will occur', 'woo_ce' ) ) ); woo_cd_admin_notice( $message ); } woo_ce_update_option( 'auto_type', sanitize_text_field( $_POST['auto_type'] ) ); woo_ce_update_option( 'auto_product_type', ( isset( $_POST['product_filter_type'] ) ? array_map( 'sanitize_text_field', $_POST['product_filter_type'] ) : array() ) ); woo_ce_update_option( 'auto_product_status', ( isset( $_POST['product_filter_status'] ) ? array_map( 'sanitize_text_field', $_POST['product_filter_status'] ) : array() ) ); woo_ce_update_option( 'auto_product_stock', sanitize_text_field( $_POST['product_filter_stock'] ) ); woo_ce_update_option( 'auto_product_category', ( isset( $_POST['product_filter_category'] ) ? array_map( 'absint', $_POST['product_filter_category'] ) : array() ) ); woo_ce_update_option( 'auto_product_tag', ( isset( $_POST['product_filter_tag'] ) ? array_map( 'absint', $_POST['product_filter_tag'] ) : array() ) ); woo_ce_update_option( 'auto_order_date', sanitize_text_field( $_POST['order_dates_filter'] ) ); woo_ce_update_option( 'auto_order_dates_from', sanitize_text_field( $_POST['order_dates_from'] ) ); woo_ce_update_option( 'auto_order_dates_to', sanitize_text_field( $_POST['order_dates_to'] ) ); woo_ce_update_option( 'auto_order_date_variable', sanitize_text_field( $_POST['order_dates_filter_variable'] ) ); woo_ce_update_option( 'auto_order_date_variable_length', sanitize_text_field( $_POST['order_dates_filter_variable_length'] ) ); woo_ce_update_option( 'auto_order_status', ( isset( $_POST['order_filter_status'] ) ? woo_ce_format_product_filters( array_map( 'sanitize_text_field', $_POST['order_filter_status'] ) ) : array() ) ); // Check if we are dealing with a string or array $auto_order_product = ( isset( $_POST['order_filter_product'] ) ? $_POST['order_filter_product'] : false ); // Select2 passes us a string whereas Chosen gives us an array if( is_array( $auto_order_product ) && count( $auto_order_product ) == 1 ) $auto_order_product = explode( ',', $auto_order_product[0] ); woo_ce_update_option( 'auto_order_product', ( !empty( $auto_order_product ) ? woo_ce_format_product_filters( array_map( 'absint', $auto_order_product ) ) : array() ) ); unset( $auto_order_product ); woo_ce_update_option( 'auto_order_billing_country', ( isset( $_POST['order_filter_billing_country'] ) ? array_map( 'sanitize_text_field', $_POST['order_filter_billing_country'] ) : array() ) ); woo_ce_update_option( 'auto_order_shipping_country', ( isset( $_POST['order_filter_shipping_country'] ) ? array_map( 'sanitize_text_field', $_POST['order_filter_shipping_country'] ) : array() ) ); woo_ce_update_option( 'auto_order_payment', ( isset( $_POST['order_filter_payment'] ) ? array_map( 'sanitize_text_field', $_POST['order_filter_payment'] ) : array() ) ); woo_ce_update_option( 'auto_order_shipping', ( isset( $_POST['order_filter_shipping'] ) ? array_map( 'sanitize_text_field', $_POST['order_filter_shipping'] ) : array() ) ); woo_ce_update_option( 'auto_format', sanitize_text_field( $_POST['auto_format'] ) ); woo_ce_update_option( 'auto_method', sanitize_text_field( $_POST['auto_method'] ) ); woo_ce_update_option( 'auto_ftp_method_host', ( isset( $_POST['ftp_method_host'] ) ? woo_ce_format_ftp_host( sanitize_text_field( $_POST['ftp_method_host'] ) ) : '' ) ); woo_ce_update_option( 'auto_ftp_method_user', sanitize_text_field( $_POST['ftp_method_user'] ) ); // Update FTP password only if it is filled in if( !empty( $_POST['ftp_method_pass'] ) ) woo_ce_update_option( 'auto_ftp_method_pass', sanitize_text_field( $_POST['ftp_method_pass'] ) ); woo_ce_update_option( 'auto_ftp_method_port', sanitize_text_field( $_POST['ftp_method_port'] ) ); woo_ce_update_option( 'auto_ftp_method_protocol', sanitize_text_field( $_POST['ftp_method_protocol'] ) ); woo_ce_update_option( 'auto_ftp_method_path', sanitize_text_field( $_POST['ftp_method_path'] ) ); // Strip file extension from export filename $ftp_filename = strip_tags( $_POST['ftp_method_filename'] ); if( ( strpos( $ftp_filename, '.csv' ) !== false ) || ( strpos( $ftp_filename, '.xml' ) !== false ) || ( strpos( $ftp_filename, '.xls' ) !== false ) || ( strpos( $ftp_filename, '.xlsx' ) !== false ) ) $ftp_filename = str_replace( array( '.csv', '.xml', '.xls', '.xlsx' ), '', $ftp_filename ); woo_ce_update_option( 'auto_ftp_method_filename', $ftp_filename ); unset( $ftp_filename ); woo_ce_update_option( 'auto_ftp_method_passive', sanitize_text_field( $_POST['ftp_method_passive'] ) ); woo_ce_update_option( 'auto_ftp_method_timeout', sanitize_text_field( $_POST['ftp_method_timeout'] ) ); woo_ce_update_option( 'scheduled_fields', sanitize_text_field( $_POST['scheduled_fields'] ) ); // CRON settings $enable_cron = absint( $_POST['enable_cron'] ); // Display additional notice if Enabled CRON is enabled/disabled if( woo_ce_get_option( 'enable_cron', 0 ) <> $enable_cron ) { $message = sprintf( __( 'CRON support has been %s.', 'woo_ce' ), ( ( $enable_cron == 1 ) ? __( 'enabled', 'woo_ce' ) : __( 'disabled', 'woo_ce' ) ) ); woo_cd_admin_notice( $message ); } woo_ce_update_option( 'enable_cron', $enable_cron ); woo_ce_update_option( 'secret_key', sanitize_text_field( $_POST['secret_key'] ) ); woo_ce_update_option( 'cron_fields', sanitize_text_field( $_POST['cron_fields'] ) ); // Orders Screen woo_ce_update_option( 'order_actions_csv', ( isset( $_POST['order_actions_csv'] ) ? absint( $_POST['order_actions_csv'] ) : 0 ) ); woo_ce_update_option( 'order_actions_xml', ( isset( $_POST['order_actions_xml'] ) ? absint( $_POST['order_actions_xml'] ) : 0 ) ); woo_ce_update_option( 'order_actions_xls', ( isset( $_POST['order_actions_xls'] ) ? absint( $_POST['order_actions_xls'] ) : 0 ) ); woo_ce_update_option( 'order_actions_xlsx', ( isset( $_POST['order_actions_xlsx'] ) ? absint( $_POST['order_actions_xlsx'] ) : 0 ) ); // Export Triggers woo_ce_update_option( 'enable_trigger_new_order', ( isset( $_POST['enable_trigger_new_order'] ) ? absint( $_POST['enable_trigger_new_order'] ) : 0 ) ); woo_ce_update_option( 'trigger_new_order_format', sanitize_text_field( $_POST['trigger_new_order_format'] ) ); woo_ce_update_option( 'trigger_new_order_method', sanitize_text_field( $_POST['trigger_new_order_method'] ) ); woo_ce_update_option( 'trigger_new_order_fields', sanitize_text_field( $_POST['trigger_new_order_fields'] ) ); $message = __( 'Changes have been saved.', 'woo_ce' ); woo_cd_admin_notice( $message ); }