balmet.com

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

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


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