From b7b001964b2b9bfa3de3fd39c0255dc5d6e28e08 Mon Sep 17 00:00:00 2001 From: Dominik Schilling Date: Mon, 11 Mar 2019 09:45:53 +0200 Subject: [PATCH] Apply fixes for new coding standards --- classes/class-wp-widget-disable.php | 6 +++--- phpcs.xml.dist | 2 +- uninstall.php | 29 +++++++++++------------------ views/admin.php | 11 +++-------- wp-widget-disable.php | 4 ++-- 5 files changed, 20 insertions(+), 32 deletions(-) diff --git a/classes/class-wp-widget-disable.php b/classes/class-wp-widget-disable.php index f43c9b5..0806174 100644 --- a/classes/class-wp-widget-disable.php +++ b/classes/class-wp-widget-disable.php @@ -192,7 +192,7 @@ public function has_settings_errors() { public function save_network_options() { $data = []; - // phpcs:disable WordPress.CSRF.NonceVerification.NoNonceVerification + // phpcs:disable WordPress.Security.NonceVerification if ( isset( $_POST[ $this->dashboard_widgets_option ] ) ) { $data = $this->sanitize_dashboard_widgets( $_POST[ $this->dashboard_widgets_option ] ); } @@ -401,7 +401,7 @@ public function sanitize_sidebar_widgets( $input ) { // Check to see if the current option has a value. If so, process it. if ( isset( $input[ $key ] ) ) { // Strip all HTML and PHP tags and properly handle quoted strings. - $output[ $key ] = strip_tags( stripslashes( $input[ $key ] ) ); + $output[ $key ] = wp_strip_all_tags( stripslashes( $input[ $key ] ) ); } } @@ -462,7 +462,7 @@ public function sanitize_dashboard_widgets( $input ) { // Check to see if the current option has a value. If so, process it. if ( isset( $input[ $key ] ) ) { // Strip all HTML and PHP tags and properly handle quoted strings. - $output[ $key ] = strip_tags( stripslashes( $input[ $key ] ) ); + $output[ $key ] = wp_strip_all_tags( stripslashes( $input[ $key ] ) ); } } diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 0c2acf2..b4168dc 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -17,7 +17,7 @@ - + diff --git a/uninstall.php b/uninstall.php index cf765b1..dcbd65c 100644 --- a/uninstall.php +++ b/uninstall.php @@ -1,38 +1,31 @@ - * @license GPL-2.0+ - * @link http://wp.required.ch/plugins/wp-widget-disable - * @copyright 2015 required gmbh + * Included when the plugin is uninstalled. */ defined( 'WP_UNINSTALL_PLUGIN' ) || die; -$options = [ +$widget_disable_options = [ 'rplus_wp_widget_disable_sidebar_option', 'rplus_wp_widget_disable_dashboard_option', ]; if ( ! is_multisite() ) { - foreach ( $options as $option ) { - delete_option( $option ); + foreach ( $widget_disable_options as $widget_disable_option ) { + delete_option( $widget_disable_option ); } } else { global $wpdb; - $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" ); - $original_blog_id = get_current_blog_id(); + $widget_disable_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" ); - foreach ( $blog_ids as $blog_id ) { - switch_to_blog( $blog_id ); + foreach ( $widget_disable_ids as $widget_disable_id ) { + switch_to_blog( $widget_disable_id ); - foreach ( $options as $option ) { - delete_option( $option ); + foreach ( $widget_disable_options as $widget_disable_option ) { + delete_option( $widget_disable_option ); } - } - switch_to_blog( $original_blog_id ); + restore_current_blog( $widget_disable_id ); + } } diff --git a/views/admin.php b/views/admin.php index 3ca0add..8d7bdf3 100644 --- a/views/admin.php +++ b/views/admin.php @@ -3,15 +3,10 @@ * Represents the view for the administration dashboard. * * This includes the header, options, and other information that should provide - * The User Interface to the end user. - * - * @package WP_Widget_Disable - * @author Silvan Hagen - * @license GPL-2.0+ - * @link http://wp.required.ch/plugins/wp-widget-disable - * @copyright 2015 required gmbh + * the User Interface to the end user. */ +// phpcs:disable WordPress.NamingConventions, VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable -- Variables are not global. $sidebar_tab_url = add_query_arg( [ 'page' => 'wp-widget-disable', @@ -28,7 +23,7 @@ $active_tab = $this->sidebar_widgets_option; -// phpcs:ignore WordPress.CSRF.NonceVerification.NoNonceVerification +// phpcs:ignore WordPress.Security.NonceVerification if ( is_network_admin() || ( isset( $_GET['tab'] ) && 'dashboard' === $_GET['tab'] ) ) { $active_tab = $this->dashboard_widgets_option; } diff --git a/wp-widget-disable.php b/wp-widget-disable.php index 0b09fdc..084f7af 100644 --- a/wp-widget-disable.php +++ b/wp-widget-disable.php @@ -48,8 +48,8 @@ // Pull in the plugin classes and initialize. include __DIR__ . '/classes/class-wp-widget-disable.php'; - $wp_widget_disable = new WP_Widget_Disable(); - add_action( 'plugins_loaded', array( $wp_widget_disable, 'add_hooks' ) ); + $widget_disable = new WP_Widget_Disable(); + add_action( 'plugins_loaded', array( $widget_disable, 'add_hooks' ) ); } unset( $requirements_check );