Skip to content

Commit 5fc21c4

Browse files
committed
Fix localization, variable rennaming, use builtin function for send mail
1 parent 2579375 commit 5fc21c4

File tree

1 file changed

+25
-17
lines changed

1 file changed

+25
-17
lines changed

classes/admin/class-import.php

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public function __construct() {
99
}
1010

1111
public static function admin_menu() {
12-
$hook = add_submenu_page('edit.php?post_type=member', 'Import / Export members', 'Import / Export members', 'manage_options', 'member-import-export', array( __CLASS__, 'page' ));
12+
$hook = add_submenu_page('edit.php?post_type=member', __('Import / Export members', 'mpt'), __('Import / Export members', 'mpt'), 'manage_options', 'member-import-export', array( __CLASS__, 'page' ));
1313
add_action( 'admin_head-'.$hook, array( __CLASS__ , 'admin_head' ) );
1414
}
1515

@@ -40,13 +40,18 @@ public static function admin_init_import() {
4040
return false;
4141
}
4242

43+
// Setup new report
4344
self::$_rapport_arr = array(
4445
'report_date' => time(),
4546
'ignore_line' => array(),
4647
'import_status' => array(),
4748
);
48-
$csv = self::load_csv( $_FILES['csv-file']['tmp_name'], true );
49-
self::insert_members( $csv );
49+
50+
// Load CSV
51+
$rows = self::load_csv( $_FILES['csv-file']['tmp_name'], true );
52+
53+
// Insert members from CSV data
54+
self::insert_members( $rows );
5055

5156
// Save last report
5257
return update_option( self::option_name, self::$_rapport_arr );
@@ -61,7 +66,7 @@ public static function admin_init_import() {
6166
* @return array an array containing all the line.
6267
*/
6368
private static function load_csv( $file, $has_header = false ) {
64-
$csv = array();
69+
$rows = array();
6570
$headers = array();
6671
$current_line = 1; // use to track current line of the CSV file in case of error
6772

@@ -87,33 +92,32 @@ private static function load_csv( $file, $has_header = false ) {
8792
}
8893

8994
$csv_line = array();
90-
9195
foreach( $headers as $header_name => $col_index ) {
9296
$csv_line[ $header_name ] = utf8_encode( $tmp[ $col_index ] );
9397
}
9498

95-
$csv[] = $csv_line;
99+
$rows[] = $csv_line;
96100

97101
$current_line++;
98102
}
99103
fclose($handle);
100104

101-
return $csv;
105+
return $rows;
102106
}
103107

104108
/**
105109
* Insert/update the members.
106110
*
107-
* @param array $csv an array containing the CSV line.
111+
* @param array $rows an array containing the CSV line.
108112
*
109113
* @return array
110114
*/
111-
public static function insert_members( $csv ) {
112-
if( empty( $csv ) ) {
115+
public static function insert_members( $rows ) {
116+
if( empty( $rows ) ) {
113117
return false;
114118
}
115119

116-
foreach( $csv as $member ) {
120+
foreach( $rows as $member ) {
117121

118122
$tmp_member = new MPT_Member();
119123
$tmp_member->fill_by('email', $member['email']);
@@ -123,6 +127,7 @@ public static function insert_members( $csv ) {
123127
if( 'email' == $meta_name || 'password' == $meta_name ) {
124128
continue;
125129
}
130+
126131
$tmp_member->set_meta_value( $meta_name, $meta_value );
127132
}
128133

@@ -155,14 +160,17 @@ public static function insert_members( $csv ) {
155160
$tmp_member->set_meta_value( $meta_name, $meta_value );
156161
}
157162
}
163+
164+
//Send member notification
165+
$tmp_member->register_notification( $args['password'] );
158166

159167
// Send a mail to the new registered user.
160-
$message = sprintf(__('Account creation for [%s] :', 'mpt'), get_bloginfo( 'name' )) . "\r\n";
161-
$message .= sprintf(__('Name: %s %s', 'mpt'), $args['last_name'], $args['first_name']) . "\r\n";
162-
$message .= sprintf(__('Username: %s', 'mpt'), $args['username']) . "\r\n";
163-
$message .= sprintf(__('Password: %s', 'mpt'), $args['password']) . "\r\n";
164-
$message .= mpt_get_login_permalink() . "\r\n";
165-
@wp_mail($args['email'], sprintf(__('[%s] Your username and password', 'mpt'), get_bloginfo( 'name' )), $message);
168+
//$message = sprintf(__('Account creation for [%s] :', 'mpt'), get_bloginfo( 'name' )) . "\r\n";
169+
//$message .= sprintf(__('Name: %s %s', 'mpt'), $args['last_name'], $args['first_name']) . "\r\n";
170+
//$message .= sprintf(__('Username: %s', 'mpt'), $args['username']) . "\r\n";
171+
//$message .= sprintf(__('Password: %s', 'mpt'), $args['password']) . "\r\n";
172+
//$message .= mpt_get_login_permalink() . "\r\n";
173+
//@wp_mail($args['email'], sprintf(__('[%s] Your username and password', 'mpt'), get_bloginfo( 'name' )), $message);
166174

167175
self::$_rapport_arr['import_status'][] = array( 'member' => $member['email'], 'operation' => 'created', 'status' => 'success' );
168176
} else {

0 commit comments

Comments
 (0)