path_csv = $upload_dir['basedir'] . "/export-users.csv"; add_action( 'init', array( $this, 'download_export_file' ) ); add_action( 'admin_init', array( $this, 'download_export_file' ) ); add_action( 'wp_ajax_acui_export_users_csv', array( $this, 'export_users_csv' ) ); add_action( 'wp_ajax_acui_export_save_settings', array( $this, 'ajax_save_settings' ) ); } static function enqueue(){ wp_enqueue_script( 'acui_export_js', plugins_url( 'assets/export.js', dirname( __FILE__ ) ), false, ACUI_VERSION, true ); wp_localize_script( 'acui_export_js', 'acui_export_js_object', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ), 'starting_process' => __( 'Starting process', 'import-users-from-csv-with-meta' ), 'step' => __( 'Step', 'import-users-from-csv-with-meta' ), 'of_approximately' => __( 'of approximately', 'import-users-from-csv-with-meta' ), 'steps' => __( 'steps', 'import-users-from-csv-with-meta' ), 'error_thrown' => __( 'Error thrown in the server, we cannot continue. Please check console to see full details about the error.', 'import-users-from-csv-with-meta' ), ) ); } static function styles(){ ?>

select( array( 'options' => ACUI_Helper::get_editable_roles(), 'name' => 'role', 'show_option_all' => false, 'show_option_none' => __( 'All roles', 'import-users-from-csv-with-meta' ), 'selected' => $settings->get( 'role' ), )); ?>
textarea( array( 'name' => 'columns', 'value' => $settings->get( 'columns' ) ) ); ?> : user_email,first_name,last_name
select( array( 'options' => ACUI_Helper::get_csv_delimiters_titles(), 'name' => 'delimiter', 'show_option_all' => false, 'show_option_none' => false, 'selected' => $settings->get( 'delimiter' ) )); ?>
checkbox( array( 'name' => 'convert_timestamp', 'current' => 'yes', 'compare_value' => $settings->get( 'convert_timestamp' ) ) ); ?> text( array( 'name' => 'datetime_format', 'value' => 'Y-m-d H:i:s', 'class' => '', 'value' => $settings->get( 'datetime_format' ) ) ); ?>
checkbox( array( 'name' => 'order_fields_alphabetically', 'current' => 'yes', 'compare_value' => $settings->get( 'order_fields_alphabetically' ) ) ); ?>
checkbox( array( 'name' => 'double_encapsulate_serialized_values', 'current' => 'yes', 'compare_value' => $settings->get( 'double_encapsulate_serialized_values' ) ) ); ?>
checkbox( array( 'name' => 'display_arrays_as_comma_separated_list_of_values', 'current' => 'yes', 'compare_value' => $settings->get( 'display_arrays_as_comma_separated_list_of_values' ) ) ); ?>
0%
set_filename( wp_unslash( $_GET['filename'] ) ); } $exporter->export(); } } function get_results(){ $bad_character_formulas_values_cleaned = get_transient( 'acui_export_bad_character_formulas_values_cleaned' ); delete_transient( 'acui_export_bad_character_formulas_values_cleaned' ); if( empty( $bad_character_formulas_values_cleaned ) ){ return ''; } $results = array(); foreach( $bad_character_formulas_values_cleaned as $info ){ $results[] = sprintf( __( 'User with id: %s has the cell of the column: %s edited because has content that may auto-run formulas in certain spreadsheet apps, new value is: %s', 'import-users-from-csv-with-meta' ), $info['user_id'], $info['key'], $info['value'] ); } $ret = '

' . __( 'Export results','import-users-from-csv-with-meta' ) . '

'; $ret .= '

' . __( 'Some values has been altered','import-users-from-csv-with-meta' ) . '

'; $ret .= ''; return $ret; } function export_users_csv(){ check_ajax_referer( 'codection-security', 'security' ); if( !current_user_can( apply_filters( 'acui_capability', 'create_users' ) ) ) wp_die( __( 'Only users who are able to create users can export them.', 'import-users-from-csv-with-meta' ) ); $step = isset( $_POST['step'] ) ? absint( $_POST['step'] ) : 1; $exporter = new ACUI_Batch_Exporter(); if( $step == 1 ){ delete_transient( 'acui_export_bad_character_formulas_values_cleaned' ); $this->save_settings(); } $exporter->set_page( $step ); $exporter->set_delimiter( sanitize_text_field( $_POST['delimiter'] ) ); $exporter->set_role( sanitize_text_field( $_POST['role'] ) ); $exporter->set_from( sanitize_text_field( $_POST['from'] ) ); $exporter->set_to( sanitize_text_field( $_POST['to'] ) ); $exporter->set_convert_timestamp( $_POST['convert_timestamp'] ); $exporter->set_datetime_format( sanitize_text_field( $_POST['datetime_format'] ) ); $exporter->set_order_fields_alphabetically( $_POST['order_fields_alphabetically'] ); $exporter->set_double_encapsulate_serialized_values( $_POST['double_encapsulate_serialized_values'] ); $exporter->set_display_arrays_as_comma_separated_list_of_values( $_POST['display_arrays_as_comma_separated_list_of_values'] ); $exporter->set_filtered_columns( ( isset( $_POST['columns'] ) && !empty( $_POST['columns'] ) ) ? $_POST['columns'] : array() ); $exporter->set_orderby( ( isset( $_POST['orderby'] ) && !empty( $_POST['orderby'] ) ) ? sanitize_text_field( $_POST['orderby'] ) : '' ); $exporter->set_order( ( isset( $_POST['order'] ) && !empty( $_POST['order'] ) ) ? sanitize_text_field( $_POST['order'] ) : 'ASC' ); $exporter->load_columns(); $exporter->generate_file(); if ( 100 <= $exporter->get_percent_complete() ) { $query_args = array( 'nonce' => wp_create_nonce( 'codection-security' ), 'action' => 'download_user_csv', 'filename' => $exporter->get_filename() ); wp_send_json_success( array( 'step' => 'done', 'percentage' => 100, 'url' => add_query_arg( $query_args, admin_url( 'tools.php?page=acui&tab=export' ) ), 'results' => $this->get_results() ) ); } else { wp_send_json_success( array( 'step' => ++$step, 'total_steps' => $exporter->get_total_steps(), 'percentage' => $exporter->get_percent_complete(), ) ); } } function ajax_save_settings(){ check_ajax_referer( 'codection-security', 'security' ); if( !current_user_can( apply_filters( 'acui_capability', 'create_users' ) ) ) wp_die( __( 'Only users who are able to create users can save settings about exporting them.', 'import-users-from-csv-with-meta' ) ); $this->save_settings(); wp_send_json_success( array( 'message' => __( 'Settings saved', 'import-users-from-csv-with-meta' ), ) ); } function save_settings(){ $settings = array(); isset( $_POST['settings'] ) ? parse_str( $_POST['settings'], $settings) : parse_str( $_POST['form'], $settings); ACUISettings()->save_multiple( 'export_backend', $settings ); } } $acui_exporter = new ACUI_Exporter();