-
Notifications
You must be signed in to change notification settings - Fork 1
/
export.php
82 lines (64 loc) · 2.59 KB
/
export.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
/*------------------------------------------------------------------------------
** File: export.php
** Description: Uses the PHPExcel library to export WordPress comments and their information to an Excel spreadsheet.
** Version: 1.0.0
** Updated: March 3rd, 2017
** Author: Christi Richards
** Homepage: https://github.com/christirichards
** Project: https://github.com/christirichards/wp-excel-comments
**------------------------------------------------------------------------------
** Created for NutritionFacts.org https://github.com/nutritionfactsorg
**------------------------------------------------------------------------------ */
define('WP_USE_THEMES', false);
require './wp-load.php';
require_once 'vendor/autoload.php';
global $wpdb;
$limit = 3000;
$query = "SELECT * FROM $wpdb->comments
WHERE 1 = 1
AND ( comment_approved = '1' OR comment_approved = '0' )
ORDER BY comment_ID DESC
LIMIT $limit";
$error = "Error: comment query failed...
<pre style='width:700px;word-wrap:break-word;white-space:normal;'>$query</pre>";
$result = $wpdb->get_results($query, ARRAY_A) or wp_die($error);
$objPHPExcel = new PHPExcel();
$objPHPExcel->getProperties()
->setCreator('Christi Richards')
->setLastModifiedBy('Christi Richards')
->setTitle('WordPress Comments')
->setSubject('A list of WordPress comments generated by PHPExcel')
->setDescription('A list of WordPress comments generated by PHPExcel')
->setKeywords('WordPress, comments, PHP, PHPExcel');
$objPHPExcel->setActiveSheetIndex(0);
$rowCount = 0;
$cell_definition = array(
'A' => 'comment_ID',
'B' => 'comment_post_ID',
'C' => 'comment_author',
'D' => 'comment_author_email',
'E' => 'comment_author_url',
'F' => 'comment_author_IP',
'G' => 'comment_date',
'H' => 'comment_content',
'I' => 'comment_agent',
'J' => 'comment_parent',
'K' => 'user_id',
);
foreach ($cell_definition as $column => $value) {
$objPHPExcel->getActiveSheet()->setCellValue("{$column}1", $value);
}
while ($rowCount < count($result)) {
$cell = $rowCount + 2;
foreach ($cell_definition as $column => $value) {
$objPHPExcel->getActiveSheet()->setCellValue($column.$cell, $result[$rowCount][$value]);
}
++$rowCount;
}
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="Comments.xlsx"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('php://output');
exit;