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" ); 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"] ) ); ?>

'; $form_data = array(); $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[ "empty_cell_action" ] = "leave"; $form_data[ "allow_update_emails" ] = "disallow"; $form_data[ "security" ] = wp_create_nonce( "codection-security" ); ob_start(); $acui_import = new ACUI_Import(); $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 ){ $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' ) . ' ' . date("Y-m-d H:i:s") . '

'; update_option( "acui_cron_log", $message ); } function process_step( $step, $initial_row ){ $message = __('Import cron task - Step #' . $step . ' - starts at', 'import-users-from-csv-with-meta' ) . ' ' . date("Y-m-d H:i:s") . '
'; $form_data = array(); $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[ "empty_cell_action" ] = "leave"; $form_data[ "allow_update_emails" ] = "disallow"; $form_data[ "security" ] = wp_create_nonce( "codection-security" ); ob_start(); $acui_import = new ACUI_Import(); $acui_import->fileupload_process_batch_cron( $form_data, $step, $initial_row ); $message .= "
" . ob_get_contents() . "
"; ob_end_clean(); $message .= __( '--Finished at', 'import-users-from-csv-with-meta' ) . ' ' . date("Y-m-d H:i:s") . '

'; update_option( "acui_cron_log", get_option( "acui_cron_log" ) . $message ); } 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 ); } } } 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"; ?>

checkbox( array( 'name' => 'cron-activated', 'compare_value' => $cron_activated ) ); ?>
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, )); ?>

.