get_seconds_by_period( $period ), 'acui_cron_process' ); } else{ update_option( "acui_cron_activated", false ); as_unschedule_all_actions( 'acui_cron_process'); } update_option( "acui_cron_send_mail", isset( $form_data["send-mail-cron"] ) && $form_data["send-mail-cron"] == "1" ); update_option( "acui_cron_send_mail_updated", isset( $form_data["send-mail-updated"] ) && $form_data["send-mail-updated"] == "1" ); update_option( "acui_cron_delete_users", isset( $form_data["cron-delete-users"] ) && $form_data["cron-delete-users"] == "1" ); if( isset( $form_data["cron-delete-users-assign-posts"] ) ) update_option( "acui_cron_delete_users_assign_posts", sanitize_text_field( $form_data["cron-delete-users-assign-posts"] ) ); update_option( "acui_move_file_cron", isset( $form_data["move-file-cron"] ) && $form_data["move-file-cron"] == "1" ); update_option( "acui_cron_path_to_move_auto_rename", isset( $form_data["path_to_move_auto_rename"] ) && $form_data["path_to_move_auto_rename"] == "1" ); update_option( "acui_cron_allow_multiple_accounts", ( isset( $form_data["allow_multiple_accounts"] ) && $form_data["allow_multiple_accounts"] == "1" ) ? "allowed" : "not_allowed" ); $submitted_user_id = isset( $form_data['cron_user_id'] ) ? absint( $form_data['cron_user_id'] ) : 0; if( $submitted_user_id && user_can( $submitted_user_id, apply_filters( 'acui_capability', 'create_users' ) ) ) update_option( "acui_cron_user_id", $submitted_user_id ); update_option( "acui_cron_path_to_file", $this->clean_path_url_csv( sanitize_text_field( $form_data["path_to_file"] ) ) ); update_option( "acui_cron_path_to_move", $this->clean_path_url_csv( sanitize_text_field( $form_data["path_to_move"] ) ) ); update_option( "acui_cron_period", sanitize_text_field( $form_data["period"] ) ); update_option( "acui_cron_role", sanitize_text_field( $form_data["role"] ) ); update_option( "acui_cron_update_roles_existing_users", isset( $form_data["update-roles-existing-users"] ) && $form_data["update-roles-existing-users"] == "1" ); update_option( "acui_cron_change_role_not_present", isset( $form_data["cron-change-role-not-present"] ) && $form_data["cron-change-role-not-present"] == "1" ); if( isset( $form_data["cron-change-role-not-present-role"] ) ) update_option( "acui_cron_change_role_not_present_role", sanitize_text_field( $form_data["cron-change-role-not-present-role"] ) ); ?>

'administrator', 'number' => 1, 'fields' => 'ID' ) ); $cron_user_id = !empty( $admins ) ? $admins[0] : 0; } if( $cron_user_id && !is_user_logged_in() ) wp_set_current_user( $cron_user_id ); } function process(){ $session_id = sanitize_key( uniqid( 'c' ) ); $message = __('Import cron task - Step #1 - starts at', 'import-users-from-csv-with-meta' ) . ' ' . current_time('mysql') . '
'; $this->set_cron_user(); $form_data = array(); $form_data[ "acui_session_id" ] = $session_id; $form_data[ "path_to_file" ] = $this->clean_path_url_csv( get_option( "acui_cron_path_to_file") ); $form_data[ "role" ] = get_option( "acui_cron_role" ); $form_data[ "update_roles_existing_users" ] = ( get_option( "acui_cron_update_roles_existing_users" ) ) ? 'yes' : 'no'; $form_data[ "update_emails_existing_users" ] = "no"; $form_data[ "empty_cell_action" ] = "leave"; $form_data[ "security" ] = wp_create_nonce( "codection-security" ); ob_start(); $acui_import = new ACUI_Import(); $result = $acui_import->fileupload_process_batch_cron( $form_data ); $message .= "
" . ob_get_contents() . "
"; ob_end_clean(); $move_file_cron = get_option( "acui_move_file_cron"); if( $move_file_cron && ( empty( $result ) || !empty( $result['done'] ) ) ){ $path_to_move = $this->clean_path_url_csv( get_option( "acui_cron_path_to_move") ); rename( $form_data[ "path_to_file" ], $path_to_move ); $this->auto_rename(); } $message .= __( '--Finished at', 'import-users-from-csv-with-meta' ) . ' ' . current_time('mysql') . '

'; update_option( "acui_cron_log", $message ); if( !empty( $result['done'] ) ){ $this->save_execution_log( $result, 1 ); } } function process_step( $step, $initial_row, $session_id = '' ){ $message = __('Import cron task - Step #' . $step . ' - starts at', 'import-users-from-csv-with-meta' ) . ' ' . current_time('mysql') . '
'; $this->set_cron_user(); $form_data = array(); $form_data[ "acui_session_id" ] = $session_id; $form_data[ "path_to_file" ] = $this->clean_path_url_csv( get_option( "acui_cron_path_to_file") ); $form_data[ "role" ] = get_option( "acui_cron_role"); $form_data[ "update_roles_existing_users" ] = ( get_option( "acui_cron_update_roles_existing_users" ) ) ? 'yes' : 'no'; $form_data[ "update_emails_existing_users" ] = "no"; $form_data[ "empty_cell_action" ] = "leave"; $form_data[ "security" ] = wp_create_nonce( "codection-security" ); ob_start(); $acui_import = new ACUI_Import(); $result = $acui_import->fileupload_process_batch_cron( $form_data, $step, $initial_row ); $message .= "
" . ob_get_contents() . "
"; ob_end_clean(); if( get_option( "acui_move_file_cron") && ( empty( $result ) || !empty( $result['done'] ) ) ){ $path_to_move = $this->clean_path_url_csv( get_option( "acui_cron_path_to_move") ); rename( $form_data[ "path_to_file" ], $path_to_move ); $this->auto_rename(); } $message .= __( '--Finished at', 'import-users-from-csv-with-meta' ) . ' ' . current_time('mysql') . '

'; update_option( "acui_cron_log", get_option( "acui_cron_log" ) . $message ); if( !empty( $result['done'] ) ){ $this->save_execution_log( $result, $step ); } } function save_execution_log( $result, $steps ){ $entry = array( 'date' => current_time( 'mysql' ), 'created' => isset( $result['results']['created'] ) ? intval( $result['results']['created'] ) : 0, 'updated' => isset( $result['results']['updated'] ) ? intval( $result['results']['updated'] ) : 0, 'deleted' => isset( $result['results']['deleted'] ) ? intval( $result['results']['deleted'] ) : 0, 'ignored' => isset( $result['results']['ignored'] ) ? intval( $result['results']['ignored'] ) : 0, 'errors' => isset( $result['errors_count'] ) ? intval( $result['errors_count'] ) : 0, 'file' => basename( get_option( 'acui_cron_path_to_file' ) ), 'steps' => intval( $steps ), ); $log = get_option( 'acui_cron_execution_log', array() ); if( !is_array( $log ) ) $log = array(); array_unshift( $log, $entry ); if( count( $log ) > 100 ) $log = array_slice( $log, 0, 100 ); update_option( 'acui_cron_execution_log', $log, false ); } function auto_rename(){ if( get_option( "acui_cron_path_to_move_auto_rename" ) != true ) return; $movefile = get_option( "acui_cron_path_to_move"); if ( $movefile && file_exists( $movefile ) ) { $parts = pathinfo( $movefile ); $filename = $parts['filename']; if ( $filename ){ $date = date( 'YmdHis' ); $newfile = $parts['dirname'] . '/' . $filename .'_' . $date . '.' . $parts['extension']; rename( $movefile , $newfile ); } } } function handle_log_action( $form_data ){ if( isset( $form_data['acui_clear_execution_log'] ) ){ delete_option( 'acui_cron_execution_log' ); } } static function get_health_status() { if( !function_exists( 'as_next_scheduled_action' ) ) include_once( plugin_dir_path( dirname( __FILE__ ) ) . "lib/action-scheduler/action-scheduler.php" ); $next_timestamp = as_next_scheduled_action( 'acui_cron_process' ); $is_registered = $next_timestamp !== false && $next_timestamp !== null; $is_activated = (bool) get_option( 'acui_cron_activated' ); $next_run_human = ''; $next_run_date = ''; if ( $is_registered && $next_timestamp > 0 ) { $next_run_date = get_date_from_gmt( date( 'Y-m-d H:i:s', $next_timestamp ), get_option( 'date_format' ) . ' ' . get_option( 'time_format' ) ); $diff = $next_timestamp - time(); if ( $diff > 0 ) { $next_run_human = human_time_diff( time(), $next_timestamp ); } } $period = get_option( 'acui_cron_period', 'hourly' ); $loaded_periods = wp_get_schedules(); $period_label = isset( $loaded_periods[ $period ]['display'] ) ? $loaded_periods[ $period ]['display'] : $period; $period_seconds = isset( $loaded_periods[ $period ]['interval'] ) ? (int) $loaded_periods[ $period ]['interval'] : 0; $period_human = $period_seconds > 0 ? human_time_diff( 0, $period_seconds ) : ''; $log = get_option( 'acui_cron_execution_log', array() ); $last_run = ( is_array( $log ) && !empty( $log ) ) ? $log[0] : null; $cron_user_id = absint( get_option( 'acui_cron_user_id' ) ); $cron_user_data = $cron_user_id ? get_userdata( $cron_user_id ) : false; $cron_user_label = $cron_user_data ? $cron_user_data->user_login . ' (#' . $cron_user_id . ')' : ''; $is_running = false; if ( function_exists( 'as_get_scheduled_actions' ) ) { $running_main = as_get_scheduled_actions( array( 'hook' => 'acui_cron_process', 'status' => 'in-progress', 'limit' => 1 ) ); $running_steps = as_get_scheduled_actions( array( 'hook' => 'acui_cron_process_step', 'status' => 'in-progress', 'limit' => 1 ) ); $is_running = ! empty( $running_main ) || ! empty( $running_steps ); } return compact( 'is_activated', 'is_registered', 'next_run_date', 'next_run_human', 'period', 'period_label', 'period_human', 'last_run', 'cron_user_label', 'is_running' ); } static function admin_gui(){ $upload_dir = wp_upload_dir(); $sample_path = $upload_dir["path"] . '/test.csv'; $sample_url = plugin_dir_url( dirname( __FILE__ ) ) . 'test.csv'; $cron_activated = get_option( "acui_cron_activated"); $send_mail_cron = get_option( "acui_cron_send_mail"); $send_mail_updated = get_option( "acui_cron_send_mail_updated"); $cron_delete_users = get_option( "acui_cron_delete_users"); $cron_delete_users_assign_posts = get_option( "acui_cron_delete_users_assign_posts"); $cron_change_role_not_present = get_option( "acui_cron_change_role_not_present" ); $cron_change_role_not_present_role = get_option( "acui_cron_change_role_not_present_role" ); $path_to_file = get_option( "acui_cron_path_to_file"); $period = get_option( "acui_cron_period"); $role = get_option( "acui_cron_role"); $update_roles_existing_users = get_option( "acui_cron_update_roles_existing_users"); $move_file_cron = get_option( "acui_move_file_cron"); $path_to_move = get_option( "acui_cron_path_to_move"); $path_to_move_auto_rename = get_option( "acui_cron_path_to_move_auto_rename"); $log = get_option( "acui_cron_log"); $allow_multiple_accounts = get_option("acui_cron_allow_multiple_accounts"); $rest_api_execute_cron_url = home_url() . '/wp-json/import-users-from-csv-with-meta/v1/execute-cron/'; if( empty( $cron_activated ) ) $cron_activated = false; if( empty( $send_mail_cron ) ) $send_mail_cron = false; if( empty( $send_mail_updated ) ) $send_mail_updated = false; if( empty( $cron_delete_users ) ) $cron_delete_users = false; if( empty( $update_roles_existing_users) ) $update_roles_existing_users = false; if( empty( $cron_delete_users_assign_posts ) ) $cron_delete_users_assign_posts = ''; if( empty( $path_to_file ) ) $path_to_file = dirname( __FILE__ ) . '/test.csv'; if( empty( $period ) ) $period = 'hourly'; if( empty( $move_file_cron ) ) $move_file_cron = false; if( empty( $path_to_move ) ) $path_to_move = dirname( __FILE__ ) . '/move.csv'; if( empty( $path_to_move_auto_rename ) ) $path_to_move_auto_rename = false; if( empty( $log ) ) $log = "No tasks done yet."; if( empty( $allow_multiple_accounts ) ) $allow_multiple_accounts = "not_allowed"; $health = self::get_health_status(); ?>

Recurring Import Addon you can create unlimited tasks, each with its own file, period, role and notification email.', 'import-users-from-csv-with-meta' ); ?>

checkbox( array( 'name' => 'cron-activated', 'compare_value' => $cron_activated ) ); ?>
apply_filters( 'acui_capability', 'create_users' ), 'fields' => array( 'ID', 'user_login', 'display_name' ), 'orderby' => 'display_name', ) ); $cron_user_id_saved = absint( get_option( 'acui_cron_user_id' ) ); ?>

text( array( 'name' => 'path_to_file', 'value' => $path_to_file, 'class' => '', 'placeholder' => __( 'Insert complete path to the file', 'import-users-from-csv-with-meta' ) ) ); ?>

select( array( 'options' => ACUI_Helper::get_loaded_periods(), 'name' => 'period', 'selected' => $period, 'show_option_all' => false, 'show_option_none' => false, )); ?>

checkbox( array( 'name' => 'send-mail-cron', 'compare_value' => $send_mail_cron ) ); ?>
checkbox( array( 'name' => 'send-mail-updated', 'compare_value' => $send_mail_updated ) ); ?>
select( array( 'options' => ACUI_Helper::get_editable_roles(), 'name' => 'role', 'selected' => $role, 'show_option_all' => false, 'show_option_none' => __( 'Disable role assignment in cron import', 'import-users-from-csv-with-meta' ), )); ?>

checkbox( array( 'name' => 'update-roles-existing-users', 'compare_value' => $update_roles_existing_users ) ); ?>
checkbox( array( 'name' => 'move-file-cron', 'compare_value' => $move_file_cron ) ); ?>
text( array( 'name' => 'path_to_move', 'value' => $path_to_move, 'class' => '', 'placeholder' => __( 'Insert complete path to the file', 'import-users-from-csv-with-meta' ) ) ); ?>

/move.csv

checkbox( array( 'name' => 'path_to_move_auto_rename', 'compare_value' => $path_to_move_auto_rename ) ); ?>

checkbox( array( 'name' => 'cron-delete-users', 'compare_value' => $cron_delete_users ) ); ?>
select( array( 'options' => ACUI_Helper::get_list_users_with_display_name(), 'name' => 'cron-delete-users-assign-posts', 'selected' => $cron_delete_users_assign_posts, 'show_option_all' => false, 'show_option_none' => __( 'Delete posts of deleted users without assigning to any user', 'import-users-from-csv-with-meta' ), )); ?>

checkbox( array( 'name' => 'cron-change-role-not-present', 'compare_value' => $cron_change_role_not_present ) ); ?>
select( array( 'options' => ACUI_Helper::get_editable_roles(), 'name' => 'cron-change-role-not-present-role', 'selected' => $cron_change_role_not_present_role, 'show_option_all' => false, 'show_option_none' => false, )); ?>

.

remove_specific_html_tags( $log, array( 'script', 'style' ) ); ?>



0 ): ?>