PluginProbe
Import WP – CSV & XML Import Export for WordPress / 2.7.12
Import WP – CSV & XML Import Export for WordPress v2.7.12
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
jc-importer / class / Common / Exporter / Mapper / CommentMapper.php

CommentMapper.php in Import WP – CSV & XML Import Export for WordPress 2.7.12, at class/Common/Exporter/Mapper/CommentMapper.php

119 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace ImportWP\Common\Exporter\Mapper;
4
5 use ImportWP\Common\Exporter\MapperInterface;
6
7 class CommentMapper extends AbstractMapper implements MapperInterface
8 {
9 private $post_type;
10
11 /**
12 * @var \WP_Comment_Query
13 */
14 private $query;
15
16 public function __construct($post_type)
17 {
18 $this->post_type = $post_type;
19 }
20
21 public function get_core_fields()
22 {
23 return array(
24 'comment_ID',
25 'comment_post_ID',
26 'comment_author',
27 'comment_author_email',
28 'comment_author_url',
29 'comment_author_IP',
30 'comment_date',
31 'comment_date_gmt',
32 'comment_content',
33 'comment_karma',
34 'comment_approved',
35 'comment_agent',
36 'comment_type',
37 'comment_parent',
38 'user_id',
39 );
40 }
41
42
43 public function get_fields()
44 {
45
46 /**
47 * @var \WPDB
48 */
49 global $wpdb;
50
51 $fields = [
52 'key' => 'main',
53 'label' => 'Comment',
54 'loop' => true,
55 'fields' => [],
56 'children' => [
57 'custom_fields' => [
58 'key' => 'custom_fields',
59 'label' => 'Custom Fields',
60 'loop' => true,
61 'loop_fields' => ['meta_key', 'meta_value'],
62 'fields' => [],
63 'children' => []
64 ]
65 ]
66
67 ];
68
69 $fields['fields'] = $this->get_core_fields();
70
71 // get comment custom fields
72 $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]));
73 foreach ($meta_fields as $field) {
74 $fields['children']['custom_fields']['fields'][] = $field;
75 }
76
77 $fields['children']['custom_fields']['fields'] = apply_filters('iwp/exporter/comment/custom_field_list', $fields['children']['custom_fields']['fields'], $this->post_type);
78
79 return $fields;
80 }
81
82 public function have_records($exporter_id)
83 {
84 $query_args = [];
85 $query_args = apply_filters('iwp/exporter/comment_query', $query_args);
86 $query_args = apply_filters(sprintf('iwp/exporter/%d/comment_query', $exporter_id), $query_args);
87 $query_args = apply_filters('iwp/exporter/comment_query/' . $this->post_type, $query_args);
88 $query_args = apply_filters(sprintf('iwp/exporter/%d/comment_query/%s', $exporter_id, $this->post_type), $query_args);
89
90 $query_args = wp_parse_args($query_args, [
91 'post_type' => $this->post_type,
92 'fields' => 'ids'
93 ]);
94
95 $this->query = new \WP_Comment_Query($query_args);
96 $this->items = $this->query->comments;
97
98 return $this->found_records() > 0;
99 }
100
101 public function found_records()
102 {
103 return count($this->items);
104 }
105
106 public function get_records()
107 {
108 return $this->items;
109 }
110
111 public function setup($i)
112 {
113 $this->record = get_comment($this->items[$i], ARRAY_A);
114 $this->record['custom_fields'] = get_comment_meta($this->record['comment_ID']);
115
116 return true;
117 }
118 }
119