/class-tgm-plugin-activation.php

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