| @@ -55,47 +55,52 @@ | ||
| 55 | 55 | |
| 56 | 56 | public function register() |
| 57 | 57 | { |
| 58 | 58 | return [ |
| 59 | - $this->register_group('Term', 'term', [ | |
| 60 | - $this->register_field('ID', 'term_id', [ | |
| 61 | - 'tooltip' => __('ID is only used to reference existing records', 'importwp') | |
| 59 | + $this->register_group(__('Term', 'jc-importer'), 'term', [ | |
| 60 | + $this->register_field(__('ID', 'jc-importer'), 'term_id', [ | |
| 61 | + 'tooltip' => __('ID is only used to reference existing records', 'jc-importer') | |
| 62 | 62 | ]), |
| 63 | - $this->register_core_field('Name', 'name', [ | |
| 64 | - 'tooltip' => __('The term name', 'importwp') | |
| 63 | + $this->register_core_field(__('Name', 'jc-importer'), 'name', [ | |
| 64 | + 'tooltip' => __('The term name', 'jc-importer') | |
| 65 | 65 | ]), |
| 66 | - $this->register_field('Description', 'description', [ | |
| 67 | - 'tooltip' => __('The term description', 'importwp') | |
| 66 | + $this->register_field(__('Description', 'jc-importer'), 'description', [ | |
| 67 | + 'tooltip' => __('The term description', 'jc-importer') | |
| 68 | 68 | ]), |
| 69 | - $this->register_field('Slug', 'slug', [ | |
| 70 | - 'tooltip' => __('The term slug to use', 'importwp') | |
| 69 | + $this->register_field(__('Slug', 'jc-importer'), 'slug', [ | |
| 70 | + 'tooltip' => __('The term slug to use', 'jc-importer') | |
| 71 | 71 | ]), |
| 72 | - $this->register_group('Parent Settings', '_parent', [ | |
| 73 | - $this->register_field('Parent', 'parent', [ | |
| 72 | + $this->register_group(__('Parent Settings', 'jc-importer'), '_parent', [ | |
| 73 | + $this->register_field(__('Parent', 'jc-importer'), 'parent', [ | |
| 74 | 74 | 'default' => '', |
| 75 | 75 | 'options' => 'callback', |
| 76 | - 'tooltip' => __('The id of the parent term', 'importwp') | |
| 76 | + 'tooltip' => __('The id of the parent term', 'jc-importer') | |
| 77 | 77 | ]), |
| 78 | - $this->register_field('Parent Field Type', '_parent_type', [ | |
| 78 | + $this->register_field(__('Parent Field Type', 'jc-importer'), '_parent_type', [ | |
| 79 | 79 | 'default' => 'id', |
| 80 | 80 | 'options' => [ |
| 81 | - ['value' => 'id', 'label' => 'ID'], | |
| 82 | - ['value' => 'slug', 'label' => 'Slug'], | |
| 83 | - ['value' => 'name', 'label' => 'Name'], | |
| 84 | - ['value' => 'column', 'label' => 'Reference Column'], | |
| 81 | + ['value' => 'id', 'label' => __('ID', 'jc-importer')], | |
| 82 | + ['value' => 'slug', 'label' => __('Slug', 'jc-importer')], | |
| 83 | + ['value' => 'name', 'label' => __('Name', 'jc-importer')], | |
| 84 | + ['value' => 'column', 'label' => __('Reference Column', 'jc-importer')], | |
| 85 | + ['value' => 'custom_field', 'label' => __('Custom Field', 'jc-importer')], | |
| 85 | 86 | ], |
| 86 | 87 | 'type' => 'select', |
| 87 | - 'tooltip' => __('Select how the parent field should be handled', 'importwp') | |
| 88 | + 'tooltip' => __('Select how the parent field should be handled', 'jc-importer') | |
| 88 | 89 | ]), |
| 89 | - $this->register_field('Parent Reference Column', '_parent_ref', [ | |
| 90 | + $this->register_field(__('Parent Reference Column', 'jc-importer'), '_parent_ref', [ | |
| 90 | 91 | 'condition' => ['_parent_type', '==', 'column'], |
| 91 | - 'tooltip' => __('Select the column/node that the parent field is referencing', 'importwp') | |
| 92 | + 'tooltip' => __('Select the column/node that the parent field is referencing', 'jc-importer') | |
| 93 | + ]), | |
| 94 | + $this->register_field(__('Custom Field Key', 'jc-importer'), '_custom_field', [ | |
| 95 | + 'condition' => ['_parent_type', '==', 'custom_field'], | |
| 96 | + 'tooltip' => __('Enter the name of the custom field.', 'jc-importer') | |
| 92 | 97 | ]) |
| 93 | 98 | ]), |
| 94 | - $this->register_field('Alias of', 'alias_of', [ | |
| 95 | - 'tooltip' => __('Slug of the term to make this term an alias of', 'importwp') | |
| 99 | + $this->register_field(__('Alias of', 'jc-importer'), 'alias_of', [ | |
| 100 | + 'tooltip' => __('Slug of the term to make this term an alias of', 'jc-importer') | |
| 96 | 101 | ]), |
| 97 | - ]) | |
| 102 | + ], ['link' => 'https://www.importwp.com/docs/wordpress-taxonomy-importer-template/']) | |
| 98 | 103 | ]; |
| 99 | 104 | } |
| 100 | 105 | |
| 101 | 106 | public function register_settings() |
| @@ -196,12 +201,19 @@ | ||
| 196 | 201 | $parent_id = intval($term_field_map['parent']); |
| 197 | 202 | } elseif ($parent_field_type === 'column') { |
| 198 | 203 | |
| 199 | 204 | // reference column |
| 200 | - $temp_id = $this->get_term_by_cf('term_parent', $term_field_map['parent']); | |
| 205 | + $temp_id = $this->get_term_by_cf('_iwp_ref_term_parent', $term_field_map['parent']); | |
| 201 | 206 | if (intval($temp_id > 0)) { |
| 202 | 207 | $parent_id = intval($temp_id); |
| 203 | 208 | } |
| 209 | + } elseif ($parent_field_type === 'custom_field') { | |
| 210 | + | |
| 211 | + $parent_custom_field = $data->getValue('term._parent._custom_field'); | |
| 212 | + $temp_id = $this->get_term_by_cf($parent_custom_field, $term_field_map['parent']); | |
| 213 | + if (intval($temp_id > 0)) { | |
| 214 | + $parent_id = intval($temp_id); | |
| 215 | + } | |
| 204 | 216 | } |
| 205 | 217 | |
| 206 | 218 | if ($parent_id > 0) { |
| 207 | 219 | $term_field_map['parent'] = $parent_id; |
| @@ -232,9 +244,9 @@ | ||
| 232 | 244 | 'fields' => 'ids', |
| 233 | 245 | 'hide_empty' => false, |
| 234 | 246 | 'meta_query' => [ |
| 235 | 247 | [ |
| 236 | - 'key' => '_iwp_ref_' . $field, | |
| 248 | + 'key' => $field, | |
| 237 | 249 | 'value' => $value, |
| 238 | 250 | 'compare' => '=' |
| 239 | 251 | ] |
| 240 | 252 | ] |
| @@ -296,14 +308,14 @@ | ||
| 296 | 308 | if (!isset($parent['map'])) { |
| 297 | 309 | $parent['map'] = []; |
| 298 | 310 | } |
| 299 | 311 | |
| 300 | - $parent['map'][$matches[1]] = sprintf('{%d}', $index); | |
| 312 | + $parent['map'][$matches[1]] = sprintf('{%s}', $index); | |
| 301 | 313 | } elseif (isset($this->field_map[$field])) { |
| 302 | 314 | |
| 303 | 315 | // Handle core fields |
| 304 | 316 | $field_key = $this->field_map[$field]; |
| 305 | - $map[$field_key] = sprintf('{%d}', $index); | |
| 317 | + $map[$field_key] = sprintf('{%s}', $index); | |
| 306 | 318 | |
| 307 | 319 | if (in_array($field, $this->optional_fields)) { |
| 308 | 320 | $enabled[] = $field_key; |
| 309 | 321 | } |
| @@ -342,6 +354,32 @@ | ||
| 342 | 354 | return [ |
| 343 | 355 | 'map' => $map, |
| 344 | 356 | 'enabled' => $enabled |
| 345 | 357 | ]; |
| 358 | + } | |
| 359 | + | |
| 360 | + public function get_permission_fields($importer_model) | |
| 361 | + { | |
| 362 | + $permission_fields = parent::get_permission_fields($importer_model); | |
| 363 | + | |
| 364 | + $permission_fields['core'] = [ | |
| 365 | + 'term_id' => __('ID', 'jc-importer'), | |
| 366 | + 'name' => __('Name', 'jc-importer'), | |
| 367 | + 'description' => __('Description', 'jc-importer'), | |
| 368 | + 'slug' => __('Slug', 'jc-importer'), | |
| 369 | + 'alias_of' => __('Alias Of', 'jc-importer'), | |
| 370 | + 'parent' => __('Parent', 'jc-importer'), | |
| 371 | + ]; | |
| 372 | + | |
| 373 | + return $permission_fields; | |
| 374 | + } | |
| 375 | + | |
| 376 | + public function get_unique_identifier_options($importer_model, $unique_fields = []) | |
| 377 | + { | |
| 378 | + $output = parent::get_unique_identifier_options($importer_model, $unique_fields); | |
| 379 | + | |
| 380 | + return array_merge( | |
| 381 | + $output, | |
| 382 | + $this->get_unique_identifier_options_from_map($importer_model, $unique_fields, $this->field_map, $this->optional_fields) | |
| 383 | + ); | |
| 346 | 384 | } |
| 347 | 385 | } |