Plugin Directory

Changeset 3443059


Ignore:
Timestamp:
01/20/2026 08:59:05 AM (2 months ago)
Author:
Kuckovic
Message:

Fixed errors after running "Plugin Check"

Location:
cleanup-wp/trunk
Files:
1 added
2 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • cleanup-wp/trunk/cleanup-wp.php

    r3443030 r3443059  
    66 * Author: Aris Kuckovic
    77 * Author URI: https://branchout.dk/
    8  * Version: 2.2.0
     8 * Version: 2.2.1
    99 * License: GPLv2 or later
     10 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
    1011 * Text Domain: cleanup-wp
    11  * Domain Path: /languages
    1212 * Requires at least: 6.0
    1313 * Requires PHP: 7.4
     
    1818defined('ABSPATH') || exit;
    1919
    20 define('CLEANUP_WP_VERSION', '2.2.0');
     20define('CLEANUP_WP_VERSION', '2.2.1');
    2121define('CLEANUP_WP_FILE', __FILE__);
    2222define('CLEANUP_WP_DIR', plugin_dir_path(__FILE__));
  • cleanup-wp/trunk/includes/class-cleanup.php

    r3443019 r3443059  
    275275        }
    276276
     277        /* translators: %d: Number of themes deleted */
    277278        return $this->done(sprintf(__('%d theme(s) deleted.', 'cleanup-wp'), $count));
    278279    }
     
    407408            return $this->already_done();
    408409        }
     410        /* translators: %s: Current category name */
    409411        return '<span class="dashicons dashicons-category"></span> ' . sprintf(__('Will rename "%s" to "News"', 'cleanup-wp'), $term->name);
    410412    }
     
    490492            return $this->already_done();
    491493        }
     494        /* translators: %s: Timezone name */
    492495        return '<span class="dashicons dashicons-clock"></span> ' . sprintf(__('Will set timezone to %s', 'cleanup-wp'), $tz);
    493496    }
     
    497500        update_option('timezone_string', $tz);
    498501        update_option('gmt_offset', '');
     502        /* translators: %s: Timezone name */
    499503        return $this->done(sprintf(__('Timezone set to %s', 'cleanup-wp'), $tz));
    500504    }
     
    508512            $page = get_post(get_option('page_on_front'));
    509513            if ($page) {
     514                /* translators: %s: Page title */
    510515                return $this->already_done(sprintf(__('Homepage is "%s"', 'cleanup-wp'), $page->post_title));
    511516            }
    512517        }
    513518        $title = $options['homepage_title'] ?? __('Home', 'cleanup-wp');
     519        /* translators: %s: Page title */
    514520        return '<span class="dashicons dashicons-admin-home"></span> ' . sprintf(__('Will create "%s" as homepage', 'cleanup-wp'), $title);
    515521    }
     
    532538        update_option('page_on_front', $page_id);
    533539
     540        /* translators: %s: Page title */
    534541        return $this->done(sprintf(__('Homepage "%s" created.', 'cleanup-wp'), $title));
    535542    }
     
    544551
    545552    private function will_delete(string $what): string {
     553        /* translators: %s: Name of item to be deleted */
    546554        return '<span class="dashicons dashicons-trash"></span> ' . sprintf(__('Will delete: %s', 'cleanup-wp'), $what);
    547555    }
  • cleanup-wp/trunk/includes/class-optimize.php

    r3443019 r3443059  
    220220
    221221    public function do_block_author_scans(): void {
     222        // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Security feature blocking enumeration attacks, no user form submission
    222223        if (isset($_GET['author']) && !is_admin()) {
    223             wp_redirect(home_url(), 301);
     224            wp_safe_redirect(home_url(), 301);
    224225            exit;
    225226        }
     
    236237        $wp_meta_boxes['dashboard'] = [];
    237238
    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');
    240241    }
    241242}
  • cleanup-wp/trunk/includes/class-plugin.php

    r3443019 r3443059  
    2929
    3030    private function init_hooks(): void {
    31         add_action('init', [$this, 'load_textdomain']);
    3231        add_action('admin_menu', [$this, 'add_admin_menu']);
    3332        add_action('admin_enqueue_scripts', [$this, 'enqueue_assets']);
     
    4039        // Apply active optimizations
    4140        $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');
    4641    }
    4742
     
    9287    public function render_admin_page(): void {
    9388        if (!current_user_can('manage_options')) {
    94             wp_die(__('Permission denied.', 'cleanup-wp'));
     89            wp_die(esc_html__('Permission denied.', 'cleanup-wp'));
    9590        }
    9691
     
    227222
    228223    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
    233241        $all_tasks = $this->cleanup->get_tasks();
     242        $valid_tasks = array_keys($all_tasks);
     243        $tasks = array_intersect($posted_tasks, $valid_tasks);
    234244        $results = [];
    235245
     
    247257
    248258    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
    253276        $all_tasks = $this->cleanup->get_tasks();
     277        $valid_tasks = array_keys($all_tasks);
     278        $tasks = array_intersect($posted_tasks, $valid_tasks);
     279
    254280        $executed = get_option('cleanup_wp_executed', []);
    255281        if (!is_array($executed)) {
     
    282308
    283309    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'])) : '';
    287318        $enabled = !empty($_POST['enabled']);
    288319
     
    305336        update_option('cleanup_wp_optimizations', $active);
    306337
     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
    307346        wp_send_json_success([
    308347            'option'  => $option,
    309348            '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,
    313350        ]);
    314351    }
    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     }
    336352}
Note: See TracChangeset for help on using the changeset viewer.