PluginProbe
Import WP – CSV & XML Import Export for WordPress / 2.7.1
Import WP – CSV & XML Import Export for WordPress v2.7.1
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.1, at class/Common/Exporter/Mapper/CommentMapper.php

104 lines 2.7 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 private 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()
83 {
84 $this->query = new \WP_Comment_Query(array(
85 'post_type' => $this->post_type
86 ));
87
88 return $this->found_records() > 0;
89 }
90
91 public function found_records()
92 {
93 return count($this->query->comments);
94 }
95
96 public function setup($i)
97 {
98 $this->record = (array)$this->query->comments[$i];
99 $this->record['custom_fields'] = get_comment_meta($this->record['comment_ID']);
100
101 return true;
102 }
103 }
104