From 6bf19478670f1f29e29b76b84c5cb07b11999c03 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 7 Jan 2016 22:16:35 +0100 Subject: [PATCH] Prevent TGMPA notice showing on WP core update pages. Prevents core/plugin/theme updates screens looking like: ![screenshot](http://snag.gy/mIFC6.jpg) --- class-tgm-plugin-activation.php | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/class-tgm-plugin-activation.php b/class-tgm-plugin-activation.php index 248d2245..4ea6d3a5 100755 --- a/class-tgm-plugin-activation.php +++ b/class-tgm-plugin-activation.php @@ -1001,7 +1001,7 @@ protected function activate_single_plugin( $file_path, $slug, $automatic = false */ public function notices() { // Remove nag on the install page / Return early if the nag message has been dismissed or user < author. - if ( $this->is_tgmpa_page() || get_user_meta( get_current_user_id(), 'tgmpa_dismissed_notice_' . $this->id, true ) || ! current_user_can( apply_filters( 'tgmpa_show_admin_notice_capability', 'publish_posts' ) ) ) { + if ( ( $this->is_tgmpa_page() || $this->is_core_update_page() ) || get_user_meta( get_current_user_id(), 'tgmpa_dismissed_notice_' . $this->id, true ) || ! current_user_can( apply_filters( 'tgmpa_show_admin_notice_capability', 'publish_posts' ) ) ) { return; } @@ -1600,6 +1600,35 @@ protected function is_tgmpa_page() { return isset( $_GET['page'] ) && $this->menu === $_GET['page']; } + /** + * Determine if we're on a WP Core installation/upgrade page. + * + * @since 2.x.x + * + * @return boolean True when on a WP Core installation/upgrade page, false otherwise. + */ + protected function is_core_update_page() { + // Current screen is not always available, most notably on the customizer screen. + if ( ! function_exists( 'get_current_screen' ) ) { + return false; + } + + $screen = get_current_screen(); + + if ( 'update-core' === $screen->base ) { + // Core update screen. + return true; + } elseif ( 'plugins' === $screen->base && isset( $_POST['action'] ) ) { // WPCS: CSRF ok. + // Plugins bulk update screen. + return true; + } elseif ( 'update' === $screen->base && isset( $_POST['action'] ) ) { // WPCS: CSRF ok. + // Individual updates (ajax call). + return true; + } + + return false; + } + /** * Retrieve the URL to the TGMPA Install page. *