diff --git a/CHANGELOG.md b/CHANGELOG.md index 1654722..a5cb4ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +### [3.0.1] - 2024-09-19 + +* Enhancement: Code cleanup, ensuring WordPress 6.6 compatibility. + ### [3.0.0] - 2022-03-17 + * Fixed: Replace use of jQuery to avoid deprecation warnings. * Changed: Requires at least PHP 7.4 and WordPress 6.0. diff --git a/classes/class-wp-widget-disable.php b/classes/class-wp-widget-disable.php index a528e35..7f99ea4 100644 --- a/classes/class-wp-widget-disable.php +++ b/classes/class-wp-widget-disable.php @@ -51,7 +51,7 @@ class WP_Widget_Disable { /** * Adds hooks. */ - public function add_hooks() { + public function add_hooks(): void { add_action( 'init', [ $this, 'load_textdomain' ] ); // Add the options page and menu item. @@ -85,7 +85,7 @@ public function add_hooks() { * * @return string The URL to the plugin directory. */ - protected function get_url() { + protected function get_url(): string { return plugin_dir_url( __DIR__ ); } @@ -94,7 +94,7 @@ protected function get_url() { * * @return string The absolute path to the plugin directory. */ - protected function get_path() { + protected function get_path(): string { return plugin_dir_path( __DIR__ ); } @@ -105,14 +105,14 @@ protected function get_path() { * * @return string The plugin basename. */ - protected function get_basename() { + protected function get_basename(): string { return plugin_basename( $this->get_path() . 'wp-widget-disable.php' ); } /** * Initializes the plugin, registers textdomain, etc. */ - public function load_textdomain() { + public function load_textdomain(): void { load_plugin_textdomain( 'wp-widget-disable' ); } @@ -121,7 +121,7 @@ public function load_textdomain() { * * @since 1.0.0 */ - public function admin_menu() { + public function admin_menu(): void { if ( is_network_admin() ) { $this->page_hook = add_submenu_page( 'settings.php', @@ -151,7 +151,7 @@ public function admin_menu() { * * @since 2.0.0 */ - public function settings_page_load_callback() { + public function settings_page_load_callback(): void { $key = md5( $_SERVER['HTTP_USER_AGENT'] ); add_filter( 'pre_site_transient_browser_' . $key, '__return_null' ); @@ -166,7 +166,7 @@ public function settings_page_load_callback() { * * @since 1.6.0 */ - public function settings_page_callback() { + public function settings_page_callback(): void { include trailingslashit( $this->get_path() ) . 'views/admin.php'; } @@ -175,7 +175,7 @@ public function settings_page_callback() { * * @since 1.7.0 */ - public function settings_errors() { + public function settings_errors(): void { settings_errors( 'wp-widget-disable' ); } @@ -186,7 +186,7 @@ public function settings_errors() { * * @return bool True if settings errors exist, false if not. */ - public function has_settings_errors() { + public function has_settings_errors(): bool { return count( get_settings_errors( 'wp-widget-disable' ) ) > 0; } @@ -199,7 +199,7 @@ public function has_settings_errors() { * * @since 1.9.0 */ - public function save_network_options() { + public function save_network_options(): void { $data = []; // phpcs:disable WordPress.Security.NonceVerification @@ -234,10 +234,10 @@ public function save_network_options() { * * @since 1.0.0 * - * @param array $links Plugin action links. - * @return array + * @param mixed[] $links Plugin action links. + * @return mixed[] */ - public function plugin_action_links( array $links ) { + public function plugin_action_links( array $links ): array { $settings_url = add_query_arg( [ 'page' => 'wp-widget-disable' ], admin_url( 'themes.php' ) @@ -265,7 +265,7 @@ public function plugin_action_links( array $links ) { /** * Set the default sidebar widgets. */ - public function set_default_sidebar_widgets() { + public function set_default_sidebar_widgets(): void { $widgets = []; if ( ! empty( $GLOBALS['wp_widget_factory'] ) ) { @@ -283,9 +283,9 @@ public function set_default_sidebar_widgets() { /** * Get the default dashboard widgets. * - * @return array Sidebar widgets. + * @return mixed[] Sidebar widgets. */ - protected function get_default_dashboard_widgets() { + protected function get_default_dashboard_widgets(): array { global $wp_meta_boxes; $screen = is_network_admin() ? 'dashboard-network' : 'dashboard'; @@ -337,7 +337,7 @@ protected function get_default_dashboard_widgets() { * * @since 1.0.0 */ - public function disable_sidebar_widgets() { + public function disable_sidebar_widgets(): void { $widgets = (array) get_option( $this->sidebar_widgets_option, [] ); if ( ! empty( $widgets ) ) { foreach ( array_keys( $widgets ) as $widget_class ) { @@ -351,9 +351,9 @@ public function disable_sidebar_widgets() { * * @since 2.0.0 * - * @return array List of disabled widget IDs. + * @return mixed[] List of disabled widget IDs. */ - protected function get_disabled_dashboard_widgets() { + protected function get_disabled_dashboard_widgets(): array { $widgets = (array) get_option( $this->dashboard_widgets_option, [] ); if ( is_network_admin() ) { @@ -371,7 +371,7 @@ protected function get_disabled_dashboard_widgets() { * * @since 2.0.0 */ - public function disable_dashboard_widgets_with_remote_requests() { + public function disable_dashboard_widgets_with_remote_requests(): void { $widgets = $this->get_disabled_dashboard_widgets(); if ( ! $widgets ) { @@ -403,7 +403,7 @@ public function disable_dashboard_widgets_with_remote_requests() { * * @since 1.0.0 */ - public function disable_dashboard_widgets() { + public function disable_dashboard_widgets(): void { $widgets = $this->get_disabled_dashboard_widgets(); if ( ! $widgets ) { @@ -438,10 +438,10 @@ public function disable_dashboard_widgets() { * * @since 1.0.0 * - * @param array $input Sidebar widgets to disable. - * @return array + * @param mixed[] $input Sidebar widgets to disable. + * @return mixed[] */ - public function sanitize_sidebar_widgets( $input ) { + public function sanitize_sidebar_widgets( ?array $input ): array { // phpcs:ignore Squiz.Commenting.FunctionComment.IncorrectTypeHint -- mixed is not a valid type hint in PHP 7.4. // If there are settings errors the input was already sanitized. // See https://core.trac.wordpress.org/ticket/21989. if ( $this->has_settings_errors() ) { @@ -498,10 +498,10 @@ public function sanitize_sidebar_widgets( $input ) { * * @since 1.0.0 * - * @param array $input Dashboards widgets to disable. - * @return array + * @param mixed[] $input Dashboards widgets to disable. + * @return mixed[] */ - public function sanitize_dashboard_widgets( $input ) { + public function sanitize_dashboard_widgets( ?array $input ): array { // phpcs:ignore Squiz.Commenting.FunctionComment.IncorrectTypeHint -- mixed is not a valid type hint in PHP 7.4. // If there are settings errors the input was already sanitized. // See https://core.trac.wordpress.org/ticket/21989. if ( $this->has_settings_errors() ) { @@ -558,7 +558,7 @@ public function sanitize_dashboard_widgets( $input ) { * * @since 1.0.0 */ - public function register_settings() { + public function register_settings(): void { register_setting( $this->sidebar_widgets_option, $this->sidebar_widgets_option, @@ -568,7 +568,7 @@ public function register_settings() { add_settings_section( 'widget_disable_widget_section', __( 'Disable Sidebar Widgets', 'wp-widget-disable' ), - function () { + function (): void { echo '

'; _e( 'Choose the sidebar widgets you would like to disable. Note that developers can still display widgets using PHP.', 'wp-widget-disable' ); echo '

'; @@ -593,7 +593,7 @@ function () { add_settings_section( 'widget_disable_dashboard_section', __( 'Disable Dashboard Widgets', 'wp-widget-disable' ), - function () { + function (): void { echo '

'; _e( 'Choose the dashboard widgets you would like to disable.', 'wp-widget-disable' ); echo '

'; @@ -615,7 +615,7 @@ function () { * * @since 1.0.0 */ - public function render_sidebar_checkboxes() { + public function render_sidebar_checkboxes(): void { $widgets = $this->sidebar_widgets; $widgets = wp_list_sort( $widgets, [ 'name' => 'ASC' ], null, true ); @@ -663,7 +663,7 @@ public function render_sidebar_checkboxes() { * * @since 1.0.0 */ - public function render_dashboard_checkboxes() { + public function render_dashboard_checkboxes(): void { $widgets = $this->get_default_dashboard_widgets(); $flat_widgets = []; @@ -796,10 +796,8 @@ public function render_dashboard_checkboxes() { /** * Check if block editor is enabled for widgets. - * - * @return bool */ - public function use_widgets_block_editor() { + public function use_widgets_block_editor(): bool { if ( function_exists( 'wp_use_widgets_block_editor' ) ) { return wp_use_widgets_block_editor(); } @@ -809,9 +807,9 @@ public function use_widgets_block_editor() { /** * Get list of widgets to hide from legacy widget block. * - * @return array + * @return mixed[] */ - public function get_widgets_to_hide_from_legacy_widget_block() { + public function get_widgets_to_hide_from_legacy_widget_block(): array { if ( function_exists( 'get_legacy_widget_block_editor_settings' ) ) { return get_legacy_widget_block_editor_settings()['widgetTypesToHideFromLegacyWidgetBlock']; } diff --git a/composer.json b/composer.json index 1064573..e1f6115 100644 --- a/composer.json +++ b/composer.json @@ -21,8 +21,8 @@ }, "require-dev": { "dealerdirect/phpcodesniffer-composer-installer": "^0.7 || ^1.0", - "phpunit/phpunit": "^5 || ^7", - "wearerequired/coding-standards": "^1.6", + "phpunit/phpunit": "^7 || ^9", + "wearerequired/coding-standards": "^5.0", "yoast/phpunit-polyfills": "^1.0" }, "minimum-stability": "dev", diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 0bcca09..d376dff 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -4,6 +4,11 @@ . + + + + + diff --git a/readme.txt b/readme.txt index 6089b33..53a5166 100644 --- a/readme.txt +++ b/readme.txt @@ -1,8 +1,8 @@ # Widget Disable # -Contributors: wearerequired, neverything, swissspidy, ocean90, grapplerulrich +Contributors: wearerequired, neverything, swissspidy, ocean90, grapplerulrich, hubersen Tags: widgets, admin, dashboard, sidebar widgets, dashboard widgets, disable widgets Requires at least: 6.0 -Tested up to: 6.2 +Tested up to: 6.6 Requires PHP: 7.4 Stable tag: 3.0.0 License: GPLv2 or later @@ -44,6 +44,11 @@ Developed by [required](https://required.com/ "Team of experienced web professio ## Changelog +### 3.0.1 - 2024-09-19 + +* Enhancement: Code cleanup, ensuring WordPress 6.6 compatibility. + + ### 3.0.0 - 2023-03-26 * Fixed: Replace use of jQuery to avoid deprecation warnings. diff --git a/wp-widget-disable.php b/wp-widget-disable.php index 1996885..85a91d6 100644 --- a/wp-widget-disable.php +++ b/wp-widget-disable.php @@ -3,7 +3,7 @@ * Plugin Name: Widget Disable * Plugin URI: https://required.com/services/wordpress-plugins/wp-widget-disable/ * Description: Disable sidebar and dashboard widgets with an easy to use interface. Simply use the checkboxes provided under Appearance -> Disable Widgets and select the widgets you'd like to hide. - * Version: 3.0.0 + * Version: 3.0.1 * Requires at least: 6.0 * Requires PHP: 7.4 * Author: required @@ -11,7 +11,7 @@ * License: GPLv2+ * Text Domain: wp-widget-disable * - * Copyright (c) 2015-2023 required (email: support@required.ch) + * Copyright (c) 2015-2024 required (email: support@required.ch) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License, version 2 or, at