balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

class-tgm-plugin-activation.php (130156B)


      1 <?php
      2 /**
      3  * Plugin installation and activation for WordPress themes.
      4  *
      5  * Please note that this is a drop-in library for a theme or plugin.
      6  * The authors of this library (Thomas, Gary and Juliette) are NOT responsible
      7  * for the support of your plugin or theme. Please contact the plugin
      8  * or theme author for support.
      9  *
     10  * @package   TGM-Plugin-Activation
     11  * @version   2.6.1 for parent theme Marafi for publication on ThemeForest
     12  * @link      http://tgmpluginactivation.com/
     13  * @author    Thomas Griffin, Gary Jones, Juliette Reinders Folmer
     14  * @copyright Copyright (c) 2011, Thomas Griffin
     15  * @license   GPL-2.0+
     16  */
     17 
     18 /*
     19 	Copyright 2011 Thomas Griffin (thomasgriffinmedia.com)
     20 
     21 	This program is free software; you can redistribute it and/or modify
     22 	it under the terms of the GNU General Public License, version 2, as
     23 	published by the Free Software Foundation.
     24 
     25 	This program is distributed in the hope that it will be useful,
     26 	but WITHOUT ANY WARRANTY; without even the implied warranty of
     27 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     28 	GNU General Public License for more details.
     29 
     30 	You should have received a copy of the GNU General Public License
     31 	along with this program; if not, write to the Free Software
     32 	Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
     33 */
     34 
     35 if ( ! class_exists( 'TGM_Plugin_Activation' ) ) {
     36 
     37 	/**
     38 	 * Automatic plugin installation and activation library.
     39 	 *
     40 	 * Creates a way to automatically install and activate plugins from within themes.
     41 	 * The plugins can be either bundled, downloaded from the WordPress
     42 	 * Plugin Repository or downloaded from another external source.
     43 	 *
     44 	 * @since 1.0.0
     45 	 *
     46 	 * @package TGM-Plugin-Activation
     47 	 * @author  Thomas Griffin
     48 	 * @author  Gary Jones
     49 	 */
     50 	class TGM_Plugin_Activation {
     51 		/**
     52 		 * TGMPA version number.
     53 		 *
     54 		 * @since 2.5.0
     55 		 *
     56 		 * @const string Version number.
     57 		 */
     58 		const TGMPA_VERSION = '2.6.1';
     59 
     60 		/**
     61 		 * Regular expression to test if a URL is a WP plugin repo URL.
     62 		 *
     63 		 * @const string Regex.
     64 		 *
     65 		 * @since 2.5.0
     66 		 */
     67 		const WP_REPO_REGEX = '|^http[s]?://wordpress\.org/(?:extend/)?plugins/|';
     68 
     69 		/**
     70 		 * Arbitrary regular expression to test if a string starts with a URL.
     71 		 *
     72 		 * @const string Regex.
     73 		 *
     74 		 * @since 2.5.0
     75 		 */
     76 		const IS_URL_REGEX = '|^http[s]?://|';
     77 
     78 		/**
     79 		 * Holds a copy of itself, so it can be referenced by the class name.
     80 		 *
     81 		 * @since 1.0.0
     82 		 *
     83 		 * @var TGM_Plugin_Activation
     84 		 */
     85 		public static $instance;
     86 
     87 		/**
     88 		 * Holds arrays of plugin details.
     89 		 *
     90 		 * @since 1.0.0
     91 		 * @since 2.5.0 the array has the plugin slug as an associative key.
     92 		 *
     93 		 * @var array
     94 		 */
     95 		public $plugins = array();
     96 
     97 		/**
     98 		 * Holds arrays of plugin names to use to sort the plugins array.
     99 		 *
    100 		 * @since 2.5.0
    101 		 *
    102 		 * @var array
    103 		 */
    104 		protected $sort_order = array();
    105 
    106 		/**
    107 		 * Whether any plugins have the 'force_activation' setting set to true.
    108 		 *
    109 		 * @since 2.5.0
    110 		 *
    111 		 * @var bool
    112 		 */
    113 		protected $has_forced_activation = false;
    114 
    115 		/**
    116 		 * Whether any plugins have the 'force_deactivation' setting set to true.
    117 		 *
    118 		 * @since 2.5.0
    119 		 *
    120 		 * @var bool
    121 		 */
    122 		protected $has_forced_deactivation = false;
    123 
    124 		/**
    125 		 * Name of the unique ID to hash notices.
    126 		 *
    127 		 * @since 2.4.0
    128 		 *
    129 		 * @var string
    130 		 */
    131 		public $id = 'tgmpa';
    132 
    133 		/**
    134 		 * Name of the query-string argument for the admin page.
    135 		 *
    136 		 * @since 1.0.0
    137 		 *
    138 		 * @var string
    139 		 */
    140 		protected $menu = 'tgmpa-install-plugins';
    141 
    142 		/**
    143 		 * Parent menu file slug.
    144 		 *
    145 		 * @since 2.5.0
    146 		 *
    147 		 * @var string
    148 		 */
    149 		public $parent_slug = 'themes.php';
    150 
    151 		/**
    152 		 * Capability needed to view the plugin installation menu item.
    153 		 *
    154 		 * @since 2.5.0
    155 		 *
    156 		 * @var string
    157 		 */
    158 		public $capability = 'edit_theme_options';
    159 
    160 		/**
    161 		 * Default absolute path to folder containing bundled plugin zip files.
    162 		 *
    163 		 * @since 2.0.0
    164 		 *
    165 		 * @var string Absolute path prefix to zip file location for bundled plugins. Default is empty string.
    166 		 */
    167 		public $default_path = '';
    168 
    169 		/**
    170 		 * Flag to show admin notices or not.
    171 		 *
    172 		 * @since 2.1.0
    173 		 *
    174 		 * @var boolean
    175 		 */
    176 		public $has_notices = true;
    177 
    178 		/**
    179 		 * Flag to determine if the user can dismiss the notice nag.
    180 		 *
    181 		 * @since 2.4.0
    182 		 *
    183 		 * @var boolean
    184 		 */
    185 		public $dismissable = true;
    186 
    187 		/**
    188 		 * Message to be output above nag notice if dismissable is false.
    189 		 *
    190 		 * @since 2.4.0
    191 		 *
    192 		 * @var string
    193 		 */
    194 		public $dismiss_msg = '';
    195 
    196 		/**
    197 		 * Flag to set automatic activation of plugins. Off by default.
    198 		 *
    199 		 * @since 2.2.0
    200 		 *
    201 		 * @var boolean
    202 		 */
    203 		public $is_automatic = false;
    204 
    205 		/**
    206 		 * Optional message to display before the plugins table.
    207 		 *
    208 		 * @since 2.2.0
    209 		 *
    210 		 * @var string Message filtered by wp_kses_post(). Default is empty string.
    211 		 */
    212 		public $message = '';
    213 
    214 		/**
    215 		 * Holds configurable array of strings.
    216 		 *
    217 		 * Default values are added in the constructor.
    218 		 *
    219 		 * @since 2.0.0
    220 		 *
    221 		 * @var array
    222 		 */
    223 		public $strings = array();
    224 
    225 		/**
    226 		 * Holds the version of WordPress.
    227 		 *
    228 		 * @since 2.4.0
    229 		 *
    230 		 * @var int
    231 		 */
    232 		public $wp_version;
    233 
    234 		/**
    235 		 * Holds the hook name for the admin page.
    236 		 *
    237 		 * @since 2.5.0
    238 		 *
    239 		 * @var string
    240 		 */
    241 		public $page_hook;
    242 
    243 		/**
    244 		 * Adds a reference of this object to $instance, populates default strings,
    245 		 * does the tgmpa_init action hook, and hooks in the interactions to init.
    246 		 *
    247 		 * {@internal This method should be `protected`, but as too many TGMPA implementations
    248 		 * haven't upgraded beyond v2.3.6 yet, this gives backward compatibility issues.
    249 		 * Reverted back to public for the time being.}}
    250 		 *
    251 		 * @since 1.0.0
    252 		 *
    253 		 * @see TGM_Plugin_Activation::init()
    254 		 */
    255 		public function __construct() {
    256 			// Set the current WordPress version.
    257 			$this->wp_version = $GLOBALS['wp_version'];
    258 
    259 			// Announce that the class is ready, and pass the object (for advanced use).
    260 			do_action_ref_array( 'tgmpa_init', array( $this ) );
    261 
    262 			/*
    263 			 * Load our text domain and allow for overloading the fall-back file.
    264 			 *
    265 			 * {@internal IMPORTANT! If this code changes, review the regex in the custom TGMPA
    266 			 * generator on the website.}}
    267 			 */
    268 			add_action( 'init', array( $this, 'load_textdomain' ), 5 );
    269 			add_filter( 'load_textdomain_mofile', array( $this, 'overload_textdomain_mofile' ), 10, 2 );
    270 
    271 			// When the rest of WP has loaded, kick-start the rest of the class.
    272 			add_action( 'init', array( $this, 'init' ) );
    273 		}
    274 
    275 		/**
    276 		 * Magic method to (not) set protected properties from outside of this class.
    277 		 *
    278 		 * {@internal hackedihack... There is a serious bug in v2.3.2 - 2.3.6  where the `menu` property
    279 		 * is being assigned rather than tested in a conditional, effectively rendering it useless.
    280 		 * This 'hack' prevents this from happening.}}
    281 		 *
    282 		 * @see https://github.com/TGMPA/TGM-Plugin-Activation/blob/2.3.6/tgm-plugin-activation/class-tgm-plugin-activation.php#L1593
    283 		 *
    284 		 * @since 2.5.2
    285 		 *
    286 		 * @param string $name  Name of an inaccessible property.
    287 		 * @param mixed  $value Value to assign to the property.
    288 		 * @return void  Silently fail to set the property when this is tried from outside of this class context.
    289 		 *               (Inside this class context, the __set() method if not used as there is direct access.)
    290 		 */
    291 		public function __set( $name, $value ) {
    292 			return;
    293 		}
    294 
    295 		/**
    296 		 * Magic method to get the value of a protected property outside of this class context.
    297 		 *
    298 		 * @since 2.5.2
    299 		 *
    300 		 * @param string $name Name of an inaccessible property.
    301 		 * @return mixed The property value.
    302 		 */
    303 		public function __get( $name ) {
    304 			return $this->{$name};
    305 		}
    306 
    307 		/**
    308 		 * Initialise the interactions between this class and WordPress.
    309 		 *
    310 		 * Hooks in three new methods for the class: admin_menu, notices and styles.
    311 		 *
    312 		 * @since 2.0.0
    313 		 *
    314 		 * @see TGM_Plugin_Activation::admin_menu()
    315 		 * @see TGM_Plugin_Activation::notices()
    316 		 * @see TGM_Plugin_Activation::styles()
    317 		 */
    318 		public function init() {
    319 			/**
    320 			 * By default TGMPA only loads on the WP back-end and not in an Ajax call. Using this filter
    321 			 * you can overrule that behaviour.
    322 			 *
    323 			 * @since 2.5.0
    324 			 *
    325 			 * @param bool $load Whether or not TGMPA should load.
    326 			 *                   Defaults to the return of `is_admin() && ! defined( 'DOING_AJAX' )`.
    327 			 */
    328 			if ( true !== apply_filters( 'tgmpa_load', ( is_admin() && ! defined( 'DOING_AJAX' ) ) ) ) {
    329 				return;
    330 			}
    331 
    332 			// Load class strings.
    333 			$this->strings = array(
    334 				'page_title'                      => esc_html__( 'Install Required Plugins', 'aapside' ),
    335 				'menu_title'                      => esc_html__( 'Install Plugins', 'aapside' ),
    336 				/* translators: %s: plugin name. */
    337 				'installing'                      => esc_html__( 'Installing Plugin: %s', 'aapside' ),
    338 				/* translators: %s: plugin name. */
    339 				'updating'                        => esc_html__( 'Updating Plugin: %s', 'aapside' ),
    340 				'oops'                            => esc_html__( 'Something went wrong with the plugin API.', 'aapside' ),
    341 				'notice_can_install_required'     => _n_noop(
    342 				/* translators: 1: plugin name(s). */
    343 					'This theme requires the following plugin: %1$s.',
    344 					'This theme requires the following plugins: %1$s.',
    345 					'aapside'
    346 				),
    347 				'notice_can_install_recommended'  => _n_noop(
    348 				/* translators: 1: plugin name(s). */
    349 					'This theme recommends the following plugin: %1$s.',
    350 					'This theme recommends the following plugins: %1$s.',
    351 					'aapside'
    352 				),
    353 				'notice_ask_to_update'            => _n_noop(
    354 				/* translators: 1: plugin name(s). */
    355 					'The following plugin needs to be updated to its latest version to ensure maximum compatibility with this theme: %1$s.',
    356 					'The following plugins need to be updated to their latest version to ensure maximum compatibility with this theme: %1$s.',
    357 					'aapside'
    358 				),
    359 				'notice_ask_to_update_maybe'      => _n_noop(
    360 				/* translators: 1: plugin name(s). */
    361 					'There is an update available for: %1$s.',
    362 					'There are updates available for the following plugins: %1$s.',
    363 					'aapside'
    364 				),
    365 				'notice_can_activate_required'    => _n_noop(
    366 				/* translators: 1: plugin name(s). */
    367 					'The following required plugin is currently inactive: %1$s.',
    368 					'The following required plugins are currently inactive: %1$s.',
    369 					'aapside'
    370 				),
    371 				'notice_can_activate_recommended' => _n_noop(
    372 				/* translators: 1: plugin name(s). */
    373 					'The following recommended plugin is currently inactive: %1$s.',
    374 					'The following recommended plugins are currently inactive: %1$s.',
    375 					'aapside'
    376 				),
    377 				'install_link'                    => _n_noop(
    378 					'Begin installing plugin',
    379 					'Begin installing plugins',
    380 					'aapside'
    381 				),
    382 				'update_link'                     => _n_noop(
    383 					'Begin updating plugin',
    384 					'Begin updating plugins',
    385 					'aapside'
    386 				),
    387 				'activate_link'                   => _n_noop(
    388 					'Begin activating plugin',
    389 					'Begin activating plugins',
    390 					'aapside'
    391 				),
    392 				'return'                          => esc_html__( 'Return to Required Plugins Installer', 'aapside' ),
    393 				'dashboard'                       => esc_html__( 'Return to the Dashboard', 'aapside' ),
    394 				'plugin_activated'                => esc_html__( 'Plugin activated successfully.', 'aapside' ),
    395 				'activated_successfully'          => esc_html__( 'The following plugin was activated successfully:', 'aapside' ),
    396 				/* translators: 1: plugin name. */
    397 				'plugin_already_active'           => esc_html__( 'No action taken. Plugin %1$s was already active.', 'aapside' ),
    398 				/* translators: 1: plugin name. */
    399 				'plugin_needs_higher_version'     => esc_html__( 'Plugin not activated. A higher version of %s is needed for this theme. Please update the plugin.', 'aapside' ),
    400 				/* translators: 1: dashboard link. */
    401 				'complete'                        => esc_html__( 'All plugins installed and activated successfully. %1$s', 'aapside' ),
    402 				'dismiss'                         => esc_html__( 'Dismiss this notice', 'aapside' ),
    403 				'notice_cannot_install_activate'  => esc_html__( 'There are one or more required or recommended plugins to install, update or activate.', 'aapside' ),
    404 				'contact_admin'                   => esc_html__( 'Please contact the administrator of this site for help.', 'aapside' ),
    405 			);
    406 
    407 			do_action( 'tgmpa_register' );
    408 
    409 			/* After this point, the plugins should be registered and the configuration set. */
    410 
    411 			// Proceed only if we have plugins to handle.
    412 			if ( empty( $this->plugins ) || ! is_array( $this->plugins ) ) {
    413 				return;
    414 			}
    415 
    416 			// Set up the menu and notices if we still have outstanding actions.
    417 			if ( true !== $this->is_tgmpa_complete() ) {
    418 				// Sort the plugins.
    419 				array_multisort( $this->sort_order, SORT_ASC, $this->plugins );
    420 
    421 				add_action( 'admin_menu', array( $this, 'admin_menu' ) );
    422 				add_action( 'admin_head', array( $this, 'dismiss' ) );
    423 
    424 				// Prevent the normal links from showing underneath a single install/update page.
    425 				add_filter( 'install_plugin_complete_actions', array( $this, 'actions' ) );
    426 				add_filter( 'update_plugin_complete_actions', array( $this, 'actions' ) );
    427 
    428 				if ( $this->has_notices ) {
    429 					add_action( 'admin_notices', array( $this, 'notices' ) );
    430 					add_action( 'admin_init', array( $this, 'admin_init' ), 1 );
    431 					add_action( 'admin_enqueue_scripts', array( $this, 'thickbox' ) );
    432 				}
    433 			}
    434 
    435 			// If needed, filter plugin action links.
    436 			add_action( 'load-plugins.php', array( $this, 'add_plugin_action_link_filters' ), 1 );
    437 
    438 			// Make sure things get reset on switch theme.
    439 			add_action( 'switch_theme', array( $this, 'flush_plugins_cache' ) );
    440 
    441 			if ( $this->has_notices ) {
    442 				add_action( 'switch_theme', array( $this, 'update_dismiss' ) );
    443 			}
    444 
    445 			// Setup the force activation hook.
    446 			if ( true === $this->has_forced_activation ) {
    447 				add_action( 'admin_init', array( $this, 'force_activation' ) );
    448 			}
    449 
    450 			// Setup the force deactivation hook.
    451 			if ( true === $this->has_forced_deactivation ) {
    452 				add_action( 'switch_theme', array( $this, 'force_deactivation' ) );
    453 			}
    454 		}
    455 
    456 		/**
    457 		 * Load translations.
    458 		 *
    459 		 * @since 2.6.0
    460 		 *
    461 		 * (@internal Uses `load_theme_textdomain()` rather than `load_plugin_textdomain()` to
    462 		 * get round the different ways of handling the path and deprecated notices being thrown
    463 		 * and such. For plugins, the actual file name will be corrected by a filter.}}
    464 		 *
    465 		 * {@internal IMPORTANT! If this function changes, review the regex in the custom TGMPA
    466 		 * generator on the website.}}
    467 		 */
    468 		public function load_textdomain() {
    469 			if ( is_textdomain_loaded( 'aapside' ) ) {
    470 				return;
    471 			}
    472 
    473 			if ( false !== strpos( __FILE__, WP_PLUGIN_DIR ) || false !== strpos( __FILE__, WPMU_PLUGIN_DIR ) ) {
    474 				// Plugin, we'll need to adjust the file name.
    475 				add_action( 'load_textdomain_mofile', array( $this, 'correct_plugin_mofile' ), 10, 2 );
    476 				load_theme_textdomain( 'aapside', dirname( __FILE__ ) . '/languages' );
    477 				remove_action( 'load_textdomain_mofile', array( $this, 'correct_plugin_mofile' ), 10 );
    478 			} else {
    479 				load_theme_textdomain( 'aapside', dirname( __FILE__ ) . '/languages' );
    480 			}
    481 		}
    482 
    483 		/**
    484 		 * Correct the .mo file name for (must-use) plugins.
    485 		 *
    486 		 * Themese use `/path/{locale}.mo` while plugins use `/path/{text-domain}-{locale}.mo`.
    487 		 *
    488 		 * {@internal IMPORTANT! If this function changes, review the regex in the custom TGMPA
    489 		 * generator on the website.}}
    490 		 *
    491 		 * @since 2.6.0
    492 		 *
    493 		 * @param string $mofile Full path to the target mofile.
    494 		 * @param string $domain The domain for which a language file is being loaded.
    495 		 * @return string $mofile
    496 		 */
    497 		public function correct_plugin_mofile( $mofile, $domain ) {
    498 			// Exit early if not our domain (just in case).
    499 			if ( 'aapside' !== $domain ) {
    500 				return $mofile;
    501 			}
    502 			return preg_replace( '`/([a-z]{2}_[A-Z]{2}.mo)$`', '/tgmpa-$1', $mofile );
    503 		}
    504 
    505 		/**
    506 		 * Potentially overload the fall-back translation file for the current language.
    507 		 *
    508 		 * WP, by default since WP 3.7, will load a local translation first and if none
    509 		 * can be found, will try and find a translation in the /wp-content/languages/ directory.
    510 		 * As this library is theme/plugin agnostic, translation files for TGMPA can exist both
    511 		 * in the WP_LANG_DIR /plugins/ subdirectory as well as in the /themes/ subdirectory.
    512 		 *
    513 		 * This method makes sure both directories are checked.
    514 		 *
    515 		 * {@internal IMPORTANT! If this function changes, review the regex in the custom TGMPA
    516 		 * generator on the website.}}
    517 		 *
    518 		 * @since 2.6.0
    519 		 *
    520 		 * @param string $mofile Full path to the target mofile.
    521 		 * @param string $domain The domain for which a language file is being loaded.
    522 		 * @return string $mofile
    523 		 */
    524 		public function overload_textdomain_mofile( $mofile, $domain ) {
    525 			// Exit early if not our domain, not a WP_LANG_DIR load or if the file exists and is readable.
    526 			if ( 'aapside' !== $domain || false === strpos( $mofile, WP_LANG_DIR ) || @is_readable( $mofile ) ) {
    527 				return $mofile;
    528 			}
    529 
    530 			// Current fallback file is not valid, let's try the alternative option.
    531 			if ( false !== strpos( $mofile, '/themes/' ) ) {
    532 				return str_replace( '/themes/', '/plugins/', $mofile );
    533 			} elseif ( false !== strpos( $mofile, '/plugins/' ) ) {
    534 				return str_replace( '/plugins/', '/themes/', $mofile );
    535 			} else {
    536 				return $mofile;
    537 			}
    538 		}
    539 
    540 		/**
    541 		 * Hook in plugin action link filters for the WP native plugins page.
    542 		 *
    543 		 * - Prevent activation of plugins which don't meet the minimum version requirements.
    544 		 * - Prevent deactivation of force-activated plugins.
    545 		 * - Add update notice if update available.
    546 		 *
    547 		 * @since 2.5.0
    548 		 */
    549 		public function add_plugin_action_link_filters() {
    550 			foreach ( $this->plugins as $slug => $plugin ) {
    551 				if ( false === $this->can_plugin_activate( $slug ) ) {
    552 					add_filter( 'plugin_action_links_' . $plugin['file_path'], array( $this, 'filter_plugin_action_links_activate' ), 20 );
    553 				}
    554 
    555 				if ( true === $plugin['force_activation'] ) {
    556 					add_filter( 'plugin_action_links_' . $plugin['file_path'], array( $this, 'filter_plugin_action_links_deactivate' ), 20 );
    557 				}
    558 
    559 				if ( false !== $this->does_plugin_require_update( $slug ) ) {
    560 					add_filter( 'plugin_action_links_' . $plugin['file_path'], array( $this, 'filter_plugin_action_links_update' ), 20 );
    561 				}
    562 			}
    563 		}
    564 
    565 		/**
    566 		 * Remove the 'Activate' link on the WP native plugins page if the plugin does not meet the
    567 		 * minimum version requirements.
    568 		 *
    569 		 * @since 2.5.0
    570 		 *
    571 		 * @param array $actions Action links.
    572 		 * @return array
    573 		 */
    574 		public function filter_plugin_action_links_activate( $actions ) {
    575 			unset( $actions['activate'] );
    576 
    577 			return $actions;
    578 		}
    579 
    580 		/**
    581 		 * Remove the 'Deactivate' link on the WP native plugins page if the plugin has been set to force activate.
    582 		 *
    583 		 * @since 2.5.0
    584 		 *
    585 		 * @param array $actions Action links.
    586 		 * @return array
    587 		 */
    588 		public function filter_plugin_action_links_deactivate( $actions ) {
    589 			unset( $actions['deactivate'] );
    590 
    591 			return $actions;
    592 		}
    593 
    594 		/**
    595 		 * Add a 'Requires update' link on the WP native plugins page if the plugin does not meet the
    596 		 * minimum version requirements.
    597 		 *
    598 		 * @since 2.5.0
    599 		 *
    600 		 * @param array $actions Action links.
    601 		 * @return array
    602 		 */
    603 		public function filter_plugin_action_links_update( $actions ) {
    604 			$actions['update'] = sprintf(
    605 				'<a href="%1$s" title="%2$s" class="edit">%3$s</a>',
    606 				esc_url( $this->get_tgmpa_status_url( 'update' ) ),
    607 				esc_attr__( 'This plugin needs to be updated to be compatible with your theme.', 'aapside' ),
    608 				esc_html__( 'Update Required', 'aapside' )
    609 			);
    610 
    611 			return $actions;
    612 		}
    613 
    614 		/**
    615 		 * Handles calls to show plugin information via links in the notices.
    616 		 *
    617 		 * We get the links in the admin notices to point to the TGMPA page, rather
    618 		 * than the typical plugin-install.php file, so we can prepare everything
    619 		 * beforehand.
    620 		 *
    621 		 * WP does not make it easy to show the plugin information in the thickbox -
    622 		 * here we have to require a file that includes a function that does the
    623 		 * main work of displaying it, enqueue some styles, set up some globals and
    624 		 * finally call that function before exiting.
    625 		 *
    626 		 * Down right easy once you know how...
    627 		 *
    628 		 * Returns early if not the TGMPA page.
    629 		 *
    630 		 * @since 2.1.0
    631 		 *
    632 		 * @global string $tab Used as iframe div class names, helps with styling
    633 		 * @global string $body_id Used as the iframe body ID, helps with styling
    634 		 *
    635 		 * @return null Returns early if not the TGMPA page.
    636 		 */
    637 		public function admin_init() {
    638 			if ( ! $this->is_tgmpa_page() ) {
    639 				return;
    640 			}
    641 
    642 			if ( isset( $_REQUEST['tab'] ) && 'plugin-information' === $_REQUEST['tab'] ) {
    643 				// Needed for install_plugin_information().
    644 				require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
    645 
    646 				wp_enqueue_style( 'plugin-install' );
    647 
    648 				global $tab, $body_id;
    649 				$body_id = 'plugin-information';
    650 				// @codingStandardsIgnoreStart
    651 				$tab     = 'plugin-information';
    652 				// @codingStandardsIgnoreEnd
    653 
    654 				install_plugin_information();
    655 
    656 				exit;
    657 			}
    658 		}
    659 
    660 		/**
    661 		 * Enqueue thickbox scripts/styles for plugin info.
    662 		 *
    663 		 * Thickbox is not automatically included on all admin pages, so we must
    664 		 * manually enqueue it for those pages.
    665 		 *
    666 		 * Thickbox is only loaded if the user has not dismissed the admin
    667 		 * notice or if there are any plugins left to install and activate.
    668 		 *
    669 		 * @since 2.1.0
    670 		 */
    671 		public function thickbox() {
    672 			if ( ! get_user_meta( get_current_user_id(), 'tgmpa_dismissed_notice_' . $this->id, true ) ) {
    673 				add_thickbox();
    674 			}
    675 		}
    676 
    677 		/**
    678 		 * Adds submenu page if there are plugin actions to take.
    679 		 *
    680 		 * This method adds the submenu page letting users know that a required
    681 		 * plugin needs to be installed.
    682 		 *
    683 		 * This page disappears once the plugin has been installed and activated.
    684 		 *
    685 		 * @since 1.0.0
    686 		 *
    687 		 * @see TGM_Plugin_Activation::init()
    688 		 * @see TGM_Plugin_Activation::install_plugins_page()
    689 		 *
    690 		 * @return null Return early if user lacks capability to install a plugin.
    691 		 */
    692 		public function admin_menu() {
    693 			// Make sure privileges are correct to see the page.
    694 			if ( ! current_user_can( 'install_plugins' ) ) {
    695 				return;
    696 			}
    697 
    698 			$args = apply_filters(
    699 				'tgmpa_admin_menu_args',
    700 				array(
    701 					'parent_slug' => $this->parent_slug,                     // Parent Menu slug.
    702 					'page_title'  => $this->strings['page_title'],           // Page title.
    703 					'menu_title'  => $this->strings['menu_title'],           // Menu title.
    704 					'capability'  => $this->capability,                      // Capability.
    705 					'menu_slug'   => $this->menu,                            // Menu slug.
    706 					'function'    => array( $this, 'install_plugins_page' ), // Callback.
    707 				)
    708 			);
    709 
    710 			$this->add_admin_menu( $args );
    711 		}
    712 
    713 		/**
    714 		 * Add the menu item.
    715 		 *
    716 		 * {@internal IMPORTANT! If this function changes, review the regex in the custom TGMPA
    717 		 * generator on the website.}}
    718 		 *
    719 		 * @since 2.5.0
    720 		 *
    721 		 * @param array $args Menu item configuration.
    722 		 */
    723 		protected function add_admin_menu( array $args ) {
    724 			$this->page_hook = add_theme_page( $args['page_title'], $args['menu_title'], $args['capability'], $args['menu_slug'], $args['function'] );
    725 		}
    726 
    727 		/**
    728 		 * Echoes plugin installation form.
    729 		 *
    730 		 * This method is the callback for the admin_menu method function.
    731 		 * This displays the admin page and form area where the user can select to install and activate the plugin.
    732 		 * Aborts early if we're processing a plugin installation action.
    733 		 *
    734 		 * @since 1.0.0
    735 		 *
    736 		 * @return null Aborts early if we're processing a plugin installation action.
    737 		 */
    738 		public function install_plugins_page() {
    739 			// Store new instance of plugin table in object.
    740 			$plugin_table = new TGMPA_List_Table;
    741 
    742 			// Return early if processing a plugin installation action.
    743 			if ( ( ( 'tgmpa-bulk-install' === $plugin_table->current_action() || 'tgmpa-bulk-update' === $plugin_table->current_action() ) && $plugin_table->process_bulk_actions() ) || $this->do_plugin_install() ) {
    744 				return;
    745 			}
    746 
    747 			// Force refresh of available plugin information so we'll know about manual updates/deletes.
    748 			wp_clean_plugins_cache( false );
    749 
    750 			?>
    751 			<div class="tgmpa wrap">
    752 				<h1><?php echo esc_html( get_admin_page_title() ); ?></h1>
    753 				<?php $plugin_table->prepare_items(); ?>
    754 
    755 				<?php
    756 				if ( ! empty( $this->message ) && is_string( $this->message ) ) {
    757 					echo wp_kses_post( $this->message );
    758 				}
    759 				?>
    760 				<?php $plugin_table->views(); ?>
    761 
    762 				<form id="tgmpa-plugins" action="" method="post">
    763 					<input type="hidden" name="tgmpa-page" value="<?php echo esc_attr( $this->menu ); ?>" />
    764 					<input type="hidden" name="plugin_status" value="<?php echo esc_attr( $plugin_table->view_context ); ?>" />
    765 					<?php $plugin_table->display(); ?>
    766 				</form>
    767 			</div>
    768 			<?php
    769 		}
    770 
    771 		/**
    772 		 * Installs, updates or activates a plugin depending on the action link clicked by the user.
    773 		 *
    774 		 * Checks the $_GET variable to see which actions have been
    775 		 * passed and responds with the appropriate method.
    776 		 *
    777 		 * Uses WP_Filesystem to process and handle the plugin installation
    778 		 * method.
    779 		 *
    780 		 * @since 1.0.0
    781 		 *
    782 		 * @uses WP_Filesystem
    783 		 * @uses WP_Error
    784 		 * @uses WP_Upgrader
    785 		 * @uses Plugin_Upgrader
    786 		 * @uses Plugin_Installer_Skin
    787 		 * @uses Plugin_Upgrader_Skin
    788 		 *
    789 		 * @return boolean True on success, false on failure.
    790 		 */
    791 		protected function do_plugin_install() {
    792 			if ( empty( $_GET['plugin'] ) ) {
    793 				return false;
    794 			}
    795 
    796 			// All plugin information will be stored in an array for processing.
    797 			$slug = $this->sanitize_key( urldecode( $_GET['plugin'] ) );
    798 
    799 			if ( ! isset( $this->plugins[ $slug ] ) ) {
    800 				return false;
    801 			}
    802 
    803 			// Was an install or upgrade action link clicked?
    804 			if ( ( isset( $_GET['tgmpa-install'] ) && 'install-plugin' === $_GET['tgmpa-install'] ) || ( isset( $_GET['tgmpa-update'] ) && 'update-plugin' === $_GET['tgmpa-update'] ) ) {
    805 
    806 				$install_type = 'install';
    807 				if ( isset( $_GET['tgmpa-update'] ) && 'update-plugin' === $_GET['tgmpa-update'] ) {
    808 					$install_type = 'update';
    809 				}
    810 
    811 				check_admin_referer( 'tgmpa-' . $install_type, 'tgmpa-nonce' );
    812 
    813 				// Pass necessary information via URL if WP_Filesystem is needed.
    814 				$url = wp_nonce_url(
    815 					add_query_arg(
    816 						array(
    817 							'plugin'                 => urlencode( $slug ),
    818 							'tgmpa-' . $install_type => $install_type . '-plugin',
    819 						),
    820 						$this->get_tgmpa_url()
    821 					),
    822 					'tgmpa-' . $install_type,
    823 					'tgmpa-nonce'
    824 				);
    825 
    826 				$method = ''; // Leave blank so WP_Filesystem can populate it as necessary.
    827 
    828 				if ( false === ( $creds = request_filesystem_credentials( esc_url_raw( $url ), $method, false, false, array() ) ) ) {
    829 					return true;
    830 				}
    831 
    832 				if ( ! WP_Filesystem( $creds ) ) {
    833 					request_filesystem_credentials( esc_url_raw( $url ), $method, true, false, array() ); // Setup WP_Filesystem.
    834 					return true;
    835 				}
    836 
    837 				/* If we arrive here, we have the filesystem. */
    838 
    839 				// Prep variables for Plugin_Installer_Skin class.
    840 				$extra         = array();
    841 				$extra['slug'] = $slug; // Needed for potentially renaming of directory name.
    842 				$source        = $this->get_download_url( $slug );
    843 				$api           = ( 'repo' === $this->plugins[ $slug ]['source_type'] ) ? $this->get_plugins_api( $slug ) : null;
    844 				$api           = ( false !== $api ) ? $api : null;
    845 
    846 				$url = add_query_arg(
    847 					array(
    848 						'action' => $install_type . '-plugin',
    849 						'plugin' => urlencode( $slug ),
    850 					),
    851 					'update.php'
    852 				);
    853 
    854 				if ( ! class_exists( 'Plugin_Upgrader', false ) ) {
    855 					require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
    856 				}
    857 
    858 				$title     = ( 'update' === $install_type ) ? $this->strings['updating'] : $this->strings['installing'];
    859 				$skin_args = array(
    860 					'type'   => ( 'bundled' !== $this->plugins[ $slug ]['source_type'] ) ? 'web' : 'upload',
    861 					'title'  => sprintf( $title, $this->plugins[ $slug ]['name'] ),
    862 					'url'    => esc_url_raw( $url ),
    863 					'nonce'  => $install_type . '-plugin_' . $slug,
    864 					'plugin' => '',
    865 					'api'    => $api,
    866 					'extra'  => $extra,
    867 				);
    868 				unset( $title );
    869 
    870 				if ( 'update' === $install_type ) {
    871 					$skin_args['plugin'] = $this->plugins[ $slug ]['file_path'];
    872 					$skin                = new Plugin_Upgrader_Skin( $skin_args );
    873 				} else {
    874 					$skin = new Plugin_Installer_Skin( $skin_args );
    875 				}
    876 
    877 				// Create a new instance of Plugin_Upgrader.
    878 				$upgrader = new Plugin_Upgrader( $skin );
    879 
    880 				// Perform the action and install the plugin from the $source urldecode().
    881 				add_filter( 'upgrader_source_selection', array( $this, 'maybe_adjust_source_dir' ), 1, 3 );
    882 
    883 				if ( 'update' === $install_type ) {
    884 					// Inject our info into the update transient.
    885 					$to_inject                    = array( $slug => $this->plugins[ $slug ] );
    886 					$to_inject[ $slug ]['source'] = $source;
    887 					$this->inject_update_info( $to_inject );
    888 
    889 					$upgrader->upgrade( $this->plugins[ $slug ]['file_path'] );
    890 				} else {
    891 					$upgrader->install( $source );
    892 				}
    893 
    894 				remove_filter( 'upgrader_source_selection', array( $this, 'maybe_adjust_source_dir' ), 1 );
    895 
    896 				// Make sure we have the correct file path now the plugin is installed/updated.
    897 				$this->populate_file_path( $slug );
    898 
    899 				// Only activate plugins if the config option is set to true and the plugin isn't
    900 				// already active (upgrade).
    901 				if ( $this->is_automatic && ! $this->is_plugin_active( $slug ) ) {
    902 					$plugin_activate = $upgrader->plugin_info(); // Grab the plugin info from the Plugin_Upgrader method.
    903 					if ( false === $this->activate_single_plugin( $plugin_activate, $slug, true ) ) {
    904 						return true; // Finish execution of the function early as we encountered an error.
    905 					}
    906 				}
    907 
    908 				$this->show_tgmpa_version();
    909 
    910 				// Display message based on if all plugins are now active or not.
    911 				if ( $this->is_tgmpa_complete() ) {
    912 					echo '<p>', sprintf( esc_html( $this->strings['complete'] ), '<a href="' . esc_url( self_admin_url() ) . '">' . esc_html__( 'Return to the Dashboard', 'aapside' ) . '</a>' ), '</p>';
    913 					echo '<style type="text/css">#adminmenu .wp-submenu li.current { display: none !important; }</style>';
    914 				} else {
    915 					echo '<p><a href="', esc_url( $this->get_tgmpa_url() ), '" target="_parent">', esc_html( $this->strings['return'] ), '</a></p>';
    916 				}
    917 
    918 				return true;
    919 			} elseif ( isset( $this->plugins[ $slug ]['file_path'], $_GET['tgmpa-activate'] ) && 'activate-plugin' === $_GET['tgmpa-activate'] ) {
    920 				// Activate action link was clicked.
    921 				check_admin_referer( 'tgmpa-activate', 'tgmpa-nonce' );
    922 
    923 				if ( false === $this->activate_single_plugin( $this->plugins[ $slug ]['file_path'], $slug ) ) {
    924 					return true; // Finish execution of the function early as we encountered an error.
    925 				}
    926 			}
    927 
    928 			return false;
    929 		}
    930 
    931 		/**
    932 		 * Inject information into the 'update_plugins' site transient as WP checks that before running an update.
    933 		 *
    934 		 * @since 2.5.0
    935 		 *
    936 		 * @param array $plugins The plugin information for the plugins which are to be updated.
    937 		 */
    938 		public function inject_update_info( $plugins ) {
    939 			$repo_updates = get_site_transient( 'update_plugins' );
    940 
    941 			if ( ! is_object( $repo_updates ) ) {
    942 				$repo_updates = new stdClass;
    943 			}
    944 
    945 			foreach ( $plugins as $slug => $plugin ) {
    946 				$file_path = $plugin['file_path'];
    947 
    948 				if ( empty( $repo_updates->response[ $file_path ] ) ) {
    949 					$repo_updates->response[ $file_path ] = new stdClass;
    950 				}
    951 
    952 				// We only really need to set package, but let's do all we can in case WP changes something.
    953 				$repo_updates->response[ $file_path ]->slug        = $slug;
    954 				$repo_updates->response[ $file_path ]->plugin      = $file_path;
    955 				$repo_updates->response[ $file_path ]->new_version = $plugin['version'];
    956 				$repo_updates->response[ $file_path ]->package     = $plugin['source'];
    957 				if ( empty( $repo_updates->response[ $file_path ]->url ) && ! empty( $plugin['external_url'] ) ) {
    958 					$repo_updates->response[ $file_path ]->url = $plugin['external_url'];
    959 				}
    960 			}
    961 
    962 			set_site_transient( 'update_plugins', $repo_updates );
    963 		}
    964 
    965 		/**
    966 		 * Adjust the plugin directory name if necessary.
    967 		 *
    968 		 * The final destination directory of a plugin is based on the subdirectory name found in the
    969 		 * (un)zipped source. In some cases - most notably GitHub repository plugin downloads -, this
    970 		 * subdirectory name is not the same as the expected slug and the plugin will not be recognized
    971 		 * as installed. This is fixed by adjusting the temporary unzipped source subdirectory name to
    972 		 * the expected plugin slug.
    973 		 *
    974 		 * @since 2.5.0
    975 		 *
    976 		 * @param string       $source        Path to upgrade/zip-file-name.tmp/subdirectory/.
    977 		 * @param string       $remote_source Path to upgrade/zip-file-name.tmp.
    978 		 * @param \WP_Upgrader $upgrader      Instance of the upgrader which installs the plugin.
    979 		 * @return string $source
    980 		 */
    981 		public function maybe_adjust_source_dir( $source, $remote_source, $upgrader ) {
    982 			if ( ! $this->is_tgmpa_page() || ! is_object( $GLOBALS['wp_filesystem'] ) ) {
    983 				return $source;
    984 			}
    985 
    986 			// Check for single file plugins.
    987 			$source_files = array_keys( $GLOBALS['wp_filesystem']->dirlist( $remote_source ) );
    988 			if ( 1 === count( $source_files ) && false === $GLOBALS['wp_filesystem']->is_dir( $source ) ) {
    989 				return $source;
    990 			}
    991 
    992 			// Multi-file plugin, let's see if the directory is correctly named.
    993 			$desired_slug = '';
    994 
    995 			// Figure out what the slug is supposed to be.
    996 			if ( false === $upgrader->bulk && ! empty( $upgrader->skin->options['extra']['slug'] ) ) {
    997 				$desired_slug = $upgrader->skin->options['extra']['slug'];
    998 			} else {
    999 				// Bulk installer contains less info, so fall back on the info registered here.
   1000 				foreach ( $this->plugins as $slug => $plugin ) {
   1001 					if ( ! empty( $upgrader->skin->plugin_names[ $upgrader->skin->i ] ) && $plugin['name'] === $upgrader->skin->plugin_names[ $upgrader->skin->i ] ) {
   1002 						$desired_slug = $slug;
   1003 						break;
   1004 					}
   1005 				}
   1006 				unset( $slug, $plugin );
   1007 			}
   1008 
   1009 			if ( ! empty( $desired_slug ) ) {
   1010 				$subdir_name = untrailingslashit( str_replace( trailingslashit( $remote_source ), '', $source ) );
   1011 
   1012 				if ( ! empty( $subdir_name ) && $subdir_name !== $desired_slug ) {
   1013 					$from_path = untrailingslashit( $source );
   1014 					$to_path   = trailingslashit( $remote_source ) . $desired_slug;
   1015 
   1016 					if ( true === $GLOBALS['wp_filesystem']->move( $from_path, $to_path ) ) {
   1017 						return trailingslashit( $to_path );
   1018 					} else {
   1019 						return new WP_Error( 'rename_failed', esc_html__( 'The remote plugin package does not contain a folder with the desired slug and renaming did not work.', 'aapside' ) . ' ' . esc_html__( 'Please contact the plugin provider and ask them to package their plugin according to the WordPress guidelines.', 'aapside' ), array( 'found' => $subdir_name, 'expected' => $desired_slug ) );
   1020 					}
   1021 				} elseif ( empty( $subdir_name ) ) {
   1022 					return new WP_Error( 'packaged_wrong', esc_html__( 'The remote plugin package consists of more than one file, but the files are not packaged in a folder.', 'aapside' ) . ' ' . esc_html__( 'Please contact the plugin provider and ask them to package their plugin according to the WordPress guidelines.', 'aapside' ), array( 'found' => $subdir_name, 'expected' => $desired_slug ) );
   1023 				}
   1024 			}
   1025 
   1026 			return $source;
   1027 		}
   1028 
   1029 		/**
   1030 		 * Activate a single plugin and send feedback about the result to the screen.
   1031 		 *
   1032 		 * @since 2.5.0
   1033 		 *
   1034 		 * @param string $file_path Path within wp-plugins/ to main plugin file.
   1035 		 * @param string $slug      Plugin slug.
   1036 		 * @param bool   $automatic Whether this is an automatic activation after an install. Defaults to false.
   1037 		 *                          This determines the styling of the output messages.
   1038 		 * @return bool False if an error was encountered, true otherwise.
   1039 		 */
   1040 		protected function activate_single_plugin( $file_path, $slug, $automatic = false ) {
   1041 			if ( $this->can_plugin_activate( $slug ) ) {
   1042 				$activate = activate_plugin( $file_path );
   1043 
   1044 				if ( is_wp_error( $activate ) ) {
   1045 					echo '<div id="message" class="error"><p>', wp_kses_post( $activate->get_error_message() ), '</p></div>',
   1046 					'<p><a href="', esc_url( $this->get_tgmpa_url() ), '" target="_parent">', esc_html( $this->strings['return'] ), '</a></p>';
   1047 
   1048 					return false; // End it here if there is an error with activation.
   1049 				} else {
   1050 					if ( ! $automatic ) {
   1051 						// Make sure message doesn't display again if bulk activation is performed
   1052 						// immediately after a single activation.
   1053 						if ( ! isset( $_POST['action'] ) ) { // WPCS: CSRF OK.
   1054 							echo '<div id="message" class="updated"><p>', esc_html( $this->strings['activated_successfully'] ), ' <strong>', esc_html( $this->plugins[ $slug ]['name'] ), '.</strong></p></div>';
   1055 						}
   1056 					} else {
   1057 						// Simpler message layout for use on the plugin install page.
   1058 						echo '<p>', esc_html( $this->strings['plugin_activated'] ), '</p>';
   1059 					}
   1060 				}
   1061 			} elseif ( $this->is_plugin_active( $slug ) ) {
   1062 				// No simpler message format provided as this message should never be encountered
   1063 				// on the plugin install page.
   1064 				echo '<div id="message" class="error"><p>',
   1065 				sprintf(
   1066 					esc_html( $this->strings['plugin_already_active'] ),
   1067 					'<strong>' . esc_html( $this->plugins[ $slug ]['name'] ) . '</strong>'
   1068 				),
   1069 				'</p></div>';
   1070 			} elseif ( $this->does_plugin_require_update( $slug ) ) {
   1071 				if ( ! $automatic ) {
   1072 					// Make sure message doesn't display again if bulk activation is performed
   1073 					// immediately after a single activation.
   1074 					if ( ! isset( $_POST['action'] ) ) { // WPCS: CSRF OK.
   1075 						echo '<div id="message" class="error"><p>',
   1076 						sprintf(
   1077 							esc_html( $this->strings['plugin_needs_higher_version'] ),
   1078 							'<strong>' . esc_html( $this->plugins[ $slug ]['name'] ) . '</strong>'
   1079 						),
   1080 						'</p></div>';
   1081 					}
   1082 				} else {
   1083 					// Simpler message layout for use on the plugin install page.
   1084 					echo '<p>', sprintf( esc_html( $this->strings['plugin_needs_higher_version'] ), esc_html( $this->plugins[ $slug ]['name'] ) ), '</p>';
   1085 				}
   1086 			}
   1087 
   1088 			return true;
   1089 		}
   1090 
   1091 		/**
   1092 		 * Echoes required plugin notice.
   1093 		 *
   1094 		 * Outputs a message telling users that a specific plugin is required for
   1095 		 * their theme. If appropriate, it includes a link to the form page where
   1096 		 * users can install and activate the plugin.
   1097 		 *
   1098 		 * Returns early if we're on the Install page.
   1099 		 *
   1100 		 * @since 1.0.0
   1101 		 *
   1102 		 * @global object $current_screen
   1103 		 *
   1104 		 * @return null Returns early if we're on the Install page.
   1105 		 */
   1106 		public function notices() {
   1107 			// Remove nag on the install page / Return early if the nag message has been dismissed or user < author.
   1108 			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' ) ) ) {
   1109 				return;
   1110 			}
   1111 
   1112 			// Store for the plugin slugs by message type.
   1113 			$message = array();
   1114 
   1115 			// Initialize counters used to determine plurality of action link texts.
   1116 			$install_link_count          = 0;
   1117 			$update_link_count           = 0;
   1118 			$activate_link_count         = 0;
   1119 			$total_required_action_count = 0;
   1120 
   1121 			foreach ( $this->plugins as $slug => $plugin ) {
   1122 				if ( $this->is_plugin_active( $slug ) && false === $this->does_plugin_have_update( $slug ) ) {
   1123 					continue;
   1124 				}
   1125 
   1126 				if ( ! $this->is_plugin_installed( $slug ) ) {
   1127 					if ( current_user_can( 'install_plugins' ) ) {
   1128 						$install_link_count++;
   1129 
   1130 						if ( true === $plugin['required'] ) {
   1131 							$message['notice_can_install_required'][] = $slug;
   1132 						} else {
   1133 							$message['notice_can_install_recommended'][] = $slug;
   1134 						}
   1135 					}
   1136 					if ( true === $plugin['required'] ) {
   1137 						$total_required_action_count++;
   1138 					}
   1139 				} else {
   1140 					if ( ! $this->is_plugin_active( $slug ) && $this->can_plugin_activate( $slug ) ) {
   1141 						if ( current_user_can( 'activate_plugins' ) ) {
   1142 							$activate_link_count++;
   1143 
   1144 							if ( true === $plugin['required'] ) {
   1145 								$message['notice_can_activate_required'][] = $slug;
   1146 							} else {
   1147 								$message['notice_can_activate_recommended'][] = $slug;
   1148 							}
   1149 						}
   1150 						if ( true === $plugin['required'] ) {
   1151 							$total_required_action_count++;
   1152 						}
   1153 					}
   1154 
   1155 					if ( $this->does_plugin_require_update( $slug ) || false !== $this->does_plugin_have_update( $slug ) ) {
   1156 
   1157 						if ( current_user_can( 'update_plugins' ) ) {
   1158 							$update_link_count++;
   1159 
   1160 							if ( $this->does_plugin_require_update( $slug ) ) {
   1161 								$message['notice_ask_to_update'][] = $slug;
   1162 							} elseif ( false !== $this->does_plugin_have_update( $slug ) ) {
   1163 								$message['notice_ask_to_update_maybe'][] = $slug;
   1164 							}
   1165 						}
   1166 						if ( true === $plugin['required'] ) {
   1167 							$total_required_action_count++;
   1168 						}
   1169 					}
   1170 				}
   1171 			}
   1172 			unset( $slug, $plugin );
   1173 
   1174 			// If we have notices to display, we move forward.
   1175 			if ( ! empty( $message ) || $total_required_action_count > 0 ) {
   1176 				krsort( $message ); // Sort messages.
   1177 				$rendered = '';
   1178 
   1179 				// As add_settings_error() wraps the final message in a <p> and as the final message can't be
   1180 				// filtered, using <p>'s in our html would render invalid html output.
   1181 				$line_template = '<span style="display: block; margin: 0.5em 0.5em 0 0; clear: both;">%s</span>' . "\n";
   1182 
   1183 				if ( ! current_user_can( 'activate_plugins' ) && ! current_user_can( 'install_plugins' ) && ! current_user_can( 'update_plugins' ) ) {
   1184 					$rendered  = esc_html( $this->strings['notice_cannot_install_activate'] ) . ' ' . esc_html( $this->strings['contact_admin'] );
   1185 					$rendered .= $this->create_user_action_links_for_notice( 0, 0, 0, $line_template );
   1186 				} else {
   1187 
   1188 					// If dismissable is false and a message is set, output it now.
   1189 					if ( ! $this->dismissable && ! empty( $this->dismiss_msg ) ) {
   1190 						$rendered .= sprintf( $line_template, wp_kses_post( $this->dismiss_msg ) );
   1191 					}
   1192 
   1193 					// Render the individual message lines for the notice.
   1194 					foreach ( $message as $type => $plugin_group ) {
   1195 						$linked_plugins = array();
   1196 
   1197 						// Get the external info link for a plugin if one is available.
   1198 						foreach ( $plugin_group as $plugin_slug ) {
   1199 							$linked_plugins[] = $this->get_info_link( $plugin_slug );
   1200 						}
   1201 						unset( $plugin_slug );
   1202 
   1203 						$count          = count( $plugin_group );
   1204 						$linked_plugins = array_map( array( 'TGMPA_Utils', 'wrap_in_em' ), $linked_plugins );
   1205 						$last_plugin    = array_pop( $linked_plugins ); // Pop off last name to prep for readability.
   1206 						$imploded       = empty( $linked_plugins ) ? $last_plugin : ( implode( ', ', $linked_plugins ) . ' ' . esc_html_x( 'and', 'plugin A *and* plugin B', 'aapside' ) . ' ' . $last_plugin );
   1207 
   1208 						$rendered .= sprintf(
   1209 							$line_template,
   1210 							sprintf(
   1211 								translate_nooped_plural( $this->strings[ $type ], $count, 'aapside' ),
   1212 								$imploded,
   1213 								$count
   1214 							)
   1215 						);
   1216 
   1217 					}
   1218 					unset( $type, $plugin_group, $linked_plugins, $count, $last_plugin, $imploded );
   1219 
   1220 					$rendered .= $this->create_user_action_links_for_notice( $install_link_count, $update_link_count, $activate_link_count, $line_template );
   1221 				}
   1222 
   1223 				// Register the nag messages and prepare them to be processed.
   1224 				add_settings_error( 'tgmpa', 'tgmpa', $rendered, $this->get_admin_notice_class() );
   1225 			}
   1226 
   1227 			// Admin options pages already output settings_errors, so this is to avoid duplication.
   1228 			if ( 'options-general' !== $GLOBALS['current_screen']->parent_base ) {
   1229 				$this->display_settings_errors();
   1230 			}
   1231 		}
   1232 
   1233 		/**
   1234 		 * Generate the user action links for the admin notice.
   1235 		 *
   1236 		 * @since 2.6.0
   1237 		 *
   1238 		 * @param int $install_count  Number of plugins to install.
   1239 		 * @param int $update_count   Number of plugins to update.
   1240 		 * @param int $activate_count Number of plugins to activate.
   1241 		 * @param int $line_template  Template for the HTML tag to output a line.
   1242 		 * @return string Action links.
   1243 		 */
   1244 		protected function create_user_action_links_for_notice( $install_count, $update_count, $activate_count, $line_template ) {
   1245 			// Setup action links.
   1246 			$action_links = array(
   1247 				'install'  => '',
   1248 				'update'   => '',
   1249 				'activate' => '',
   1250 				'dismiss'  => $this->dismissable ? '<a href="' . esc_url( wp_nonce_url( add_query_arg( 'tgmpa-dismiss', 'dismiss_admin_notices' ), 'tgmpa-dismiss-' . get_current_user_id() ) ) . '" class="dismiss-notice" target="_parent">' . esc_html( $this->strings['dismiss'] ) . '</a>' : '',
   1251 			);
   1252 
   1253 			$link_template = '<a href="%2$s">%1$s</a>';
   1254 
   1255 			if ( current_user_can( 'install_plugins' ) ) {
   1256 				if ( $install_count > 0 ) {
   1257 					$action_links['install'] = sprintf(
   1258 						$link_template,
   1259 						translate_nooped_plural( $this->strings['install_link'], $install_count, 'aapside' ),
   1260 						esc_url( $this->get_tgmpa_status_url( 'install' ) )
   1261 					);
   1262 				}
   1263 				if ( $update_count > 0 ) {
   1264 					$action_links['update'] = sprintf(
   1265 						$link_template,
   1266 						translate_nooped_plural( $this->strings['update_link'], $update_count, 'aapside' ),
   1267 						esc_url( $this->get_tgmpa_status_url( 'update' ) )
   1268 					);
   1269 				}
   1270 			}
   1271 
   1272 			if ( current_user_can( 'activate_plugins' ) && $activate_count > 0 ) {
   1273 				$action_links['activate'] = sprintf(
   1274 					$link_template,
   1275 					translate_nooped_plural( $this->strings['activate_link'], $activate_count, 'aapside' ),
   1276 					esc_url( $this->get_tgmpa_status_url( 'activate' ) )
   1277 				);
   1278 			}
   1279 
   1280 			$action_links = apply_filters( 'tgmpa_notice_action_links', $action_links );
   1281 
   1282 			$action_links = array_filter( (array) $action_links ); // Remove any empty array items.
   1283 
   1284 			if ( ! empty( $action_links ) ) {
   1285 				$action_links = sprintf( $line_template, implode( ' | ', $action_links ) );
   1286 				return apply_filters( 'tgmpa_notice_rendered_action_links', $action_links );
   1287 			} else {
   1288 				return '';
   1289 			}
   1290 		}
   1291 
   1292 		/**
   1293 		 * Get admin notice class.
   1294 		 *
   1295 		 * Work around all the changes to the various admin notice classes between WP 4.4 and 3.7
   1296 		 * (lowest supported version by TGMPA).
   1297 		 *
   1298 		 * @since 2.6.0
   1299 		 *
   1300 		 * @return string
   1301 		 */
   1302 		protected function get_admin_notice_class() {
   1303 			if ( ! empty( $this->strings['nag_type'] ) ) {
   1304 				return sanitize_html_class( strtolower( $this->strings['nag_type'] ) );
   1305 			} else {
   1306 				if ( version_compare( $this->wp_version, '4.2', '>=' ) ) {
   1307 					return 'notice-warning';
   1308 				} elseif ( version_compare( $this->wp_version, '4.1', '>=' ) ) {
   1309 					return 'notice';
   1310 				} else {
   1311 					return 'updated';
   1312 				}
   1313 			}
   1314 		}
   1315 
   1316 		/**
   1317 		 * Display settings errors and remove those which have been displayed to avoid duplicate messages showing
   1318 		 *
   1319 		 * @since 2.5.0
   1320 		 */
   1321 		protected function display_settings_errors() {
   1322 			global $wp_settings_errors;
   1323 
   1324 			settings_errors( 'tgmpa' );
   1325 
   1326 			foreach ( (array) $wp_settings_errors as $key => $details ) {
   1327 				if ( 'tgmpa' === $details['setting'] ) {
   1328 					unset( $wp_settings_errors[ $key ] );
   1329 					break;
   1330 				}
   1331 			}
   1332 		}
   1333 
   1334 		/**
   1335 		 * Register dismissal of admin notices.
   1336 		 *
   1337 		 * Acts on the dismiss link in the admin nag messages.
   1338 		 * If clicked, the admin notice disappears and will no longer be visible to this user.
   1339 		 *
   1340 		 * @since 2.1.0
   1341 		 */
   1342 		public function dismiss() {
   1343 			if ( isset( $_GET['tgmpa-dismiss'] ) && check_admin_referer( 'tgmpa-dismiss-' . get_current_user_id() ) ) {
   1344 				update_user_meta( get_current_user_id(), 'tgmpa_dismissed_notice_' . $this->id, 1 );
   1345 			}
   1346 		}
   1347 
   1348 		/**
   1349 		 * Add individual plugin to our collection of plugins.
   1350 		 *
   1351 		 * If the required keys are not set or the plugin has already
   1352 		 * been registered, the plugin is not added.
   1353 		 *
   1354 		 * @since 2.0.0
   1355 		 *
   1356 		 * @param array|null $plugin Array of plugin arguments or null if invalid argument.
   1357 		 * @return null Return early if incorrect argument.
   1358 		 */
   1359 		public function register( $plugin ) {
   1360 			if ( empty( $plugin['slug'] ) || empty( $plugin['name'] ) ) {
   1361 				return;
   1362 			}
   1363 
   1364 			if ( empty( $plugin['slug'] ) || ! is_string( $plugin['slug'] ) || isset( $this->plugins[ $plugin['slug'] ] ) ) {
   1365 				return;
   1366 			}
   1367 
   1368 			$defaults = array(
   1369 				'name'               => '',      // String
   1370 				'slug'               => '',      // String
   1371 				'source'             => 'repo',  // String
   1372 				'required'           => false,   // Boolean
   1373 				'version'            => '',      // String
   1374 				'force_activation'   => false,   // Boolean
   1375 				'force_deactivation' => false,   // Boolean
   1376 				'external_url'       => '',      // String
   1377 				'is_callable'        => '',      // String|Array.
   1378 			);
   1379 
   1380 			// Prepare the received data.
   1381 			$plugin = wp_parse_args( $plugin, $defaults );
   1382 
   1383 			// Standardize the received slug.
   1384 			$plugin['slug'] = $this->sanitize_key( $plugin['slug'] );
   1385 
   1386 			// Forgive users for using string versions of booleans or floats for version number.
   1387 			$plugin['version']            = (string) $plugin['version'];
   1388 			$plugin['source']             = empty( $plugin['source'] ) ? 'repo' : $plugin['source'];
   1389 			$plugin['required']           = TGMPA_Utils::validate_bool( $plugin['required'] );
   1390 			$plugin['force_activation']   = TGMPA_Utils::validate_bool( $plugin['force_activation'] );
   1391 			$plugin['force_deactivation'] = TGMPA_Utils::validate_bool( $plugin['force_deactivation'] );
   1392 
   1393 			// Enrich the received data.
   1394 			$plugin['file_path']   = $this->_get_plugin_basename_from_slug( $plugin['slug'] );
   1395 			$plugin['source_type'] = $this->get_plugin_source_type( $plugin['source'] );
   1396 
   1397 			// Set the class properties.
   1398 			$this->plugins[ $plugin['slug'] ]    = $plugin;
   1399 			$this->sort_order[ $plugin['slug'] ] = $plugin['name'];
   1400 
   1401 			// Should we add the force activation hook ?
   1402 			if ( true === $plugin['force_activation'] ) {
   1403 				$this->has_forced_activation = true;
   1404 			}
   1405 
   1406 			// Should we add the force deactivation hook ?
   1407 			if ( true === $plugin['force_deactivation'] ) {
   1408 				$this->has_forced_deactivation = true;
   1409 			}
   1410 		}
   1411 
   1412 		/**
   1413 		 * Determine what type of source the plugin comes from.
   1414 		 *
   1415 		 * @since 2.5.0
   1416 		 *
   1417 		 * @param string $source The source of the plugin as provided, either empty (= WP repo), a file path
   1418 		 *                       (= bundled) or an external URL.
   1419 		 * @return string 'repo', 'external', or 'bundled'
   1420 		 */
   1421 		protected function get_plugin_source_type( $source ) {
   1422 			if ( 'repo' === $source || preg_match( self::WP_REPO_REGEX, $source ) ) {
   1423 				return 'repo';
   1424 			} elseif ( preg_match( self::IS_URL_REGEX, $source ) ) {
   1425 				return 'external';
   1426 			} else {
   1427 				return 'bundled';
   1428 			}
   1429 		}
   1430 
   1431 		/**
   1432 		 * Sanitizes a string key.
   1433 		 *
   1434 		 * Near duplicate of WP Core `sanitize_key()`. The difference is that uppercase characters *are*
   1435 		 * allowed, so as not to break upgrade paths from non-standard bundled plugins using uppercase
   1436 		 * characters in the plugin directory path/slug. Silly them.
   1437 		 *
   1438 		 * @see https://developer.wordpress.org/reference/hooks/sanitize_key/
   1439 		 *
   1440 		 * @since 2.5.0
   1441 		 *
   1442 		 * @param string $key String key.
   1443 		 * @return string Sanitized key
   1444 		 */
   1445 		public function sanitize_key( $key ) {
   1446 			$raw_key = $key;
   1447 			$key     = preg_replace( '`[^A-Za-z0-9_-]`', '', $key );
   1448 
   1449 			/**
   1450 			 * Filter a sanitized key string.
   1451 			 *
   1452 			 * @since 2.5.0
   1453 			 *
   1454 			 * @param string $key     Sanitized key.
   1455 			 * @param string $raw_key The key prior to sanitization.
   1456 			 */
   1457 			return apply_filters( 'tgmpa_sanitize_key', $key, $raw_key );
   1458 		}
   1459 
   1460 		/**
   1461 		 * Amend default configuration settings.
   1462 		 *
   1463 		 * @since 2.0.0
   1464 		 *
   1465 		 * @param array $config Array of config options to pass as class properties.
   1466 		 */
   1467 		public function config( $config ) {
   1468 			$keys = array(
   1469 				'id',
   1470 				'default_path',
   1471 				'has_notices',
   1472 				'dismissable',
   1473 				'dismiss_msg',
   1474 				'menu',
   1475 				'parent_slug',
   1476 				'capability',
   1477 				'is_automatic',
   1478 				'message',
   1479 				'strings',
   1480 			);
   1481 
   1482 			foreach ( $keys as $key ) {
   1483 				if ( isset( $config[ $key ] ) ) {
   1484 					if ( is_array( $config[ $key ] ) ) {
   1485 						$this->$key = array_merge( $this->$key, $config[ $key ] );
   1486 					} else {
   1487 						$this->$key = $config[ $key ];
   1488 					}
   1489 				}
   1490 			}
   1491 		}
   1492 
   1493 		/**
   1494 		 * Amend action link after plugin installation.
   1495 		 *
   1496 		 * @since 2.0.0
   1497 		 *
   1498 		 * @param array $install_actions Existing array of actions.
   1499 		 * @return false|array Amended array of actions.
   1500 		 */
   1501 		public function actions( $install_actions ) {
   1502 			// Remove action links on the TGMPA install page.
   1503 			if ( $this->is_tgmpa_page() ) {
   1504 				return false;
   1505 			}
   1506 
   1507 			return $install_actions;
   1508 		}
   1509 
   1510 		/**
   1511 		 * Flushes the plugins cache on theme switch to prevent stale entries
   1512 		 * from remaining in the plugin table.
   1513 		 *
   1514 		 * @since 2.4.0
   1515 		 *
   1516 		 * @param bool $clear_update_cache Optional. Whether to clear the Plugin updates cache.
   1517 		 *                                 Parameter added in v2.5.0.
   1518 		 */
   1519 		public function flush_plugins_cache( $clear_update_cache = true ) {
   1520 			wp_clean_plugins_cache( $clear_update_cache );
   1521 		}
   1522 
   1523 		/**
   1524 		 * Set file_path key for each installed plugin.
   1525 		 *
   1526 		 * @since 2.1.0
   1527 		 *
   1528 		 * @param string $plugin_slug Optional. If set, only (re-)populates the file path for that specific plugin.
   1529 		 *                            Parameter added in v2.5.0.
   1530 		 */
   1531 		public function populate_file_path( $plugin_slug = '' ) {
   1532 			if ( ! empty( $plugin_slug ) && is_string( $plugin_slug ) && isset( $this->plugins[ $plugin_slug ] ) ) {
   1533 				$this->plugins[ $plugin_slug ]['file_path'] = $this->_get_plugin_basename_from_slug( $plugin_slug );
   1534 			} else {
   1535 				// Add file_path key for all plugins.
   1536 				foreach ( $this->plugins as $slug => $values ) {
   1537 					$this->plugins[ $slug ]['file_path'] = $this->_get_plugin_basename_from_slug( $slug );
   1538 				}
   1539 			}
   1540 		}
   1541 
   1542 		/**
   1543 		 * Helper function to extract the file path of the plugin file from the
   1544 		 * plugin slug, if the plugin is installed.
   1545 		 *
   1546 		 * @since 2.0.0
   1547 		 *
   1548 		 * @param string $slug Plugin slug (typically folder name) as provided by the developer.
   1549 		 * @return string Either file path for plugin if installed, or just the plugin slug.
   1550 		 */
   1551 		protected function _get_plugin_basename_from_slug( $slug ) {
   1552 			$keys = array_keys( $this->get_plugins() );
   1553 
   1554 			foreach ( $keys as $key ) {
   1555 				if ( preg_match( '|^' . $slug . '/|', $key ) ) {
   1556 					return $key;
   1557 				}
   1558 			}
   1559 
   1560 			return $slug;
   1561 		}
   1562 
   1563 		/**
   1564 		 * Retrieve plugin data, given the plugin name.
   1565 		 *
   1566 		 * Loops through the registered plugins looking for $name. If it finds it,
   1567 		 * it returns the $data from that plugin. Otherwise, returns false.
   1568 		 *
   1569 		 * @since 2.1.0
   1570 		 *
   1571 		 * @param string $name Name of the plugin, as it was registered.
   1572 		 * @param string $data Optional. Array key of plugin data to return. Default is slug.
   1573 		 * @return string|boolean Plugin slug if found, false otherwise.
   1574 		 */
   1575 		public function _get_plugin_data_from_name( $name, $data = 'slug' ) {
   1576 			foreach ( $this->plugins as $values ) {
   1577 				if ( $name === $values['name'] && isset( $values[ $data ] ) ) {
   1578 					return $values[ $data ];
   1579 				}
   1580 			}
   1581 
   1582 			return false;
   1583 		}
   1584 
   1585 		/**
   1586 		 * Retrieve the download URL for a package.
   1587 		 *
   1588 		 * @since 2.5.0
   1589 		 *
   1590 		 * @param string $slug Plugin slug.
   1591 		 * @return string Plugin download URL or path to local file or empty string if undetermined.
   1592 		 */
   1593 		public function get_download_url( $slug ) {
   1594 			$dl_source = '';
   1595 
   1596 			switch ( $this->plugins[ $slug ]['source_type'] ) {
   1597 				case 'repo':
   1598 					return $this->get_wp_repo_download_url( $slug );
   1599 				case 'external':
   1600 					return $this->plugins[ $slug ]['source'];
   1601 				case 'bundled':
   1602 					return $this->default_path . $this->plugins[ $slug ]['source'];
   1603 			}
   1604 
   1605 			return $dl_source; // Should never happen.
   1606 		}
   1607 
   1608 		/**
   1609 		 * Retrieve the download URL for a WP repo package.
   1610 		 *
   1611 		 * @since 2.5.0
   1612 		 *
   1613 		 * @param string $slug Plugin slug.
   1614 		 * @return string Plugin download URL.
   1615 		 */
   1616 		protected function get_wp_repo_download_url( $slug ) {
   1617 			$source = '';
   1618 			$api    = $this->get_plugins_api( $slug );
   1619 
   1620 			if ( false !== $api && isset( $api->download_link ) ) {
   1621 				$source = $api->download_link;
   1622 			}
   1623 
   1624 			return $source;
   1625 		}
   1626 
   1627 		/**
   1628 		 * Try to grab information from WordPress API.
   1629 		 *
   1630 		 * @since 2.5.0
   1631 		 *
   1632 		 * @param string $slug Plugin slug.
   1633 		 * @return object Plugins_api response object on success, WP_Error on failure.
   1634 		 */
   1635 		protected function get_plugins_api( $slug ) {
   1636 			static $api = array(); // Cache received responses.
   1637 
   1638 			if ( ! isset( $api[ $slug ] ) ) {
   1639 				if ( ! function_exists( 'plugins_api' ) ) {
   1640 					require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
   1641 				}
   1642 
   1643 				$response = plugins_api( 'plugin_information', array( 'slug' => $slug, 'fields' => array( 'sections' => false ) ) );
   1644 
   1645 				$api[ $slug ] = false;
   1646 
   1647 				if ( is_wp_error( $response ) ) {
   1648 					wp_die( esc_html( $this->strings['oops'] ) );
   1649 				} else {
   1650 					$api[ $slug ] = $response;
   1651 				}
   1652 			}
   1653 
   1654 			return $api[ $slug ];
   1655 		}
   1656 
   1657 		/**
   1658 		 * Retrieve a link to a plugin information page.
   1659 		 *
   1660 		 * @since 2.5.0
   1661 		 *
   1662 		 * @param string $slug Plugin slug.
   1663 		 * @return string Fully formed html link to a plugin information page if available
   1664 		 *                or the plugin name if not.
   1665 		 */
   1666 		public function get_info_link( $slug ) {
   1667 			if ( ! empty( $this->plugins[ $slug ]['external_url'] ) && preg_match( self::IS_URL_REGEX, $this->plugins[ $slug ]['external_url'] ) ) {
   1668 				$link = sprintf(
   1669 					'<a href="%1$s" target="_blank">%2$s</a>',
   1670 					esc_url( $this->plugins[ $slug ]['external_url'] ),
   1671 					esc_html( $this->plugins[ $slug ]['name'] )
   1672 				);
   1673 			} elseif ( 'repo' === $this->plugins[ $slug ]['source_type'] ) {
   1674 				$url = add_query_arg(
   1675 					array(
   1676 						'tab'       => 'plugin-information',
   1677 						'plugin'    => urlencode( $slug ),
   1678 						'TB_iframe' => 'true',
   1679 						'width'     => '640',
   1680 						'height'    => '500',
   1681 					),
   1682 					self_admin_url( 'plugin-install.php' )
   1683 				);
   1684 
   1685 				$link = sprintf(
   1686 					'<a href="%1$s" class="thickbox">%2$s</a>',
   1687 					esc_url( $url ),
   1688 					esc_html( $this->plugins[ $slug ]['name'] )
   1689 				);
   1690 			} else {
   1691 				$link = esc_html( $this->plugins[ $slug ]['name'] ); // No hyperlink.
   1692 			}
   1693 
   1694 			return $link;
   1695 		}
   1696 
   1697 		/**
   1698 		 * Determine if we're on the TGMPA Install page.
   1699 		 *
   1700 		 * @since 2.1.0
   1701 		 *
   1702 		 * @return boolean True when on the TGMPA page, false otherwise.
   1703 		 */
   1704 		protected function is_tgmpa_page() {
   1705 			return isset( $_GET['page'] ) && $this->menu === $_GET['page'];
   1706 		}
   1707 
   1708 		/**
   1709 		 * Determine if we're on a WP Core installation/upgrade page.
   1710 		 *
   1711 		 * @since 2.6.0
   1712 		 *
   1713 		 * @return boolean True when on a WP Core installation/upgrade page, false otherwise.
   1714 		 */
   1715 		protected function is_core_update_page() {
   1716 			// Current screen is not always available, most notably on the customizer screen.
   1717 			if ( ! function_exists( 'get_current_screen' ) ) {
   1718 				return false;
   1719 			}
   1720 
   1721 			$screen = get_current_screen();
   1722 
   1723 			if ( 'update-core' === $screen->base ) {
   1724 				// Core update screen.
   1725 				return true;
   1726 			} elseif ( 'plugins' === $screen->base && ! empty( $_POST['action'] ) ) { // WPCS: CSRF ok.
   1727 				// Plugins bulk update screen.
   1728 				return true;
   1729 			} elseif ( 'update' === $screen->base && ! empty( $_POST['action'] ) ) { // WPCS: CSRF ok.
   1730 				// Individual updates (ajax call).
   1731 				return true;
   1732 			}
   1733 
   1734 			return false;
   1735 		}
   1736 
   1737 		/**
   1738 		 * Retrieve the URL to the TGMPA Install page.
   1739 		 *
   1740 		 * I.e. depending on the config settings passed something along the lines of:
   1741 		 * http://example.com/wp-admin/themes.php?page=tgmpa-install-plugins
   1742 		 *
   1743 		 * @since 2.5.0
   1744 		 *
   1745 		 * @return string Properly encoded URL (not escaped).
   1746 		 */
   1747 		public function get_tgmpa_url() {
   1748 			static $url;
   1749 
   1750 			if ( ! isset( $url ) ) {
   1751 				$parent = $this->parent_slug;
   1752 				if ( false === strpos( $parent, '.php' ) ) {
   1753 					$parent = 'admin.php';
   1754 				}
   1755 				$url = add_query_arg(
   1756 					array(
   1757 						'page' => urlencode( $this->menu ),
   1758 					),
   1759 					self_admin_url( $parent )
   1760 				);
   1761 			}
   1762 
   1763 			return $url;
   1764 		}
   1765 
   1766 		/**
   1767 		 * Retrieve the URL to the TGMPA Install page for a specific plugin status (view).
   1768 		 *
   1769 		 * I.e. depending on the config settings passed something along the lines of:
   1770 		 * http://example.com/wp-admin/themes.php?page=tgmpa-install-plugins&plugin_status=install
   1771 		 *
   1772 		 * @since 2.5.0
   1773 		 *
   1774 		 * @param string $status Plugin status - either 'install', 'update' or 'activate'.
   1775 		 * @return string Properly encoded URL (not escaped).
   1776 		 */
   1777 		public function get_tgmpa_status_url( $status ) {
   1778 			return add_query_arg(
   1779 				array(
   1780 					'plugin_status' => urlencode( $status ),
   1781 				),
   1782 				$this->get_tgmpa_url()
   1783 			);
   1784 		}
   1785 
   1786 		/**
   1787 		 * Determine whether there are open actions for plugins registered with TGMPA.
   1788 		 *
   1789 		 * @since 2.5.0
   1790 		 *
   1791 		 * @return bool True if complete, i.e. no outstanding actions. False otherwise.
   1792 		 */
   1793 		public function is_tgmpa_complete() {
   1794 			$complete = true;
   1795 			foreach ( $this->plugins as $slug => $plugin ) {
   1796 				if ( ! $this->is_plugin_active( $slug ) || false !== $this->does_plugin_have_update( $slug ) ) {
   1797 					$complete = false;
   1798 					break;
   1799 				}
   1800 			}
   1801 
   1802 			return $complete;
   1803 		}
   1804 
   1805 		/**
   1806 		 * Check if a plugin is installed. Does not take must-use plugins into account.
   1807 		 *
   1808 		 * @since 2.5.0
   1809 		 *
   1810 		 * @param string $slug Plugin slug.
   1811 		 * @return bool True if installed, false otherwise.
   1812 		 */
   1813 		public function is_plugin_installed( $slug ) {
   1814 			$installed_plugins = $this->get_plugins(); // Retrieve a list of all installed plugins (WP cached).
   1815 
   1816 			return ( ! empty( $installed_plugins[ $this->plugins[ $slug ]['file_path'] ] ) );
   1817 		}
   1818 
   1819 		/**
   1820 		 * Check if a plugin is active.
   1821 		 *
   1822 		 * @since 2.5.0
   1823 		 *
   1824 		 * @param string $slug Plugin slug.
   1825 		 * @return bool True if active, false otherwise.
   1826 		 */
   1827 		public function is_plugin_active( $slug ) {
   1828 			return ( ( ! empty( $this->plugins[ $slug ]['is_callable'] ) && is_callable( $this->plugins[ $slug ]['is_callable'] ) ) || is_plugin_active( $this->plugins[ $slug ]['file_path'] ) );
   1829 		}
   1830 
   1831 		/**
   1832 		 * Check if a plugin can be updated, i.e. if we have information on the minimum WP version required
   1833 		 * available, check whether the current install meets them.
   1834 		 *
   1835 		 * @since 2.5.0
   1836 		 *
   1837 		 * @param string $slug Plugin slug.
   1838 		 * @return bool True if OK to update, false otherwise.
   1839 		 */
   1840 		public function can_plugin_update( $slug ) {
   1841 			// We currently can't get reliable info on non-WP-repo plugins - issue #380.
   1842 			if ( 'repo' !== $this->plugins[ $slug ]['source_type'] ) {
   1843 				return true;
   1844 			}
   1845 
   1846 			$api = $this->get_plugins_api( $slug );
   1847 
   1848 			if ( false !== $api && isset( $api->requires ) ) {
   1849 				return version_compare( $this->wp_version, $api->requires, '>=' );
   1850 			}
   1851 
   1852 			// No usable info received from the plugins API, presume we can update.
   1853 			return true;
   1854 		}
   1855 
   1856 		/**
   1857 		 * Check to see if the plugin is 'updatetable', i.e. installed, with an update available
   1858 		 * and no WP version requirements blocking it.
   1859 		 *
   1860 		 * @since 2.6.0
   1861 		 *
   1862 		 * @param string $slug Plugin slug.
   1863 		 * @return bool True if OK to proceed with update, false otherwise.
   1864 		 */
   1865 		public function is_plugin_updatetable( $slug ) {
   1866 			if ( ! $this->is_plugin_installed( $slug ) ) {
   1867 				return false;
   1868 			} else {
   1869 				return ( false !== $this->does_plugin_have_update( $slug ) && $this->can_plugin_update( $slug ) );
   1870 			}
   1871 		}
   1872 
   1873 		/**
   1874 		 * Check if a plugin can be activated, i.e. is not currently active and meets the minimum
   1875 		 * plugin version requirements set in TGMPA (if any).
   1876 		 *
   1877 		 * @since 2.5.0
   1878 		 *
   1879 		 * @param string $slug Plugin slug.
   1880 		 * @return bool True if OK to activate, false otherwise.
   1881 		 */
   1882 		public function can_plugin_activate( $slug ) {
   1883 			return ( ! $this->is_plugin_active( $slug ) && ! $this->does_plugin_require_update( $slug ) );
   1884 		}
   1885 
   1886 		/**
   1887 		 * Retrieve the version number of an installed plugin.
   1888 		 *
   1889 		 * @since 2.5.0
   1890 		 *
   1891 		 * @param string $slug Plugin slug.
   1892 		 * @return string Version number as string or an empty string if the plugin is not installed
   1893 		 *                or version unknown (plugins which don't comply with the plugin header standard).
   1894 		 */
   1895 		public function get_installed_version( $slug ) {
   1896 			$installed_plugins = $this->get_plugins(); // Retrieve a list of all installed plugins (WP cached).
   1897 
   1898 			if ( ! empty( $installed_plugins[ $this->plugins[ $slug ]['file_path'] ]['Version'] ) ) {
   1899 				return $installed_plugins[ $this->plugins[ $slug ]['file_path'] ]['Version'];
   1900 			}
   1901 
   1902 			return '';
   1903 		}
   1904 
   1905 		/**
   1906 		 * Check whether a plugin complies with the minimum version requirements.
   1907 		 *
   1908 		 * @since 2.5.0
   1909 		 *
   1910 		 * @param string $slug Plugin slug.
   1911 		 * @return bool True when a plugin needs to be updated, otherwise false.
   1912 		 */
   1913 		public function does_plugin_require_update( $slug ) {
   1914 			$installed_version = $this->get_installed_version( $slug );
   1915 			$minimum_version   = $this->plugins[ $slug ]['version'];
   1916 
   1917 			return version_compare( $minimum_version, $installed_version, '>' );
   1918 		}
   1919 
   1920 		/**
   1921 		 * Check whether there is an update available for a plugin.
   1922 		 *
   1923 		 * @since 2.5.0
   1924 		 *
   1925 		 * @param string $slug Plugin slug.
   1926 		 * @return false|string Version number string of the available update or false if no update available.
   1927 		 */
   1928 		public function does_plugin_have_update( $slug ) {
   1929 			// Presume bundled and external plugins will point to a package which meets the minimum required version.
   1930 			if ( 'repo' !== $this->plugins[ $slug ]['source_type'] ) {
   1931 				if ( $this->does_plugin_require_update( $slug ) ) {
   1932 					return $this->plugins[ $slug ]['version'];
   1933 				}
   1934 
   1935 				return false;
   1936 			}
   1937 
   1938 			$repo_updates = get_site_transient( 'update_plugins' );
   1939 
   1940 			if ( isset( $repo_updates->response[ $this->plugins[ $slug ]['file_path'] ]->new_version ) ) {
   1941 				return $repo_updates->response[ $this->plugins[ $slug ]['file_path'] ]->new_version;
   1942 			}
   1943 
   1944 			return false;
   1945 		}
   1946 
   1947 		/**
   1948 		 * Retrieve potential upgrade notice for a plugin.
   1949 		 *
   1950 		 * @since 2.5.0
   1951 		 *
   1952 		 * @param string $slug Plugin slug.
   1953 		 * @return string The upgrade notice or an empty string if no message was available or provided.
   1954 		 */
   1955 		public function get_upgrade_notice( $slug ) {
   1956 			// We currently can't get reliable info on non-WP-repo plugins - issue #380.
   1957 			if ( 'repo' !== $this->plugins[ $slug ]['source_type'] ) {
   1958 				return '';
   1959 			}
   1960 
   1961 			$repo_updates = get_site_transient( 'update_plugins' );
   1962 
   1963 			if ( ! empty( $repo_updates->response[ $this->plugins[ $slug ]['file_path'] ]->upgrade_notice ) ) {
   1964 				return $repo_updates->response[ $this->plugins[ $slug ]['file_path'] ]->upgrade_notice;
   1965 			}
   1966 
   1967 			return '';
   1968 		}
   1969 
   1970 		/**
   1971 		 * Wrapper around the core WP get_plugins function, making sure it's actually available.
   1972 		 *
   1973 		 * @since 2.5.0
   1974 		 *
   1975 		 * @param string $plugin_folder Optional. Relative path to single plugin folder.
   1976 		 * @return array Array of installed plugins with plugin information.
   1977 		 */
   1978 		public function get_plugins( $plugin_folder = '' ) {
   1979 			if ( ! function_exists( 'get_plugins' ) ) {
   1980 				require_once ABSPATH . 'wp-admin/includes/plugin.php';
   1981 			}
   1982 
   1983 			return get_plugins( $plugin_folder );
   1984 		}
   1985 
   1986 		/**
   1987 		 * Delete dismissable nag option when theme is switched.
   1988 		 *
   1989 		 * This ensures that the user(s) is/are again reminded via nag of required
   1990 		 * and/or recommended plugins if they re-activate the theme.
   1991 		 *
   1992 		 * @since 2.1.1
   1993 		 */
   1994 		public function update_dismiss() {
   1995 			delete_metadata( 'user', null, 'tgmpa_dismissed_notice_' . $this->id, null, true );
   1996 		}
   1997 
   1998 		/**
   1999 		 * Forces plugin activation if the parameter 'force_activation' is
   2000 		 * set to true.
   2001 		 *
   2002 		 * This allows theme authors to specify certain plugins that must be
   2003 		 * active at all times while using the current theme.
   2004 		 *
   2005 		 * Please take special care when using this parameter as it has the
   2006 		 * potential to be harmful if not used correctly. Setting this parameter
   2007 		 * to true will not allow the specified plugin to be deactivated unless
   2008 		 * the user switches themes.
   2009 		 *
   2010 		 * @since 2.2.0
   2011 		 */
   2012 		public function force_activation() {
   2013 			foreach ( $this->plugins as $slug => $plugin ) {
   2014 				if ( true === $plugin['force_activation'] ) {
   2015 					if ( ! $this->is_plugin_installed( $slug ) ) {
   2016 						// Oops, plugin isn't there so iterate to next condition.
   2017 						continue;
   2018 					} elseif ( $this->can_plugin_activate( $slug ) ) {
   2019 						// There we go, activate the plugin.
   2020 						activate_plugin( $plugin['file_path'] );
   2021 					}
   2022 				}
   2023 			}
   2024 		}
   2025 
   2026 		/**
   2027 		 * Forces plugin deactivation if the parameter 'force_deactivation'
   2028 		 * is set to true and adds the plugin to the 'recently active' plugins list.
   2029 		 *
   2030 		 * This allows theme authors to specify certain plugins that must be
   2031 		 * deactivated upon switching from the current theme to another.
   2032 		 *
   2033 		 * Please take special care when using this parameter as it has the
   2034 		 * potential to be harmful if not used correctly.
   2035 		 *
   2036 		 * @since 2.2.0
   2037 		 */
   2038 		public function force_deactivation() {
   2039 			$deactivated = array();
   2040 
   2041 			foreach ( $this->plugins as $slug => $plugin ) {
   2042 				/*
   2043 				 * Only proceed forward if the parameter is set to true and plugin is active
   2044 				 * as a 'normal' (not must-use) plugin.
   2045 				 */
   2046 				if ( true === $plugin['force_deactivation'] && is_plugin_active( $plugin['file_path'] ) ) {
   2047 					deactivate_plugins( $plugin['file_path'] );
   2048 					$deactivated[ $plugin['file_path'] ] = time();
   2049 				}
   2050 			}
   2051 
   2052 			if ( ! empty( $deactivated ) ) {
   2053 				update_option( 'recently_activated', $deactivated + (array) get_option( 'recently_activated' ) );
   2054 			}
   2055 		}
   2056 
   2057 		/**
   2058 		 * Echo the current TGMPA version number to the page.
   2059 		 *
   2060 		 * @since 2.5.0
   2061 		 */
   2062 		public function show_tgmpa_version() {
   2063 			echo '<p style="float: right; padding: 0em 1.5em 0.5em 0;"><strong><small>',
   2064 			esc_html(
   2065 				sprintf(
   2066 				/* translators: %s: version number */
   2067 					esc_html__( 'TGMPA v%s', 'aapside' ),
   2068 					self::TGMPA_VERSION
   2069 				)
   2070 			),
   2071 			'</small></strong></p>';
   2072 		}
   2073 
   2074 		/**
   2075 		 * Returns the singleton instance of the class.
   2076 		 *
   2077 		 * @since 2.4.0
   2078 		 *
   2079 		 * @return \TGM_Plugin_Activation The TGM_Plugin_Activation object.
   2080 		 */
   2081 		public static function get_instance() {
   2082 			if ( ! isset( self::$instance ) && ! ( self::$instance instanceof self ) ) {
   2083 				self::$instance = new self();
   2084 			}
   2085 
   2086 			return self::$instance;
   2087 		}
   2088 	}
   2089 
   2090 	if ( ! function_exists( 'load_tgm_plugin_activation' ) ) {
   2091 		/**
   2092 		 * Ensure only one instance of the class is ever invoked.
   2093 		 *
   2094 		 * @since 2.5.0
   2095 		 */
   2096 		function load_tgm_plugin_activation() {
   2097 			$GLOBALS['tgmpa'] = TGM_Plugin_Activation::get_instance();
   2098 		}
   2099 	}
   2100 
   2101 	if ( did_action( 'plugins_loaded' ) ) {
   2102 		load_tgm_plugin_activation();
   2103 	} else {
   2104 		add_action( 'plugins_loaded', 'load_tgm_plugin_activation' );
   2105 	}
   2106 }
   2107 
   2108 if ( ! function_exists( 'tgmpa' ) ) {
   2109 	/**
   2110 	 * Helper function to register a collection of required plugins.
   2111 	 *
   2112 	 * @since 2.0.0
   2113 	 * @api
   2114 	 *
   2115 	 * @param array $plugins An array of plugin arrays.
   2116 	 * @param array $config  Optional. An array of configuration values.
   2117 	 */
   2118 	function tgmpa( $plugins, $config = array() ) {
   2119 		$instance = call_user_func( array( get_class( $GLOBALS['tgmpa'] ), 'get_instance' ) );
   2120 
   2121 		foreach ( $plugins as $plugin ) {
   2122 			call_user_func( array( $instance, 'register' ), $plugin );
   2123 		}
   2124 
   2125 		if ( ! empty( $config ) && is_array( $config ) ) {
   2126 			// Send out notices for deprecated arguments passed.
   2127 			if ( isset( $config['notices'] ) ) {
   2128 				_deprecated_argument( __FUNCTION__, '2.2.0', 'The `notices` config parameter was renamed to `has_notices` in TGMPA 2.2.0. Please adjust your configuration.' );
   2129 				if ( ! isset( $config['has_notices'] ) ) {
   2130 					$config['has_notices'] = $config['notices'];
   2131 				}
   2132 			}
   2133 
   2134 			if ( isset( $config['parent_menu_slug'] ) ) {
   2135 				_deprecated_argument( __FUNCTION__, '2.4.0', 'The `parent_menu_slug` config parameter was removed in TGMPA 2.4.0. In TGMPA 2.5.0 an alternative was (re-)introduced. Please adjust your configuration. For more information visit the website: http://tgmpluginactivation.com/configuration/#h-configuration-options.' );
   2136 			}
   2137 			if ( isset( $config['parent_url_slug'] ) ) {
   2138 				_deprecated_argument( __FUNCTION__, '2.4.0', 'The `parent_url_slug` config parameter was removed in TGMPA 2.4.0. In TGMPA 2.5.0 an alternative was (re-)introduced. Please adjust your configuration. For more information visit the website: http://tgmpluginactivation.com/configuration/#h-configuration-options.' );
   2139 			}
   2140 
   2141 			call_user_func( array( $instance, 'config' ), $config );
   2142 		}
   2143 	}
   2144 }
   2145 
   2146 /**
   2147  * WP_List_Table isn't always available. If it isn't available,
   2148  * we load it here.
   2149  *
   2150  * @since 2.2.0
   2151  */
   2152 if ( ! class_exists( 'WP_List_Table' ) ) {
   2153 	require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
   2154 }
   2155 
   2156 if ( ! class_exists( 'TGMPA_List_Table' ) ) {
   2157 
   2158 	/**
   2159 	 * List table class for handling plugins.
   2160 	 *
   2161 	 * Extends the WP_List_Table class to provide a future-compatible
   2162 	 * way of listing out all required/recommended plugins.
   2163 	 *
   2164 	 * Gives users an interface similar to the Plugin Administration
   2165 	 * area with similar (albeit stripped down) capabilities.
   2166 	 *
   2167 	 * This class also allows for the bulk install of plugins.
   2168 	 *
   2169 	 * @since 2.2.0
   2170 	 *
   2171 	 * @package TGM-Plugin-Activation
   2172 	 * @author  Thomas Griffin
   2173 	 * @author  Gary Jones
   2174 	 */
   2175 	class TGMPA_List_Table extends WP_List_Table {
   2176 		/**
   2177 		 * TGMPA instance.
   2178 		 *
   2179 		 * @since 2.5.0
   2180 		 *
   2181 		 * @var object
   2182 		 */
   2183 		protected $tgmpa;
   2184 
   2185 		/**
   2186 		 * The currently chosen view.
   2187 		 *
   2188 		 * @since 2.5.0
   2189 		 *
   2190 		 * @var string One of: 'all', 'install', 'update', 'activate'
   2191 		 */
   2192 		public $view_context = 'all';
   2193 
   2194 		/**
   2195 		 * The plugin counts for the various views.
   2196 		 *
   2197 		 * @since 2.5.0
   2198 		 *
   2199 		 * @var array
   2200 		 */
   2201 		protected $view_totals = array(
   2202 			'all'      => 0,
   2203 			'install'  => 0,
   2204 			'update'   => 0,
   2205 			'activate' => 0,
   2206 		);
   2207 
   2208 		/**
   2209 		 * References parent constructor and sets defaults for class.
   2210 		 *
   2211 		 * @since 2.2.0
   2212 		 */
   2213 		public function __construct() {
   2214 			$this->tgmpa = call_user_func( array( get_class( $GLOBALS['tgmpa'] ), 'get_instance' ) );
   2215 
   2216 			parent::__construct(
   2217 				array(
   2218 					'singular' => 'plugin',
   2219 					'plural'   => 'plugins',
   2220 					'ajax'     => false,
   2221 				)
   2222 			);
   2223 
   2224 			if ( isset( $_REQUEST['plugin_status'] ) && in_array( $_REQUEST['plugin_status'], array( 'install', 'update', 'activate' ), true ) ) {
   2225 				$this->view_context = sanitize_key( $_REQUEST['plugin_status'] );
   2226 			}
   2227 
   2228 			add_filter( 'tgmpa_table_data_items', array( $this, 'sort_table_items' ) );
   2229 		}
   2230 
   2231 		/**
   2232 		 * Get a list of CSS classes for the <table> tag.
   2233 		 *
   2234 		 * Overruled to prevent the 'plural' argument from being added.
   2235 		 *
   2236 		 * @since 2.5.0
   2237 		 *
   2238 		 * @return array CSS classnames.
   2239 		 */
   2240 		public function get_table_classes() {
   2241 			return array( 'widefat', 'fixed' );
   2242 		}
   2243 
   2244 		/**
   2245 		 * Gathers and renames all of our plugin information to be used by WP_List_Table to create our table.
   2246 		 *
   2247 		 * @since 2.2.0
   2248 		 *
   2249 		 * @return array $table_data Information for use in table.
   2250 		 */
   2251 		protected function _gather_plugin_data() {
   2252 			// Load thickbox for plugin links.
   2253 			$this->tgmpa->admin_init();
   2254 			$this->tgmpa->thickbox();
   2255 
   2256 			// Categorize the plugins which have open actions.
   2257 			$plugins = $this->categorize_plugins_to_views();
   2258 
   2259 			// Set the counts for the view links.
   2260 			$this->set_view_totals( $plugins );
   2261 
   2262 			// Prep variables for use and grab list of all installed plugins.
   2263 			$table_data = array();
   2264 			$i          = 0;
   2265 
   2266 			// Redirect to the 'all' view if no plugins were found for the selected view context.
   2267 			if ( empty( $plugins[ $this->view_context ] ) ) {
   2268 				$this->view_context = 'all';
   2269 			}
   2270 
   2271 			foreach ( $plugins[ $this->view_context ] as $slug => $plugin ) {
   2272 				$table_data[ $i ]['sanitized_plugin']  = $plugin['name'];
   2273 				$table_data[ $i ]['slug']              = $slug;
   2274 				$table_data[ $i ]['plugin']            = '<strong>' . $this->tgmpa->get_info_link( $slug ) . '</strong>';
   2275 				$table_data[ $i ]['source']            = $this->get_plugin_source_type_text( $plugin['source_type'] );
   2276 				$table_data[ $i ]['type']              = $this->get_plugin_advise_type_text( $plugin['required'] );
   2277 				$table_data[ $i ]['status']            = $this->get_plugin_status_text( $slug );
   2278 				$table_data[ $i ]['installed_version'] = $this->tgmpa->get_installed_version( $slug );
   2279 				$table_data[ $i ]['minimum_version']   = $plugin['version'];
   2280 				$table_data[ $i ]['available_version'] = $this->tgmpa->does_plugin_have_update( $slug );
   2281 
   2282 				// Prep the upgrade notice info.
   2283 				$upgrade_notice = $this->tgmpa->get_upgrade_notice( $slug );
   2284 				if ( ! empty( $upgrade_notice ) ) {
   2285 					$table_data[ $i ]['upgrade_notice'] = $upgrade_notice;
   2286 
   2287 					add_action( "tgmpa_after_plugin_row_{$slug}", array( $this, 'wp_plugin_update_row' ), 10, 2 );
   2288 				}
   2289 
   2290 				$table_data[ $i ] = apply_filters( 'tgmpa_table_data_item', $table_data[ $i ], $plugin );
   2291 
   2292 				$i++;
   2293 			}
   2294 
   2295 			return $table_data;
   2296 		}
   2297 
   2298 		/**
   2299 		 * Categorize the plugins which have open actions into views for the TGMPA page.
   2300 		 *
   2301 		 * @since 2.5.0
   2302 		 */
   2303 		protected function categorize_plugins_to_views() {
   2304 			$plugins = array(
   2305 				'all'      => array(), // Meaning: all plugins which still have open actions.
   2306 				'install'  => array(),
   2307 				'update'   => array(),
   2308 				'activate' => array(),
   2309 			);
   2310 
   2311 			foreach ( $this->tgmpa->plugins as $slug => $plugin ) {
   2312 				if ( $this->tgmpa->is_plugin_active( $slug ) && false === $this->tgmpa->does_plugin_have_update( $slug ) ) {
   2313 					// No need to display plugins if they are installed, up-to-date and active.
   2314 					continue;
   2315 				} else {
   2316 					$plugins['all'][ $slug ] = $plugin;
   2317 
   2318 					if ( ! $this->tgmpa->is_plugin_installed( $slug ) ) {
   2319 						$plugins['install'][ $slug ] = $plugin;
   2320 					} else {
   2321 						if ( false !== $this->tgmpa->does_plugin_have_update( $slug ) ) {
   2322 							$plugins['update'][ $slug ] = $plugin;
   2323 						}
   2324 
   2325 						if ( $this->tgmpa->can_plugin_activate( $slug ) ) {
   2326 							$plugins['activate'][ $slug ] = $plugin;
   2327 						}
   2328 					}
   2329 				}
   2330 			}
   2331 
   2332 			return $plugins;
   2333 		}
   2334 
   2335 		/**
   2336 		 * Set the counts for the view links.
   2337 		 *
   2338 		 * @since 2.5.0
   2339 		 *
   2340 		 * @param array $plugins Plugins order by view.
   2341 		 */
   2342 		protected function set_view_totals( $plugins ) {
   2343 			foreach ( $plugins as $type => $list ) {
   2344 				$this->view_totals[ $type ] = count( $list );
   2345 			}
   2346 		}
   2347 
   2348 		/**
   2349 		 * Get the plugin required/recommended text string.
   2350 		 *
   2351 		 * @since 2.5.0
   2352 		 *
   2353 		 * @param string $required Plugin required setting.
   2354 		 * @return string
   2355 		 */
   2356 		protected function get_plugin_advise_type_text( $required ) {
   2357 			if ( true === $required ) {
   2358 				return esc_html__( 'Required', 'aapside' );
   2359 			}
   2360 
   2361 			return esc_html__( 'Recommended', 'aapside' );
   2362 		}
   2363 
   2364 		/**
   2365 		 * Get the plugin source type text string.
   2366 		 *
   2367 		 * @since 2.5.0
   2368 		 *
   2369 		 * @param string $type Plugin type.
   2370 		 * @return string
   2371 		 */
   2372 		protected function get_plugin_source_type_text( $type ) {
   2373 			$string = '';
   2374 
   2375 			switch ( $type ) {
   2376 				case 'repo':
   2377 					$string = esc_html__( 'WordPress Repository', 'aapside' );
   2378 					break;
   2379 				case 'external':
   2380 					$string = esc_html__( 'External Source', 'aapside' );
   2381 					break;
   2382 				case 'bundled':
   2383 					$string = esc_html__( 'Pre-Packaged', 'aapside' );
   2384 					break;
   2385 			}
   2386 
   2387 			return $string;
   2388 		}
   2389 
   2390 		/**
   2391 		 * Determine the plugin status message.
   2392 		 *
   2393 		 * @since 2.5.0
   2394 		 *
   2395 		 * @param string $slug Plugin slug.
   2396 		 * @return string
   2397 		 */
   2398 		protected function get_plugin_status_text( $slug ) {
   2399 			if ( ! $this->tgmpa->is_plugin_installed( $slug ) ) {
   2400 				return esc_html__( 'Not Installed', 'aapside' );
   2401 			}
   2402 
   2403 			if ( ! $this->tgmpa->is_plugin_active( $slug ) ) {
   2404 				$install_status = esc_html__( 'Installed But Not Activated', 'aapside' );
   2405 			} else {
   2406 				$install_status = esc_html__( 'Active', 'aapside' );
   2407 			}
   2408 
   2409 			$update_status = '';
   2410 
   2411 			if ( $this->tgmpa->does_plugin_require_update( $slug ) && false === $this->tgmpa->does_plugin_have_update( $slug ) ) {
   2412 				$update_status = esc_html__( 'Required Update not Available', 'aapside' );
   2413 
   2414 			} elseif ( $this->tgmpa->does_plugin_require_update( $slug ) ) {
   2415 				$update_status = esc_html__( 'Requires Update', 'aapside' );
   2416 
   2417 			} elseif ( false !== $this->tgmpa->does_plugin_have_update( $slug ) ) {
   2418 				$update_status = esc_html__( 'Update recommended', 'aapside' );
   2419 			}
   2420 
   2421 			if ( '' === $update_status ) {
   2422 				return $install_status;
   2423 			}
   2424 
   2425 			return sprintf(
   2426 			/* translators: 1: install status, 2: update status */
   2427 				_x( '%1$s, %2$s', 'Install/Update Status', 'aapside' ),
   2428 				$install_status,
   2429 				$update_status
   2430 			);
   2431 		}
   2432 
   2433 		/**
   2434 		 * Sort plugins by Required/Recommended type and by alphabetical plugin name within each type.
   2435 		 *
   2436 		 * @since 2.5.0
   2437 		 *
   2438 		 * @param array $items Prepared table items.
   2439 		 * @return array Sorted table items.
   2440 		 */
   2441 		public function sort_table_items( $items ) {
   2442 			$type = array();
   2443 			$name = array();
   2444 
   2445 			foreach ( $items as $i => $plugin ) {
   2446 				$type[ $i ] = $plugin['type']; // Required / recommended.
   2447 				$name[ $i ] = $plugin['sanitized_plugin'];
   2448 			}
   2449 
   2450 			array_multisort( $type, SORT_DESC, $name, SORT_ASC, $items );
   2451 
   2452 			return $items;
   2453 		}
   2454 
   2455 		/**
   2456 		 * Get an associative array ( id => link ) of the views available on this table.
   2457 		 *
   2458 		 * @since 2.5.0
   2459 		 *
   2460 		 * @return array
   2461 		 */
   2462 		public function get_views() {
   2463 			$status_links = array();
   2464 
   2465 			foreach ( $this->view_totals as $type => $count ) {
   2466 				if ( $count < 1 ) {
   2467 					continue;
   2468 				}
   2469 
   2470 				switch ( $type ) {
   2471 					case 'all':
   2472 						/* translators: 1: number of plugins. */
   2473 						$text = _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $count, 'plugins', 'aapside' );
   2474 						break;
   2475 					case 'install':
   2476 						/* translators: 1: number of plugins. */
   2477 						$text = _n( 'To Install <span class="count">(%s)</span>', 'To Install <span class="count">(%s)</span>', $count, 'aapside' );
   2478 						break;
   2479 					case 'update':
   2480 						/* translators: 1: number of plugins. */
   2481 						$text = _n( 'Update Available <span class="count">(%s)</span>', 'Update Available <span class="count">(%s)</span>', $count, 'aapside' );
   2482 						break;
   2483 					case 'activate':
   2484 						/* translators: 1: number of plugins. */
   2485 						$text = _n( 'To Activate <span class="count">(%s)</span>', 'To Activate <span class="count">(%s)</span>', $count, 'aapside' );
   2486 						break;
   2487 					default:
   2488 						$text = '';
   2489 						break;
   2490 				}
   2491 
   2492 				if ( ! empty( $text ) ) {
   2493 
   2494 					$status_links[ $type ] = sprintf(
   2495 						'<a href="%s"%s>%s</a>',
   2496 						esc_url( $this->tgmpa->get_tgmpa_status_url( $type ) ),
   2497 						( $type === $this->view_context ) ? ' class="current"' : '',
   2498 						sprintf( $text, number_format_i18n( $count ) )
   2499 					);
   2500 				}
   2501 			}
   2502 
   2503 			return $status_links;
   2504 		}
   2505 
   2506 		/**
   2507 		 * Create default columns to display important plugin information
   2508 		 * like type, action and status.
   2509 		 *
   2510 		 * @since 2.2.0
   2511 		 *
   2512 		 * @param array  $item        Array of item data.
   2513 		 * @param string $column_name The name of the column.
   2514 		 * @return string
   2515 		 */
   2516 		public function column_default( $item, $column_name ) {
   2517 			return $item[ $column_name ];
   2518 		}
   2519 
   2520 		/**
   2521 		 * Required for bulk installing.
   2522 		 *
   2523 		 * Adds a checkbox for each plugin.
   2524 		 *
   2525 		 * @since 2.2.0
   2526 		 *
   2527 		 * @param array $item Array of item data.
   2528 		 * @return string The input checkbox with all necessary info.
   2529 		 */
   2530 		public function column_cb( $item ) {
   2531 			return sprintf(
   2532 				'<input type="checkbox" name="%1$s[]" value="%2$s" id="%3$s" />',
   2533 				esc_attr( $this->_args['singular'] ),
   2534 				esc_attr( $item['slug'] ),
   2535 				esc_attr( $item['sanitized_plugin'] )
   2536 			);
   2537 		}
   2538 
   2539 		/**
   2540 		 * Create default title column along with the action links.
   2541 		 *
   2542 		 * @since 2.2.0
   2543 		 *
   2544 		 * @param array $item Array of item data.
   2545 		 * @return string The plugin name and action links.
   2546 		 */
   2547 		public function column_plugin( $item ) {
   2548 			return sprintf(
   2549 				'%1$s %2$s',
   2550 				$item['plugin'],
   2551 				$this->row_actions( $this->get_row_actions( $item ), true )
   2552 			);
   2553 		}
   2554 
   2555 		/**
   2556 		 * Create version information column.
   2557 		 *
   2558 		 * @since 2.5.0
   2559 		 *
   2560 		 * @param array $item Array of item data.
   2561 		 * @return string HTML-formatted version information.
   2562 		 */
   2563 		public function column_version( $item ) {
   2564 			$output = array();
   2565 
   2566 			if ( $this->tgmpa->is_plugin_installed( $item['slug'] ) ) {
   2567 				$installed = ! empty( $item['installed_version'] ) ? $item['installed_version'] : _x( 'unknown', 'as in: "version nr unknown"', 'aapside' );
   2568 
   2569 				$color = '';
   2570 				if ( ! empty( $item['minimum_version'] ) && $this->tgmpa->does_plugin_require_update( $item['slug'] ) ) {
   2571 					$color = ' color: #ff0000; font-weight: bold;';
   2572 				}
   2573 
   2574 				$output[] = sprintf(
   2575 					'<p><span style="min-width: 32px; text-align: right; float: right;%1$s">%2$s</span>' . esc_html__( 'Installed version:', 'aapside' ) . '</p>',
   2576 					$color,
   2577 					$installed
   2578 				);
   2579 			}
   2580 
   2581 			if ( ! empty( $item['minimum_version'] ) ) {
   2582 				$output[] = sprintf(
   2583 					'<p><span style="min-width: 32px; text-align: right; float: right;">%1$s</span>' . esc_html__( 'Minimum required version:', 'aapside' ) . '</p>',
   2584 					$item['minimum_version']
   2585 				);
   2586 			}
   2587 
   2588 			if ( ! empty( $item['available_version'] ) ) {
   2589 				$color = '';
   2590 				if ( ! empty( $item['minimum_version'] ) && version_compare( $item['available_version'], $item['minimum_version'], '>=' ) ) {
   2591 					$color = ' color: #71C671; font-weight: bold;';
   2592 				}
   2593 
   2594 				$output[] = sprintf(
   2595 					'<p><span style="min-width: 32px; text-align: right; float: right;%1$s">%2$s</span>' . esc_html__( 'Available version:', 'aapside' ) . '</p>',
   2596 					$color,
   2597 					$item['available_version']
   2598 				);
   2599 			}
   2600 
   2601 			if ( empty( $output ) ) {
   2602 				return '&nbsp;'; // Let's not break the table layout.
   2603 			} else {
   2604 				return implode( "\n", $output );
   2605 			}
   2606 		}
   2607 
   2608 		/**
   2609 		 * Sets default message within the plugins table if no plugins
   2610 		 * are left for interaction.
   2611 		 *
   2612 		 * Hides the menu item to prevent the user from clicking and
   2613 		 * getting a permissions error.
   2614 		 *
   2615 		 * @since 2.2.0
   2616 		 */
   2617 		public function no_items() {
   2618 			echo esc_html__( 'No plugins to install, update or activate.', 'aapside' ) . ' <a href="' . esc_url( self_admin_url() ) . '"> ' . esc_html__( 'Return to the Dashboard', 'aapside' ) . '</a>';
   2619 			echo '<style type="text/css">#adminmenu .wp-submenu li.current { display: none !important; }</style>';
   2620 		}
   2621 
   2622 		/**
   2623 		 * Output all the column information within the table.
   2624 		 *
   2625 		 * @since 2.2.0
   2626 		 *
   2627 		 * @return array $columns The column names.
   2628 		 */
   2629 		public function get_columns() {
   2630 			$columns = array(
   2631 				'cb'     => '<input type="checkbox" />',
   2632 				'plugin' => esc_html__( 'Plugin', 'aapside' ),
   2633 				'source' => esc_html__( 'Source', 'aapside' ),
   2634 				'type'   => esc_html__( 'Type', 'aapside' ),
   2635 			);
   2636 
   2637 			if ( 'all' === $this->view_context || 'update' === $this->view_context ) {
   2638 				$columns['version'] = esc_html__( 'Version', 'aapside' );
   2639 				$columns['status']  = esc_html__( 'Status', 'aapside' );
   2640 			}
   2641 
   2642 			return apply_filters( 'tgmpa_table_columns', $columns );
   2643 		}
   2644 
   2645 		/**
   2646 		 * Get name of default primary column
   2647 		 *
   2648 		 * @since 2.5.0 / WP 4.3+ compatibility
   2649 		 * @access protected
   2650 		 *
   2651 		 * @return string
   2652 		 */
   2653 		protected function get_default_primary_column_name() {
   2654 			return 'plugin';
   2655 		}
   2656 
   2657 		/**
   2658 		 * Get the name of the primary column.
   2659 		 *
   2660 		 * @since 2.5.0 / WP 4.3+ compatibility
   2661 		 * @access protected
   2662 		 *
   2663 		 * @return string The name of the primary column.
   2664 		 */
   2665 		protected function get_primary_column_name() {
   2666 			if ( method_exists( 'WP_List_Table', 'get_primary_column_name' ) ) {
   2667 				return parent::get_primary_column_name();
   2668 			} else {
   2669 				return $this->get_default_primary_column_name();
   2670 			}
   2671 		}
   2672 
   2673 		/**
   2674 		 * Get the actions which are relevant for a specific plugin row.
   2675 		 *
   2676 		 * @since 2.5.0
   2677 		 *
   2678 		 * @param array $item Array of item data.
   2679 		 * @return array Array with relevant action links.
   2680 		 */
   2681 		protected function get_row_actions( $item ) {
   2682 			$actions      = array();
   2683 			$action_links = array();
   2684 
   2685 			// Display the 'Install' action link if the plugin is not yet available.
   2686 			if ( ! $this->tgmpa->is_plugin_installed( $item['slug'] ) ) {
   2687 				/* translators: %2$s: plugin name in screen reader markup */
   2688 				$actions['install'] = esc_html__( 'Install %2$s', 'aapside' );
   2689 			} else {
   2690 				// Display the 'Update' action link if an update is available and WP complies with plugin minimum.
   2691 				if ( false !== $this->tgmpa->does_plugin_have_update( $item['slug'] ) && $this->tgmpa->can_plugin_update( $item['slug'] ) ) {
   2692 					/* translators: %2$s: plugin name in screen reader markup */
   2693 					$actions['update'] = esc_html__( 'Update %2$s', 'aapside' );
   2694 				}
   2695 
   2696 				// Display the 'Activate' action link, but only if the plugin meets the minimum version.
   2697 				if ( $this->tgmpa->can_plugin_activate( $item['slug'] ) ) {
   2698 					/* translators: %2$s: plugin name in screen reader markup */
   2699 					$actions['activate'] = esc_html__( 'Activate %2$s', 'aapside' );
   2700 				}
   2701 			}
   2702 
   2703 			// Create the actual links.
   2704 			foreach ( $actions as $action => $text ) {
   2705 				$nonce_url = wp_nonce_url(
   2706 					add_query_arg(
   2707 						array(
   2708 							'plugin'           => urlencode( $item['slug'] ),
   2709 							'tgmpa-' . $action => $action . '-plugin',
   2710 						),
   2711 						$this->tgmpa->get_tgmpa_url()
   2712 					),
   2713 					'tgmpa-' . $action,
   2714 					'tgmpa-nonce'
   2715 				);
   2716 
   2717 				$action_links[ $action ] = sprintf(
   2718 					'<a href="%1$s">' . esc_html( $text ) . '</a>', // $text contains the second placeholder.
   2719 					esc_url( $nonce_url ),
   2720 					'<span class="screen-reader-text">' . esc_html( $item['sanitized_plugin'] ) . '</span>'
   2721 				);
   2722 			}
   2723 
   2724 			$prefix = ( defined( 'WP_NETWORK_ADMIN' ) && WP_NETWORK_ADMIN ) ? 'network_admin_' : '';
   2725 			return apply_filters( "tgmpa_{$prefix}plugin_action_links", array_filter( $action_links ), $item['slug'], $item, $this->view_context );
   2726 		}
   2727 
   2728 		/**
   2729 		 * Generates content for a single row of the table.
   2730 		 *
   2731 		 * @since 2.5.0
   2732 		 *
   2733 		 * @param object $item The current item.
   2734 		 */
   2735 		public function single_row( $item ) {
   2736 			parent::single_row( $item );
   2737 
   2738 			/**
   2739 			 * Fires after each specific row in the TGMPA Plugins list table.
   2740 			 *
   2741 			 * The dynamic portion of the hook name, `$item['slug']`, refers to the slug
   2742 			 * for the plugin.
   2743 			 *
   2744 			 * @since 2.5.0
   2745 			 */
   2746 			do_action( "tgmpa_after_plugin_row_{$item['slug']}", $item['slug'], $item, $this->view_context );
   2747 		}
   2748 
   2749 		/**
   2750 		 * Show the upgrade notice below a plugin row if there is one.
   2751 		 *
   2752 		 * @since 2.5.0
   2753 		 *
   2754 		 * @see /wp-admin/includes/update.php
   2755 		 *
   2756 		 * @param string $slug Plugin slug.
   2757 		 * @param array  $item The information available in this table row.
   2758 		 * @return null Return early if upgrade notice is empty.
   2759 		 */
   2760 		public function wp_plugin_update_row( $slug, $item ) {
   2761 			if ( empty( $item['upgrade_notice'] ) ) {
   2762 				return;
   2763 			}
   2764 
   2765 			echo '
   2766 				<tr class="plugin-update-tr">
   2767 					<td colspan="', absint( $this->get_column_count() ), '" class="plugin-update colspanchange">
   2768 						<div class="update-message">',
   2769 			esc_html__( 'Upgrade message from the plugin author:', 'aapside' ),
   2770 			' <strong>', wp_kses_data( $item['upgrade_notice'] ), '</strong>
   2771 						</div>
   2772 					</td>
   2773 				</tr>';
   2774 		}
   2775 
   2776 		/**
   2777 		 * Extra controls to be displayed between bulk actions and pagination.
   2778 		 *
   2779 		 * @since 2.5.0
   2780 		 *
   2781 		 * @param string $which 'top' or 'bottom' table navigation.
   2782 		 */
   2783 		public function extra_tablenav( $which ) {
   2784 			if ( 'bottom' === $which ) {
   2785 				$this->tgmpa->show_tgmpa_version();
   2786 			}
   2787 		}
   2788 
   2789 		/**
   2790 		 * Defines the bulk actions for handling registered plugins.
   2791 		 *
   2792 		 * @since 2.2.0
   2793 		 *
   2794 		 * @return array $actions The bulk actions for the plugin install table.
   2795 		 */
   2796 		public function get_bulk_actions() {
   2797 
   2798 			$actions = array();
   2799 
   2800 			if ( 'update' !== $this->view_context && 'activate' !== $this->view_context ) {
   2801 				if ( current_user_can( 'install_plugins' ) ) {
   2802 					$actions['tgmpa-bulk-install'] = esc_html__( 'Install', 'aapside' );
   2803 				}
   2804 			}
   2805 
   2806 			if ( 'install' !== $this->view_context ) {
   2807 				if ( current_user_can( 'update_plugins' ) ) {
   2808 					$actions['tgmpa-bulk-update'] = esc_html__( 'Update', 'aapside' );
   2809 				}
   2810 				if ( current_user_can( 'activate_plugins' ) ) {
   2811 					$actions['tgmpa-bulk-activate'] = esc_html__( 'Activate', 'aapside' );
   2812 				}
   2813 			}
   2814 
   2815 			return $actions;
   2816 		}
   2817 
   2818 		/**
   2819 		 * Processes bulk installation and activation actions.
   2820 		 *
   2821 		 * The bulk installation process looks for the $_POST information and passes that
   2822 		 * through if a user has to use WP_Filesystem to enter their credentials.
   2823 		 *
   2824 		 * @since 2.2.0
   2825 		 */
   2826 		public function process_bulk_actions() {
   2827 			// Bulk installation process.
   2828 			if ( 'tgmpa-bulk-install' === $this->current_action() || 'tgmpa-bulk-update' === $this->current_action() ) {
   2829 
   2830 				check_admin_referer( 'bulk-' . $this->_args['plural'] );
   2831 
   2832 				$install_type = 'install';
   2833 				if ( 'tgmpa-bulk-update' === $this->current_action() ) {
   2834 					$install_type = 'update';
   2835 				}
   2836 
   2837 				$plugins_to_install = array();
   2838 
   2839 				// Did user actually select any plugins to install/update ?
   2840 				if ( empty( $_POST['plugin'] ) ) {
   2841 					if ( 'install' === $install_type ) {
   2842 						$message = esc_html__( 'No plugins were selected to be installed. No action taken.', 'aapside' );
   2843 					} else {
   2844 						$message = esc_html__( 'No plugins were selected to be updated. No action taken.', 'aapside' );
   2845 					}
   2846 
   2847 					echo '<div id="message" class="error"><p>', esc_html( $message ), '</p></div>';
   2848 
   2849 					return false;
   2850 				}
   2851 
   2852 				if ( is_array( $_POST['plugin'] ) ) {
   2853 					$plugins_to_install = (array) $_POST['plugin'];
   2854 				} elseif ( is_string( $_POST['plugin'] ) ) {
   2855 					// Received via Filesystem page - un-flatten array (WP bug #19643).
   2856 					$plugins_to_install = explode( ',', $_POST['plugin'] );
   2857 				}
   2858 
   2859 				// Sanitize the received input.
   2860 				$plugins_to_install = array_map( 'urldecode', $plugins_to_install );
   2861 				$plugins_to_install = array_map( array( $this->tgmpa, 'sanitize_key' ), $plugins_to_install );
   2862 
   2863 				// Validate the received input.
   2864 				foreach ( $plugins_to_install as $key => $slug ) {
   2865 					// Check if the plugin was registered with TGMPA and remove if not.
   2866 					if ( ! isset( $this->tgmpa->plugins[ $slug ] ) ) {
   2867 						unset( $plugins_to_install[ $key ] );
   2868 						continue;
   2869 					}
   2870 
   2871 					// For install: make sure this is a plugin we *can* install and not one already installed.
   2872 					if ( 'install' === $install_type && true === $this->tgmpa->is_plugin_installed( $slug ) ) {
   2873 						unset( $plugins_to_install[ $key ] );
   2874 					}
   2875 
   2876 					// For updates: make sure this is a plugin we *can* update (update available and WP version ok).
   2877 					if ( 'update' === $install_type && false === $this->tgmpa->is_plugin_updatetable( $slug ) ) {
   2878 						unset( $plugins_to_install[ $key ] );
   2879 					}
   2880 				}
   2881 
   2882 				// No need to proceed further if we have no plugins to handle.
   2883 				if ( empty( $plugins_to_install ) ) {
   2884 					if ( 'install' === $install_type ) {
   2885 						$message = esc_html__( 'No plugins are available to be installed at this time.', 'aapside' );
   2886 					} else {
   2887 						$message = esc_html__( 'No plugins are available to be updated at this time.', 'aapside' );
   2888 					}
   2889 
   2890 					echo '<div id="message" class="error"><p>', esc_html( $message ), '</p></div>';
   2891 
   2892 					return false;
   2893 				}
   2894 
   2895 				// Pass all necessary information if WP_Filesystem is needed.
   2896 				$url = wp_nonce_url(
   2897 					$this->tgmpa->get_tgmpa_url(),
   2898 					'bulk-' . $this->_args['plural']
   2899 				);
   2900 
   2901 				// Give validated data back to $_POST which is the only place the filesystem looks for extra fields.
   2902 				$_POST['plugin'] = implode( ',', $plugins_to_install ); // Work around for WP bug #19643.
   2903 
   2904 				$method = ''; // Leave blank so WP_Filesystem can populate it as necessary.
   2905 				$fields = array_keys( $_POST ); // Extra fields to pass to WP_Filesystem.
   2906 
   2907 				if ( false === ( $creds = request_filesystem_credentials( esc_url_raw( $url ), $method, false, false, $fields ) ) ) {
   2908 					return true; // Stop the normal page form from displaying, credential request form will be shown.
   2909 				}
   2910 
   2911 				// Now we have some credentials, setup WP_Filesystem.
   2912 				if ( ! WP_Filesystem( $creds ) ) {
   2913 					// Our credentials were no good, ask the user for them again.
   2914 					request_filesystem_credentials( esc_url_raw( $url ), $method, true, false, $fields );
   2915 
   2916 					return true;
   2917 				}
   2918 
   2919 				/* If we arrive here, we have the filesystem */
   2920 
   2921 				// Store all information in arrays since we are processing a bulk installation.
   2922 				$names      = array();
   2923 				$sources    = array(); // Needed for installs.
   2924 				$file_paths = array(); // Needed for upgrades.
   2925 				$to_inject  = array(); // Information to inject into the update_plugins transient.
   2926 
   2927 				// Prepare the data for validated plugins for the install/upgrade.
   2928 				foreach ( $plugins_to_install as $slug ) {
   2929 					$name   = $this->tgmpa->plugins[ $slug ]['name'];
   2930 					$source = $this->tgmpa->get_download_url( $slug );
   2931 
   2932 					if ( ! empty( $name ) && ! empty( $source ) ) {
   2933 						$names[] = $name;
   2934 
   2935 						switch ( $install_type ) {
   2936 
   2937 							case 'install':
   2938 								$sources[] = $source;
   2939 								break;
   2940 
   2941 							case 'update':
   2942 								$file_paths[]                 = $this->tgmpa->plugins[ $slug ]['file_path'];
   2943 								$to_inject[ $slug ]           = $this->tgmpa->plugins[ $slug ];
   2944 								$to_inject[ $slug ]['source'] = $source;
   2945 								break;
   2946 						}
   2947 					}
   2948 				}
   2949 				unset( $slug, $name, $source );
   2950 
   2951 				// Create a new instance of TGMPA_Bulk_Installer.
   2952 				$installer = new TGMPA_Bulk_Installer(
   2953 					new TGMPA_Bulk_Installer_Skin(
   2954 						array(
   2955 							'url'          => esc_url_raw( $this->tgmpa->get_tgmpa_url() ),
   2956 							'nonce'        => 'bulk-' . $this->_args['plural'],
   2957 							'names'        => $names,
   2958 							'install_type' => $install_type,
   2959 						)
   2960 					)
   2961 				);
   2962 
   2963 				// Wrap the install process with the appropriate HTML.
   2964 				echo '<div class="tgmpa">',
   2965 				'<h2 style="font-size: 23px; font-weight: 400; line-height: 29px; margin: 0; padding: 9px 15px 4px 0;">', esc_html( get_admin_page_title() ), '</h2>
   2966 					<div class="update-php" style="width: 100%; height: 98%; min-height: 850px; padding-top: 1px;">';
   2967 
   2968 				// Process the bulk installation submissions.
   2969 				add_filter( 'upgrader_source_selection', array( $this->tgmpa, 'maybe_adjust_source_dir' ), 1, 3 );
   2970 
   2971 				if ( 'tgmpa-bulk-update' === $this->current_action() ) {
   2972 					// Inject our info into the update transient.
   2973 					$this->tgmpa->inject_update_info( $to_inject );
   2974 
   2975 					$installer->bulk_upgrade( $file_paths );
   2976 				} else {
   2977 					$installer->bulk_install( $sources );
   2978 				}
   2979 
   2980 				remove_filter( 'upgrader_source_selection', array( $this->tgmpa, 'maybe_adjust_source_dir' ), 1 );
   2981 
   2982 				echo '</div></div>';
   2983 
   2984 				return true;
   2985 			}
   2986 
   2987 			// Bulk activation process.
   2988 			if ( 'tgmpa-bulk-activate' === $this->current_action() ) {
   2989 				check_admin_referer( 'bulk-' . $this->_args['plural'] );
   2990 
   2991 				// Did user actually select any plugins to activate ?
   2992 				if ( empty( $_POST['plugin'] ) ) {
   2993 					echo '<div id="message" class="error"><p>', esc_html__( 'No plugins were selected to be activated. No action taken.', 'aapside' ), '</p></div>';
   2994 
   2995 					return false;
   2996 				}
   2997 
   2998 				// Grab plugin data from $_POST.
   2999 				$plugins = array();
   3000 				if ( isset( $_POST['plugin'] ) ) {
   3001 					$plugins = array_map( 'urldecode', (array) $_POST['plugin'] );
   3002 					$plugins = array_map( array( $this->tgmpa, 'sanitize_key' ), $plugins );
   3003 				}
   3004 
   3005 				$plugins_to_activate = array();
   3006 				$plugin_names        = array();
   3007 
   3008 				// Grab the file paths for the selected & inactive plugins from the registration array.
   3009 				foreach ( $plugins as $slug ) {
   3010 					if ( $this->tgmpa->can_plugin_activate( $slug ) ) {
   3011 						$plugins_to_activate[] = $this->tgmpa->plugins[ $slug ]['file_path'];
   3012 						$plugin_names[]        = $this->tgmpa->plugins[ $slug ]['name'];
   3013 					}
   3014 				}
   3015 				unset( $slug );
   3016 
   3017 				// Return early if there are no plugins to activate.
   3018 				if ( empty( $plugins_to_activate ) ) {
   3019 					echo '<div id="message" class="error"><p>', esc_html__( 'No plugins are available to be activated at this time.', 'aapside' ), '</p></div>';
   3020 
   3021 					return false;
   3022 				}
   3023 
   3024 				// Now we are good to go - let's start activating plugins.
   3025 				$activate = activate_plugins( $plugins_to_activate );
   3026 
   3027 				if ( is_wp_error( $activate ) ) {
   3028 					echo '<div id="message" class="error"><p>', wp_kses_post( $activate->get_error_message() ), '</p></div>';
   3029 				} else {
   3030 					$count        = count( $plugin_names ); // Count so we can use _n function.
   3031 					$plugin_names = array_map( array( 'TGMPA_Utils', 'wrap_in_strong' ), $plugin_names );
   3032 					$last_plugin  = array_pop( $plugin_names ); // Pop off last name to prep for readability.
   3033 					$imploded     = empty( $plugin_names ) ? $last_plugin : ( implode( ', ', $plugin_names ) . ' ' . esc_html_x( 'and', 'plugin A *and* plugin B', 'aapside' ) . ' ' . $last_plugin );
   3034 
   3035 					printf( // WPCS: xss ok.
   3036 						'<div id="message" class="updated"><p>%1$s %2$s.</p></div>',
   3037 						esc_html( _n( 'The following plugin was activated successfully:', 'The following plugins were activated successfully:', $count, 'aapside' ) ),
   3038 						$imploded
   3039 					);
   3040 
   3041 					// Update recently activated plugins option.
   3042 					$recent = (array) get_option( 'recently_activated' );
   3043 					foreach ( $plugins_to_activate as $plugin => $time ) {
   3044 						if ( isset( $recent[ $plugin ] ) ) {
   3045 							unset( $recent[ $plugin ] );
   3046 						}
   3047 					}
   3048 					update_option( 'recently_activated', $recent );
   3049 				}
   3050 
   3051 				unset( $_POST ); // Reset the $_POST variable in case user wants to perform one action after another.
   3052 
   3053 				return true;
   3054 			}
   3055 
   3056 			return false;
   3057 		}
   3058 
   3059 		/**
   3060 		 * Prepares all of our information to be outputted into a usable table.
   3061 		 *
   3062 		 * @since 2.2.0
   3063 		 */
   3064 		public function prepare_items() {
   3065 			$columns               = $this->get_columns(); // Get all necessary column information.
   3066 			$hidden                = array(); // No columns to hide, but we must set as an array.
   3067 			$sortable              = array(); // No reason to make sortable columns.
   3068 			$primary               = $this->get_primary_column_name(); // Column which has the row actions.
   3069 			$this->_column_headers = array( $columns, $hidden, $sortable, $primary ); // Get all necessary column headers.
   3070 
   3071 			// Process our bulk activations here.
   3072 			if ( 'tgmpa-bulk-activate' === $this->current_action() ) {
   3073 				$this->process_bulk_actions();
   3074 			}
   3075 
   3076 			// Store all of our plugin data into $items array so WP_List_Table can use it.
   3077 			$this->items = apply_filters( 'tgmpa_table_data_items', $this->_gather_plugin_data() );
   3078 		}
   3079 
   3080 		/* *********** DEPRECATED METHODS *********** */
   3081 
   3082 		/**
   3083 		 * Retrieve plugin data, given the plugin name.
   3084 		 *
   3085 		 * @since      2.2.0
   3086 		 * @deprecated 2.5.0 use {@see TGM_Plugin_Activation::_get_plugin_data_from_name()} instead.
   3087 		 * @see        TGM_Plugin_Activation::_get_plugin_data_from_name()
   3088 		 *
   3089 		 * @param string $name Name of the plugin, as it was registered.
   3090 		 * @param string $data Optional. Array key of plugin data to return. Default is slug.
   3091 		 * @return string|boolean Plugin slug if found, false otherwise.
   3092 		 */
   3093 		protected function _get_plugin_data_from_name( $name, $data = 'slug' ) {
   3094 			_deprecated_function( __FUNCTION__, 'TGMPA 2.5.0', 'TGM_Plugin_Activation::_get_plugin_data_from_name()' );
   3095 
   3096 			return $this->tgmpa->_get_plugin_data_from_name( $name, $data );
   3097 		}
   3098 	}
   3099 }
   3100 
   3101 
   3102 if ( ! class_exists( 'TGM_Bulk_Installer' ) ) {
   3103 
   3104 	/**
   3105 	 * Hack: Prevent TGMPA v2.4.1- bulk installer class from being loaded if 2.4.1- is loaded after 2.5+.
   3106 	 *
   3107 	 * @since 2.5.2
   3108 	 *
   3109 	 * {@internal The TGMPA_Bulk_Installer class was originally called TGM_Bulk_Installer.
   3110 	 *            For more information, see that class.}}
   3111 	 */
   3112 	class TGM_Bulk_Installer {
   3113 	}
   3114 }
   3115 if ( ! class_exists( 'TGM_Bulk_Installer_Skin' ) ) {
   3116 
   3117 	/**
   3118 	 * Hack: Prevent TGMPA v2.4.1- bulk installer skin class from being loaded if 2.4.1- is loaded after 2.5+.
   3119 	 *
   3120 	 * @since 2.5.2
   3121 	 *
   3122 	 * {@internal The TGMPA_Bulk_Installer_Skin class was originally called TGM_Bulk_Installer_Skin.
   3123 	 *            For more information, see that class.}}
   3124 	 */
   3125 	class TGM_Bulk_Installer_Skin {
   3126 	}
   3127 }
   3128 
   3129 /**
   3130  * The WP_Upgrader file isn't always available. If it isn't available,
   3131  * we load it here.
   3132  *
   3133  * We check to make sure no action or activation keys are set so that WordPress
   3134  * does not try to re-include the class when processing upgrades or installs outside
   3135  * of the class.
   3136  *
   3137  * @since 2.2.0
   3138  */
   3139 add_action( 'admin_init', 'tgmpa_load_bulk_installer' );
   3140 if ( ! function_exists( 'tgmpa_load_bulk_installer' ) ) {
   3141 	/**
   3142 	 * Load bulk installer
   3143 	 */
   3144 	function tgmpa_load_bulk_installer() {
   3145 		// Silently fail if 2.5+ is loaded *after* an older version.
   3146 		if ( ! isset( $GLOBALS['tgmpa'] ) ) {
   3147 			return;
   3148 		}
   3149 
   3150 		// Get TGMPA class instance.
   3151 		$tgmpa_instance = call_user_func( array( get_class( $GLOBALS['tgmpa'] ), 'get_instance' ) );
   3152 
   3153 		if ( isset( $_GET['page'] ) && $tgmpa_instance->menu === $_GET['page'] ) {
   3154 			if ( ! class_exists( 'Plugin_Upgrader', false ) ) {
   3155 				require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
   3156 			}
   3157 
   3158 			if ( ! class_exists( 'TGMPA_Bulk_Installer' ) ) {
   3159 
   3160 				/**
   3161 				 * Installer class to handle bulk plugin installations.
   3162 				 *
   3163 				 * Extends WP_Upgrader and customizes to suit the installation of multiple
   3164 				 * plugins.
   3165 				 *
   3166 				 * @since 2.2.0
   3167 				 *
   3168 				 * {@internal Since 2.5.0 the class is an extension of Plugin_Upgrader rather than WP_Upgrader.}}
   3169 				 * {@internal Since 2.5.2 the class has been renamed from TGM_Bulk_Installer to TGMPA_Bulk_Installer.
   3170 				 *            This was done to prevent backward compatibility issues with v2.3.6.}}
   3171 				 *
   3172 				 * @package TGM-Plugin-Activation
   3173 				 * @author  Thomas Griffin
   3174 				 * @author  Gary Jones
   3175 				 */
   3176 				class TGMPA_Bulk_Installer extends Plugin_Upgrader {
   3177 					/**
   3178 					 * Holds result of bulk plugin installation.
   3179 					 *
   3180 					 * @since 2.2.0
   3181 					 *
   3182 					 * @var string
   3183 					 */
   3184 					public $result;
   3185 
   3186 					/**
   3187 					 * Flag to check if bulk installation is occurring or not.
   3188 					 *
   3189 					 * @since 2.2.0
   3190 					 *
   3191 					 * @var boolean
   3192 					 */
   3193 					public $bulk = false;
   3194 
   3195 					/**
   3196 					 * TGMPA instance
   3197 					 *
   3198 					 * @since 2.5.0
   3199 					 *
   3200 					 * @var object
   3201 					 */
   3202 					protected $tgmpa;
   3203 
   3204 					/**
   3205 					 * Whether or not the destination directory needs to be cleared ( = on update).
   3206 					 *
   3207 					 * @since 2.5.0
   3208 					 *
   3209 					 * @var bool
   3210 					 */
   3211 					protected $clear_destination = false;
   3212 
   3213 					/**
   3214 					 * References parent constructor and sets defaults for class.
   3215 					 *
   3216 					 * @since 2.2.0
   3217 					 *
   3218 					 * @param \Bulk_Upgrader_Skin|null $skin Installer skin.
   3219 					 */
   3220 					public function __construct( $skin = null ) {
   3221 						// Get TGMPA class instance.
   3222 						$this->tgmpa = call_user_func( array( get_class( $GLOBALS['tgmpa'] ), 'get_instance' ) );
   3223 
   3224 						parent::__construct( $skin );
   3225 
   3226 						if ( isset( $this->skin->options['install_type'] ) && 'update' === $this->skin->options['install_type'] ) {
   3227 							$this->clear_destination = true;
   3228 						}
   3229 
   3230 						if ( $this->tgmpa->is_automatic ) {
   3231 							$this->activate_strings();
   3232 						}
   3233 
   3234 						add_action( 'upgrader_process_complete', array( $this->tgmpa, 'populate_file_path' ) );
   3235 					}
   3236 
   3237 					/**
   3238 					 * Sets the correct activation strings for the installer skin to use.
   3239 					 *
   3240 					 * @since 2.2.0
   3241 					 */
   3242 					public function activate_strings() {
   3243 						$this->strings['activation_failed']  = esc_html__( 'Plugin activation failed.', 'aapside' );
   3244 						$this->strings['activation_success'] = esc_html__( 'Plugin activated successfully.', 'aapside' );
   3245 					}
   3246 
   3247 					/**
   3248 					 * Performs the actual installation of each plugin.
   3249 					 *
   3250 					 * @since 2.2.0
   3251 					 *
   3252 					 * @see WP_Upgrader::run()
   3253 					 *
   3254 					 * @param array $options The installation config options.
   3255 					 * @return null|array Return early if error, array of installation data on success.
   3256 					 */
   3257 					public function run( $options ) {
   3258 						$result = parent::run( $options );
   3259 
   3260 						// Reset the strings in case we changed one during automatic activation.
   3261 						if ( $this->tgmpa->is_automatic ) {
   3262 							if ( 'update' === $this->skin->options['install_type'] ) {
   3263 								$this->upgrade_strings();
   3264 							} else {
   3265 								$this->install_strings();
   3266 							}
   3267 						}
   3268 
   3269 						return $result;
   3270 					}
   3271 
   3272 					/**
   3273 					 * Processes the bulk installation of plugins.
   3274 					 *
   3275 					 * @since 2.2.0
   3276 					 *
   3277 					 * {@internal This is basically a near identical copy of the WP Core
   3278 					 * Plugin_Upgrader::bulk_upgrade() method, with minor adjustments to deal with
   3279 					 * new installs instead of upgrades.
   3280 					 * For ease of future synchronizations, the adjustments are clearly commented, but no other
   3281 					 * comments are added. Code style has been made to comply.}}
   3282 					 *
   3283 					 * @see Plugin_Upgrader::bulk_upgrade()
   3284 					 * @see https://core.trac.wordpress.org/browser/tags/4.2.1/src/wp-admin/includes/class-wp-upgrader.php#L838
   3285 					 * (@internal Last synced: Dec 31st 2015 against https://core.trac.wordpress.org/browser/trunk?rev=36134}}
   3286 					 *
   3287 					 * @param array $plugins The plugin sources needed for installation.
   3288 					 * @param array $args    Arbitrary passed extra arguments.
   3289 					 * @return array|false   Install confirmation messages on success, false on failure.
   3290 					 */
   3291 					public function bulk_install( $plugins, $args = array() ) {
   3292 						// [TGMPA + ] Hook auto-activation in.
   3293 						add_filter( 'upgrader_post_install', array( $this, 'auto_activate' ), 10 );
   3294 
   3295 						$defaults    = array(
   3296 							'clear_update_cache' => true,
   3297 						);
   3298 						$parsed_args = wp_parse_args( $args, $defaults );
   3299 
   3300 						$this->init();
   3301 						$this->bulk = true;
   3302 
   3303 						$this->install_strings(); // [TGMPA + ] adjusted.
   3304 
   3305 						/* [TGMPA - ] $current = get_site_transient( 'update_plugins' ); */
   3306 
   3307 						/* [TGMPA - ] add_filter('upgrader_clear_destination', array($this, 'delete_old_plugin'), 10, 4); */
   3308 
   3309 						$this->skin->header();
   3310 
   3311 						// Connect to the Filesystem first.
   3312 						$res = $this->fs_connect( array( WP_CONTENT_DIR, WP_PLUGIN_DIR ) );
   3313 						if ( ! $res ) {
   3314 							$this->skin->footer();
   3315 							return false;
   3316 						}
   3317 
   3318 						$this->skin->bulk_header();
   3319 
   3320 						/*
   3321 						 * Only start maintenance mode if:
   3322 						 * - running Multisite and there are one or more plugins specified, OR
   3323 						 * - a plugin with an update available is currently active.
   3324 						 * @TODO: For multisite, maintenance mode should only kick in for individual sites if at all possible.
   3325 						 */
   3326 						$maintenance = ( is_multisite() && ! empty( $plugins ) );
   3327 
   3328 						/*
   3329 						[TGMPA - ]
   3330 						foreach ( $plugins as $plugin )
   3331 							$maintenance = $maintenance || ( is_plugin_active( $plugin ) && isset( $current->response[ $plugin] ) );
   3332 						*/
   3333 						if ( $maintenance ) {
   3334 							$this->maintenance_mode( true );
   3335 						}
   3336 
   3337 						$results = array();
   3338 
   3339 						$this->update_count   = count( $plugins );
   3340 						$this->update_current = 0;
   3341 						foreach ( $plugins as $plugin ) {
   3342 							$this->update_current++;
   3343 
   3344 							/*
   3345 							[TGMPA - ]
   3346 							$this->skin->plugin_info = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin, false, true);
   3347 
   3348 							if ( !isset( $current->response[ $plugin ] ) ) {
   3349 								$this->skin->set_result('up_to_date');
   3350 								$this->skin->before();
   3351 								$this->skin->feedback('up_to_date');
   3352 								$this->skin->after();
   3353 								$results[$plugin] = true;
   3354 								continue;
   3355 							}
   3356 
   3357 							// Get the URL to the zip file.
   3358 							$r = $current->response[ $plugin ];
   3359 
   3360 							$this->skin->plugin_active = is_plugin_active($plugin);
   3361 							*/
   3362 
   3363 							$result = $this->run(
   3364 								array(
   3365 									'package'           => $plugin, // [TGMPA + ] adjusted.
   3366 									'destination'       => WP_PLUGIN_DIR,
   3367 									'clear_destination' => false, // [TGMPA + ] adjusted.
   3368 									'clear_working'     => true,
   3369 									'is_multi'          => true,
   3370 									'hook_extra'        => array(
   3371 										'plugin' => $plugin,
   3372 									),
   3373 								)
   3374 							);
   3375 
   3376 							$results[ $plugin ] = $this->result;
   3377 
   3378 							// Prevent credentials auth screen from displaying multiple times.
   3379 							if ( false === $result ) {
   3380 								break;
   3381 							}
   3382 						} //end foreach $plugins
   3383 
   3384 						$this->maintenance_mode( false );
   3385 
   3386 						/**
   3387 						 * Fires when the bulk upgrader process is complete.
   3388 						 *
   3389 						 * @since WP 3.6.0 / TGMPA 2.5.0
   3390 						 *
   3391 						 * @param Plugin_Upgrader $this Plugin_Upgrader instance. In other contexts, $this, might
   3392 						 *                              be a Theme_Upgrader or Core_Upgrade instance.
   3393 						 * @param array           $data {
   3394 						 *     Array of bulk item update data.
   3395 						 *
   3396 						 *     @type string $action   Type of action. Default 'update'.
   3397 						 *     @type string $type     Type of update process. Accepts 'plugin', 'theme', or 'core'.
   3398 						 *     @type bool   $bulk     Whether the update process is a bulk update. Default true.
   3399 						 *     @type array  $packages Array of plugin, theme, or core packages to update.
   3400 						 * }
   3401 						 */
   3402 						do_action( 'upgrader_process_complete', $this, array(
   3403 							'action'  => 'install', // [TGMPA + ] adjusted.
   3404 							'type'    => 'plugin',
   3405 							'bulk'    => true,
   3406 							'plugins' => $plugins,
   3407 						) );
   3408 
   3409 						$this->skin->bulk_footer();
   3410 
   3411 						$this->skin->footer();
   3412 
   3413 						// Cleanup our hooks, in case something else does a upgrade on this connection.
   3414 						/* [TGMPA - ] remove_filter('upgrader_clear_destination', array($this, 'delete_old_plugin')); */
   3415 
   3416 						// [TGMPA + ] Remove our auto-activation hook.
   3417 						remove_filter( 'upgrader_post_install', array( $this, 'auto_activate' ), 10 );
   3418 
   3419 						// Force refresh of plugin update information.
   3420 						wp_clean_plugins_cache( $parsed_args['clear_update_cache'] );
   3421 
   3422 						return $results;
   3423 					}
   3424 
   3425 					/**
   3426 					 * Handle a bulk upgrade request.
   3427 					 *
   3428 					 * @since 2.5.0
   3429 					 *
   3430 					 * @see Plugin_Upgrader::bulk_upgrade()
   3431 					 *
   3432 					 * @param array $plugins The local WP file_path's of the plugins which should be upgraded.
   3433 					 * @param array $args    Arbitrary passed extra arguments.
   3434 					 * @return string|bool Install confirmation messages on success, false on failure.
   3435 					 */
   3436 					public function bulk_upgrade( $plugins, $args = array() ) {
   3437 
   3438 						add_filter( 'upgrader_post_install', array( $this, 'auto_activate' ), 10 );
   3439 
   3440 						$result = parent::bulk_upgrade( $plugins, $args );
   3441 
   3442 						remove_filter( 'upgrader_post_install', array( $this, 'auto_activate' ), 10 );
   3443 
   3444 						return $result;
   3445 					}
   3446 
   3447 					/**
   3448 					 * Abuse a filter to auto-activate plugins after installation.
   3449 					 *
   3450 					 * Hooked into the 'upgrader_post_install' filter hook.
   3451 					 *
   3452 					 * @since 2.5.0
   3453 					 *
   3454 					 * @param bool $bool The value we need to give back (true).
   3455 					 * @return bool
   3456 					 */
   3457 					public function auto_activate( $bool ) {
   3458 						// Only process the activation of installed plugins if the automatic flag is set to true.
   3459 						if ( $this->tgmpa->is_automatic ) {
   3460 							// Flush plugins cache so the headers of the newly installed plugins will be read correctly.
   3461 							wp_clean_plugins_cache();
   3462 
   3463 							// Get the installed plugin file.
   3464 							$plugin_info = $this->plugin_info();
   3465 
   3466 							// Don't try to activate on upgrade of active plugin as WP will do this already.
   3467 							if ( ! is_plugin_active( $plugin_info ) ) {
   3468 								$activate = activate_plugin( $plugin_info );
   3469 
   3470 								// Adjust the success string based on the activation result.
   3471 								$this->strings['process_success'] = $this->strings['process_success'] . "<br />\n";
   3472 
   3473 								if ( is_wp_error( $activate ) ) {
   3474 									$this->skin->error( $activate );
   3475 									$this->strings['process_success'] .= $this->strings['activation_failed'];
   3476 								} else {
   3477 									$this->strings['process_success'] .= $this->strings['activation_success'];
   3478 								}
   3479 							}
   3480 						}
   3481 
   3482 						return $bool;
   3483 					}
   3484 				}
   3485 			}
   3486 
   3487 			if ( ! class_exists( 'TGMPA_Bulk_Installer_Skin' ) ) {
   3488 
   3489 				/**
   3490 				 * Installer skin to set strings for the bulk plugin installations..
   3491 				 *
   3492 				 * Extends Bulk_Upgrader_Skin and customizes to suit the installation of multiple
   3493 				 * plugins.
   3494 				 *
   3495 				 * @since 2.2.0
   3496 				 *
   3497 				 * {@internal Since 2.5.2 the class has been renamed from TGM_Bulk_Installer_Skin to
   3498 				 *            TGMPA_Bulk_Installer_Skin.
   3499 				 *            This was done to prevent backward compatibility issues with v2.3.6.}}
   3500 				 *
   3501 				 * @see https://core.trac.wordpress.org/browser/trunk/src/wp-admin/includes/class-wp-upgrader-skins.php
   3502 				 *
   3503 				 * @package TGM-Plugin-Activation
   3504 				 * @author  Thomas Griffin
   3505 				 * @author  Gary Jones
   3506 				 */
   3507 				class TGMPA_Bulk_Installer_Skin extends Bulk_Upgrader_Skin {
   3508 					/**
   3509 					 * Holds plugin info for each individual plugin installation.
   3510 					 *
   3511 					 * @since 2.2.0
   3512 					 *
   3513 					 * @var array
   3514 					 */
   3515 					public $plugin_info = array();
   3516 
   3517 					/**
   3518 					 * Holds names of plugins that are undergoing bulk installations.
   3519 					 *
   3520 					 * @since 2.2.0
   3521 					 *
   3522 					 * @var array
   3523 					 */
   3524 					public $plugin_names = array();
   3525 
   3526 					/**
   3527 					 * Integer to use for iteration through each plugin installation.
   3528 					 *
   3529 					 * @since 2.2.0
   3530 					 *
   3531 					 * @var integer
   3532 					 */
   3533 					public $i = 0;
   3534 
   3535 					/**
   3536 					 * TGMPA instance
   3537 					 *
   3538 					 * @since 2.5.0
   3539 					 *
   3540 					 * @var object
   3541 					 */
   3542 					protected $tgmpa;
   3543 
   3544 					/**
   3545 					 * Constructor. Parses default args with new ones and extracts them for use.
   3546 					 *
   3547 					 * @since 2.2.0
   3548 					 *
   3549 					 * @param array $args Arguments to pass for use within the class.
   3550 					 */
   3551 					public function __construct( $args = array() ) {
   3552 						// Get TGMPA class instance.
   3553 						$this->tgmpa = call_user_func( array( get_class( $GLOBALS['tgmpa'] ), 'get_instance' ) );
   3554 
   3555 						// Parse default and new args.
   3556 						$defaults = array(
   3557 							'url'          => '',
   3558 							'nonce'        => '',
   3559 							'names'        => array(),
   3560 							'install_type' => 'install',
   3561 						);
   3562 						$args     = wp_parse_args( $args, $defaults );
   3563 
   3564 						// Set plugin names to $this->plugin_names property.
   3565 						$this->plugin_names = $args['names'];
   3566 
   3567 						// Extract the new args.
   3568 						parent::__construct( $args );
   3569 					}
   3570 
   3571 					/**
   3572 					 * Sets install skin strings for each individual plugin.
   3573 					 *
   3574 					 * Checks to see if the automatic activation flag is set and uses the
   3575 					 * the proper strings accordingly.
   3576 					 *
   3577 					 * @since 2.2.0
   3578 					 */
   3579 					public function add_strings() {
   3580 						if ( 'update' === $this->options['install_type'] ) {
   3581 							parent::add_strings();
   3582 							/* translators: 1: plugin name, 2: action number 3: total number of actions. */
   3583 							$this->upgrader->strings['skin_before_update_header'] = __( 'Updating Plugin %1$s (%2$d/%3$d)', 'aapside' );
   3584 						} else {
   3585 							/* translators: 1: plugin name, 2: error message. */
   3586 							$this->upgrader->strings['skin_update_failed_error'] = __( 'An error occurred while installing %1$s: <strong>%2$s</strong>.', 'aapside' );
   3587 							/* translators: 1: plugin name. */
   3588 							$this->upgrader->strings['skin_update_failed'] = __( 'The installation of %1$s failed.', 'aapside' );
   3589 
   3590 							if ( $this->tgmpa->is_automatic ) {
   3591 								// Automatic activation strings.
   3592 								$this->upgrader->strings['skin_upgrade_start'] = __( 'The installation and activation process is starting. This process may take a while on some hosts, so please be patient.', 'aapside' );
   3593 								/* translators: 1: plugin name. */
   3594 								$this->upgrader->strings['skin_update_successful'] = __( '%1$s done.' ,'aapside');
   3595 								$this->upgrader->strings['skin_upgrade_end']       = __( 'All installations and activations have been completed.', 'aapside' );
   3596 								/* translators: 1: plugin name, 2: action number 3: total number of actions. */
   3597 								$this->upgrader->strings['skin_before_update_header'] = __( 'Installing and Activating Plugin %1$s (%2$d/%3$d)', 'aapside' );
   3598 							} else {
   3599 								// Default installation strings.
   3600 								$this->upgrader->strings['skin_upgrade_start'] = __( 'The installation process is starting. This process may take a while on some hosts, so please be patient.', 'aapside' );
   3601 								/* translators: 1: plugin name. */
   3602 								$this->upgrader->strings['skin_update_successful'] = __( '%1$s done.','aapside' );
   3603 								$this->upgrader->strings['skin_upgrade_end']       = __( 'All installations have been completed.', 'aapside' );
   3604 								/* translators: 1: plugin name, 2: action number 3: total number of actions. */
   3605 								$this->upgrader->strings['skin_before_update_header'] = __( 'Installing Plugin %1$s (%2$d/%3$d)', 'aapside' );
   3606 							}
   3607 						}
   3608 					}
   3609 					/**
   3610 					 * Outputs the header strings and necessary JS before each plugin installation.
   3611 					 *
   3612 					 * @since 2.2.0
   3613 					 *
   3614 					 * @param string $title Unused in this implementation.
   3615 					 */
   3616 					public function before( $title = '' ) {
   3617 						if ( empty( $title ) ) {
   3618 							$title = esc_html( $this->plugin_names[ $this->i ] );
   3619 						}
   3620 						parent::before( $title );
   3621 					}
   3622 
   3623 					/**
   3624 					 * Outputs the footer strings and necessary JS after each plugin installation.
   3625 					 *
   3626 					 * Checks for any errors and outputs them if they exist, else output
   3627 					 * success strings.
   3628 					 *
   3629 					 * @since 2.2.0
   3630 					 *
   3631 					 * @param string $title Unused in this implementation.
   3632 					 */
   3633 					public function after( $title = '' ) {
   3634 						if ( empty( $title ) ) {
   3635 							$title = esc_html( $this->plugin_names[ $this->i ] );
   3636 						}
   3637 						parent::after( $title );
   3638 
   3639 						$this->i++;
   3640 					}
   3641 
   3642 					/**
   3643 					 * Outputs links after bulk plugin installation is complete.
   3644 					 *
   3645 					 * @since 2.2.0
   3646 					 */
   3647 					public function bulk_footer() {
   3648 						// Serve up the string to say installations (and possibly activations) are complete.
   3649 						parent::bulk_footer();
   3650 
   3651 						// Flush plugins cache so we can make sure that the installed plugins list is always up to date.
   3652 						wp_clean_plugins_cache();
   3653 
   3654 						$this->tgmpa->show_tgmpa_version();
   3655 
   3656 						// Display message based on if all plugins are now active or not.
   3657 						$update_actions = array();
   3658 
   3659 						if ( $this->tgmpa->is_tgmpa_complete() ) {
   3660 							// All plugins are active, so we display the complete string and hide the menu to protect users.
   3661 							echo '<style type="text/css">#adminmenu .wp-submenu li.current { display: none !important; }</style>';
   3662 							$update_actions['dashboard'] = sprintf(
   3663 								esc_html( $this->tgmpa->strings['complete'] ),
   3664 								'<a href="' . esc_url( self_admin_url() ) . '">' . esc_html__( 'Return to the Dashboard', 'aapside' ) . '</a>'
   3665 							);
   3666 						} else {
   3667 							$update_actions['tgmpa_page'] = '<a href="' . esc_url( $this->tgmpa->get_tgmpa_url() ) . '" target="_parent">' . esc_html( $this->tgmpa->strings['return'] ) . '</a>';
   3668 						}
   3669 
   3670 						/**
   3671 						 * Filter the list of action links available following bulk plugin installs/updates.
   3672 						 *
   3673 						 * @since 2.5.0
   3674 						 *
   3675 						 * @param array $update_actions Array of plugin action links.
   3676 						 * @param array $plugin_info    Array of information for the last-handled plugin.
   3677 						 */
   3678 						$update_actions = apply_filters( 'tgmpa_update_bulk_plugins_complete_actions', $update_actions, $this->plugin_info );
   3679 
   3680 						if ( ! empty( $update_actions ) ) {
   3681 							$this->feedback( implode( ' | ', (array) $update_actions ) );
   3682 						}
   3683 					}
   3684 
   3685 					/* *********** DEPRECATED METHODS *********** */
   3686 
   3687 					/**
   3688 					 * Flush header output buffer.
   3689 					 *
   3690 					 * @since      2.2.0
   3691 					 * @deprecated 2.5.0 use {@see Bulk_Upgrader_Skin::flush_output()} instead
   3692 					 * @see        Bulk_Upgrader_Skin::flush_output()
   3693 					 */
   3694 					public function before_flush_output() {
   3695 						_deprecated_function( __FUNCTION__, 'TGMPA 2.5.0', 'Bulk_Upgrader_Skin::flush_output()' );
   3696 						$this->flush_output();
   3697 					}
   3698 
   3699 					/**
   3700 					 * Flush footer output buffer and iterate $this->i to make sure the
   3701 					 * installation strings reference the correct plugin.
   3702 					 *
   3703 					 * @since      2.2.0
   3704 					 * @deprecated 2.5.0 use {@see Bulk_Upgrader_Skin::flush_output()} instead
   3705 					 * @see        Bulk_Upgrader_Skin::flush_output()
   3706 					 */
   3707 					public function after_flush_output() {
   3708 						_deprecated_function( __FUNCTION__, 'TGMPA 2.5.0', 'Bulk_Upgrader_Skin::flush_output()' );
   3709 						$this->flush_output();
   3710 						$this->i++;
   3711 					}
   3712 				}
   3713 			}
   3714 		}
   3715 	}
   3716 }
   3717 
   3718 if ( ! class_exists( 'TGMPA_Utils' ) ) {
   3719 
   3720 	/**
   3721 	 * Generic utilities for TGMPA.
   3722 	 *
   3723 	 * All methods are static, poor-dev name-spacing class wrapper.
   3724 	 *
   3725 	 * Class was called TGM_Utils in 2.5.0 but renamed TGMPA_Utils in 2.5.1 as this was conflicting with Soliloquy.
   3726 	 *
   3727 	 * @since 2.5.0
   3728 	 *
   3729 	 * @package TGM-Plugin-Activation
   3730 	 * @author  Juliette Reinders Folmer
   3731 	 */
   3732 	class TGMPA_Utils {
   3733 		/**
   3734 		 * Whether the PHP filter extension is enabled.
   3735 		 *
   3736 		 * @see http://php.net/book.filter
   3737 		 *
   3738 		 * @since 2.5.0
   3739 		 *
   3740 		 * @static
   3741 		 *
   3742 		 * @var bool $has_filters True is the extension is enabled.
   3743 		 */
   3744 		public static $has_filters;
   3745 
   3746 		/**
   3747 		 * Wrap an arbitrary string in <em> tags. Meant to be used in combination with array_map().
   3748 		 *
   3749 		 * @since 2.5.0
   3750 		 *
   3751 		 * @static
   3752 		 *
   3753 		 * @param string $string Text to be wrapped.
   3754 		 * @return string
   3755 		 */
   3756 		public static function wrap_in_em( $string ) {
   3757 			return '<em>' . wp_kses_post( $string ) . '</em>';
   3758 		}
   3759 
   3760 		/**
   3761 		 * Wrap an arbitrary string in <strong> tags. Meant to be used in combination with array_map().
   3762 		 *
   3763 		 * @since 2.5.0
   3764 		 *
   3765 		 * @static
   3766 		 *
   3767 		 * @param string $string Text to be wrapped.
   3768 		 * @return string
   3769 		 */
   3770 		public static function wrap_in_strong( $string ) {
   3771 			return '<strong>' . wp_kses_post( $string ) . '</strong>';
   3772 		}
   3773 
   3774 		/**
   3775 		 * Helper function: Validate a value as boolean
   3776 		 *
   3777 		 * @since 2.5.0
   3778 		 *
   3779 		 * @static
   3780 		 *
   3781 		 * @param mixed $value Arbitrary value.
   3782 		 * @return bool
   3783 		 */
   3784 		public static function validate_bool( $value ) {
   3785 			if ( ! isset( self::$has_filters ) ) {
   3786 				self::$has_filters = extension_loaded( 'filter' );
   3787 			}
   3788 
   3789 			if ( self::$has_filters ) {
   3790 				return filter_var( $value, FILTER_VALIDATE_BOOLEAN );
   3791 			} else {
   3792 				return self::emulate_filter_bool( $value );
   3793 			}
   3794 		}
   3795 
   3796 		/**
   3797 		 * Helper function: Cast a value to bool
   3798 		 *
   3799 		 * @since 2.5.0
   3800 		 *
   3801 		 * @static
   3802 		 *
   3803 		 * @param mixed $value Value to cast.
   3804 		 * @return bool
   3805 		 */
   3806 		protected static function emulate_filter_bool( $value ) {
   3807 			// @codingStandardsIgnoreStart
   3808 			static $true  = array(
   3809 				'1',
   3810 				'true', 'True', 'TRUE',
   3811 				'y', 'Y',
   3812 				'yes', 'Yes', 'YES',
   3813 				'on', 'On', 'ON',
   3814 			);
   3815 			static $false = array(
   3816 				'0',
   3817 				'false', 'False', 'FALSE',
   3818 				'n', 'N',
   3819 				'no', 'No', 'NO',
   3820 				'off', 'Off', 'OFF',
   3821 			);
   3822 			// @codingStandardsIgnoreEnd
   3823 
   3824 			if ( is_bool( $value ) ) {
   3825 				return $value;
   3826 			} elseif ( is_int( $value ) && ( 0 === $value || 1 === $value ) ) {
   3827 				return (bool) $value;
   3828 			} elseif ( ( is_float( $value ) && ! is_nan( $value ) ) && ( (float) 0 === $value || (float) 1 === $value ) ) {
   3829 				return (bool) $value;
   3830 			} elseif ( is_string( $value ) ) {
   3831 				$value = trim( $value );
   3832 				if ( in_array( $value, $true, true ) ) {
   3833 					return true;
   3834 				} elseif ( in_array( $value, $false, true ) ) {
   3835 					return false;
   3836 				} else {
   3837 					return false;
   3838 				}
   3839 			}
   3840 
   3841 			return false;
   3842 		}
   3843 	} // End of class TGMPA_Utils
   3844 } // End of class_exists wrapper