| @@ -1,13 +1,13 @@ | ||
| 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_postmeta extends WP_Optimization { |
| 6 | 6 | |
| 7 | 7 | public $ui_sort_order = 8000; |
| 8 | 8 | |
| 9 | - public $available_for_auto = false; | |
| 9 | + public $available_for_auto = true; | |
| 10 | 10 | |
| 11 | 11 | public $available_for_saving = true; |
| 12 | 12 | |
| 13 | 13 | public $auto_default = false; |
| @@ -20,8 +20,10 @@ | ||
| 20 | 20 | * @return array |
| 21 | 21 | */ |
| 22 | 22 | public function preview($params) { |
| 23 | 23 | // get data requested for preview. |
| 24 | + // `$this->wpdb->prepare` is `$wpdb->prepare` from global variable. | |
| 25 | + // phpcs:disable | |
| 24 | 26 | $sql = $this->wpdb->prepare( |
| 25 | 27 | "SELECT pm.* FROM `" . $this->wpdb->postmeta . "` pm". |
| 26 | 28 | " LEFT JOIN `" . $this->wpdb->posts . "` wp ON wp.ID = pm.post_id". |
| 27 | 29 | " WHERE wp.ID IS NULL". |
| @@ -32,13 +34,14 @@ | ||
| 32 | 34 | ) |
| 33 | 35 | ); |
| 34 | 36 | |
| 35 | 37 | $posts = $this->wpdb->get_results($sql, ARRAY_A); |
| 38 | + // phpcs:enable | |
| 36 | 39 | |
| 37 | 40 | // get total count post meta for optimization. |
| 38 | 41 | $sql = "SELECT COUNT(*) FROM `" . $this->wpdb->postmeta . "` pm LEFT JOIN `" . $this->wpdb->posts . "` wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL;"; |
| 39 | 42 | |
| 40 | - $total = $this->wpdb->get_var($sql); | |
| 43 | + $total = $this->wpdb->get_var($sql); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- Statement is safe, no user input used | |
| 41 | 44 | |
| 42 | 45 | return array( |
| 43 | 46 | 'id_key' => 'meta_id', |
| 44 | 47 | 'columns' => array( |
| @@ -43,16 +46,16 @@ | ||
| 43 | 46 | 'id_key' => 'meta_id', |
| 44 | 47 | 'columns' => array( |
| 45 | 48 | 'meta_id' => __('ID', 'wp-optimize'), |
| 46 | 49 | 'post_id' => __('Post ID', 'wp-optimize'), |
| 47 | - 'meta_key' => __('Meta Key', 'wp-optimize'), | |
| 48 | - 'meta_value' => __('Meta Value', 'wp-optimize'), | |
| 50 | + 'meta_key' => __('Meta Key', 'wp-optimize'), // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key -- This is not a query | |
| 51 | + 'meta_value' => __('Meta Value', 'wp-optimize'), // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_value -- This is not a query | |
| 49 | 52 | ), |
| 50 | 53 | 'offset' => $params['offset'], |
| 51 | 54 | 'limit' => $params['limit'], |
| 52 | 55 | 'total' => $total, |
| 53 | 56 | 'data' => $this->htmlentities_array($posts, array('ID')), |
| 54 | - 'message' => $total > 0 ? '' : __('No orphaned post meta data in your database', 'wp-optimize'), | |
| 57 | + 'message' => $total > 0 ? '' : __('No orphaned post metadata in your database', 'wp-optimize'), | |
| 55 | 58 | ); |
| 56 | 59 | } |
| 57 | 60 | |
| 58 | 61 | /** |
| @@ -58,11 +61,13 @@ | ||
| 58 | 61 | /** |
| 59 | 62 | * Do actions after optimize() function. |
| 60 | 63 | */ |
| 61 | 64 | public function after_optimize() { |
| 62 | - $message = sprintf(_n('%s orphaned post meta data deleted', '%s orphaned post meta data deleted', $this->processed_count, 'wp-optimize'), number_format_i18n($this->processed_count)); | |
| 65 | + // translators: %s: number of orphaned post metadata records | |
| 66 | + $message = sprintf(_n('%s orphaned post metadata deleted', '%s orphaned post metadata deleted', $this->processed_count, 'wp-optimize'), number_format_i18n($this->processed_count)); | |
| 63 | 67 | |
| 64 | 68 | if ($this->is_multisite_mode()) { |
| 69 | + // translators: %s: number of sites | |
| 65 | 70 | $message .= ' ' . sprintf(_n('across %s site', 'across %s sites', count($this->blogs_ids), 'wp-optimize'), count($this->blogs_ids)); |
| 66 | 71 | } |
| 67 | 72 | |
| 68 | 73 | $this->logger->info($message); |
| @@ -90,14 +95,16 @@ | ||
| 90 | 95 | * Do actions after get_info() function. |
| 91 | 96 | */ |
| 92 | 97 | public function after_get_info() { |
| 93 | 98 | if ($this->found_count) { |
| 94 | - $message = sprintf(_n('%s orphaned post meta data in your database', '%s orphaned post meta data in your database', $this->found_count, 'wp-optimize'), number_format_i18n($this->found_count)); | |
| 99 | + // translators: %s: number of orphaned post metadata records | |
| 100 | + $message = sprintf(_n('%s orphaned post metadata in your database', '%s orphaned post metadata in your database', $this->found_count, 'wp-optimize'), number_format_i18n($this->found_count)); | |
| 95 | 101 | } else { |
| 96 | - $message = __('No orphaned post meta data in your database', 'wp-optimize'); | |
| 102 | + $message = __('No orphaned post metadata in your database', 'wp-optimize'); | |
| 97 | 103 | } |
| 98 | 104 | |
| 99 | 105 | if ($this->is_multisite_mode()) { |
| 106 | + // translators: %s: number of sites | |
| 100 | 107 | $message .= ' ' . sprintf(_n('across %s site', 'across %s sites', count($this->blogs_ids), 'wp-optimize'), count($this->blogs_ids)); |
| 101 | 108 | } |
| 102 | 109 | |
| 103 | 110 | // add preview link to message. |
| @@ -112,22 +119,18 @@ | ||
| 112 | 119 | * Get count of unoptimized items. |
| 113 | 120 | */ |
| 114 | 121 | public function get_info() { |
| 115 | 122 | $sql = "SELECT COUNT(*) FROM `" . $this->wpdb->postmeta . "` pm LEFT JOIN `" . $this->wpdb->posts . "` wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL;"; |
| 116 | - $postmeta = $this->wpdb->get_var($sql); | |
| 123 | + $postmeta = $this->wpdb->get_var($sql); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- Statement is safe, no user input used | |
| 117 | 124 | |
| 118 | 125 | $this->found_count += $postmeta; |
| 119 | 126 | } |
| 120 | - | |
| 121 | - public function settings_label() { | |
| 122 | - return __('Clean post meta data', 'wp-optimize'); | |
| 123 | - } | |
| 124 | - | |
| 127 | + | |
| 125 | 128 | /** |
| 126 | - * N.B. This is not currently used; it was commented out in 1.9.1 | |
| 129 | + * Returns settings label | |
| 127 | 130 | * |
| 128 | - * @return string Returns the description once auto remove option has ran | |
| 131 | + * @return string | |
| 129 | 132 | */ |
| 130 | - public function get_auto_option_description() { | |
| 131 | - return __('Remove orphaned post meta', 'wp-optimize'); | |
| 133 | + public function settings_label() { | |
| 134 | + return __('Clean post metadata', 'wp-optimize'); | |
| 132 | 135 | } |
| 133 | 136 | } |