PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 3.2.5
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v3.2.5
4.6.1 4.6.0 4.5.5 4.5.4 4.5.3 4.5.2 3.2.20 3.2.21 3.2.22 3.2.3 3.2.5 3.2.6 3.2.7 3.2.9 3.3.0 3.3.1 3.3.2 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.7.0 3.7.1 3.8.0 All 110 releases
wp-optimize / optimizations / trackbacks.php

trackbacks.php in WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance 3.2.5, at optimizations/trackbacks.php

136 lines 4.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if (!defined('WPO_VERSION')) die('No direct access allowed');
4
5 class WP_Optimization_trackbacks extends WP_Optimization {
6
7 public $ui_sort_order = 7000;
8
9 public $available_for_saving = true;
10
11 /**
12 * Prepare data for preview widget.
13 *
14 * @param array $params
15 *
16 * @return array
17 */
18 public function preview($params) {
19
20 // get data requested for preview.
21 $sql = $this->wpdb->prepare(
22 "SELECT comment_ID, comment_author, SUBSTR(comment_content, 1, 128) AS comment_content".
23 " FROM `" . $this->wpdb->comments . "`".
24 " WHERE comment_type = 'trackback'".
25 " ORDER BY `comment_ID` LIMIT %d, %d;",
26 array(
27 $params['offset'],
28 $params['limit'],
29 )
30 );
31
32 $posts = $this->wpdb->get_results($sql, ARRAY_A);
33
34 // fix empty revision titles.
35 if (!empty($posts)) {
36 foreach ($posts as $key => $post) {
37 $posts[$key]['post_title'] = array(
38 'text' => '' == $post['post_title'] ? '('.__('no title', 'wp-optimize').')' : $post['post_title'],
39 'url' => get_edit_post_link($post['ID']),
40 );
41 }
42 }
43
44 // get total count comments for optimization.
45 $sql = "SELECT COUNT(*) FROM `" . $this->wpdb->comments . "` WHERE comment_type = 'trackback';";
46
47 $total = $this->wpdb->get_var($sql);
48
49 return array(
50 'id_key' => 'comment_ID',
51 'columns' => array(
52 'comment_ID' => __('ID', 'wp-optimize'),
53 'comment_author' => __('Author', 'wp-optimize'),
54 'comment_content' => __('Comment', 'wp-optimize'),
55 ),
56 'offset' => $params['offset'],
57 'limit' => $params['limit'],
58 'total' => $total,
59 'data' => $this->htmlentities_array($posts, array('comment_ID')),
60 'message' => $total > 0 ? '' : __('No trackbacks found', 'wp-optimize'),
61 );
62 }
63
64 /**
65 * Do actions after optimize() function.
66 */
67 public function after_optimize() {
68 $message = sprintf(_n('%s trackback deleted', '%s trackbacks deleted', $this->processed_count, 'wp-optimize'), number_format_i18n($this->processed_count));
69
70 if ($this->is_multisite_mode()) {
71 $message .= ' '. sprintf(_n('across %s site', 'across %s sites', count($this->blogs_ids), 'wp-optimize'), count($this->blogs_ids));
72 }
73
74 // add preview link for output.
75 if (0 != $this->found_count && null != $this->found_count) {
76 $message = $this->get_preview_link($message);
77 }
78
79 $this->logger->info($message);
80 $this->register_output($message);
81 }
82
83 /**
84 * Do optimization.
85 */
86 public function optimize() {
87 $clean = "DELETE c, cm FROM `" . $this->wpdb->comments . "` c LEFT JOIN `" . $this->wpdb->commentmeta . "` cm ON c.comment_ID = cm.comment_id WHERE comment_type = 'trackback'";
88
89 // if posted ids in params, then remove only selected items. used by preview widget.
90 if (isset($this->data['ids'])) {
91 $clean .= ' AND comment_ID in ('.join(',', $this->data['ids']).')';
92 }
93
94 $clean .= ";";
95
96 $comments = $this->query($clean);
97 $this->processed_count += $comments;
98
99 // update comment count
100 $update = "UPDATE `" . $this->wpdb->posts . "` as p
101 INNER JOIN (SELECT comment_post_ID as cid, COUNT(comment_post_ID) as cc
102 FROM `" . $this->wpdb->comments . "` GROUP BY comment_post_ID) AS c ON p.ID = c.cid
103 SET p.comment_count = c.cc
104 WHERE p.ID = c.cid";
105 $this->query($update);
106 }
107
108 /**
109 * Do actions after get_info() function.
110 */
111 public function after_get_info() {
112 if ($this->found_count) {
113 $message = sprintf(_n('%s Trackback found', '%s Trackbacks found', $this->found_count, 'wp-optimize'), number_format_i18n($this->found_count));
114 } else {
115 $message = __('No trackbacks found', 'wp-optimize');
116 }
117
118 if ($this->is_multisite_mode()) {
119 $message .= ' ' . sprintf(_n('across %s site', 'across %s sites', count($this->blogs_ids), 'wp-optimize'), count($this->blogs_ids));
120 }
121
122 $this->register_output($message);
123 }
124
125 public function get_info() {
126 $sql = "SELECT COUNT(*) FROM `" . $this->wpdb->comments . "` WHERE comment_type='trackback';";
127
128 $comments = $this->wpdb->get_var($sql);
129 $this->found_count += $comments;
130 }
131
132 public function settings_label() {
133 return __('Remove trackbacks', 'wp-optimize');
134 }
135 }
136