PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 3.2.12
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v3.2.12
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 / pingbacks.php

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

142 lines 4.1 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_pingbacks extends WP_Optimization {
6
7 public $ui_sort_order = 6000;
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 FROM `" . $this->wpdb->comments . "`".
23 " WHERE comment_type = 'pingback'".
24 " ORDER BY `comment_ID` LIMIT %d, %d;",
25 array(
26 $params['offset'],
27 $params['limit'],
28 )
29 );
30
31 $posts = $this->wpdb->get_results($sql, ARRAY_A);
32
33 // fix empty revision titles.
34 if (!empty($posts)) {
35 foreach ($posts as $key => $post) {
36 $posts[$key]['post_title'] = array(
37 'text' => '' == $post['post_title'] ? '('.__('no title', 'wp-optimize').')' : $post['post_title'],
38 'url' => get_edit_post_link($post['ID']),
39 );
40 }
41 }
42
43 // get total count comments for optimization.
44 $sql = "SELECT COUNT(*) FROM `" . $this->wpdb->comments . "` WHERE comment_type = 'pingback';";
45
46 $total = $this->wpdb->get_var($sql);
47
48 return array(
49 'id_key' => 'comment_ID',
50 'columns' => array(
51 'comment_ID' => __('ID', 'wp-optimize'),
52 'comment_author' => __('Author', 'wp-optimize'),
53 'comment_content' => __('Comment', 'wp-optimize'),
54 ),
55 'offset' => $params['offset'],
56 'limit' => $params['limit'],
57 'total' => $total,
58 'data' => $this->htmlentities_array($posts, array('comment_ID')),
59 'message' => $total > 0 ? '' : __('No pingbacks found', 'wp-optimize'),
60 );
61 }
62
63 /**
64 * Do actions after optimize() function.
65 */
66 public function after_optimize() {
67 $message = sprintf(_n('%s pingback deleted', '%s pingbacks deleted', $this->processed_count, 'wp-optimize'), number_format_i18n($this->processed_count));
68
69 if ($this->is_multisite_mode()) {
70 $message .= ' '.sprintf(_n('across %s site', 'across %s sites', count($this->blogs_ids), 'wp-optimize'), count($this->blogs_ids));
71 }
72
73 $this->logger->info($message);
74 $this->register_output($message);
75 }
76
77 /**
78 * Do optimization.
79 */
80 public function optimize() {
81 $clean = "DELETE FROM `" . $this->wpdb->comments . "` WHERE comment_type = 'pingback'";
82
83 // if posted ids in params, then remove only selected items. used by preview widget.
84 if (isset($this->data['ids'])) {
85 $clean .= ' AND comment_ID in ('.join(',', $this->data['ids']).')';
86 }
87
88 $clean .= ";";
89
90 $comments = $this->query($clean);
91 $this->processed_count += $comments;
92
93 // update comment count
94 $update = "UPDATE `" . $this->wpdb->posts . "` as p
95 INNER JOIN (SELECT comment_post_ID as cid, COUNT(comment_post_ID) as cc
96 FROM `" . $this->wpdb->comments . "` GROUP BY comment_post_ID) AS c ON p.ID = c.cid
97 SET p.comment_count = c.cc
98 WHERE p.ID = c.cid";
99 $this->query($update);
100
101 // clean orphaned comment meta
102 $clean = "DELETE cm FROM `" . $this->wpdb->commentmeta . "` cm LEFT JOIN `" . $this->wpdb->comments . "` c ON cm.comment_id = c.comment_ID WHERE c.comment_ID IS NULL";
103 $this->query($clean);
104 }
105
106 /**
107 * Do actions after get_info() function.
108 */
109 public function after_get_info() {
110 if ($this->found_count > 0) {
111 $message = sprintf(_n('%s pingback found', '%s pingbacks found', $this->found_count, 'wp-optimize'), number_format_i18n($this->found_count));
112 } else {
113 $message = __('No pingbacks found', 'wp-optimize');
114 }
115
116 if ($this->is_multisite_mode()) {
117 $message .= ' '.sprintf(_n('across %s site', 'across %s sites', count($this->blogs_ids), 'wp-optimize'), count($this->blogs_ids));
118 }
119
120 // add preview link to message.
121 if ($this->found_count > 0) {
122 $message = $this->get_preview_link($message);
123 }
124
125 $this->register_output($message);
126 }
127
128 /**
129 * Get count of unoptimized items.
130 */
131 public function get_info() {
132 $sql = "SELECT COUNT(*) FROM `" . $this->wpdb->comments . "` WHERE comment_type='pingback';";
133
134 $comments = $this->wpdb->get_var($sql);
135 $this->found_count += $comments;
136 }
137
138 public function settings_label() {
139 return __('Remove pingbacks', 'wp-optimize');
140 }
141 }
142