PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 2.2.11
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v2.2.11
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 2.2.11, at optimizations/pingbacks.php

134 lines 3.8 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 // clean orphaned comment meta
94 $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";
95 $this->query($clean);
96 }
97
98 /**
99 * Do actions after get_info() function.
100 */
101 public function after_get_info() {
102 if ($this->found_count > 0) {
103 $message = sprintf(_n('%s pingback found', '%s pingbacks found', $this->found_count, 'wp-optimize'), number_format_i18n($this->found_count));
104 } else {
105 $message = __('No pingbacks found', 'wp-optimize');
106 }
107
108 if ($this->is_multisite_mode()) {
109 $message .= ' '.sprintf(_n('across %s site', 'across %s sites', count($this->blogs_ids), 'wp-optimize'), count($this->blogs_ids));
110 }
111
112 // add preview link to message.
113 if ($this->found_count > 0) {
114 $message = $this->get_preview_link($message);
115 }
116
117 $this->register_output($message);
118 }
119
120 /**
121 * Get count of unoptimized items.
122 */
123 public function get_info() {
124 $sql = "SELECT COUNT(*) FROM `" . $this->wpdb->comments . "` WHERE comment_type='pingback';";
125
126 $comments = $this->wpdb->get_var($sql);
127 $this->found_count += $comments;
128 }
129
130 public function settings_label() {
131 return __('Remove pingbacks', 'wp-optimize');
132 }
133 }
134