| @@ -11,8 +11,32 @@ | ||
| 11 | 11 | { |
| 12 | 12 | protected $name = 'User'; |
| 13 | 13 | protected $mapper = 'user'; |
| 14 | 14 | |
| 15 | + protected $field_map = [ | |
| 16 | + 'ID' => 'user.ID', | |
| 17 | + 'user_login' => 'user.user_login', | |
| 18 | + 'user_email' => 'user.user_email', | |
| 19 | + 'first_name' => 'user.first_name', | |
| 20 | + 'last_name' => 'user.last_name', | |
| 21 | + 'role' => 'user.role', | |
| 22 | + 'user_url' => 'user.user_url', | |
| 23 | + 'user_pass' => 'user.user_pass', | |
| 24 | + 'user_nicename' => 'user.user_nicename', | |
| 25 | + 'display_name' => 'user.display_name', | |
| 26 | + 'description' => 'user.description', | |
| 27 | + ]; | |
| 28 | + | |
| 29 | + protected $optional_fields = [ | |
| 30 | + 'ID', | |
| 31 | + 'user_url', | |
| 32 | + 'user_pass', | |
| 33 | + 'role', | |
| 34 | + 'user_nicename', | |
| 35 | + 'display_name', | |
| 36 | + 'description' | |
| 37 | + ]; | |
| 38 | + | |
| 15 | 39 | public function __construct(EventHandler $event_handler) |
| 16 | 40 | { |
| 17 | 41 | parent::__construct($event_handler); |
| 18 | 42 | |
| @@ -26,39 +50,39 @@ | ||
| 26 | 50 | { |
| 27 | 51 | $groups = []; |
| 28 | 52 | |
| 29 | 53 | // User |
| 30 | - $groups[] = $this->register_group('User Fields', 'user', [ | |
| 31 | - $this->register_field('ID', 'ID', [ | |
| 32 | - 'tooltip' => __('ID is only used to reference existing records', 'importwp') | |
| 54 | + $groups[] = $this->register_group(__('User Fields', 'jc-importer'), 'user', [ | |
| 55 | + $this->register_field(__('ID', 'jc-importer'), 'ID', [ | |
| 56 | + 'tooltip' => __('ID is only used to reference existing records', 'jc-importer') | |
| 33 | 57 | ]), |
| 34 | - $this->register_core_field('Username', 'user_login', [ | |
| 35 | - 'tooltip' => __('The user\'s login username', 'importwp') | |
| 58 | + $this->register_core_field(__('Username', 'jc-importer'), 'user_login', [ | |
| 59 | + 'tooltip' => __('The user\'s login username', 'jc-importer') | |
| 36 | 60 | ]), |
| 37 | - $this->register_core_field('Email', 'user_email', [ | |
| 38 | - 'tooltip' => __('The user email address', 'importwp') | |
| 61 | + $this->register_core_field(__('Email', 'jc-importer'), 'user_email', [ | |
| 62 | + 'tooltip' => __('The user email address', 'jc-importer') | |
| 39 | 63 | ]), |
| 40 | - $this->register_core_field('First Name', 'first_name', [ | |
| 41 | - 'tooltip' => __('The user\'s first name', 'importwp') | |
| 64 | + $this->register_core_field(__('First Name', 'jc-importer'), 'first_name', [ | |
| 65 | + 'tooltip' => __('The user\'s first name', 'jc-importer') | |
| 42 | 66 | ]), |
| 43 | - $this->register_core_field('Last Name', 'last_name', [ | |
| 44 | - 'tooltip' => __('The user\'s last name', 'importwp') | |
| 67 | + $this->register_core_field(__('Last Name', 'jc-importer'), 'last_name', [ | |
| 68 | + 'tooltip' => __('The user\'s last name', 'jc-importer') | |
| 45 | 69 | ]), |
| 46 | - $this->register_field('Role', 'role', [ | |
| 47 | - 'tooltip' => __('The plain-text user password', 'importwp'), | |
| 70 | + $this->register_field(__('Role', 'jc-importer'), 'role', [ | |
| 71 | + 'tooltip' => __('The plain-text user password', 'jc-importer'), | |
| 48 | 72 | 'options' => 'callback', |
| 49 | 73 | 'default' => 'subscriber' |
| 50 | 74 | ]), |
| 51 | - $this->register_field('Website', 'user_url', [ | |
| 52 | - 'tooltip' => __('The user\'s website address', 'importwp') | |
| 75 | + $this->register_field(__('Website', 'jc-importer'), 'user_url', [ | |
| 76 | + 'tooltip' => __('The user\'s website address', 'jc-importer') | |
| 53 | 77 | ]), |
| 54 | - $this->register_field('Password', 'user_pass', [ | |
| 55 | - 'tooltip' => __('The plain-text user password', 'importwp') | |
| 78 | + $this->register_field(__('Password', 'jc-importer'), 'user_pass', [ | |
| 79 | + 'tooltip' => __('The plain-text user password', 'jc-importer') | |
| 56 | 80 | ]), |
| 57 | - $this->register_field('Nicename', 'user_nicename', []), | |
| 58 | - $this->register_field('Display Name', 'display_name', []), | |
| 59 | - $this->register_field('Description', 'description', []), | |
| 60 | - ]); | |
| 81 | + $this->register_field(__('Nicename', 'jc-importer'), 'user_nicename', []), | |
| 82 | + $this->register_field(__('Display Name', 'jc-importer'), 'display_name', []), | |
| 83 | + $this->register_field(__('Description', 'jc-importer'), 'description', []), | |
| 84 | + ], ['link' => 'https://www.importwp.com/docs/wordpress-user-importer-template/']); | |
| 61 | 85 | |
| 62 | 86 | return $groups; |
| 63 | 87 | } |
| 64 | 88 | |
| @@ -66,15 +90,15 @@ | ||
| 66 | 90 | |
| 67 | 91 | public function register_settings() |
| 68 | 92 | { |
| 69 | 93 | return [ |
| 70 | - $this->register_field('Enable user notifications.', 'notify_users', [ | |
| 94 | + $this->register_field(__('Enable user notifications.', 'jc-importer'), 'notify_users', [ | |
| 71 | 95 | 'type' => 'checkbox', |
| 72 | - 'tooltip' => __('Trigger the action to send WordPress notification emails', 'importwp') | |
| 96 | + 'tooltip' => __('Trigger the action to send WordPress notification emails', 'jc-importer') | |
| 73 | 97 | ]), |
| 74 | - $this->register_field('Generate user password.', 'generate_pass', [ | |
| 98 | + $this->register_field(__('Generate user password.', 'jc-importer'), 'generate_pass', [ | |
| 75 | 99 | 'type' => 'checkbox', |
| 76 | - 'tooltip' => __('Enable the generation of user passwords', 'importwp') | |
| 100 | + 'tooltip' => __('Enable the generation of user passwords', 'jc-importer') | |
| 77 | 101 | ]), |
| 78 | 102 | ]; |
| 79 | 103 | } |
| 80 | 104 | |
| @@ -123,19 +147,9 @@ | ||
| 123 | 147 | continue; |
| 124 | 148 | } |
| 125 | 149 | } |
| 126 | 150 | |
| 127 | - $optional_fields = [ | |
| 128 | - 'ID', | |
| 129 | - 'user_url', | |
| 130 | - 'user_pass', | |
| 131 | - 'role', | |
| 132 | - 'user_nicename', | |
| 133 | - 'display_name', | |
| 134 | - 'description' | |
| 135 | - ]; | |
| 136 | - | |
| 137 | - foreach ($optional_fields as $optional_field) { | |
| 151 | + foreach ($this->optional_fields as $optional_field) { | |
| 138 | 152 | if (true !== $this->importer->isEnabledField('user.' . $optional_field)) { |
| 139 | 153 | unset($user_field_map[$optional_field]); |
| 140 | 154 | } |
| 141 | 155 | } |
| @@ -204,6 +218,78 @@ | ||
| 204 | 218 | ]; |
| 205 | 219 | } |
| 206 | 220 | |
| 207 | 221 | return $result; |
| 222 | + } | |
| 223 | + | |
| 224 | + /** | |
| 225 | + * Convert fields/headings to data map | |
| 226 | + * | |
| 227 | + * @param mixed $fields | |
| 228 | + * @return array | |
| 229 | + */ | |
| 230 | + public function generate_field_map($fields, $importer) | |
| 231 | + { | |
| 232 | + $result = parent::generate_field_map($fields, $importer); | |
| 233 | + $map = $result['map']; | |
| 234 | + $enabled = $result['enabled']; | |
| 235 | + | |
| 236 | + foreach ($fields as $index => $field) { | |
| 237 | + if (isset($this->field_map[$field])) { | |
| 238 | + | |
| 239 | + // Handle core fields | |
| 240 | + $field_key = $this->field_map[$field]; | |
| 241 | + $map[$field_key] = sprintf('{%s}', $index); | |
| 242 | + | |
| 243 | + if (in_array($field, $this->optional_fields)) { | |
| 244 | + $enabled[] = $field_key; | |
| 245 | + } | |
| 246 | + | |
| 247 | + if (in_array($field, ['role'])) { | |
| 248 | + $map[$field_key . '._enable_text'] = 'yes'; | |
| 249 | + } | |
| 250 | + } | |
| 251 | + } | |
| 252 | + | |
| 253 | + return [ | |
| 254 | + 'map' => $map, | |
| 255 | + 'enabled' => $enabled | |
| 256 | + ]; | |
| 257 | + } | |
| 258 | + | |
| 259 | + public function get_permission_fields($importer_model) | |
| 260 | + { | |
| 261 | + $permission_fields = parent::get_permission_fields($importer_model); | |
| 262 | + | |
| 263 | + $permission_fields['core'] = [ | |
| 264 | + 'ID' => __('ID', 'jc-importer'), | |
| 265 | + 'user_pass' => __('Password', 'jc-importer'), | |
| 266 | + 'user_login' => __('Login', 'jc-importer'), | |
| 267 | + 'user_nicename' => __('Nice name', 'jc-importer'), | |
| 268 | + 'user_url' => __('Url', 'jc-importer'), | |
| 269 | + 'user_email' => __('Email', 'jc-importer'), | |
| 270 | + 'display_name' => __('Display Name', 'jc-importer'), | |
| 271 | + 'nickname' => __('Nick name', 'jc-importer'), | |
| 272 | + 'first_name' => __('First name', 'jc-importer'), | |
| 273 | + 'last_name' => __('Last name', 'jc-importer'), | |
| 274 | + 'description' => __('Description', 'jc-importer'), | |
| 275 | + 'rich_editing' => __('Rich Editing', 'jc-importer'), | |
| 276 | + 'user_registered' => __('User Registered', 'jc-importer'), | |
| 277 | + 'role' => __('Role', 'jc-importer'), | |
| 278 | + 'jabber' => __('Jabber', 'jc-importer'), | |
| 279 | + 'aim' => __('Aim', 'jc-importer'), | |
| 280 | + 'yim' => __('Yim', 'jc-importer'), | |
| 281 | + ]; | |
| 282 | + | |
| 283 | + return $permission_fields; | |
| 284 | + } | |
| 285 | + | |
| 286 | + public function get_unique_identifier_options($importer_model, $unique_fields = []) | |
| 287 | + { | |
| 288 | + $output = parent::get_unique_identifier_options($importer_model, $unique_fields); | |
| 289 | + | |
| 290 | + return array_merge( | |
| 291 | + $output, | |
| 292 | + $this->get_unique_identifier_options_from_map($importer_model, $unique_fields, $this->field_map, $this->optional_fields) | |
| 293 | + ); | |
| 208 | 294 | } |
| 209 | 295 | } |