PluginProbe
Import WP – CSV & XML Import Export for WordPress / 2.15.0
Import WP – CSV & XML Import Export for WordPress v2.15.0
2.15.1 2.15.0 2.14.24 2.14.23 2.7.0 2.7.1 2.7.10 2.7.11 2.7.12 2.7.13 2.7.14 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 2.7.9 2.8.0 2.8.1 2.8.2 2.8.3 2.9.0 2.9.1 All 144 releases
← All changes | class/Common/Exporter/Mapper/CommentMapper.php +31 -5 2.7.14 → 2.15.0 View file →
@@ -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' => []
@@ -69,15 +72,25 @@
69 72 $fields['fields'] = $this->get_core_fields();
70 73
71 74 // get comment custom fields
72 75 $meta_fields = $wpdb->get_col($wpdb->prepare("SELECT DISTINCT cm.meta_key FROM " . $wpdb->comments . " as c INNER JOIN " . $wpdb->commentmeta . " as cm ON c.comment_ID = cm.comment_id WHERE c.comment_post_ID IN (SELECT ID from " . $wpdb->posts . " WHERE post_type=%s)", [$this->post_type]));
76 + $custom_file_fields = apply_filters('iwp/exporter/comment/custom_file_id_fields', []);
73 77 foreach ($meta_fields as $field) {
74 78 $fields['children']['custom_fields']['fields'][] = $field;
79 +
80 + if (in_array($field, $custom_file_fields)) {
81 + $fields['children']['custom_fields']['fields'][] = $field . '::id';
82 + $fields['children']['custom_fields']['fields'][] = $field . '::url';
83 + $fields['children']['custom_fields']['fields'][] = $field . '::title';
84 + $fields['children']['custom_fields']['fields'][] = $field . '::alt';
85 + $fields['children']['custom_fields']['fields'][] = $field . '::caption';
86 + $fields['children']['custom_fields']['fields'][] = $field . '::description';
87 + }
75 88 }
76 89
77 90 $fields['children']['custom_fields']['fields'] = apply_filters('iwp/exporter/comment/custom_field_list', $fields['children']['custom_fields']['fields'], $this->post_type);
78 91
79 - return $fields;
92 + return $this->parse_fields($fields);
80 93 }
81 94
82 95 public function have_records($exporter_id)
83 96 {
@@ -109,10 +122,23 @@
109 122 }
110 123
111 124 public function setup($i)
112 125 {
113 - $this->record = get_comment($this->items[$i], ARRAY_A);
114 - $this->record['custom_fields'] = get_comment_meta($this->record['comment_ID']);
126 + $comment = get_comment($this->items[$i], ARRAY_A);
115 127
128 + $this->record = new ExporterRecord($comment, 'comment');
129 + $this->record = apply_filters('iwp/exporter/comment/setup_data', $this->record, $this->post_type);
130 +
116 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;
117 143 }
118 144 }