TGM_Plugin_Activation

Automatic plugin installation and activation library.

Defined (1)

The class is defined in the following location(s).

/class-tgm-plugin-activation.php  
  1. class TGM_Plugin_Activation { 
  2. /** 
  3. * TGMPA version number. 
  4. * @since 2.5.0 
  5. * @const string Version number. 
  6. */ 
  7. const TGMPA_VERSION = '2.6.1'; 
  8.  
  9. /** 
  10. * Regular expression to test if a URL is a WP plugin repo URL. 
  11. * @const string Regex. 
  12. * @since 2.5.0 
  13. */ 
  14. const WP_REPO_REGEX = '|^http[s]?://wordpress\.org/(?:extend/)?plugins/|'; 
  15.  
  16. /** 
  17. * Arbitrary regular expression to test if a string starts with a URL. 
  18. * @const string Regex. 
  19. * @since 2.5.0 
  20. */ 
  21. const IS_URL_REGEX = '|^http[s]?://|'; 
  22.  
  23. /** 
  24. * Holds a copy of itself, so it can be referenced by the class name. 
  25. * @since 1.0.0 
  26. * @var TGM_Plugin_Activation 
  27. */ 
  28. public static $instance; 
  29.  
  30. /** 
  31. * Holds arrays of plugin details. 
  32. * @since 1.0.0 
  33. * @since 2.5.0 the array has the plugin slug as an associative key. 
  34. * @var array 
  35. */ 
  36. public $plugins = array(); 
  37.  
  38. /** 
  39. * Holds arrays of plugin names to use to sort the plugins array. 
  40. * @since 2.5.0 
  41. * @var array 
  42. */ 
  43. protected $sort_order = array(); 
  44.  
  45. /** 
  46. * Whether any plugins have the 'force_activation' setting set to true. 
  47. * @since 2.5.0 
  48. * @var bool 
  49. */ 
  50. protected $has_forced_activation = false; 
  51.  
  52. /** 
  53. * Whether any plugins have the 'force_deactivation' setting set to true. 
  54. * @since 2.5.0 
  55. * @var bool 
  56. */ 
  57. protected $has_forced_deactivation = false; 
  58.  
  59. /** 
  60. * Name of the unique ID to hash notices. 
  61. * @since 2.4.0 
  62. * @var string 
  63. */ 
  64. public $id = 'tgmpa'; 
  65.  
  66. /** 
  67. * Name of the query-string argument for the admin page. 
  68. * @since 1.0.0 
  69. * @var string 
  70. */ 
  71. protected $menu = 'tgmpa-install-plugins'; 
  72.  
  73. /** 
  74. * Parent menu file slug. 
  75. * @since 2.5.0 
  76. * @var string 
  77. */ 
  78. public $parent_slug = 'themes.php'; 
  79.  
  80. /** 
  81. * Capability needed to view the plugin installation menu item. 
  82. * @since 2.5.0 
  83. * @var string 
  84. */ 
  85. public $capability = 'edit_theme_options'; 
  86.  
  87. /** 
  88. * Default absolute path to folder containing bundled plugin zip files. 
  89. * @since 2.0.0 
  90. * @var string Absolute path prefix to zip file location for bundled plugins. Default is empty string. 
  91. */ 
  92. public $default_path = ''; 
  93.  
  94. /** 
  95. * Flag to show admin notices or not. 
  96. * @since 2.1.0 
  97. * @var boolean 
  98. */ 
  99. public $has_notices = true; 
  100.  
  101. /** 
  102. * Flag to determine if the user can dismiss the notice nag. 
  103. * @since 2.4.0 
  104. * @var boolean 
  105. */ 
  106. public $dismissable = true; 
  107.  
  108. /** 
  109. * Message to be output above nag notice if dismissable is false. 
  110. * @since 2.4.0 
  111. * @var string 
  112. */ 
  113. public $dismiss_msg = ''; 
  114.  
  115. /** 
  116. * Flag to set automatic activation of plugins. Off by default. 
  117. * @since 2.2.0 
  118. * @var boolean 
  119. */ 
  120. public $is_automatic = false; 
  121.  
  122. /** 
  123. * Optional message to display before the plugins table. 
  124. * @since 2.2.0 
  125. * @var string Message filtered by wp_kses_post(). Default is empty string. 
  126. */ 
  127. public $message = ''; 
  128.  
  129. /** 
  130. * Holds configurable array of strings. 
  131. * Default values are added in the constructor. 
  132. * @since 2.0.0 
  133. * @var array 
  134. */ 
  135. public $strings = array(); 
  136.  
  137. /** 
  138. * Holds the version of WordPress. 
  139. * @since 2.4.0 
  140. * @var int 
  141. */ 
  142. public $wp_version; 
  143.  
  144. /** 
  145. * Holds the hook name for the admin page. 
  146. * @since 2.5.0 
  147. * @var string 
  148. */ 
  149. public $page_hook; 
  150.  
  151. /** 
  152. * Adds a reference of this object to $instance, populates default strings,  
  153. * does the tgmpa_init action hook, and hooks in the interactions to init. 
  154. * {@internal This method should be `protected`, but as too many TGMPA implementations 
  155. * haven't upgraded beyond v2.3.6 yet, this gives backward compatibility issues. 
  156. * Reverted back to public for the time being.}} 
  157. * @since 1.0.0 
  158. * @see TGM_Plugin_Activation::init() 
  159. */ 
  160. public function __construct() { 
  161. // Set the current WordPress version. 
  162. $this->wp_version = $GLOBALS['wp_version']; 
  163.  
  164. // Announce that the class is ready, and pass the object (for advanced use). 
  165. do_action_ref_array( 'tgmpa_init', array( $this ) ); 
  166.  
  167.  
  168.  
  169. // When the rest of WP has loaded, kick-start the rest of the class. 
  170. add_action( 'init', array( $this, 'init' ) ); 
  171.  
  172. /** 
  173. * Magic method to (not) set protected properties from outside of this class. 
  174. * {@internal hackedihack... There is a serious bug in v2.3.2 - 2.3.6 where the `menu` property 
  175. * is being assigned rather than tested in a conditional, effectively rendering it useless. 
  176. * This 'hack' prevents this from happening.}} 
  177. * @see https://github.com/TGMPA/TGM-Plugin-Activation/blob/2.3.6/tgm-plugin-activation/class-tgm-plugin-activation.php#L1593 
  178. * @since 2.5.2 
  179. * @param string $name Name of an inaccessible property. 
  180. * @param mixed $value Value to assign to the property. 
  181. * @return void Silently fail to set the property when this is tried from outside of this class context. 
  182. * (Inside this class context, the __set() method if not used as there is direct access.) 
  183. */ 
  184. public function __set( $name, $value ) { 
  185. return; 
  186.  
  187. /** 
  188. * Magic method to get the value of a protected property outside of this class context. 
  189. * @since 2.5.2 
  190. * @param string $name Name of an inaccessible property. 
  191. * @return mixed The property value. 
  192. */ 
  193. public function __get( $name ) { 
  194. return $this->{$name}; 
  195.  
  196. /** 
  197. * Initialise the interactions between this class and WordPress. 
  198. * Hooks in three new methods for the class: admin_menu, notices and styles. 
  199. * @since 2.0.0 
  200. * @see TGM_Plugin_Activation::admin_menu() 
  201. * @see TGM_Plugin_Activation::notices() 
  202. * @see TGM_Plugin_Activation::styles() 
  203. */ 
  204. public function init() { 
  205. /** 
  206. * By default TGMPA only loads on the WP back-end and not in an Ajax call. Using this filter 
  207. * you can overrule that behaviour. 
  208. * @since 2.5.0 
  209. * @param bool $load Whether or not TGMPA should load. 
  210. * Defaults to the return of `is_admin() && ! defined( 'DOING_AJAX' )`. 
  211. */ 
  212. if ( true !== apply_filters( 'tgmpa_load', ( is_admin() && ! defined( 'DOING_AJAX' ) ) ) ) { 
  213. return; 
  214.  
  215. // Load class strings. 
  216. $this->strings = array( 
  217. 'page_title' => __( 'Install Required Plugins', 'enigma' ),  
  218. 'menu_title' => __( 'Install Plugins', 'enigma' ),  
  219. /** translators: %s: plugin name. */ 
  220. 'installing' => __( 'Installing Plugin: %s', 'enigma' ),  
  221. /** translators: %s: plugin name. */ 
  222. 'updating' => __( 'Updating Plugin: %s', 'enigma' ),  
  223. 'oops' => __( 'Something went wrong with the plugin API.', 'enigma' ),  
  224. 'notice_can_install_required' => _n_noop( 
  225. /** translators: 1: plugin name(s). */ 
  226. 'This theme requires the following plugin: %1$s.',  
  227. 'This theme requires the following plugins: %1$s.',  
  228. 'enigma' 
  229. ),  
  230. 'notice_can_install_recommended' => _n_noop( 
  231. /** translators: 1: plugin name(s). */ 
  232. 'This theme recommends the following plugin: %1$s.',  
  233. 'This theme recommends the following plugins: %1$s.',  
  234. 'enigma' 
  235. ),  
  236. 'notice_ask_to_update' => _n_noop( 
  237. /** translators: 1: plugin name(s). */ 
  238. 'The following plugin needs to be updated to its latest version to ensure maximum compatibility with this theme: %1$s.',  
  239. 'The following plugins need to be updated to their latest version to ensure maximum compatibility with this theme: %1$s.',  
  240. 'enigma' 
  241. ),  
  242. 'notice_ask_to_update_maybe' => _n_noop( 
  243. /** translators: 1: plugin name(s). */ 
  244. 'There is an update available for: %1$s.',  
  245. 'There are updates available for the following plugins: %1$s.',  
  246. 'enigma' 
  247. ),  
  248. 'notice_can_activate_required' => _n_noop( 
  249. /** translators: 1: plugin name(s). */ 
  250. 'The following required plugin is currently inactive: %1$s.',  
  251. 'The following required plugins are currently inactive: %1$s.',  
  252. 'enigma' 
  253. ),  
  254. 'notice_can_activate_recommended' => _n_noop( 
  255. /** translators: 1: plugin name(s). */ 
  256. 'The following recommended plugin is currently inactive: %1$s.',  
  257. 'The following recommended plugins are currently inactive: %1$s.',  
  258. 'enigma' 
  259. ),  
  260. 'install_link' => _n_noop( 
  261. 'Begin installing plugin',  
  262. 'Begin installing plugins',  
  263. 'enigma' 
  264. ),  
  265. 'update_link' => _n_noop( 
  266. 'Begin updating plugin',  
  267. 'Begin updating plugins',  
  268. 'enigma' 
  269. ),  
  270. 'activate_link' => _n_noop( 
  271. 'Begin activating plugin',  
  272. 'Begin activating plugins',  
  273. 'enigma' 
  274. ),  
  275. 'return' => __( 'Return to Required Plugins Installer', 'enigma' ),  
  276. 'dashboard' => __( 'Return to the Dashboard', 'enigma' ),  
  277. 'plugin_activated' => __( 'Plugin activated successfully.', 'enigma' ),  
  278. 'activated_successfully' => __( 'The following plugin was activated successfully:', 'enigma' ),  
  279. /** translators: 1: plugin name. */ 
  280. 'plugin_already_active' => __( 'No action taken. Plugin %1$s was already active.', 'enigma' ),  
  281. /** translators: 1: plugin name. */ 
  282. 'plugin_needs_higher_version' => __( 'Plugin not activated. A higher version of %s is needed for this theme. Please update the plugin.', 'enigma' ),  
  283. /** translators: 1: dashboard link. */ 
  284. 'complete' => __( 'All plugins installed and activated successfully. %1$s', 'enigma' ),  
  285. 'dismiss' => __( 'Dismiss this notice', 'enigma' ),  
  286. 'notice_cannot_install_activate' => __( 'There are one or more required or recommended plugins to install, update or activate.', 'enigma' ),  
  287. 'contact_admin' => __( 'Please contact the administrator of this site for help.', 'enigma' ),  
  288. ); 
  289.  
  290. do_action( 'tgmpa_register' ); 
  291.  
  292. /** After this point, the plugins should be registered and the configuration set. */ 
  293.  
  294. // Proceed only if we have plugins to handle. 
  295. if ( empty( $this->plugins ) || ! is_array( $this->plugins ) ) { 
  296. return; 
  297.  
  298. // Set up the menu and notices if we still have outstanding actions. 
  299. if ( true !== $this->is_tgmpa_complete() ) { 
  300. // Sort the plugins. 
  301. array_multisort( $this->sort_order, SORT_ASC, $this->plugins ); 
  302.  
  303. add_action( 'admin_menu', array( $this, 'admin_menu' ) ); 
  304. add_action( 'admin_head', array( $this, 'dismiss' ) ); 
  305.  
  306. // Prevent the normal links from showing underneath a single install/update page. 
  307. add_filter( 'install_plugin_complete_actions', array( $this, 'actions' ) ); 
  308. add_filter( 'update_plugin_complete_actions', array( $this, 'actions' ) ); 
  309.  
  310. if ( $this->has_notices ) { 
  311. add_action( 'admin_notices', array( $this, 'notices' ) ); 
  312. add_action( 'admin_init', array( $this, 'admin_init' ), 1 ); 
  313. add_action( 'admin_enqueue_scripts', array( $this, 'thickbox' ) ); 
  314.  
  315. // If needed, filter plugin action links. 
  316. add_action( 'load-plugins.php', array( $this, 'add_plugin_action_link_filters' ), 1 ); 
  317.  
  318. // Make sure things get reset on switch theme. 
  319. add_action( 'switch_theme', array( $this, 'flush_plugins_cache' ) ); 
  320.  
  321. if ( $this->has_notices ) { 
  322. add_action( 'switch_theme', array( $this, 'update_dismiss' ) ); 
  323.  
  324. // Setup the force activation hook. 
  325. if ( true === $this->has_forced_activation ) { 
  326. add_action( 'admin_init', array( $this, 'force_activation' ) ); 
  327.  
  328. // Setup the force deactivation hook. 
  329. if ( true === $this->has_forced_deactivation ) { 
  330. add_action( 'switch_theme', array( $this, 'force_deactivation' ) ); 
  331.  
  332.  
  333.  
  334.  
  335.  
  336.  
  337.  
  338. /** 
  339. * Hook in plugin action link filters for the WP native plugins page. 
  340. * - Prevent activation of plugins which don't meet the minimum version requirements. 
  341. * - Prevent deactivation of force-activated plugins. 
  342. * - Add update notice if update available. 
  343. * @since 2.5.0 
  344. */ 
  345. public function add_plugin_action_link_filters() { 
  346. foreach ( $this->plugins as $slug => $plugin ) { 
  347. if ( false === $this->can_plugin_activate( $slug ) ) { 
  348. add_filter( 'plugin_action_links_' . $plugin['file_path'], array( $this, 'filter_plugin_action_links_activate' ), 20 ); 
  349.  
  350. if ( true === $plugin['force_activation'] ) { 
  351. add_filter( 'plugin_action_links_' . $plugin['file_path'], array( $this, 'filter_plugin_action_links_deactivate' ), 20 ); 
  352.  
  353. if ( false !== $this->does_plugin_require_update( $slug ) ) { 
  354. add_filter( 'plugin_action_links_' . $plugin['file_path'], array( $this, 'filter_plugin_action_links_update' ), 20 ); 
  355.  
  356. /** 
  357. * Remove the 'Activate' link on the WP native plugins page if the plugin does not meet the 
  358. * minimum version requirements. 
  359. * @since 2.5.0 
  360. * @param array $actions Action links. 
  361. * @return array 
  362. */ 
  363. public function filter_plugin_action_links_activate( $actions ) { 
  364. unset( $actions['activate'] ); 
  365.  
  366. return $actions; 
  367.  
  368. /** 
  369. * Remove the 'Deactivate' link on the WP native plugins page if the plugin has been set to force activate. 
  370. * @since 2.5.0 
  371. * @param array $actions Action links. 
  372. * @return array 
  373. */ 
  374. public function filter_plugin_action_links_deactivate( $actions ) { 
  375. unset( $actions['deactivate'] ); 
  376.  
  377. return $actions; 
  378.  
  379. /** 
  380. * Add a 'Requires update' link on the WP native plugins page if the plugin does not meet the 
  381. * minimum version requirements. 
  382. * @since 2.5.0 
  383. * @param array $actions Action links. 
  384. * @return array 
  385. */ 
  386. public function filter_plugin_action_links_update( $actions ) { 
  387. $actions['update'] = sprintf( 
  388. '<a href="%1$s" title="%2$s" class="edit">%3$s</a>',  
  389. esc_url( $this->get_tgmpa_status_url( 'update' ) ),  
  390. esc_attr__( 'This plugin needs to be updated to be compatible with your theme.', 'enigma' ),  
  391. esc_html__( 'Update Required', 'enigma' ) 
  392. ); 
  393.  
  394. return $actions; 
  395.  
  396. /** 
  397. * Handles calls to show plugin information via links in the notices. 
  398. * We get the links in the admin notices to point to the TGMPA page, rather 
  399. * than the typical plugin-install.php file, so we can prepare everything 
  400. * beforehand. 
  401. * WP does not make it easy to show the plugin information in the thickbox - 
  402. * here we have to require a file that includes a function that does the 
  403. * main work of displaying it, enqueue some styles, set up some globals and 
  404. * finally call that function before exiting. 
  405. * Down right easy once you know how... 
  406. * Returns early if not the TGMPA page. 
  407. * @since 2.1.0 
  408. * @global string $tab Used as iframe div class names, helps with styling 
  409. * @global string $body_id Used as the iframe body ID, helps with styling 
  410. * @return null Returns early if not the TGMPA page. 
  411. */ 
  412. public function admin_init() { 
  413. if ( ! $this->is_tgmpa_page() ) { 
  414. return; 
  415.  
  416. if ( isset( $_REQUEST['tab'] ) && 'plugin-information' === $_REQUEST['tab'] ) { 
  417. // Needed for install_plugin_information(). 
  418. require_once ABSPATH . 'wp-admin/includes/plugin-install.php'; 
  419.  
  420. wp_enqueue_style( 'plugin-install' ); 
  421.  
  422. global $tab, $body_id; 
  423. $body_id = 'plugin-information'; 
  424. // @codingStandardsIgnoreStart 
  425. $tab = 'plugin-information'; 
  426. // @codingStandardsIgnoreEnd 
  427.  
  428. install_plugin_information(); 
  429.  
  430. exit; 
  431.  
  432. /** 
  433. * Enqueue thickbox scripts/styles for plugin info. 
  434. * Thickbox is not automatically included on all admin pages, so we must 
  435. * manually enqueue it for those pages. 
  436. * Thickbox is only loaded if the user has not dismissed the admin 
  437. * notice or if there are any plugins left to install and activate. 
  438. * @since 2.1.0 
  439. */ 
  440. public function thickbox() { 
  441. if ( ! get_user_meta( get_current_user_id(), 'tgmpa_dismissed_notice_' . $this->id, true ) ) { 
  442. add_thickbox(); 
  443.  
  444. /** 
  445. * Adds submenu page if there are plugin actions to take. 
  446. * This method adds the submenu page letting users know that a required 
  447. * plugin needs to be installed. 
  448. * This page disappears once the plugin has been installed and activated. 
  449. * @since 1.0.0 
  450. * @see TGM_Plugin_Activation::init() 
  451. * @see TGM_Plugin_Activation::install_plugins_page() 
  452. * @return null Return early if user lacks capability to install a plugin. 
  453. */ 
  454. public function admin_menu() { 
  455. // Make sure privileges are correct to see the page. 
  456. if ( ! current_user_can( 'install_plugins' ) ) { 
  457. return; 
  458.  
  459. $args = apply_filters( 
  460. 'tgmpa_admin_menu_args',  
  461. array( 
  462. 'parent_slug' => $this->parent_slug, // Parent Menu slug. 
  463. 'page_title' => $this->strings['page_title'], // Page title. 
  464. 'menu_title' => $this->strings['menu_title'], // Menu title. 
  465. 'capability' => $this->capability, // Capability. 
  466. 'menu_slug' => $this->menu, // Menu slug. 
  467. 'function' => array( $this, 'install_plugins_page' ), // Callback. 
  468. ); 
  469.  
  470. $this->add_admin_menu( $args ); 
  471.  
  472. /** 
  473. * Add the menu item. 
  474. * {@internal IMPORTANT! If this function changes, review the regex in the custom TGMPA 
  475. * generator on the website.}} 
  476. * @since 2.5.0 
  477. * @param array $args Menu item configuration. 
  478. */ 
  479. protected function add_admin_menu( array $args ) { 
  480. $this->page_hook = add_theme_page( $args['page_title'], $args['menu_title'], $args['capability'], $args['menu_slug'], $args['function'] ); 
  481.  
  482. /** 
  483. * Echoes plugin installation form. 
  484. * This method is the callback for the admin_menu method function. 
  485. * This displays the admin page and form area where the user can select to install and activate the plugin. 
  486. * Aborts early if we're processing a plugin installation action. 
  487. * @since 1.0.0 
  488. * @return null Aborts early if we're processing a plugin installation action. 
  489. */ 
  490. public function install_plugins_page() { 
  491. // Store new instance of plugin table in object. 
  492. $plugin_table = new TGMPA_List_Table; 
  493.  
  494. // Return early if processing a plugin installation action. 
  495. if ( ( ( 'tgmpa-bulk-install' === $plugin_table->current_action() || 'tgmpa-bulk-update' === $plugin_table->current_action() ) && $plugin_table->process_bulk_actions() ) || $this->do_plugin_install() ) { 
  496. return; 
  497.  
  498. // Force refresh of available plugin information so we'll know about manual updates/deletes. 
  499. wp_clean_plugins_cache( false ); 
  500.  
  501. ?> 
  502. <div class="tgmpa wrap"> 
  503. <h1><?php echo esc_html( get_admin_page_title() ); ?></h1> 
  504. <?php $plugin_table->prepare_items(); ?> 
  505.  
  506. <?php 
  507. if ( ! empty( $this->message ) && is_string( $this->message ) ) { 
  508. echo wp_kses_post( $this->message ); 
  509. ?> 
  510. <?php $plugin_table->views(); ?> 
  511.  
  512. <form id="tgmpa-plugins" action="" method="post"> 
  513. <input type="hidden" name="tgmpa-page" value="<?php echo esc_attr( $this->menu ); ?>" /> 
  514. <input type="hidden" name="plugin_status" value="<?php echo esc_attr( $plugin_table->view_context ); ?>" /> 
  515. <?php $plugin_table->display(); ?> 
  516. </form> 
  517. </div> 
  518. <?php 
  519.  
  520. /** 
  521. * Installs, updates or activates a plugin depending on the action link clicked by the user. 
  522. * Checks the $_GET variable to see which actions have been 
  523. * passed and responds with the appropriate method. 
  524. * Uses WP_Filesystem to process and handle the plugin installation 
  525. * method. 
  526. * @since 1.0.0 
  527. * @uses WP_Filesystem 
  528. * @uses WP_Error 
  529. * @uses WP_Upgrader 
  530. * @uses Plugin_Upgrader 
  531. * @uses Plugin_Installer_Skin 
  532. * @uses Plugin_Upgrader_Skin 
  533. * @return boolean True on success, false on failure. 
  534. */ 
  535. protected function do_plugin_install() { 
  536. if ( empty( $_GET['plugin'] ) ) { 
  537. return false; 
  538.  
  539. // All plugin information will be stored in an array for processing. 
  540. $slug = $this->sanitize_key( urldecode( $_GET['plugin'] ) ); 
  541.  
  542. if ( ! isset( $this->plugins[ $slug ] ) ) { 
  543. return false; 
  544.  
  545. // Was an install or upgrade action link clicked? 
  546. if ( ( isset( $_GET['tgmpa-install'] ) && 'install-plugin' === $_GET['tgmpa-install'] ) || ( isset( $_GET['tgmpa-update'] ) && 'update-plugin' === $_GET['tgmpa-update'] ) ) { 
  547.  
  548. $install_type = 'install'; 
  549. if ( isset( $_GET['tgmpa-update'] ) && 'update-plugin' === $_GET['tgmpa-update'] ) { 
  550. $install_type = 'update'; 
  551.  
  552. check_admin_referer( 'tgmpa-' . $install_type, 'tgmpa-nonce' ); 
  553.  
  554. // Pass necessary information via URL if WP_Filesystem is needed. 
  555. $url = wp_nonce_url( 
  556. add_query_arg( 
  557. array( 
  558. 'plugin' => urlencode( $slug ),  
  559. 'tgmpa-' . $install_type => $install_type . '-plugin',  
  560. ),  
  561. $this->get_tgmpa_url() 
  562. ),  
  563. 'tgmpa-' . $install_type,  
  564. 'tgmpa-nonce' 
  565. ); 
  566.  
  567. $method = ''; // Leave blank so WP_Filesystem can populate it as necessary. 
  568.  
  569. if ( false === ( $creds = request_filesystem_credentials( esc_url_raw( $url ), $method, false, false, array() ) ) ) { 
  570. return true; 
  571.  
  572. if ( ! WP_Filesystem( $creds ) ) { 
  573. request_filesystem_credentials( esc_url_raw( $url ), $method, true, false, array() ); // Setup WP_Filesystem. 
  574. return true; 
  575.  
  576. /** If we arrive here, we have the filesystem. */ 
  577.  
  578. // Prep variables for Plugin_Installer_Skin class. 
  579. $extra = array(); 
  580. $extra['slug'] = $slug; // Needed for potentially renaming of directory name. 
  581. $source = $this->get_download_url( $slug ); 
  582. $api = ( 'repo' === $this->plugins[ $slug ]['source_type'] ) ? $this->get_plugins_api( $slug ) : null; 
  583. $api = ( false !== $api ) ? $api : null; 
  584.  
  585. $url = add_query_arg( 
  586. array( 
  587. 'action' => $install_type . '-plugin',  
  588. 'plugin' => urlencode( $slug ),  
  589. ),  
  590. 'update.php' 
  591. ); 
  592.  
  593. if ( ! class_exists( 'Plugin_Upgrader', false ) ) { 
  594. require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; 
  595.  
  596. $title = ( 'update' === $install_type ) ? $this->strings['updating'] : $this->strings['installing']; 
  597. $skin_args = array( 
  598. 'type' => ( 'bundled' !== $this->plugins[ $slug ]['source_type'] ) ? 'web' : 'upload',  
  599. 'title' => sprintf( $title, $this->plugins[ $slug ]['name'] ),  
  600. 'url' => esc_url_raw( $url ),  
  601. 'nonce' => $install_type . '-plugin_' . $slug,  
  602. 'plugin' => '',  
  603. 'api' => $api,  
  604. 'extra' => $extra,  
  605. ); 
  606. unset( $title ); 
  607.  
  608. if ( 'update' === $install_type ) { 
  609. $skin_args['plugin'] = $this->plugins[ $slug ]['file_path']; 
  610. $skin = new Plugin_Upgrader_Skin( $skin_args ); 
  611. } else { 
  612. $skin = new Plugin_Installer_Skin( $skin_args ); 
  613.  
  614. // Create a new instance of Plugin_Upgrader. 
  615. $upgrader = new Plugin_Upgrader( $skin ); 
  616.  
  617. // Perform the action and install the plugin from the $source urldecode(). 
  618. add_filter( 'upgrader_source_selection', array( $this, 'maybe_adjust_source_dir' ), 1, 3 ); 
  619.  
  620. if ( 'update' === $install_type ) { 
  621. // Inject our info into the update transient. 
  622. $to_inject = array( $slug => $this->plugins[ $slug ] ); 
  623. $to_inject[ $slug ]['source'] = $source; 
  624. $this->inject_update_info( $to_inject ); 
  625.  
  626. $upgrader->upgrade( $this->plugins[ $slug ]['file_path'] ); 
  627. } else { 
  628. $upgrader->install( $source ); 
  629.  
  630. remove_filter( 'upgrader_source_selection', array( $this, 'maybe_adjust_source_dir' ), 1 ); 
  631.  
  632. // Make sure we have the correct file path now the plugin is installed/updated. 
  633. $this->populate_file_path( $slug ); 
  634.  
  635. // Only activate plugins if the config option is set to true and the plugin isn't 
  636. // already active (upgrade). 
  637. if ( $this->is_automatic && ! $this->is_plugin_active( $slug ) ) { 
  638. $plugin_activate = $upgrader->plugin_info(); // Grab the plugin info from the Plugin_Upgrader method. 
  639. if ( false === $this->activate_single_plugin( $plugin_activate, $slug, true ) ) { 
  640. return true; // Finish execution of the function early as we encountered an error. 
  641.  
  642. $this->show_tgmpa_version(); 
  643.  
  644. // Display message based on if all plugins are now active or not. 
  645. if ( $this->is_tgmpa_complete() ) { 
  646. echo '<p>', sprintf( esc_html( $this->strings['complete'] ), '<a href="' . esc_url( self_admin_url() ) . '">' . esc_html__( 'Return to the Dashboard', 'enigma' ) . '</a>' ), '</p>'; 
  647. echo '<style type="text/css">#adminmenu .wp-submenu li.current { display: none !important; }</style>'; 
  648. } else { 
  649. echo '<p><a href="', esc_url( $this->get_tgmpa_url() ), '" target="_parent">', esc_html( $this->strings['return'] ), '</a></p>'; 
  650.  
  651. return true; 
  652. } elseif ( isset( $this->plugins[ $slug ]['file_path'], $_GET['tgmpa-activate'] ) && 'activate-plugin' === $_GET['tgmpa-activate'] ) { 
  653. // Activate action link was clicked. 
  654. check_admin_referer( 'tgmpa-activate', 'tgmpa-nonce' ); 
  655.  
  656. if ( false === $this->activate_single_plugin( $this->plugins[ $slug ]['file_path'], $slug ) ) { 
  657. return true; // Finish execution of the function early as we encountered an error. 
  658.  
  659. return false; 
  660.  
  661. /** 
  662. * Inject information into the 'update_plugins' site transient as WP checks that before running an update. 
  663. * @since 2.5.0 
  664. * @param array $plugins The plugin information for the plugins which are to be updated. 
  665. */ 
  666. public function inject_update_info( $plugins ) { 
  667. $repo_updates = get_site_transient( 'update_plugins' ); 
  668.  
  669. if ( ! is_object( $repo_updates ) ) { 
  670. $repo_updates = new stdClass; 
  671.  
  672. foreach ( $plugins as $slug => $plugin ) { 
  673. $file_path = $plugin['file_path']; 
  674.  
  675. if ( empty( $repo_updates->response[ $file_path ] ) ) { 
  676. $repo_updates->response[ $file_path ] = new stdClass; 
  677.  
  678. // We only really need to set package, but let's do all we can in case WP changes something. 
  679. $repo_updates->response[ $file_path ]->slug = $slug; 
  680. $repo_updates->response[ $file_path ]->plugin = $file_path; 
  681. $repo_updates->response[ $file_path ]->new_version = $plugin['version']; 
  682. $repo_updates->response[ $file_path ]->package = $plugin['source']; 
  683. if ( empty( $repo_updates->response[ $file_path ]->url ) && ! empty( $plugin['external_url'] ) ) { 
  684. $repo_updates->response[ $file_path ]->url = $plugin['external_url']; 
  685.  
  686. set_site_transient( 'update_plugins', $repo_updates ); 
  687.  
  688. /** 
  689. * Adjust the plugin directory name if necessary. 
  690. * The final destination directory of a plugin is based on the subdirectory name found in the 
  691. * (un)zipped source. In some cases - most notably GitHub repository plugin downloads -, this 
  692. * subdirectory name is not the same as the expected slug and the plugin will not be recognized 
  693. * as installed. This is fixed by adjusting the temporary unzipped source subdirectory name to 
  694. * the expected plugin slug. 
  695. * @since 2.5.0 
  696. * @param string $source Path to upgrade/zip-file-name.tmp/subdirectory/. 
  697. * @param string $remote_source Path to upgrade/zip-file-name.tmp. 
  698. * @param \WP_Upgrader $upgrader Instance of the upgrader which installs the plugin. 
  699. * @return string $source 
  700. */ 
  701. public function maybe_adjust_source_dir( $source, $remote_source, $upgrader ) { 
  702. if ( ! $this->is_tgmpa_page() || ! is_object( $GLOBALS['wp_filesystem'] ) ) { 
  703. return $source; 
  704.  
  705. // Check for single file plugins. 
  706. $source_files = array_keys( $GLOBALS['wp_filesystem']->dirlist( $remote_source ) ); 
  707. if ( 1 === count( $source_files ) && false === $GLOBALS['wp_filesystem']->is_dir( $source ) ) { 
  708. return $source; 
  709.  
  710. // Multi-file plugin, let's see if the directory is correctly named. 
  711. $desired_slug = ''; 
  712.  
  713. // Figure out what the slug is supposed to be. 
  714. if ( false === $upgrader->bulk && ! empty( $upgrader->skin->options['extra']['slug'] ) ) { 
  715. $desired_slug = $upgrader->skin->options['extra']['slug']; 
  716. } else { 
  717. // Bulk installer contains less info, so fall back on the info registered here. 
  718. foreach ( $this->plugins as $slug => $plugin ) { 
  719. if ( ! empty( $upgrader->skin->plugin_names[ $upgrader->skin->i ] ) && $plugin['name'] === $upgrader->skin->plugin_names[ $upgrader->skin->i ] ) { 
  720. $desired_slug = $slug; 
  721. break; 
  722. unset( $slug, $plugin ); 
  723.  
  724. if ( ! empty( $desired_slug ) ) { 
  725. $subdir_name = untrailingslashit( str_replace( trailingslashit( $remote_source ), '', $source ) ); 
  726.  
  727. if ( ! empty( $subdir_name ) && $subdir_name !== $desired_slug ) { 
  728. $from_path = untrailingslashit( $source ); 
  729. $to_path = trailingslashit( $remote_source ) . $desired_slug; 
  730.  
  731. if ( true === $GLOBALS['wp_filesystem']->move( $from_path, $to_path ) ) { 
  732. return trailingslashit( $to_path ); 
  733. } else { 
  734. return new WP_Error( 'rename_failed', esc_html__( 'The remote plugin package does not contain a folder with the desired slug and renaming did not work.', 'enigma' ) . ' ' . esc_html__( 'Please contact the plugin provider and ask them to package their plugin according to the WordPress guidelines.', 'enigma' ), array( 'found' => $subdir_name, 'expected' => $desired_slug ) ); 
  735. } elseif ( empty( $subdir_name ) ) { 
  736. return new WP_Error( 'packaged_wrong', esc_html__( 'The remote plugin package consists of more than one file, but the files are not packaged in a folder.', 'enigma' ) . ' ' . esc_html__( 'Please contact the plugin provider and ask them to package their plugin according to the WordPress guidelines.', 'enigma' ), array( 'found' => $subdir_name, 'expected' => $desired_slug ) ); 
  737.  
  738. return $source; 
  739.  
  740. /** 
  741. * Activate a single plugin and send feedback about the result to the screen. 
  742. * @since 2.5.0 
  743. * @param string $file_path Path within wp-plugins/ to main plugin file. 
  744. * @param string $slug Plugin slug. 
  745. * @param bool $automatic Whether this is an automatic activation after an install. Defaults to false. 
  746. * This determines the styling of the output messages. 
  747. * @return bool False if an error was encountered, true otherwise. 
  748. */ 
  749. protected function activate_single_plugin( $file_path, $slug, $automatic = false ) { 
  750. if ( $this->can_plugin_activate( $slug ) ) { 
  751. $activate = activate_plugin( $file_path ); 
  752.  
  753. if ( is_wp_error( $activate ) ) { 
  754. echo '<div id="message" class="error"><p>', wp_kses_post( $activate->get_error_message() ), '</p></div>',  
  755. '<p><a href="', esc_url( $this->get_tgmpa_url() ), '" target="_parent">', esc_html( $this->strings['return'] ), '</a></p>'; 
  756.  
  757. return false; // End it here if there is an error with activation. 
  758. } else { 
  759. if ( ! $automatic ) { 
  760. // Make sure message doesn't display again if bulk activation is performed 
  761. // immediately after a single activation. 
  762. if ( ! isset( $_POST['action'] ) ) { // WPCS: CSRF OK. 
  763. echo '<div id="message" class="updated"><p>', esc_html( $this->strings['activated_successfully'] ), ' <strong>', esc_html( $this->plugins[ $slug ]['name'] ), '.</strong></p></div>'; 
  764. } else { 
  765. // Simpler message layout for use on the plugin install page. 
  766. echo '<p>', esc_html( $this->strings['plugin_activated'] ), '</p>'; 
  767. } elseif ( $this->is_plugin_active( $slug ) ) { 
  768. // No simpler message format provided as this message should never be encountered 
  769. // on the plugin install page. 
  770. echo '<div id="message" class="error"><p>',  
  771. sprintf( 
  772. esc_html( $this->strings['plugin_already_active'] ),  
  773. '<strong>' . esc_html( $this->plugins[ $slug ]['name'] ) . '</strong>' 
  774. ),  
  775. '</p></div>'; 
  776. } elseif ( $this->does_plugin_require_update( $slug ) ) { 
  777. if ( ! $automatic ) { 
  778. // Make sure message doesn't display again if bulk activation is performed 
  779. // immediately after a single activation. 
  780. if ( ! isset( $_POST['action'] ) ) { // WPCS: CSRF OK. 
  781. echo '<div id="message" class="error"><p>',  
  782. sprintf( 
  783. esc_html( $this->strings['plugin_needs_higher_version'] ),  
  784. '<strong>' . esc_html( $this->plugins[ $slug ]['name'] ) . '</strong>' 
  785. ),  
  786. '</p></div>'; 
  787. } else { 
  788. // Simpler message layout for use on the plugin install page. 
  789. echo '<p>', sprintf( esc_html( $this->strings['plugin_needs_higher_version'] ), esc_html( $this->plugins[ $slug ]['name'] ) ), '</p>'; 
  790.  
  791. return true; 
  792.  
  793. /** 
  794. * Echoes required plugin notice. 
  795. * Outputs a message telling users that a specific plugin is required for 
  796. * their theme. If appropriate, it includes a link to the form page where 
  797. * users can install and activate the plugin. 
  798. * Returns early if we're on the Install page. 
  799. * @since 1.0.0 
  800. * @global object $current_screen 
  801. * @return null Returns early if we're on the Install page. 
  802. */ 
  803. public function notices() { 
  804. // Remove nag on the install page / Return early if the nag message has been dismissed or user < author. 
  805. 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' ) ) ) { 
  806. return; 
  807.  
  808. // Store for the plugin slugs by message type. 
  809. $message = array(); 
  810.  
  811. // Initialize counters used to determine plurality of action link texts. 
  812. $install_link_count = 0; 
  813. $update_link_count = 0; 
  814. $activate_link_count = 0; 
  815. $total_required_action_count = 0; 
  816.  
  817. foreach ( $this->plugins as $slug => $plugin ) { 
  818. if ( $this->is_plugin_active( $slug ) && false === $this->does_plugin_have_update( $slug ) ) { 
  819. continue; 
  820.  
  821. if ( ! $this->is_plugin_installed( $slug ) ) { 
  822. if ( current_user_can( 'install_plugins' ) ) { 
  823. $install_link_count++; 
  824.  
  825. if ( true === $plugin['required'] ) { 
  826. $message['notice_can_install_required'][] = $slug; 
  827. } else { 
  828. $message['notice_can_install_recommended'][] = $slug; 
  829. if ( true === $plugin['required'] ) { 
  830. $total_required_action_count++; 
  831. } else { 
  832. if ( ! $this->is_plugin_active( $slug ) && $this->can_plugin_activate( $slug ) ) { 
  833. if ( current_user_can( 'activate_plugins' ) ) { 
  834. $activate_link_count++; 
  835.  
  836. if ( true === $plugin['required'] ) { 
  837. $message['notice_can_activate_required'][] = $slug; 
  838. } else { 
  839. $message['notice_can_activate_recommended'][] = $slug; 
  840. if ( true === $plugin['required'] ) { 
  841. $total_required_action_count++; 
  842.  
  843. if ( $this->does_plugin_require_update( $slug ) || false !== $this->does_plugin_have_update( $slug ) ) { 
  844.  
  845. if ( current_user_can( 'update_plugins' ) ) { 
  846. $update_link_count++; 
  847.  
  848. if ( $this->does_plugin_require_update( $slug ) ) { 
  849. $message['notice_ask_to_update'][] = $slug; 
  850. } elseif ( false !== $this->does_plugin_have_update( $slug ) ) { 
  851. $message['notice_ask_to_update_maybe'][] = $slug; 
  852. if ( true === $plugin['required'] ) { 
  853. $total_required_action_count++; 
  854. unset( $slug, $plugin ); 
  855.  
  856. // If we have notices to display, we move forward. 
  857. if ( ! empty( $message ) || $total_required_action_count > 0 ) { 
  858. krsort( $message ); // Sort messages. 
  859. $rendered = ''; 
  860.  
  861. // As add_settings_error() wraps the final message in a <p> and as the final message can't be 
  862. // filtered, using <p>'s in our html would render invalid html output. 
  863. $line_template = '<span style="display: block; margin: 0.5em 0.5em 0 0; clear: both;">%s</span>' . "\n"; 
  864.  
  865. if ( ! current_user_can( 'activate_plugins' ) && ! current_user_can( 'install_plugins' ) && ! current_user_can( 'update_plugins' ) ) { 
  866. $rendered = esc_html( $this->strings['notice_cannot_install_activate'] ) . ' ' . esc_html( $this->strings['contact_admin'] ); 
  867. $rendered .= $this->create_user_action_links_for_notice( 0, 0, 0, $line_template ); 
  868. } else { 
  869.  
  870. // If dismissable is false and a message is set, output it now. 
  871. if ( ! $this->dismissable && ! empty( $this->dismiss_msg ) ) { 
  872. $rendered .= sprintf( $line_template, wp_kses_post( $this->dismiss_msg ) ); 
  873.  
  874. // Render the individual message lines for the notice. 
  875. foreach ( $message as $type => $plugin_group ) { 
  876. $linked_plugins = array(); 
  877.  
  878. // Get the external info link for a plugin if one is available. 
  879. foreach ( $plugin_group as $plugin_slug ) { 
  880. $linked_plugins[] = $this->get_info_link( $plugin_slug ); 
  881. unset( $plugin_slug ); 
  882.  
  883. $count = count( $plugin_group ); 
  884. $linked_plugins = array_map( array( 'TGMPA_Utils', 'wrap_in_em' ), $linked_plugins ); 
  885. $last_plugin = array_pop( $linked_plugins ); // Pop off last name to prep for readability. 
  886. $imploded = empty( $linked_plugins ) ? $last_plugin : ( implode( ', ', $linked_plugins ) . ' ' . esc_html_x( 'and', 'plugin A *and* plugin B', 'enigma' ) . ' ' . $last_plugin ); 
  887.  
  888. $rendered .= sprintf( 
  889. $line_template,  
  890. sprintf( 
  891. translate_nooped_plural( $this->strings[ $type ], $count, 'enigma' ),  
  892. $imploded,  
  893. $count 
  894. ); 
  895.  
  896. unset( $type, $plugin_group, $linked_plugins, $count, $last_plugin, $imploded ); 
  897.  
  898. $rendered .= $this->create_user_action_links_for_notice( $install_link_count, $update_link_count, $activate_link_count, $line_template ); 
  899.  
  900. // Register the nag messages and prepare them to be processed. 
  901. add_settings_error( 'tgmpa', 'tgmpa', $rendered, $this->get_admin_notice_class() ); 
  902.  
  903. // Admin options pages already output settings_errors, so this is to avoid duplication. 
  904. if ( 'options-general' !== $GLOBALS['current_screen']->parent_base ) { 
  905. $this->display_settings_errors(); 
  906.  
  907. /** 
  908. * Generate the user action links for the admin notice. 
  909. * @since 2.6.0 
  910. * @param int $install_count Number of plugins to install. 
  911. * @param int $update_count Number of plugins to update. 
  912. * @param int $activate_count Number of plugins to activate. 
  913. * @param int $line_template Template for the HTML tag to output a line. 
  914. * @return string Action links. 
  915. */ 
  916. protected function create_user_action_links_for_notice( $install_count, $update_count, $activate_count, $line_template ) { 
  917. // Setup action links. 
  918. $action_links = array( 
  919. 'install' => '',  
  920. 'update' => '',  
  921. 'activate' => '',  
  922. '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>' : '',  
  923. ); 
  924.  
  925. $link_template = '<a href="%2$s">%1$s</a>'; 
  926.  
  927. if ( current_user_can( 'install_plugins' ) ) { 
  928. if ( $install_count > 0 ) { 
  929. $action_links['install'] = sprintf( 
  930. $link_template,  
  931. translate_nooped_plural( $this->strings['install_link'], $install_count, 'enigma' ),  
  932. esc_url( $this->get_tgmpa_status_url( 'install' ) ) 
  933. ); 
  934. if ( $update_count > 0 ) { 
  935. $action_links['update'] = sprintf( 
  936. $link_template,  
  937. translate_nooped_plural( $this->strings['update_link'], $update_count, 'enigma' ),  
  938. esc_url( $this->get_tgmpa_status_url( 'update' ) ) 
  939. ); 
  940.  
  941. if ( current_user_can( 'activate_plugins' ) && $activate_count > 0 ) { 
  942. $action_links['activate'] = sprintf( 
  943. $link_template,  
  944. translate_nooped_plural( $this->strings['activate_link'], $activate_count, 'enigma' ),  
  945. esc_url( $this->get_tgmpa_status_url( 'activate' ) ) 
  946. ); 
  947.  
  948. $action_links = apply_filters( 'tgmpa_notice_action_links', $action_links ); 
  949.  
  950. $action_links = array_filter( (array) $action_links ); // Remove any empty array items. 
  951.  
  952. if ( ! empty( $action_links ) ) { 
  953. $action_links = sprintf( $line_template, implode( ' | ', $action_links ) ); 
  954. return apply_filters( 'tgmpa_notice_rendered_action_links', $action_links ); 
  955. } else { 
  956. return ''; 
  957.  
  958. /** 
  959. * Get admin notice class. 
  960. * Work around all the changes to the various admin notice classes between WP 4.4 and 3.7 
  961. * (lowest supported version by TGMPA). 
  962. * @since 2.6.0 
  963. * @return string 
  964. */ 
  965. protected function get_admin_notice_class() { 
  966. if ( ! empty( $this->strings['nag_type'] ) ) { 
  967. return sanitize_html_class( strtolower( $this->strings['nag_type'] ) ); 
  968. } else { 
  969. if ( version_compare( $this->wp_version, '4.2', '>=' ) ) { 
  970. return 'notice-warning'; 
  971. } elseif ( version_compare( $this->wp_version, '4.1', '>=' ) ) { 
  972. return 'notice'; 
  973. } else { 
  974. return 'updated'; 
  975.  
  976. /** 
  977. * Display settings errors and remove those which have been displayed to avoid duplicate messages showing 
  978. * @since 2.5.0 
  979. */ 
  980. protected function display_settings_errors() { 
  981. global $wp_settings_errors; 
  982.  
  983. settings_errors( 'tgmpa' ); 
  984.  
  985. foreach ( (array) $wp_settings_errors as $key => $details ) { 
  986. if ( 'tgmpa' === $details['setting'] ) { 
  987. unset( $wp_settings_errors[ $key ] ); 
  988. break; 
  989.  
  990. /** 
  991. * Register dismissal of admin notices. 
  992. * Acts on the dismiss link in the admin nag messages. 
  993. * If clicked, the admin notice disappears and will no longer be visible to this user. 
  994. * @since 2.1.0 
  995. */ 
  996. public function dismiss() { 
  997. if ( isset( $_GET['tgmpa-dismiss'] ) && check_admin_referer( 'tgmpa-dismiss-' . get_current_user_id() ) ) { 
  998. update_user_meta( get_current_user_id(), 'tgmpa_dismissed_notice_' . $this->id, 1 ); 
  999.  
  1000. /** 
  1001. * Add individual plugin to our collection of plugins. 
  1002. * If the required keys are not set or the plugin has already 
  1003. * been registered, the plugin is not added. 
  1004. * @since 2.0.0 
  1005. * @param array|null $plugin Array of plugin arguments or null if invalid argument. 
  1006. * @return null Return early if incorrect argument. 
  1007. */ 
  1008. public function register( $plugin ) { 
  1009. if ( empty( $plugin['slug'] ) || empty( $plugin['name'] ) ) { 
  1010. return; 
  1011.  
  1012. if ( empty( $plugin['slug'] ) || ! is_string( $plugin['slug'] ) || isset( $this->plugins[ $plugin['slug'] ] ) ) { 
  1013. return; 
  1014.  
  1015. $defaults = array( 
  1016. 'name' => '', // String 
  1017. 'slug' => '', // String 
  1018. 'source' => 'repo', // String 
  1019. 'required' => false, // Boolean 
  1020. 'version' => '', // String 
  1021. 'force_activation' => false, // Boolean 
  1022. 'force_deactivation' => false, // Boolean 
  1023. 'external_url' => '', // String 
  1024. 'is_callable' => '', // String|Array. 
  1025. ); 
  1026.  
  1027. // Prepare the received data. 
  1028. $plugin = wp_parse_args( $plugin, $defaults ); 
  1029.  
  1030. // Standardize the received slug. 
  1031. $plugin['slug'] = $this->sanitize_key( $plugin['slug'] ); 
  1032.  
  1033. // Forgive users for using string versions of booleans or floats for version number. 
  1034. $plugin['version'] = (string) $plugin['version']; 
  1035. $plugin['source'] = empty( $plugin['source'] ) ? 'repo' : $plugin['source']; 
  1036. $plugin['required'] = TGMPA_Utils::validate_bool( $plugin['required'] ); 
  1037. $plugin['force_activation'] = TGMPA_Utils::validate_bool( $plugin['force_activation'] ); 
  1038. $plugin['force_deactivation'] = TGMPA_Utils::validate_bool( $plugin['force_deactivation'] ); 
  1039.  
  1040. // Enrich the received data. 
  1041. $plugin['file_path'] = $this->_get_plugin_basename_from_slug( $plugin['slug'] ); 
  1042. $plugin['source_type'] = $this->get_plugin_source_type( $plugin['source'] ); 
  1043.  
  1044. // Set the class properties. 
  1045. $this->plugins[ $plugin['slug'] ] = $plugin; 
  1046. $this->sort_order[ $plugin['slug'] ] = $plugin['name']; 
  1047.  
  1048. // Should we add the force activation hook ? 
  1049. if ( true === $plugin['force_activation'] ) { 
  1050. $this->has_forced_activation = true; 
  1051.  
  1052. // Should we add the force deactivation hook ? 
  1053. if ( true === $plugin['force_deactivation'] ) { 
  1054. $this->has_forced_deactivation = true; 
  1055.  
  1056. /** 
  1057. * Determine what type of source the plugin comes from. 
  1058. * @since 2.5.0 
  1059. * @param string $source The source of the plugin as provided, either empty (= WP repo), a file path 
  1060. * (= bundled) or an external URL. 
  1061. * @return string 'repo', 'external', or 'bundled' 
  1062. */ 
  1063. protected function get_plugin_source_type( $source ) { 
  1064. if ( 'repo' === $source || preg_match( self::WP_REPO_REGEX, $source ) ) { 
  1065. return 'repo'; 
  1066. } elseif ( preg_match( self::IS_URL_REGEX, $source ) ) { 
  1067. return 'external'; 
  1068. } else { 
  1069. return 'bundled'; 
  1070.  
  1071. /** 
  1072. * Sanitizes a string key. 
  1073. * Near duplicate of WP Core `sanitize_key()`. The difference is that uppercase characters *are* 
  1074. * allowed, so as not to break upgrade paths from non-standard bundled plugins using uppercase 
  1075. * characters in the plugin directory path/slug. Silly them. 
  1076. * @see https://developer.wordpress.org/reference/hooks/sanitize_key/ 
  1077. * @since 2.5.0 
  1078. * @param string $key String key. 
  1079. * @return string Sanitized key 
  1080. */ 
  1081. public function sanitize_key( $key ) { 
  1082. $raw_key = $key; 
  1083. $key = preg_replace( '`[^A-Za-z0-9_-]`', '', $key ); 
  1084.  
  1085. /** 
  1086. * Filter a sanitized key string. 
  1087. * @since 2.5.0 
  1088. * @param string $key Sanitized key. 
  1089. * @param string $raw_key The key prior to sanitization. 
  1090. */ 
  1091. return apply_filters( 'tgmpa_sanitize_key', $key, $raw_key ); 
  1092.  
  1093. /** 
  1094. * Amend default configuration settings. 
  1095. * @since 2.0.0 
  1096. * @param array $config Array of config options to pass as class properties. 
  1097. */ 
  1098. public function config( $config ) { 
  1099. $keys = array( 
  1100. 'id',  
  1101. 'default_path',  
  1102. 'has_notices',  
  1103. 'dismissable',  
  1104. 'dismiss_msg',  
  1105. 'menu',  
  1106. 'parent_slug',  
  1107. 'capability',  
  1108. 'is_automatic',  
  1109. 'message',  
  1110. 'strings',  
  1111. ); 
  1112.  
  1113. foreach ( $keys as $key ) { 
  1114. if ( isset( $config[ $key ] ) ) { 
  1115. if ( is_array( $config[ $key ] ) ) { 
  1116. $this->$key = array_merge( $this->$key, $config[ $key ] ); 
  1117. } else { 
  1118. $this->$key = $config[ $key ]; 
  1119.  
  1120. /** 
  1121. * Amend action link after plugin installation. 
  1122. * @since 2.0.0 
  1123. * @param array $install_actions Existing array of actions. 
  1124. * @return false|array Amended array of actions. 
  1125. */ 
  1126. public function actions( $install_actions ) { 
  1127. // Remove action links on the TGMPA install page. 
  1128. if ( $this->is_tgmpa_page() ) { 
  1129. return false; 
  1130.  
  1131. return $install_actions; 
  1132.  
  1133. /** 
  1134. * Flushes the plugins cache on theme switch to prevent stale entries 
  1135. * from remaining in the plugin table. 
  1136. * @since 2.4.0 
  1137. * @param bool $clear_update_cache Optional. Whether to clear the Plugin updates cache. 
  1138. * Parameter added in v2.5.0. 
  1139. */ 
  1140. public function flush_plugins_cache( $clear_update_cache = true ) { 
  1141. wp_clean_plugins_cache( $clear_update_cache ); 
  1142.  
  1143. /** 
  1144. * Set file_path key for each installed plugin. 
  1145. * @since 2.1.0 
  1146. * @param string $plugin_slug Optional. If set, only (re-)populates the file path for that specific plugin. 
  1147. * Parameter added in v2.5.0. 
  1148. */ 
  1149. public function populate_file_path( $plugin_slug = '' ) { 
  1150. if ( ! empty( $plugin_slug ) && is_string( $plugin_slug ) && isset( $this->plugins[ $plugin_slug ] ) ) { 
  1151. $this->plugins[ $plugin_slug ]['file_path'] = $this->_get_plugin_basename_from_slug( $plugin_slug ); 
  1152. } else { 
  1153. // Add file_path key for all plugins. 
  1154. foreach ( $this->plugins as $slug => $values ) { 
  1155. $this->plugins[ $slug ]['file_path'] = $this->_get_plugin_basename_from_slug( $slug ); 
  1156.  
  1157. /** 
  1158. * Helper function to extract the file path of the plugin file from the 
  1159. * plugin slug, if the plugin is installed. 
  1160. * @since 2.0.0 
  1161. * @param string $slug Plugin slug (typically folder name) as provided by the developer. 
  1162. * @return string Either file path for plugin if installed, or just the plugin slug. 
  1163. */ 
  1164. protected function _get_plugin_basename_from_slug( $slug ) { 
  1165. $keys = array_keys( $this->get_plugins() ); 
  1166.  
  1167. foreach ( $keys as $key ) { 
  1168. if ( preg_match( '|^' . $slug . '/|', $key ) ) { 
  1169. return $key; 
  1170.  
  1171. return $slug; 
  1172.  
  1173. /** 
  1174. * Retrieve plugin data, given the plugin name. 
  1175. * Loops through the registered plugins looking for $name. If it finds it,  
  1176. * it returns the $data from that plugin. Otherwise, returns false. 
  1177. * @since 2.1.0 
  1178. * @param string $name Name of the plugin, as it was registered. 
  1179. * @param string $data Optional. Array key of plugin data to return. Default is slug. 
  1180. * @return string|boolean Plugin slug if found, false otherwise. 
  1181. */ 
  1182. public function _get_plugin_data_from_name( $name, $data = 'slug' ) { 
  1183. foreach ( $this->plugins as $values ) { 
  1184. if ( $name === $values['name'] && isset( $values[ $data ] ) ) { 
  1185. return $values[ $data ]; 
  1186.  
  1187. return false; 
  1188.  
  1189. /** 
  1190. * Retrieve the download URL for a package. 
  1191. * @since 2.5.0 
  1192. * @param string $slug Plugin slug. 
  1193. * @return string Plugin download URL or path to local file or empty string if undetermined. 
  1194. */ 
  1195. public function get_download_url( $slug ) { 
  1196. $dl_source = ''; 
  1197.  
  1198. switch ( $this->plugins[ $slug ]['source_type'] ) { 
  1199. case 'repo': 
  1200. return $this->get_wp_repo_download_url( $slug ); 
  1201. case 'external': 
  1202. return $this->plugins[ $slug ]['source']; 
  1203. case 'bundled': 
  1204. return $this->default_path . $this->plugins[ $slug ]['source']; 
  1205.  
  1206. return $dl_source; // Should never happen. 
  1207.  
  1208. /** 
  1209. * Retrieve the download URL for a WP repo package. 
  1210. * @since 2.5.0 
  1211. * @param string $slug Plugin slug. 
  1212. * @return string Plugin download URL. 
  1213. */ 
  1214. protected function get_wp_repo_download_url( $slug ) { 
  1215. $source = ''; 
  1216. $api = $this->get_plugins_api( $slug ); 
  1217.  
  1218. if ( false !== $api && isset( $api->download_link ) ) { 
  1219. $source = $api->download_link; 
  1220.  
  1221. return $source; 
  1222.  
  1223. /** 
  1224. * Try to grab information from WordPress API. 
  1225. * @since 2.5.0 
  1226. * @param string $slug Plugin slug. 
  1227. * @return object Plugins_api response object on success, WP_Error on failure. 
  1228. */ 
  1229. protected function get_plugins_api( $slug ) { 
  1230. static $api = array(); // Cache received responses. 
  1231.  
  1232. if ( ! isset( $api[ $slug ] ) ) { 
  1233. if ( ! function_exists( 'plugins_api' ) ) { 
  1234. require_once ABSPATH . 'wp-admin/includes/plugin-install.php'; 
  1235.  
  1236. $response = plugins_api( 'plugin_information', array( 'slug' => $slug, 'fields' => array( 'sections' => false ) ) ); 
  1237.  
  1238. $api[ $slug ] = false; 
  1239.  
  1240. if ( is_wp_error( $response ) ) { 
  1241. wp_die( esc_html( $this->strings['oops'] ) ); 
  1242. } else { 
  1243. $api[ $slug ] = $response; 
  1244.  
  1245. return $api[ $slug ]; 
  1246.  
  1247. /** 
  1248. * Retrieve a link to a plugin information page. 
  1249. * @since 2.5.0 
  1250. * @param string $slug Plugin slug. 
  1251. * @return string Fully formed html link to a plugin information page if available 
  1252. * or the plugin name if not. 
  1253. */ 
  1254. public function get_info_link( $slug ) { 
  1255. if ( ! empty( $this->plugins[ $slug ]['external_url'] ) && preg_match( self::IS_URL_REGEX, $this->plugins[ $slug ]['external_url'] ) ) { 
  1256. $link = sprintf( 
  1257. '<a href="%1$s" target="_blank">%2$s</a>',  
  1258. esc_url( $this->plugins[ $slug ]['external_url'] ),  
  1259. esc_html( $this->plugins[ $slug ]['name'] ) 
  1260. ); 
  1261. } elseif ( 'repo' === $this->plugins[ $slug ]['source_type'] ) { 
  1262. $url = add_query_arg( 
  1263. array( 
  1264. 'tab' => 'plugin-information',  
  1265. 'plugin' => urlencode( $slug ),  
  1266. 'TB_iframe' => 'true',  
  1267. 'width' => '640',  
  1268. 'height' => '500',  
  1269. ),  
  1270. self_admin_url( 'plugin-install.php' ) 
  1271. ); 
  1272.  
  1273. $link = sprintf( 
  1274. '<a href="%1$s" class="thickbox">%2$s</a>',  
  1275. esc_url( $url ),  
  1276. esc_html( $this->plugins[ $slug ]['name'] ) 
  1277. ); 
  1278. } else { 
  1279. $link = esc_html( $this->plugins[ $slug ]['name'] ); // No hyperlink. 
  1280.  
  1281. return $link; 
  1282.  
  1283. /** 
  1284. * Determine if we're on the TGMPA Install page. 
  1285. * @since 2.1.0 
  1286. * @return boolean True when on the TGMPA page, false otherwise. 
  1287. */ 
  1288. protected function is_tgmpa_page() { 
  1289. return isset( $_GET['page'] ) && $this->menu === $_GET['page']; 
  1290.  
  1291. /** 
  1292. * Determine if we're on a WP Core installation/upgrade page. 
  1293. * @since 2.6.0 
  1294. * @return boolean True when on a WP Core installation/upgrade page, false otherwise. 
  1295. */ 
  1296. protected function is_core_update_page() { 
  1297. // Current screen is not always available, most notably on the customizer screen. 
  1298. if ( ! function_exists( 'get_current_screen' ) ) { 
  1299. return false; 
  1300.  
  1301. $screen = get_current_screen(); 
  1302.  
  1303. if ( 'update-core' === $screen->base ) { 
  1304. // Core update screen. 
  1305. return true; 
  1306. } elseif ( 'plugins' === $screen->base && ! empty( $_POST['action'] ) ) { // WPCS: CSRF ok. 
  1307. // Plugins bulk update screen. 
  1308. return true; 
  1309. } elseif ( 'update' === $screen->base && ! empty( $_POST['action'] ) ) { // WPCS: CSRF ok. 
  1310. // Individual updates (ajax call). 
  1311. return true; 
  1312.  
  1313. return false; 
  1314.  
  1315. /** 
  1316. * Retrieve the URL to the TGMPA Install page. 
  1317. * I.e. depending on the config settings passed something along the lines of: 
  1318. * http://example.com/wp-admin/themes.php?page=tgmpa-install-plugins 
  1319. * @since 2.5.0 
  1320. * @return string Properly encoded URL (not escaped). 
  1321. */ 
  1322. public function get_tgmpa_url() { 
  1323. static $url; 
  1324.  
  1325. if ( ! isset( $url ) ) { 
  1326. $parent = $this->parent_slug; 
  1327. if ( false === strpos( $parent, '.php' ) ) { 
  1328. $parent = 'admin.php'; 
  1329. $url = add_query_arg( 
  1330. array( 
  1331. 'page' => urlencode( $this->menu ),  
  1332. ),  
  1333. self_admin_url( $parent ) 
  1334. ); 
  1335.  
  1336. return $url; 
  1337.  
  1338. /** 
  1339. * Retrieve the URL to the TGMPA Install page for a specific plugin status (view). 
  1340. * I.e. depending on the config settings passed something along the lines of: 
  1341. * http://example.com/wp-admin/themes.php?page=tgmpa-install-plugins&plugin_status=install 
  1342. * @since 2.5.0 
  1343. * @param string $status Plugin status - either 'install', 'update' or 'activate'. 
  1344. * @return string Properly encoded URL (not escaped). 
  1345. */ 
  1346. public function get_tgmpa_status_url( $status ) { 
  1347. return add_query_arg( 
  1348. array( 
  1349. 'plugin_status' => urlencode( $status ),  
  1350. ),  
  1351. $this->get_tgmpa_url() 
  1352. ); 
  1353.  
  1354. /** 
  1355. * Determine whether there are open actions for plugins registered with TGMPA. 
  1356. * @since 2.5.0 
  1357. * @return bool True if complete, i.e. no outstanding actions. False otherwise. 
  1358. */ 
  1359. public function is_tgmpa_complete() { 
  1360. $complete = true; 
  1361. foreach ( $this->plugins as $slug => $plugin ) { 
  1362. if ( ! $this->is_plugin_active( $slug ) || false !== $this->does_plugin_have_update( $slug ) ) { 
  1363. $complete = false; 
  1364. break; 
  1365.  
  1366. return $complete; 
  1367.  
  1368. /** 
  1369. * Check if a plugin is installed. Does not take must-use plugins into account. 
  1370. * @since 2.5.0 
  1371. * @param string $slug Plugin slug. 
  1372. * @return bool True if installed, false otherwise. 
  1373. */ 
  1374. public function is_plugin_installed( $slug ) { 
  1375. $installed_plugins = $this->get_plugins(); // Retrieve a list of all installed plugins (WP cached). 
  1376.  
  1377. return ( ! empty( $installed_plugins[ $this->plugins[ $slug ]['file_path'] ] ) ); 
  1378.  
  1379. /** 
  1380. * Check if a plugin is active. 
  1381. * @since 2.5.0 
  1382. * @param string $slug Plugin slug. 
  1383. * @return bool True if active, false otherwise. 
  1384. */ 
  1385. public function is_plugin_active( $slug ) { 
  1386. return ( ( ! empty( $this->plugins[ $slug ]['is_callable'] ) && is_callable( $this->plugins[ $slug ]['is_callable'] ) ) || is_plugin_active( $this->plugins[ $slug ]['file_path'] ) ); 
  1387.  
  1388. /** 
  1389. * Check if a plugin can be updated, i.e. if we have information on the minimum WP version required 
  1390. * available, check whether the current install meets them. 
  1391. * @since 2.5.0 
  1392. * @param string $slug Plugin slug. 
  1393. * @return bool True if OK to update, false otherwise. 
  1394. */ 
  1395. public function can_plugin_update( $slug ) { 
  1396. // We currently can't get reliable info on non-WP-repo plugins - issue #380. 
  1397. if ( 'repo' !== $this->plugins[ $slug ]['source_type'] ) { 
  1398. return true; 
  1399.  
  1400. $api = $this->get_plugins_api( $slug ); 
  1401.  
  1402. if ( false !== $api && isset( $api->requires ) ) { 
  1403. return version_compare( $this->wp_version, $api->requires, '>=' ); 
  1404.  
  1405. // No usable info received from the plugins API, presume we can update. 
  1406. return true; 
  1407.  
  1408. /** 
  1409. * Check to see if the plugin is 'updatetable', i.e. installed, with an update available 
  1410. * and no WP version requirements blocking it. 
  1411. * @since 2.6.0 
  1412. * @param string $slug Plugin slug. 
  1413. * @return bool True if OK to proceed with update, false otherwise. 
  1414. */ 
  1415. public function is_plugin_updatetable( $slug ) { 
  1416. if ( ! $this->is_plugin_installed( $slug ) ) { 
  1417. return false; 
  1418. } else { 
  1419. return ( false !== $this->does_plugin_have_update( $slug ) && $this->can_plugin_update( $slug ) ); 
  1420.  
  1421. /** 
  1422. * Check if a plugin can be activated, i.e. is not currently active and meets the minimum 
  1423. * plugin version requirements set in TGMPA (if any). 
  1424. * @since 2.5.0 
  1425. * @param string $slug Plugin slug. 
  1426. * @return bool True if OK to activate, false otherwise. 
  1427. */ 
  1428. public function can_plugin_activate( $slug ) { 
  1429. return ( ! $this->is_plugin_active( $slug ) && ! $this->does_plugin_require_update( $slug ) ); 
  1430.  
  1431. /** 
  1432. * Retrieve the version number of an installed plugin. 
  1433. * @since 2.5.0 
  1434. * @param string $slug Plugin slug. 
  1435. * @return string Version number as string or an empty string if the plugin is not installed 
  1436. * or version unknown (plugins which don't comply with the plugin header standard). 
  1437. */ 
  1438. public function get_installed_version( $slug ) { 
  1439. $installed_plugins = $this->get_plugins(); // Retrieve a list of all installed plugins (WP cached). 
  1440.  
  1441. if ( ! empty( $installed_plugins[ $this->plugins[ $slug ]['file_path'] ]['Version'] ) ) { 
  1442. return $installed_plugins[ $this->plugins[ $slug ]['file_path'] ]['Version']; 
  1443.  
  1444. return ''; 
  1445.  
  1446. /** 
  1447. * Check whether a plugin complies with the minimum version requirements. 
  1448. * @since 2.5.0 
  1449. * @param string $slug Plugin slug. 
  1450. * @return bool True when a plugin needs to be updated, otherwise false. 
  1451. */ 
  1452. public function does_plugin_require_update( $slug ) { 
  1453. $installed_version = $this->get_installed_version( $slug ); 
  1454. $minimum_version = $this->plugins[ $slug ]['version']; 
  1455.  
  1456. return version_compare( $minimum_version, $installed_version, '>' ); 
  1457.  
  1458. /** 
  1459. * Check whether there is an update available for a plugin. 
  1460. * @since 2.5.0 
  1461. * @param string $slug Plugin slug. 
  1462. * @return false|string Version number string of the available update or false if no update available. 
  1463. */ 
  1464. public function does_plugin_have_update( $slug ) { 
  1465. // Presume bundled and external plugins will point to a package which meets the minimum required version. 
  1466. if ( 'repo' !== $this->plugins[ $slug ]['source_type'] ) { 
  1467. if ( $this->does_plugin_require_update( $slug ) ) { 
  1468. return $this->plugins[ $slug ]['version']; 
  1469.  
  1470. return false; 
  1471.  
  1472. $repo_updates = get_site_transient( 'update_plugins' ); 
  1473.  
  1474. if ( isset( $repo_updates->response[ $this->plugins[ $slug ]['file_path'] ]->new_version ) ) { 
  1475. return $repo_updates->response[ $this->plugins[ $slug ]['file_path'] ]->new_version; 
  1476.  
  1477. return false; 
  1478.  
  1479. /** 
  1480. * Retrieve potential upgrade notice for a plugin. 
  1481. * @since 2.5.0 
  1482. * @param string $slug Plugin slug. 
  1483. * @return string The upgrade notice or an empty string if no message was available or provided. 
  1484. */ 
  1485. public function get_upgrade_notice( $slug ) { 
  1486. // We currently can't get reliable info on non-WP-repo plugins - issue #380. 
  1487. if ( 'repo' !== $this->plugins[ $slug ]['source_type'] ) { 
  1488. return ''; 
  1489.  
  1490. $repo_updates = get_site_transient( 'update_plugins' ); 
  1491.  
  1492. if ( ! empty( $repo_updates->response[ $this->plugins[ $slug ]['file_path'] ]->upgrade_notice ) ) { 
  1493. return $repo_updates->response[ $this->plugins[ $slug ]['file_path'] ]->upgrade_notice; 
  1494.  
  1495. return ''; 
  1496.  
  1497. /** 
  1498. * Wrapper around the core WP get_plugins function, making sure it's actually available. 
  1499. * @since 2.5.0 
  1500. * @param string $plugin_folder Optional. Relative path to single plugin folder. 
  1501. * @return array Array of installed plugins with plugin information. 
  1502. */ 
  1503. public function get_plugins( $plugin_folder = '' ) { 
  1504. if ( ! function_exists( 'get_plugins' ) ) { 
  1505. require_once ABSPATH . 'wp-admin/includes/plugin.php'; 
  1506.  
  1507. return get_plugins( $plugin_folder ); 
  1508.  
  1509. /** 
  1510. * Delete dismissable nag option when theme is switched. 
  1511. * This ensures that the user(s) is/are again reminded via nag of required 
  1512. * and/or recommended plugins if they re-activate the theme. 
  1513. * @since 2.1.1 
  1514. */ 
  1515. public function update_dismiss() { 
  1516. delete_metadata( 'user', null, 'tgmpa_dismissed_notice_' . $this->id, null, true ); 
  1517.  
  1518. /** 
  1519. * Forces plugin activation if the parameter 'force_activation' is 
  1520. * set to true. 
  1521. * This allows theme authors to specify certain plugins that must be 
  1522. * active at all times while using the current theme. 
  1523. * Please take special care when using this parameter as it has the 
  1524. * potential to be harmful if not used correctly. Setting this parameter 
  1525. * to true will not allow the specified plugin to be deactivated unless 
  1526. * the user switches themes. 
  1527. * @since 2.2.0 
  1528. */ 
  1529. public function force_activation() { 
  1530. foreach ( $this->plugins as $slug => $plugin ) { 
  1531. if ( true === $plugin['force_activation'] ) { 
  1532. if ( ! $this->is_plugin_installed( $slug ) ) { 
  1533. // Oops, plugin isn't there so iterate to next condition. 
  1534. continue; 
  1535. } elseif ( $this->can_plugin_activate( $slug ) ) { 
  1536. // There we go, activate the plugin. 
  1537. activate_plugin( $plugin['file_path'] ); 
  1538.  
  1539. /** 
  1540. * Forces plugin deactivation if the parameter 'force_deactivation' 
  1541. * is set to true and adds the plugin to the 'recently active' plugins list. 
  1542. * This allows theme authors to specify certain plugins that must be 
  1543. * deactivated upon switching from the current theme to another. 
  1544. * Please take special care when using this parameter as it has the 
  1545. * potential to be harmful if not used correctly. 
  1546. * @since 2.2.0 
  1547. */ 
  1548. public function force_deactivation() { 
  1549. $deactivated = array(); 
  1550.  
  1551. foreach ( $this->plugins as $slug => $plugin ) { 
  1552. /** 
  1553. * Only proceed forward if the parameter is set to true and plugin is active 
  1554. * as a 'normal' (not must-use) plugin. 
  1555. */ 
  1556. if ( true === $plugin['force_deactivation'] && is_plugin_active( $plugin['file_path'] ) ) { 
  1557. deactivate_plugins( $plugin['file_path'] ); 
  1558. $deactivated[ $plugin['file_path'] ] = time(); 
  1559.  
  1560. if ( ! empty( $deactivated ) ) { 
  1561. update_option( 'recently_activated', $deactivated + (array) get_option( 'recently_activated' ) ); 
  1562.  
  1563. /** 
  1564. * Echo the current TGMPA version number to the page. 
  1565. * @since 2.5.0 
  1566. */ 
  1567. public function show_tgmpa_version() { 
  1568. echo '<p style="float: right; padding: 0em 1.5em 0.5em 0;"><strong><small>',  
  1569. esc_html( 
  1570. sprintf( 
  1571. /** translators: %s: version number */ 
  1572. __( 'TGMPA v%s', 'enigma' ),  
  1573. self::TGMPA_VERSION 
  1574. ),  
  1575. '</small></strong></p>'; 
  1576.  
  1577. /** 
  1578. * Returns the singleton instance of the class. 
  1579. * @since 2.4.0 
  1580. * @return \TGM_Plugin_Activation The TGM_Plugin_Activation object. 
  1581. */ 
  1582. public static function get_instance() { 
  1583. if ( ! isset( self::$instance ) && ! ( self::$instance instanceof self ) ) { 
  1584. self::$instance = new self(); 
  1585.  
  1586. return self::$instance;