Import users from CSV with meta - Version 1.16.2

Version Description

  • Email sending function created
  • Test email button included
Download this release

Release Info

Developer carazo
Plugin Icon 128x128 Import users from CSV with meta
Version 1.16.2
Comparing to
See all releases

Code changes from version 1.16.1.5 to 1.16.2

assets/email-options.js ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ jQuery(document).ready(function($){
2
+ 'use strict';
3
+
4
+ $( '#acui_email_option_remove_upload_button' ).click( function(){
5
+ var data = {
6
+ 'action': 'acui_mail_options_remove_attachment',
7
+ 'security': email_options.nonce,
8
+ };
9
+
10
+ $.post( ajaxurl, data, function( response ) {
11
+ location.reload();
12
+ });
13
+ } );
14
+
15
+ $( '#acui_email_template_remove_upload_button' ).click( function(){
16
+ $( '#email_template_attachment_file' ).val( '' );
17
+ $( '#email_template_attachment_id' ).val( '' );
18
+ } );
19
+
20
+ $( '#send_test_email' ).click( function(){
21
+ var data = {
22
+ 'action': 'acui_send_test_email',
23
+ 'security': email_options.security,
24
+ };
25
+
26
+ $.post( ajaxurl, data, function( response ) {
27
+ alert( email_options.success_message );
28
+ });
29
+ })
30
+ });
assets/email-template-attachment-admin.js CHANGED
@@ -59,20 +59,4 @@
59
  $( '#save_mail_template_options' ).click();
60
  });
61
  } );
62
-
63
- $( '#acui_email_option_remove_upload_button' ).click( function(){
64
- var data = {
65
- 'action': 'acui_mail_options_remove_attachment',
66
- 'security': email_template_attachment_admin.nonce,
67
- };
68
-
69
- $.post( ajaxurl, data, function( response ) {
70
- location.reload();
71
- });
72
- } );
73
-
74
- $( '#acui_email_template_remove_upload_button' ).click( function(){
75
- $( '#email_template_attachment_file' ).val( '' );
76
- $( '#email_template_attachment_id' ).val( '' );
77
- } );
78
  });
59
  $( '#save_mail_template_options' ).click();
60
  });
61
  } );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
  });
classes/email-options.php CHANGED
@@ -1,11 +1,11 @@
1
  <?php
2
-
3
  if ( ! defined( 'ABSPATH' ) ) exit;
4
 
5
  class ACUI_Email_Options{
6
  function __construct(){
7
  add_action( 'admin_enqueue_scripts', array( $this, 'load_scripts' ), 10, 1 );
8
  add_action( 'wp_ajax_acui_mail_options_remove_attachment', array( $this, 'ajax_remove_attachment' ) );
 
9
  }
10
 
11
  public static function admin_gui(){
@@ -97,6 +97,7 @@ class ACUI_Email_Options{
97
 
98
  <br/>
99
  <input class="button-primary" type="submit" value="<?php _e( 'Save email template and options', 'import-users-from-csv-with-meta'); ?>" id="save_mail_template_options"/>
 
100
 
101
  <?php wp_nonce_field( 'codection-security', 'security' ); ?>
102
 
@@ -106,20 +107,93 @@ class ACUI_Email_Options{
106
  <?php
107
  }
108
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
  function load_scripts( $hook ) {
110
  global $typenow;
111
 
112
  if( $typenow == 'acui_email_template' || $hook == 'tools_page_acui' ) {
113
  wp_enqueue_media();
114
- wp_register_script( 'email-template-attachment-admin', esc_url( plugins_url( 'assets/email-template-attachment-admin.js', dirname( __FILE__ ) ) ), array( 'jquery' ) );
115
- wp_localize_script( 'email-template-attachment-admin', 'email_template_attachment_admin',
116
  array(
117
  'title' => __( 'Choose or upload file', 'import-users-from-csv-with-meta' ),
118
  'button' => __( 'Use this file', 'import-users-from-csv-with-meta' ),
119
  'security' => wp_create_nonce( "codection-security" )
120
  )
121
  );
122
- wp_enqueue_script( 'email-template-attachment-admin' );
 
 
 
 
 
 
 
 
 
 
 
123
  }
124
  }
125
 
@@ -127,6 +201,12 @@ class ACUI_Email_Options{
127
  check_ajax_referer( 'codection-security', 'security' );
128
  update_option( "acui_mail_attachment_id", "" );
129
  }
 
 
 
 
 
 
130
  }
131
 
132
  new ACUI_Email_Options();
1
  <?php
 
2
  if ( ! defined( 'ABSPATH' ) ) exit;
3
 
4
  class ACUI_Email_Options{
5
  function __construct(){
6
  add_action( 'admin_enqueue_scripts', array( $this, 'load_scripts' ), 10, 1 );
7
  add_action( 'wp_ajax_acui_mail_options_remove_attachment', array( $this, 'ajax_remove_attachment' ) );
8
+ add_action( 'wp_ajax_acui_send_test_email', array( $this, 'ajax_send_test_email' ) );
9
  }
10
 
11
  public static function admin_gui(){
97
 
98
  <br/>
99
  <input class="button-primary" type="submit" value="<?php _e( 'Save email template and options', 'import-users-from-csv-with-meta'); ?>" id="save_mail_template_options"/>
100
+ <input class="button-primary" type="button" value="<?php _e( 'Send test email', 'import-users-from-csv-with-meta'); ?>" id="send_test_email" title="<?php _e( 'This test email will be sent to the current user', 'import-users-from-csv-with-meta'); ?>"/>
101
 
102
  <?php wp_nonce_field( 'codection-security', 'security' ); ?>
103
 
107
  <?php
108
  }
109
 
110
+ public static function send_email( $user_object, $positions = array(), $headers = array(), $data = array(), $created = false, $password = '' ){
111
+ $key = get_password_reset_key( $user_object );
112
+ $wp_users_fields = acui_get_wp_users_fields();
113
+
114
+ $user_id = $user_object->ID;
115
+ $user_login= $user_object->user_login;
116
+ $user_email = $user_object->user_email;
117
+
118
+ $body = get_option( "acui_mail_body" );
119
+ $subject = get_option( "acui_mail_subject" );
120
+
121
+ $body = str_replace( "**loginurl**", wp_login_url(), $body );
122
+ $body = str_replace( "**username**", $user_login, $body );
123
+ $body = str_replace( "**lostpasswordurl**", wp_lostpassword_url(), $body );
124
+ $subject = str_replace( "**username**", $user_login, $subject );
125
+
126
+ if( !is_wp_error( $key ) ){
127
+ $passwordreseturl = apply_filters( 'acui_email_passwordreseturl', network_site_url( 'wp-login.php?action=rp&key=' . $key . '&login=' . rawurlencode( $user_login ), 'login' ) );
128
+ $body = str_replace( "**passwordreseturl**", $passwordreseturl, $body );
129
+
130
+ $passwordreseturllink = wp_sprintf( '<a href="%s">%s</a>', $passwordreseturl, __( 'Password reset link', 'import-users-from-csv-with-meta' ) );
131
+ $body = str_replace( "**passwordreseturllink**", $passwordreseturllink, $body );
132
+ }
133
+
134
+ if( empty( $password ) && !$created ){
135
+ $password = __( 'Password has not been changed', 'import-users-from-csv-with-meta' );
136
+ }
137
+
138
+ $body = str_replace( "**password**", $password, $body );
139
+ $body = str_replace( "**email**", $user_email, $body );
140
+
141
+ foreach ( $wp_users_fields as $wp_users_field ) {
142
+ if( $positions[ $wp_users_field ] != false && $wp_users_field != "password" ){
143
+ $body = str_replace( "**" . $wp_users_field . "**", $data[ $positions[ $wp_users_field ] ] , $body );
144
+ $subject = str_replace( "**" . $wp_users_field . "**", $data[ $positions[ $wp_users_field ] ] , $subject );
145
+ }
146
+ }
147
+
148
+ for( $i = 0 ; $i < count( $headers ); $i++ ) {
149
+ $data[ $i ] = ( is_array( $data[ $i ] ) ) ? implode( "-", $data[ $i ] ) : $data[ $i ];
150
+ $body = str_replace( "**" . $headers[ $i ] . "**", $data[ $i ] , $body );
151
+ $subject = str_replace( "**" . $headers[ $i ] . "**", $data[ $i ] , $subject );
152
+ }
153
+
154
+ $body = apply_filters( 'acui_import_email_body_before_wpautop', $body, $headers, $data, $created, $user_id );
155
+
156
+ $body = wpautop( $body );
157
+
158
+ $attachments = array();
159
+ $attachment_id = get_option( 'acui_mail_attachment_id' );
160
+ if( !empty( $attachment_id ) )
161
+ $attachments[] = get_attached_file( $attachment_id );
162
+
163
+ $email_to = apply_filters( 'acui_import_email_to', $user_email, $headers, $data, $created, $user_id );
164
+ $subject = apply_filters( 'acui_import_email_subject', $subject, $headers, $data, $created, $user_id );
165
+ $body = apply_filters( 'acui_import_email_body', $body, $headers, $data, $created, $user_id );
166
+ $headers_mail = apply_filters( 'acui_import_email_headers', array( 'Content-Type: text/html; charset=UTF-8' ), $headers, $data, $created, $user_id );
167
+ $attachments = apply_filters( 'acui_import_email_attachments', $attachments, $headers, $data, $created, $user_id );
168
+
169
+ wp_mail( $email_to, $subject, $body, $headers_mail, $attachments );
170
+ }
171
+
172
  function load_scripts( $hook ) {
173
  global $typenow;
174
 
175
  if( $typenow == 'acui_email_template' || $hook == 'tools_page_acui' ) {
176
  wp_enqueue_media();
177
+ wp_register_script( 'acui-email-template-attachment-admin', esc_url( plugins_url( 'assets/email-template-attachment-admin.js', dirname( __FILE__ ) ) ), array( 'jquery' ) );
178
+ wp_localize_script( 'acui-email-template-attachment-admin', 'email_template_attachment_admin',
179
  array(
180
  'title' => __( 'Choose or upload file', 'import-users-from-csv-with-meta' ),
181
  'button' => __( 'Use this file', 'import-users-from-csv-with-meta' ),
182
  'security' => wp_create_nonce( "codection-security" )
183
  )
184
  );
185
+ wp_enqueue_script( 'acui-email-template-attachment-admin' );
186
+ }
187
+
188
+ if( $hook == 'tools_page_acui' ){
189
+ wp_register_script( 'acui-email-options', esc_url( plugins_url( 'assets/email-options.js', dirname( __FILE__ ) ) ), array( 'jquery' ) );
190
+ wp_localize_script( 'acui-email-options', 'email_options',
191
+ array(
192
+ 'security' => wp_create_nonce( "codection-security" ),
193
+ 'success_message' => __( 'Test email sent', 'import-users-from-csv-with-meta' ),
194
+ )
195
+ );
196
+ wp_enqueue_script( 'acui-email-options' );
197
  }
198
  }
199
 
201
  check_ajax_referer( 'codection-security', 'security' );
202
  update_option( "acui_mail_attachment_id", "" );
203
  }
204
+
205
+ function ajax_send_test_email(){
206
+ check_ajax_referer( 'codection-security', 'security' );
207
+
208
+ self::send_email( wp_get_current_user() );
209
+ }
210
  }
211
 
212
  new ACUI_Email_Options();
import-users-from-csv-with-meta.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Import and export users and customers
4
  Plugin URI: https://www.codection.com
5
  Description: Using this plugin you will be able to import and export users or customers choosing many options and interacting with lots of other plugins
6
- Version: 1.16.1.5
7
  Author: codection
8
  Author URI: https://codection.com
9
  License: GPL2
3
  Plugin Name: Import and export users and customers
4
  Plugin URI: https://www.codection.com
5
  Description: Using this plugin you will be able to import and export users or customers choosing many options and interacting with lots of other plugins
6
+ Version: 1.16.2
7
  Author: codection
8
  Author URI: https://codection.com
9
  License: GPL2
importer.php CHANGED
@@ -606,63 +606,9 @@ function acui_import_users( $file, $form_data, $attach_id = 0, $is_cron = false,
606
  }
607
 
608
  // send mail
609
- if( isset( $mail_for_this_user ) && $mail_for_this_user ):
610
- $key = get_password_reset_key( $user_object );
611
- $user_login= $user_object->user_login;
612
-
613
- $body = get_option( "acui_mail_body" );
614
- $subject = get_option( "acui_mail_subject" );
615
-
616
- $body = str_replace( "**loginurl**", wp_login_url(), $body );
617
- $body = str_replace( "**username**", $user_login, $body );
618
- $body = str_replace( "**lostpasswordurl**", wp_lostpassword_url(), $body );
619
- $subject = str_replace( "**username**", $user_login, $subject );
620
-
621
- if( !is_wp_error( $key ) ){
622
- $passwordreseturl = apply_filters( 'acui_email_passwordreseturl', network_site_url( 'wp-login.php?action=rp&key=' . $key . '&login=' . rawurlencode( $user_login ), 'login' ) );
623
- $body = str_replace( "**passwordreseturl**", $passwordreseturl, $body );
624
-
625
- $passwordreseturllink = wp_sprintf( '<a href="%s">%s</a>', $passwordreseturl, __( 'Password reset link', 'import-users-from-csv-with-meta' ) );
626
- $body = str_replace( "**passwordreseturllink**", $passwordreseturllink, $body );
627
- }
628
-
629
- if( empty( $password ) && !$created ){
630
- $password = __( 'Password has not been changed', 'import-users-from-csv-with-meta' );
631
- }
632
-
633
- $body = str_replace( "**password**", $password, $body );
634
- $body = str_replace( "**email**", $email, $body );
635
-
636
- foreach ( $wp_users_fields as $wp_users_field ) {
637
- if( $positions[ $wp_users_field ] != false && $wp_users_field != "password" ){
638
- $body = str_replace( "**" . $wp_users_field . "**", $data[ $positions[ $wp_users_field ] ] , $body );
639
- $subject = str_replace( "**" . $wp_users_field . "**", $data[ $positions[ $wp_users_field ] ] , $subject );
640
- }
641
- }
642
-
643
- for( $i = 0 ; $i < count( $headers ); $i++ ) {
644
- $data[ $i ] = ( is_array( $data[ $i ] ) ) ? implode( "-", $data[ $i ] ) : $data[ $i ];
645
- $body = str_replace( "**" . $headers[ $i ] . "**", $data[ $i ] , $body );
646
- $subject = str_replace( "**" . $headers[ $i ] . "**", $data[ $i ] , $subject );
647
- }
648
-
649
- $body = apply_filters( 'acui_import_email_body_before_wpautop', $body, $headers, $data, $created, $user_id );
650
-
651
- $body = wpautop( $body );
652
-
653
- $attachments = array();
654
- $attachment_id = get_option( 'acui_mail_attachment_id' );
655
- if( !empty( $attachment_id ) )
656
- $attachments[] = get_attached_file( $attachment_id );
657
-
658
- $email_to = apply_filters( 'acui_import_email_to', $email, $headers, $data, $created, $user_id );
659
- $subject = apply_filters( 'acui_import_email_subject', $subject, $headers, $data, $created, $user_id );
660
- $body = apply_filters( 'acui_import_email_body', $body, $headers, $data, $created, $user_id );
661
- $headers_mail = apply_filters( 'acui_import_email_headers', array( 'Content-Type: text/html; charset=UTF-8' ), $headers, $data, $created, $user_id );
662
- $attachments = apply_filters( 'acui_import_email_attachments', $attachments, $headers, $data, $created, $user_id );
663
-
664
- wp_mail( $email_to, $subject, $body, $headers_mail, $attachments );
665
- endif;
666
 
667
  endif;
668
 
606
  }
607
 
608
  // send mail
609
+ if( isset( $mail_for_this_user ) && $mail_for_this_user ){
610
+ ACUI_Email_Options::send_email( $user_object, $positions, $headers, $data, $created, $password );
611
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
612
 
613
  endif;
614
 
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://codection.com/go/donate-import-users-from-csv-with-meta/
4
  Tags: csv, import, importer, meta data, meta, user, users, user meta, editor, profile, custom, fields, delimiter, update, insert
5
  Requires at least: 3.4
6
  Tested up to: 5.5.1
7
- Stable tag: 1.16.1.5
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -99,6 +99,10 @@ Plugin will automatically detect:
99
 
100
  == Changelog ==
101
 
 
 
 
 
102
  = 1.16.1.5 =
103
  * Fixed problem importing ACF textarea and other type fields
104
 
4
  Tags: csv, import, importer, meta data, meta, user, users, user meta, editor, profile, custom, fields, delimiter, update, insert
5
  Requires at least: 3.4
6
  Tested up to: 5.5.1
7
+ Stable tag: 1.16.2
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
99
 
100
  == Changelog ==
101
 
102
+ = 1.16.2 =
103
+ * Email sending function created
104
+ * Test email button included
105
+
106
  = 1.16.1.5 =
107
  * Fixed problem importing ACF textarea and other type fields
108