Changeset 3443059
- Timestamp:
- 01/20/2026 08:59:05 AM (2 months ago)
- Location:
- cleanup-wp/trunk
- Files:
-
- 1 added
- 2 deleted
- 4 edited
-
README.md (deleted)
-
cleanup-wp.php (modified) (2 diffs)
-
includes/class-cleanup.php (modified) (7 diffs)
-
includes/class-optimize.php (modified) (2 diffs)
-
includes/class-plugin.php (modified) (7 diffs)
-
languages (deleted)
-
readme.txt (added)
Legend:
- Unmodified
- Added
- Removed
-
cleanup-wp/trunk/cleanup-wp.php
r3443030 r3443059 6 6 * Author: Aris Kuckovic 7 7 * Author URI: https://branchout.dk/ 8 * Version: 2.2. 08 * Version: 2.2.1 9 9 * License: GPLv2 or later 10 * License URI: https://www.gnu.org/licenses/gpl-2.0.html 10 11 * Text Domain: cleanup-wp 11 * Domain Path: /languages12 12 * Requires at least: 6.0 13 13 * Requires PHP: 7.4 … … 18 18 defined('ABSPATH') || exit; 19 19 20 define('CLEANUP_WP_VERSION', '2.2. 0');20 define('CLEANUP_WP_VERSION', '2.2.1'); 21 21 define('CLEANUP_WP_FILE', __FILE__); 22 22 define('CLEANUP_WP_DIR', plugin_dir_path(__FILE__)); -
cleanup-wp/trunk/includes/class-cleanup.php
r3443019 r3443059 275 275 } 276 276 277 /* translators: %d: Number of themes deleted */ 277 278 return $this->done(sprintf(__('%d theme(s) deleted.', 'cleanup-wp'), $count)); 278 279 } … … 407 408 return $this->already_done(); 408 409 } 410 /* translators: %s: Current category name */ 409 411 return '<span class="dashicons dashicons-category"></span> ' . sprintf(__('Will rename "%s" to "News"', 'cleanup-wp'), $term->name); 410 412 } … … 490 492 return $this->already_done(); 491 493 } 494 /* translators: %s: Timezone name */ 492 495 return '<span class="dashicons dashicons-clock"></span> ' . sprintf(__('Will set timezone to %s', 'cleanup-wp'), $tz); 493 496 } … … 497 500 update_option('timezone_string', $tz); 498 501 update_option('gmt_offset', ''); 502 /* translators: %s: Timezone name */ 499 503 return $this->done(sprintf(__('Timezone set to %s', 'cleanup-wp'), $tz)); 500 504 } … … 508 512 $page = get_post(get_option('page_on_front')); 509 513 if ($page) { 514 /* translators: %s: Page title */ 510 515 return $this->already_done(sprintf(__('Homepage is "%s"', 'cleanup-wp'), $page->post_title)); 511 516 } 512 517 } 513 518 $title = $options['homepage_title'] ?? __('Home', 'cleanup-wp'); 519 /* translators: %s: Page title */ 514 520 return '<span class="dashicons dashicons-admin-home"></span> ' . sprintf(__('Will create "%s" as homepage', 'cleanup-wp'), $title); 515 521 } … … 532 538 update_option('page_on_front', $page_id); 533 539 540 /* translators: %s: Page title */ 534 541 return $this->done(sprintf(__('Homepage "%s" created.', 'cleanup-wp'), $title)); 535 542 } … … 544 551 545 552 private function will_delete(string $what): string { 553 /* translators: %s: Name of item to be deleted */ 546 554 return '<span class="dashicons dashicons-trash"></span> ' . sprintf(__('Will delete: %s', 'cleanup-wp'), $what); 547 555 } -
cleanup-wp/trunk/includes/class-optimize.php
r3443019 r3443059 220 220 221 221 public function do_block_author_scans(): void { 222 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Security feature blocking enumeration attacks, no user form submission 222 223 if (isset($_GET['author']) && !is_admin()) { 223 wp_ redirect(home_url(), 301);224 wp_safe_redirect(home_url(), 301); 224 225 exit; 225 226 } … … 236 237 $wp_meta_boxes['dashboard'] = []; 237 238 238 wp_add_dashboard_widget('dashboard_site_health', __('Site Health Status' ), 'wp_dashboard_site_health');239 wp_add_dashboard_widget('dashboard_right_now', __('At a Glance' ), 'wp_dashboard_right_now');239 wp_add_dashboard_widget('dashboard_site_health', __('Site Health Status', 'cleanup-wp'), 'wp_dashboard_site_health'); 240 wp_add_dashboard_widget('dashboard_right_now', __('At a Glance', 'cleanup-wp'), 'wp_dashboard_right_now'); 240 241 } 241 242 } -
cleanup-wp/trunk/includes/class-plugin.php
r3443019 r3443059 29 29 30 30 private function init_hooks(): void { 31 add_action('init', [$this, 'load_textdomain']);32 31 add_action('admin_menu', [$this, 'add_admin_menu']); 33 32 add_action('admin_enqueue_scripts', [$this, 'enqueue_assets']); … … 40 39 // Apply active optimizations 41 40 $this->optimize->apply_active(); 42 }43 44 public function load_textdomain(): void {45 load_plugin_textdomain('cleanup-wp', false, dirname(plugin_basename(CLEANUP_WP_FILE)) . '/languages');46 41 } 47 42 … … 92 87 public function render_admin_page(): void { 93 88 if (!current_user_can('manage_options')) { 94 wp_die( __('Permission denied.', 'cleanup-wp'));89 wp_die(esc_html__('Permission denied.', 'cleanup-wp')); 95 90 } 96 91 … … 227 222 228 223 public function ajax_preview(): void { 229 $this->verify_request(); 230 231 $tasks = $this->get_posted_tasks(); 232 $options = $this->get_posted_options(); 224 if (!check_ajax_referer('cleanup_wp_nonce', 'nonce', false)) { 225 wp_send_json_error(['message' => __('Security check failed.', 'cleanup-wp')]); 226 } 227 if (!current_user_can('manage_options')) { 228 wp_send_json_error(['message' => __('Permission denied.', 'cleanup-wp')]); 229 } 230 231 // Get and validate tasks 232 $posted_tasks = isset($_POST['tasks']) && is_array($_POST['tasks']) 233 ? array_map('sanitize_text_field', wp_unslash($_POST['tasks'])) 234 : []; 235 236 // Get options 237 $options = isset($_POST['options']) && is_array($_POST['options']) 238 ? array_map('sanitize_text_field', wp_unslash($_POST['options'])) 239 : []; 240 233 241 $all_tasks = $this->cleanup->get_tasks(); 242 $valid_tasks = array_keys($all_tasks); 243 $tasks = array_intersect($posted_tasks, $valid_tasks); 234 244 $results = []; 235 245 … … 247 257 248 258 public function ajax_execute(): void { 249 $this->verify_request(); 250 251 $tasks = $this->get_posted_tasks(); 252 $options = $this->get_posted_options(); 259 if (!check_ajax_referer('cleanup_wp_nonce', 'nonce', false)) { 260 wp_send_json_error(['message' => __('Security check failed.', 'cleanup-wp')]); 261 } 262 if (!current_user_can('manage_options')) { 263 wp_send_json_error(['message' => __('Permission denied.', 'cleanup-wp')]); 264 } 265 266 // Get and validate tasks 267 $posted_tasks = isset($_POST['tasks']) && is_array($_POST['tasks']) 268 ? array_map('sanitize_text_field', wp_unslash($_POST['tasks'])) 269 : []; 270 271 // Get options 272 $options = isset($_POST['options']) && is_array($_POST['options']) 273 ? array_map('sanitize_text_field', wp_unslash($_POST['options'])) 274 : []; 275 253 276 $all_tasks = $this->cleanup->get_tasks(); 277 $valid_tasks = array_keys($all_tasks); 278 $tasks = array_intersect($posted_tasks, $valid_tasks); 279 254 280 $executed = get_option('cleanup_wp_executed', []); 255 281 if (!is_array($executed)) { … … 282 308 283 309 public function ajax_toggle(): void { 284 $this->verify_request(); 285 286 $option = sanitize_text_field($_POST['option'] ?? ''); 310 if (!check_ajax_referer('cleanup_wp_nonce', 'nonce', false)) { 311 wp_send_json_error(['message' => __('Security check failed.', 'cleanup-wp')]); 312 } 313 if (!current_user_can('manage_options')) { 314 wp_send_json_error(['message' => __('Permission denied.', 'cleanup-wp')]); 315 } 316 317 $option = isset($_POST['option']) ? sanitize_text_field(wp_unslash($_POST['option'])) : ''; 287 318 $enabled = !empty($_POST['enabled']); 288 319 … … 305 336 update_option('cleanup_wp_optimizations', $active); 306 337 338 if ($enabled) { 339 /* translators: %s: Name of the optimization option */ 340 $message = sprintf(__('%s enabled.', 'cleanup-wp'), $all_options[$option]['label']); 341 } else { 342 /* translators: %s: Name of the optimization option */ 343 $message = sprintf(__('%s disabled.', 'cleanup-wp'), $all_options[$option]['label']); 344 } 345 307 346 wp_send_json_success([ 308 347 'option' => $option, 309 348 'enabled' => $enabled, 310 'message' => $enabled 311 ? sprintf(__('%s enabled.', 'cleanup-wp'), $all_options[$option]['label']) 312 : sprintf(__('%s disabled.', 'cleanup-wp'), $all_options[$option]['label']), 349 'message' => $message, 313 350 ]); 314 351 } 315 316 private function verify_request(): void {317 if (!check_ajax_referer('cleanup_wp_nonce', 'nonce', false)) {318 wp_send_json_error(['message' => __('Security check failed.', 'cleanup-wp')]);319 }320 321 if (!current_user_can('manage_options')) {322 wp_send_json_error(['message' => __('Permission denied.', 'cleanup-wp')]);323 }324 }325 326 private function get_posted_tasks(): array {327 $tasks = isset($_POST['tasks']) ? array_map('sanitize_text_field', $_POST['tasks']) : [];328 $valid = array_keys($this->cleanup->get_tasks());329 return array_intersect($tasks, $valid);330 }331 332 private function get_posted_options(): array {333 $options = isset($_POST['options']) ? $_POST['options'] : [];334 return array_map('sanitize_text_field', $options);335 }336 352 }
Note: See TracChangeset
for help on using the changeset viewer.