| @@ -1,7 +1,7 @@ | ||
| 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 | /** |
| 6 | 6 | * Class WP_Optimization_attachments |
| 7 | 7 | */ |
| @@ -26,11 +26,13 @@ | ||
| 26 | 26 | * Do actions after optimize() function. |
| 27 | 27 | */ |
| 28 | 28 | public function after_optimize() { |
| 29 | 29 | |
| 30 | + // translators: %s: number of orphaned attachments | |
| 30 | 31 | $message = sprintf(_n('%s orphaned attachment deleted', '%s orphaned attachments deleted', $this->processed_count, 'wp-optimize'), number_format_i18n($this->processed_count)); |
| 31 | 32 | |
| 32 | 33 | if ($this->is_multisite_mode()) { |
| 34 | + // translators: %s: number of sites | |
| 33 | 35 | $message .= ' '.sprintf(_n('across %s site', 'across %s sites', count($this->blogs_ids), 'wp-optimize'), count($this->blogs_ids)); |
| 34 | 36 | } |
| 35 | 37 | |
| 36 | 38 | $this->logger->info($message); |
| @@ -42,11 +44,11 @@ | ||
| 42 | 44 | * Do optimization. |
| 43 | 45 | */ |
| 44 | 46 | public function optimize() { |
| 45 | 47 | |
| 46 | - $sql = "SELECT p.ID FROM `".$this->wpdb->posts."` p LEFT JOIN `".$this->wpdb->posts."` pp ON pp.ID = p.post_parent WHERE p.post_parent > 0 AND p.post_type = 'attachment' AND pp.ID IS NULL;"; | |
| 47 | - | |
| 48 | - $attachment_ids = $this->wpdb->get_col($sql); | |
| 48 | + $sql = "SELECT p.ID FROM `{$this->wpdb->posts}` p LEFT JOIN `{$this->wpdb->posts}` pp ON pp.ID = p.post_parent WHERE p.post_parent > %d AND p.post_type = %s AND pp.ID IS NULL;"; | |
| 49 | + | |
| 50 | + $attachment_ids = $this->wpdb->get_col($this->wpdb->prepare($sql, 0, 'attachment')); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- `$this->wpdb` is `$wpdb` | |
| 49 | 51 | $count_ids = count($attachment_ids); |
| 50 | 52 | |
| 51 | 53 | if ($count_ids > 0) { |
| 52 | 54 | foreach ($attachment_ids as $attachment_id) { |
| @@ -63,8 +65,9 @@ | ||
| 63 | 65 | */ |
| 64 | 66 | public function after_get_info() { |
| 65 | 67 | |
| 66 | 68 | if ($this->found_count) { |
| 69 | + // translators: %s: number of orphaned attachments | |
| 67 | 70 | $message = sprintf(_n('%s orphaned attachment found', '%s orphaned attachments found', $this->found_count, 'wp-optimize'), number_format_i18n($this->found_count)); |
| 68 | 71 | } else { |
| 69 | 72 | $message = __('No orphaned attachments found', 'wp-optimize'); |
| 70 | 73 | } |
| @@ -69,8 +72,9 @@ | ||
| 69 | 72 | $message = __('No orphaned attachments found', 'wp-optimize'); |
| 70 | 73 | } |
| 71 | 74 | |
| 72 | 75 | if ($this->is_multisite_mode()) { |
| 76 | + // translators: %s: number of sites | |
| 73 | 77 | $message .= ' '.sprintf(_n('across %s site', 'across %s sites', count($this->blogs_ids), 'wp-optimize'), count($this->blogs_ids)); |
| 74 | 78 | } |
| 75 | 79 | |
| 76 | 80 | $this->register_output($message); |
| @@ -80,10 +84,10 @@ | ||
| 80 | 84 | * Estimate count of unoptimized items. |
| 81 | 85 | */ |
| 82 | 86 | public function get_info() { |
| 83 | 87 | |
| 84 | - $sql = "SELECT COUNT(*) FROM `" . $this->wpdb->posts . "` p LEFT JOIN `" . $this->wpdb->posts . "` pp ON pp.ID = p.post_parent WHERE p.post_parent > 0 AND p.post_type = 'attachment' AND pp.ID IS NULL;"; | |
| 85 | - $postmeta = $this->wpdb->get_var($sql); | |
| 88 | + $sql = "SELECT COUNT(*) FROM `{$this->wpdb->posts}` p LEFT JOIN `{$this->wpdb->posts}` pp ON pp.ID = p.post_parent WHERE p.post_parent > %d AND p.post_type = %s AND pp.ID IS NULL;"; | |
| 89 | + $postmeta = $this->wpdb->get_var($this->wpdb->prepare($sql, 0, 'attachment')); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- `$this->wpdb` is `$wpdb` | |
| 86 | 90 | |
| 87 | 91 | $this->found_count += $postmeta; |
| 88 | 92 | |
| 89 | 93 | } |
| @@ -90,20 +94,10 @@ | ||
| 90 | 94 | |
| 91 | 95 | /** |
| 92 | 96 | * Returns settings label |
| 93 | 97 | * |
| 94 | - * @return string|void | |
| 98 | + * @return string | |
| 95 | 99 | */ |
| 96 | 100 | public function settings_label() { |
| 97 | - return __('Remove orphaned attachments', 'wp-optimize'); | |
| 98 | - } | |
| 99 | - | |
| 100 | - /** | |
| 101 | - * Return description | |
| 102 | - * N.B. This is not currently used; it was commented out in 1.9.1 | |
| 103 | - * | |
| 104 | - * @return string|void | |
| 105 | - */ | |
| 106 | - public function get_auto_option_description() { | |
| 107 | 101 | return __('Remove orphaned attachments', 'wp-optimize'); |
| 108 | 102 | } |
| 109 | 103 | } |