| @@ -1,8 +1,9 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace ImportWP\Common\Exporter\Mapper; |
| 4 | 4 | |
| 5 | +use ImportWP\Common\Exporter\ExporterRecord; | |
| 5 | 6 | use ImportWP\Common\Exporter\MapperInterface; |
| 6 | 7 | |
| 7 | 8 | class CommentMapper extends AbstractMapper implements MapperInterface |
| 8 | 9 | { |
| @@ -15,8 +16,10 @@ | ||
| 15 | 16 | |
| 16 | 17 | public function __construct($post_type) |
| 17 | 18 | { |
| 18 | 19 | $this->post_type = $post_type; |
| 20 | + | |
| 21 | + add_filter('iwp/exporter_record/comment', [$this, 'get_record_data'], 10, 3); | |
| 19 | 22 | } |
| 20 | 23 | |
| 21 | 24 | public function get_core_fields() |
| 22 | 25 | { |
| @@ -49,15 +52,15 @@ | ||
| 49 | 52 | global $wpdb; |
| 50 | 53 | |
| 51 | 54 | $fields = [ |
| 52 | 55 | 'key' => 'main', |
| 53 | - 'label' => 'Comment', | |
| 56 | + 'label' => __('Comment', 'jc-importer'), | |
| 54 | 57 | 'loop' => true, |
| 55 | 58 | 'fields' => [], |
| 56 | 59 | 'children' => [ |
| 57 | 60 | 'custom_fields' => [ |
| 58 | 61 | 'key' => 'custom_fields', |
| 59 | - 'label' => 'Custom Fields', | |
| 62 | + 'label' => __('Custom Fields', 'jc-importer'), | |
| 60 | 63 | 'loop' => true, |
| 61 | 64 | 'loop_fields' => ['meta_key', 'meta_value'], |
| 62 | 65 | 'fields' => [], |
| 63 | 66 | 'children' => [] |
| @@ -85,9 +88,9 @@ | ||
| 85 | 88 | } |
| 86 | 89 | |
| 87 | 90 | $fields['children']['custom_fields']['fields'] = apply_filters('iwp/exporter/comment/custom_field_list', $fields['children']['custom_fields']['fields'], $this->post_type); |
| 88 | 91 | |
| 89 | - return $fields; | |
| 92 | + return $this->parse_fields($fields); | |
| 90 | 93 | } |
| 91 | 94 | |
| 92 | 95 | public function have_records($exporter_id) |
| 93 | 96 | { |
| @@ -119,11 +122,23 @@ | ||
| 119 | 122 | } |
| 120 | 123 | |
| 121 | 124 | public function setup($i) |
| 122 | 125 | { |
| 123 | - $this->record = get_comment($this->items[$i], ARRAY_A); | |
| 124 | - $this->record['custom_fields'] = get_comment_meta($this->record['comment_ID']); | |
| 125 | - $this->record = $this->modify_custom_field_data($this->record, 'comment'); | |
| 126 | + $comment = get_comment($this->items[$i], ARRAY_A); | |
| 126 | 127 | |
| 128 | + $this->record = new ExporterRecord($comment, 'comment'); | |
| 129 | + $this->record = apply_filters('iwp/exporter/comment/setup_data', $this->record, $this->post_type); | |
| 130 | + | |
| 127 | 131 | return true; |
| 132 | + } | |
| 133 | + | |
| 134 | + public function get_record_data($value, $key, $record) | |
| 135 | + { | |
| 136 | + switch ($key) { | |
| 137 | + case 'custom_fields': | |
| 138 | + $value = get_comment_meta($record['comment_ID']); | |
| 139 | + $value = $this->modify_custom_field_data($value, 'comment'); | |
| 140 | + break; | |
| 141 | + } | |
| 142 | + return $value; | |
| 128 | 143 | } |
| 129 | 144 | } |