| @@ -1,10 +1,12 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -if (!defined('WPO_VERSION')) die('No direct access allowed'); | |
| 3 | +if (!defined('ABSPATH')) die('No direct access allowed'); | |
| 4 | 4 | |
| 5 | 5 | class WP_Optimization_trackbacks extends WP_Optimization { |
| 6 | 6 | |
| 7 | + public $available_for_auto = true; | |
| 8 | + | |
| 7 | 9 | public $ui_sort_order = 7000; |
| 8 | 10 | |
| 9 | 11 | public $available_for_saving = true; |
| 10 | 12 | |
| @@ -17,8 +19,10 @@ | ||
| 17 | 19 | */ |
| 18 | 20 | public function preview($params) { |
| 19 | 21 | |
| 20 | 22 | // get data requested for preview. |
| 23 | + // `$this->wpdb->prepare` is global `$wpdb->prepare` | |
| 24 | + // phpcs:disable | |
| 21 | 25 | $sql = $this->wpdb->prepare( |
| 22 | 26 | "SELECT comment_ID, comment_author, SUBSTR(comment_content, 1, 128) AS comment_content". |
| 23 | 27 | " FROM `" . $this->wpdb->comments . "`". |
| 24 | 28 | " WHERE comment_type = 'trackback'". |
| @@ -29,14 +33,15 @@ | ||
| 29 | 33 | ) |
| 30 | 34 | ); |
| 31 | 35 | |
| 32 | 36 | $posts = $this->wpdb->get_results($sql, ARRAY_A); |
| 37 | + // phpcs:enable | |
| 33 | 38 | |
| 34 | 39 | // fix empty revision titles. |
| 35 | 40 | if (!empty($posts)) { |
| 36 | 41 | foreach ($posts as $key => $post) { |
| 37 | 42 | $posts[$key]['post_title'] = array( |
| 38 | - 'text' => '' == $post['post_title'] ? '('.__('no title', 'wp-optimize').')' : $post['post_title'], | |
| 43 | + 'text' => '' === $post['post_title'] ? '('.__('no title', 'wp-optimize').')' : $post['post_title'], | |
| 39 | 44 | 'url' => get_edit_post_link($post['ID']), |
| 40 | 45 | ); |
| 41 | 46 | } |
| 42 | 47 | } |
| @@ -43,9 +48,9 @@ | ||
| 43 | 48 | |
| 44 | 49 | // get total count comments for optimization. |
| 45 | 50 | $sql = "SELECT COUNT(*) FROM `" . $this->wpdb->comments . "` WHERE comment_type = 'trackback';"; |
| 46 | 51 | |
| 47 | - $total = $this->wpdb->get_var($sql); | |
| 52 | + $total = $this->wpdb->get_var($sql); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- Safe, no user input used | |
| 48 | 53 | |
| 49 | 54 | return array( |
| 50 | 55 | 'id_key' => 'comment_ID', |
| 51 | 56 | 'columns' => array( |
| @@ -64,16 +69,18 @@ | ||
| 64 | 69 | /** |
| 65 | 70 | * Do actions after optimize() function. |
| 66 | 71 | */ |
| 67 | 72 | public function after_optimize() { |
| 73 | + // translators: %s is the number of deleted trackbacks | |
| 68 | 74 | $message = sprintf(_n('%s trackback deleted', '%s trackbacks deleted', $this->processed_count, 'wp-optimize'), number_format_i18n($this->processed_count)); |
| 69 | 75 | |
| 70 | 76 | if ($this->is_multisite_mode()) { |
| 77 | + // translators: %s is the number of sites | |
| 71 | 78 | $message .= ' '. sprintf(_n('across %s site', 'across %s sites', count($this->blogs_ids), 'wp-optimize'), count($this->blogs_ids)); |
| 72 | 79 | } |
| 73 | 80 | |
| 74 | 81 | // add preview link for output. |
| 75 | - if (0 != $this->found_count && null != $this->found_count) { | |
| 82 | + if ($this->found_count > 0) { | |
| 76 | 83 | $message = $this->get_preview_link($message); |
| 77 | 84 | } |
| 78 | 85 | |
| 79 | 86 | $this->logger->info($message); |
| @@ -109,8 +116,9 @@ | ||
| 109 | 116 | * Do actions after get_info() function. |
| 110 | 117 | */ |
| 111 | 118 | public function after_get_info() { |
| 112 | 119 | if ($this->found_count) { |
| 120 | + // translators: %s is the number of found trackbacks | |
| 113 | 121 | $message = sprintf(_n('%s Trackback found', '%s Trackbacks found', $this->found_count, 'wp-optimize'), number_format_i18n($this->found_count)); |
| 114 | 122 | } else { |
| 115 | 123 | $message = __('No trackbacks found', 'wp-optimize'); |
| 116 | 124 | } |
| @@ -115,8 +123,9 @@ | ||
| 115 | 123 | $message = __('No trackbacks found', 'wp-optimize'); |
| 116 | 124 | } |
| 117 | 125 | |
| 118 | 126 | if ($this->is_multisite_mode()) { |
| 127 | + // translators: %s is the number of sites | |
| 119 | 128 | $message .= ' ' . sprintf(_n('across %s site', 'across %s sites', count($this->blogs_ids), 'wp-optimize'), count($this->blogs_ids)); |
| 120 | 129 | } |
| 121 | 130 | |
| 122 | 131 | $this->register_output($message); |
| @@ -124,12 +133,17 @@ | ||
| 124 | 133 | |
| 125 | 134 | public function get_info() { |
| 126 | 135 | $sql = "SELECT COUNT(*) FROM `" . $this->wpdb->comments . "` WHERE comment_type='trackback';"; |
| 127 | 136 | |
| 128 | - $comments = $this->wpdb->get_var($sql); | |
| 137 | + $comments = $this->wpdb->get_var($sql); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- Safe, no user input used | |
| 129 | 138 | $this->found_count += $comments; |
| 130 | 139 | } |
| 131 | - | |
| 140 | + | |
| 141 | + /** | |
| 142 | + * Do actions after get_info() function. | |
| 143 | + * | |
| 144 | + * @return string | |
| 145 | + */ | |
| 132 | 146 | public function settings_label() { |
| 133 | 147 | return __('Remove trackbacks', 'wp-optimize'); |
| 134 | 148 | } |
| 135 | 149 | } |