From b43dbbccaddea9884503c1ed0516692b62d80dd5 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 21 May 2015 06:09:43 +0200 Subject: [PATCH 1/5] Leaner loading: don't run on ajax calls --- class-tgm-plugin-activation.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/class-tgm-plugin-activation.php b/class-tgm-plugin-activation.php index d618b8ba..4a2569b9 100644 --- a/class-tgm-plugin-activation.php +++ b/class-tgm-plugin-activation.php @@ -288,13 +288,15 @@ protected function __construct() { public function init() { /** - * By default TGMPA only loads on the WP back-end. Using this filter you can overrule that behaviour. + * By default TGMPA only loads on the WP back-end and not in an Ajax call. Using this filter + * you can overrule that behaviour. * * @since 2.5.0 * - * @param bool $load Whether or not TGMPA should load. Defaults to the return of `is_admin()`. + * @param bool $load Whether or not TGMPA should load. + * Defaults to the return of `is_admin() && ! defined( 'DOING_AJAX' )`. */ - if ( true !== apply_filters( 'tgmpa_load', is_admin() ) ) { + if ( true !== apply_filters( 'tgmpa_load', ( is_admin() && ! defined( 'DOING_AJAX' ) ) ) ) { return; } From 1de22e2e60017710e75ea8e0e5c4337a33787734 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 21 May 2015 06:10:34 +0200 Subject: [PATCH 2/5] Leaner loading: only add the plugin action link filters if on the plugins.php page --- class-tgm-plugin-activation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/class-tgm-plugin-activation.php b/class-tgm-plugin-activation.php index 4a2569b9..934da172 100644 --- a/class-tgm-plugin-activation.php +++ b/class-tgm-plugin-activation.php @@ -405,7 +405,7 @@ public function init() { add_action( 'admin_enqueue_scripts', array( $this, 'thickbox' ) ); } - $this->add_plugin_action_link_filters(); + add_action( 'load-plugins.php', array( $this, 'add_plugin_action_link_filters' ), 1 ); } From 4ab6c79b834b49f413ad6873ce7dd53ac3b0176f Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 21 May 2015 06:14:08 +0200 Subject: [PATCH 3/5] (C)Leaner loading: don't accidentally run the bulk process twice. The bulk process is called before the table generation for install/update and during for activate. If the install/update call would be made with invalid data, the process would (unnecessarily) be run twice. --- class-tgm-plugin-activation.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/class-tgm-plugin-activation.php b/class-tgm-plugin-activation.php index 934da172..382c2f63 100644 --- a/class-tgm-plugin-activation.php +++ b/class-tgm-plugin-activation.php @@ -2907,8 +2907,8 @@ public function prepare_items() { $sortable = array(); // No reason to make sortable columns. $this->_column_headers = array( $columns, $hidden, $sortable ); // Get all necessary column headers. - // Process our bulk actions here. - if ( false !== $this->current_action() ) { + // Process our bulk activations here. + if ( 'tgmpa-bulk-activate' === $this->current_action() ) { $this->process_bulk_actions(); } From 3e4830b0656d5d11e8bc3db7471a5dd69f1da623 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 21 May 2015 06:16:11 +0200 Subject: [PATCH 4/5] Better error messages for when no plugins were received to take action on. --- class-tgm-plugin-activation.php | 57 +++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 21 deletions(-) diff --git a/class-tgm-plugin-activation.php b/class-tgm-plugin-activation.php index 382c2f63..0a7cc3cd 100644 --- a/class-tgm-plugin-activation.php +++ b/class-tgm-plugin-activation.php @@ -2696,33 +2696,42 @@ public function process_bulk_actions() { } $plugins_to_install = array(); + + // Did user actually select any plugins to install/update ? + if ( empty( $_POST['plugin'] ) ) { + if ( 'install' === $install_type ) { + $message = __( 'No plugins were selected to be installed. No action taken.', 'tgmpa' ); + } else { + $message = __( 'No plugins were selected to be updated. No action taken.', 'tgmpa' ); + } - if ( ! empty( $_POST['plugin'] ) ) { + echo '

', esc_html( $message ), '

'; + return false; + } - if ( is_array( $_POST['plugin'] ) ) { - $plugins_to_install = (array) $_POST['plugin']; + if ( is_array( $_POST['plugin'] ) ) { + $plugins_to_install = (array) $_POST['plugin']; - } elseif ( is_string( $_POST['plugin'] ) ) { - // Received via Filesystem page - un-flatten array (WP bug #19643). - $plugins_to_install = explode( ',', $_POST['plugin'] ); - } + } elseif ( is_string( $_POST['plugin'] ) ) { + // Received via Filesystem page - un-flatten array (WP bug #19643). + $plugins_to_install = explode( ',', $_POST['plugin'] ); + } - // Sanitize the received input. - $plugins_to_install = array_map( 'urldecode', $plugins_to_install ); - $plugins_to_install = array_map( array( $this->tgmpa, 'sanitize_key' ), $plugins_to_install ); + // Sanitize the received input. + $plugins_to_install = array_map( 'urldecode', $plugins_to_install ); + $plugins_to_install = array_map( array( $this->tgmpa, 'sanitize_key' ), $plugins_to_install ); - // Validate the received input. - foreach ( $plugins_to_install as $key => $slug ) { - // Check if the plugin was registered with TGMPA and remove if not. - if ( ! isset( $this->tgmpa->plugins[ $slug ] ) ) { - unset( $plugins_to_install[ $key ] ); - continue; - } + // Validate the received input. + foreach ( $plugins_to_install as $key => $slug ) { + // Check if the plugin was registered with TGMPA and remove if not. + if ( ! isset( $this->tgmpa->plugins[ $slug ] ) ) { + unset( $plugins_to_install[ $key ] ); + continue; + } - // For updates: make sure this is a plugin we *can* update (update available and WP version ok). - if ( 'update' === $install_type && ( $this->tgmpa->is_plugin_installed( $slug ) && ( false === $this->tgmpa->does_plugin_have_update( $slug ) || ! $this->tgmpa->can_plugin_update( $slug ) ) ) ) { - unset( $plugins_to_install[ $key ] ); - } + // For updates: make sure this is a plugin we *can* update (update available and WP version ok). + if ( 'update' === $install_type && ( $this->tgmpa->is_plugin_installed( $slug ) && ( false === $this->tgmpa->does_plugin_have_update( $slug ) || ! $this->tgmpa->can_plugin_update( $slug ) ) ) ) { + unset( $plugins_to_install[ $key ] ); } } @@ -2833,6 +2842,12 @@ public function process_bulk_actions() { check_admin_referer( 'bulk-' . $this->_args['plural'] ); + // Did user actually select any plugins to activate ? + if ( empty( $_POST['plugin'] ) ) { + echo '

', esc_html__( 'No plugins were selected to be activated. No action taken.', 'tgmpa' ), '

'; + return false; + } + // Grab plugin data from $_POST. $plugins = array(); if ( isset( $_POST['plugin'] ) ) { From b4447dbe9dddfafc17b85eda54790625ce385438 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Wed, 3 Jun 2015 18:34:56 +0200 Subject: [PATCH 5/5] Typo --- class-tgm-plugin-activation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/class-tgm-plugin-activation.php b/class-tgm-plugin-activation.php index 0a7cc3cd..c98ad08a 100644 --- a/class-tgm-plugin-activation.php +++ b/class-tgm-plugin-activation.php @@ -395,7 +395,7 @@ public function init() { add_action( 'admin_menu', array( $this, 'admin_menu' ) ); add_action( 'admin_head', array( $this, 'dismiss' ) ); - // Prevent the normal links from showing underneath an single install/update page. + // Prevent the normal links from showing underneath a single install/update page. add_filter( 'install_plugin_complete_actions', array( $this, 'actions' ) ); add_filter( 'update_plugin_complete_actions', array( $this, 'actions' ) );