WP Mail SMTP by WPForms - Version 1.3.2

Version Description

  • 2018-06-29 =
  • Make sure that other plugins/themes are not conflicting with our TGMPA library.
Download this release

Release Info

Developer slaFFik
Plugin Icon 128x128 WP Mail SMTP by WPForms
Version 1.3.2
Comparing to
See all releases

Code changes from version 1.3.1 to 1.3.2

Files changed (4) hide show
  1. readme.txt +3 -0
  2. src/Core.php +3 -3
  3. src/TGMPA.php +3129 -3160
  4. wp_mail_smtp.php +2 -2
readme.txt CHANGED
@@ -146,6 +146,9 @@ By all means please contact us to discuss features or options you'd like to see
146
147
== Changelog ==
148
149
= 1.3.1 - 2018-06-29 =
150
* Fixed: Other SMTP: Clear new Debug messages about failed email delivery on next successful email sending.
151
* Fixed: Introduce conditional autoloader to workaround Gmail PHP 5.5 requirement and its library compatibility issues vs PHP 5.3+ minimum viable plugin version.
146
147
== Changelog ==
148
149
+ = 1.3.2 - 2018-06-29 =
150
+ * Make sure that other plugins/themes are not conflicting with our TGMPA library.
151
+
152
= 1.3.1 - 2018-06-29 =
153
* Fixed: Other SMTP: Clear new Debug messages about failed email delivery on next successful email sending.
154
* Fixed: Introduce conditional autoloader to workaround Gmail PHP 5.5 requirement and its library compatibility issues vs PHP 5.3+ minimum viable plugin version.
src/Core.php CHANGED
@@ -53,10 +53,10 @@ class Core {
53
add_action( 'plugins_loaded', array( $this, 'init_notifications' ) );
54
55
// Recommendations.
56
- if ( ! class_exists( 'WPMailSMTP\TGM_Plugin_Activation', false ) ) {
57
require_once __DIR__ . '/TGMPA.php';
58
}
59
- add_action( 'tgmpa_register', array( $this, 'init_recommendations' ) );
60
61
add_action( 'init', array( $this, 'init' ) );
62
}
@@ -265,7 +265,7 @@ class Core {
265
),
266
) );
267
268
- tgmpa( (array) $plugins, (array) $config );
269
}
270
271
/**
53
add_action( 'plugins_loaded', array( $this, 'init_notifications' ) );
54
55
// Recommendations.
56
+ if ( ! class_exists( '\WPMailSMTP\TGM_Plugin_Activation', false ) ) {
57
require_once __DIR__ . '/TGMPA.php';
58
}
59
+ add_action( 'wpms_tgmpa_register', array( $this, 'init_recommendations' ) );
60
61
add_action( 'init', array( $this, 'init' ) );
62
}
265
),
266
) );
267
268
+ \WPMailSMTP\tgmpa( (array) $plugins, (array) $config );
269
}
270
271
/**
src/TGMPA.php CHANGED
@@ -35,2122 +35,2123 @@ namespace WPMailSMTP;
35
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
36
*/
37
38
- if ( ! class_exists( 'TGM_Plugin_Activation' ) ) {
39
-
40
/**
41
- * Automatic plugin installation and activation library.
42
*
43
- * Creates a way to automatically install and activate plugins from within themes.
44
- * The plugins can be either bundled, downloaded from the WordPress
45
- * Plugin Repository or downloaded from another external source.
46
- *
47
- * @since 1.0.0
48
*
49
- * @package TGM-Plugin-Activation
50
- * @author Thomas Griffin
51
- * @author Gary Jones
52
*/
53
- class TGM_Plugin_Activation {
54
- /**
55
- * TGMPA version number.
56
- *
57
- * @since 2.5.0
58
- *
59
- * @const string Version number.
60
- */
61
- const TGMPA_VERSION = '2.6.1';
62
63
- /**
64
- * Regular expression to test if a URL is a WP plugin repo URL.
65
- *
66
- * @const string Regex.
67
- *
68
- * @since 2.5.0
69
- */
70
- const WP_REPO_REGEX = '|^http[s]?://wordpress\.org/(?:extend/)?plugins/|';
71
-
72
- /**
73
- * Arbitrary regular expression to test if a string starts with a URL.
74
- *
75
- * @const string Regex.
76
- *
77
- * @since 2.5.0
78
- */
79
- const IS_URL_REGEX = '|^http[s]?://|';
80
81
- /**
82
- * Holds a copy of itself, so it can be referenced by the class name.
83
- *
84
- * @since 1.0.0
85
- *
86
- * @var TGM_Plugin_Activation
87
- */
88
- public static $instance;
89
90
- /**
91
- * Holds arrays of plugin details.
92
- *
93
- * @since 1.0.0
94
- * @since 2.5.0 the array has the plugin slug as an associative key.
95
- *
96
- * @var array
97
- */
98
- public $plugins = array();
99
100
- /**
101
- * Holds arrays of plugin names to use to sort the plugins array.
102
- *
103
- * @since 2.5.0
104
- *
105
- * @var array
106
- */
107
- protected $sort_order = array();
108
109
- /**
110
- * Whether any plugins have the 'force_activation' setting set to true.
111
- *
112
- * @since 2.5.0
113
- *
114
- * @var bool
115
- */
116
- protected $has_forced_activation = false;
117
118
- /**
119
- * Whether any plugins have the 'force_deactivation' setting set to true.
120
- *
121
- * @since 2.5.0
122
- *
123
- * @var bool
124
- */
125
- protected $has_forced_deactivation = false;
126
127
- /**
128
- * Name of the unique ID to hash notices.
129
- *
130
- * @since 2.4.0
131
- *
132
- * @var string
133
- */
134
- public $id = 'tgmpa';
135
136
- /**
137
- * Name of the query-string argument for the admin page.
138
- *
139
- * @since 1.0.0
140
- *
141
- * @var string
142
- */
143
- protected $menu = 'tgmpa-install-plugins';
144
145
- /**
146
- * Parent menu file slug.
147
- *
148
- * @since 2.5.0
149
- *
150
- * @var string
151
- */
152
- public $parent_slug = 'themes.php';
153
154
- /**
155
- * Capability needed to view the plugin installation menu item.
156
- *
157
- * @since 2.5.0
158
- *
159
- * @var string
160
- */
161
- public $capability = 'edit_theme_options';
162
163
- /**
164
- * Default absolute path to folder containing bundled plugin zip files.
165
- *
166
- * @since 2.0.0
167
- *
168
- * @var string Absolute path prefix to zip file location for bundled plugins. Default is empty string.
169
- */
170
- public $default_path = '';
171
172
- /**
173
- * Flag to show admin notices or not.
174
- *
175
- * @since 2.1.0
176
- *
177
- * @var boolean
178
- */
179
- public $has_notices = true;
180
181
- /**
182
- * Flag to determine if the user can dismiss the notice nag.
183
- *
184
- * @since 2.4.0
185
- *
186
- * @var boolean
187
- */
188
- public $dismissable = true;
189
190
- /**
191
- * Message to be output above nag notice if dismissable is false.
192
- *
193
- * @since 2.4.0
194
- *
195
- * @var string
196
- */
197
- public $dismiss_msg = '';
198
199
- /**
200
- * Flag to set automatic activation of plugins. Off by default.
201
- *
202
- * @since 2.2.0
203
- *
204
- * @var boolean
205
- */
206
- public $is_automatic = false;
207
208
- /**
209
- * Optional message to display before the plugins table.
210
- *
211
- * @since 2.2.0
212
- *
213
- * @var string Message filtered by wp_kses_post(). Default is empty string.
214
- */
215
- public $message = '';
216
217
- /**
218
- * Holds configurable array of strings.
219
- *
220
- * Default values are added in the constructor.
221
- *
222
- * @since 2.0.0
223
- *
224
- * @var array
225
- */
226
- public $strings = array();
227
228
- /**
229
- * Holds the version of WordPress.
230
- *
231
- * @since 2.4.0
232
- *
233
- * @var int
234
- */
235
- public $wp_version;
236
237
- /**
238
- * Holds the hook name for the admin page.
239
- *
240
- * @since 2.5.0
241
- *
242
- * @var string
243
- */
244
- public $page_hook;
245
246
- /**
247
- * Adds a reference of this object to $instance, populates default strings,
248
- * does the tgmpa_init action hook, and hooks in the interactions to init.
249
- *
250
- * {@internal This method should be `protected`, but as too many TGMPA implementations
251
- * haven't upgraded beyond v2.3.6 yet, this gives backward compatibility issues.
252
- * Reverted back to public for the time being.}}
253
- *
254
- * @since 1.0.0
255
- *
256
- * @see TGM_Plugin_Activation::init()
257
- */
258
- public function __construct() {
259
- // Set the current WordPress version.
260
- $this->wp_version = $GLOBALS['wp_version'];
261
262
- // Announce that the class is ready, and pass the object (for advanced use).
263
- do_action_ref_array( 'tgmpa_init', array( $this ) );
264
265
- /*
266
- * Load our text domain and allow for overloading the fall-back file.
267
- *
268
- * {@internal IMPORTANT! If this code changes, review the regex in the custom TGMPA
269
- * generator on the website.}}
270
- */
271
- add_action( 'init', array( $this, 'load_textdomain' ), 5 );
272
- add_filter( 'load_textdomain_mofile', array( $this, 'overload_textdomain_mofile' ), 10, 2 );
273
274
- // When the rest of WP has loaded, kick-start the rest of the class.
275
- add_action( 'init', array( $this, 'init' ) );
276
- }
277
278
/**
279
- * Magic method to (not) set protected properties from outside of this class.
280
- *
281
- * {@internal hackedihack... There is a serious bug in v2.3.2 - 2.3.6 where the `menu` property
282
- * is being assigned rather than tested in a conditional, effectively rendering it useless.
283
- * This 'hack' prevents this from happening.}}
284
- *
285
- * @see https://github.com/TGMPA/TGM-Plugin-Activation/blob/2.3.6/tgm-plugin-activation/class-tgm-plugin-activation.php#L1593
286
*
287
- * @since 2.5.2
288
*
289
- * @param string $name Name of an inaccessible property.
290
- * @param mixed $value Value to assign to the property.
291
- * @return void Silently fail to set the property when this is tried from outside of this class context.
292
- * (Inside this class context, the __set() method if not used as there is direct access.)
293
*/
294
- public function __set( $name, $value ) {
295
return;
296
}
297
298
- /**
299
- * Magic method to get the value of a protected property outside of this class context.
300
- *
301
- * @since 2.5.2
302
- *
303
- * @param string $name Name of an inaccessible property.
304
- * @return mixed The property value.
305
- */
306
- public function __get( $name ) {
307
- return $this->{$name};
308
- }
309
-
310
- /**
311
- * Initialise the interactions between this class and WordPress.
312
- *
313
- * Hooks in three new methods for the class: admin_menu, notices and styles.
314
- *
315
- * @since 2.0.0
316
- *
317
- * @see TGM_Plugin_Activation::admin_menu()
318
- * @see TGM_Plugin_Activation::notices()
319
- * @see TGM_Plugin_Activation::styles()
320
- */
321
- public function init() {
322
- /**
323
- * By default TGMPA only loads on the WP back-end and not in an Ajax call. Using this filter
324
- * you can overrule that behaviour.
325
- *
326
- * @since 2.5.0
327
- *
328
- * @param bool $load Whether or not TGMPA should load.
329
- * Defaults to the return of `is_admin() && ! defined( 'DOING_AJAX' )`.
330
- */
331
- if ( true !== apply_filters( 'tgmpa_load', ( is_admin() && ! defined( 'DOING_AJAX' ) ) ) ) {
332
- return;
333
- }
334
-
335
- // Load class strings.
336
- $this->strings = array(
337
- 'page_title' => __( 'Install Required Plugins', 'tgmpa' ),
338
- 'menu_title' => __( 'Install Plugins', 'tgmpa' ),
339
- /* translators: %s: plugin name. */
340
- 'installing' => __( 'Installing Plugin: %s', 'tgmpa' ),
341
- /* translators: %s: plugin name. */
342
- 'updating' => __( 'Updating Plugin: %s', 'tgmpa' ),
343
- 'oops' => __( 'Something went wrong with the plugin API.', 'tgmpa' ),
344
- 'notice_can_install_required' => _n_noop(
345
/* translators: 1: plugin name(s). */
346
- 'This theme requires the following plugin: %1$s.',
347
- 'This theme requires the following plugins: %1$s.',
348
- 'tgmpa'
349
- ),
350
- 'notice_can_install_recommended' => _n_noop(
351
/* translators: 1: plugin name(s). */
352
- 'This theme recommends the following plugin: %1$s.',
353
- 'This theme recommends the following plugins: %1$s.',
354
- 'tgmpa'
355
- ),
356
- 'notice_ask_to_update' => _n_noop(
357
/* translators: 1: plugin name(s). */
358
- 'The following plugin needs to be updated to its latest version to ensure maximum compatibility with this theme: %1$s.',
359
- 'The following plugins need to be updated to their latest version to ensure maximum compatibility with this theme: %1$s.',
360
- 'tgmpa'
361
- ),
362
- 'notice_ask_to_update_maybe' => _n_noop(
363
/* translators: 1: plugin name(s). */
364
- 'There is an update available for: %1$s.',
365
- 'There are updates available for the following plugins: %1$s.',
366
- 'tgmpa'
367
- ),
368
- 'notice_can_activate_required' => _n_noop(
369
/* translators: 1: plugin name(s). */
370
- 'The following required plugin is currently inactive: %1$s.',
371
- 'The following required plugins are currently inactive: %1$s.',
372
- 'tgmpa'
373
- ),
374
- 'notice_can_activate_recommended' => _n_noop(
375
/* translators: 1: plugin name(s). */
376
- 'The following recommended plugin is currently inactive: %1$s.',
377
- 'The following recommended plugins are currently inactive: %1$s.',
378
- 'tgmpa'
379
- ),
380
- 'install_link' => _n_noop(
381
- 'Begin installing plugin',
382
- 'Begin installing plugins',
383
- 'tgmpa'
384
- ),
385
- 'update_link' => _n_noop(
386
- 'Begin updating plugin',
387
- 'Begin updating plugins',
388
- 'tgmpa'
389
- ),
390
- 'activate_link' => _n_noop(
391
- 'Begin activating plugin',
392
- 'Begin activating plugins',
393
- 'tgmpa'
394
- ),
395
- 'return' => __( 'Return to Required Plugins Installer', 'tgmpa' ),
396
- 'dashboard' => __( 'Return to the Dashboard', 'tgmpa' ),
397
- 'plugin_activated' => __( 'Plugin activated successfully.', 'tgmpa' ),
398
- 'activated_successfully' => __( 'The following plugin was activated successfully:', 'tgmpa' ),
399
- /* translators: 1: plugin name. */
400
- 'plugin_already_active' => __( 'No action taken. Plugin %1$s was already active.', 'tgmpa' ),
401
- /* translators: 1: plugin name. */
402
- 'plugin_needs_higher_version' => __( 'Plugin not activated. A higher version of %s is needed for this theme. Please update the plugin.', 'tgmpa' ),
403
- /* translators: 1: dashboard link. */
404
- 'complete' => __( 'All plugins installed and activated successfully. %1$s', 'tgmpa' ),
405
- 'dismiss' => __( 'Dismiss this notice', 'tgmpa' ),
406
- 'notice_cannot_install_activate' => __( 'There are one or more required or recommended plugins to install, update or activate.', 'tgmpa' ),
407
- 'contact_admin' => __( 'Please contact the administrator of this site for help.', 'tgmpa' ),
408
- );
409
410
- do_action( 'tgmpa_register' );
411
412
- /* After this point, the plugins should be registered and the configuration set. */
413
414
- // Proceed only if we have plugins to handle.
415
- if ( empty( $this->plugins ) || ! is_array( $this->plugins ) ) {
416
- return;
417
- }
418
419
- // Set up the menu and notices if we still have outstanding actions.
420
- if ( true !== $this->is_tgmpa_complete() ) {
421
- // Sort the plugins.
422
- array_multisort( $this->sort_order, SORT_ASC, $this->plugins );
423
424
- add_action( 'admin_menu', array( $this, 'admin_menu' ) );
425
- add_action( 'admin_head', array( $this, 'dismiss' ) );
426
427
- // Prevent the normal links from showing underneath a single install/update page.
428
- add_filter( 'install_plugin_complete_actions', array( $this, 'actions' ) );
429
- add_filter( 'update_plugin_complete_actions', array( $this, 'actions' ) );
430
431
- if ( $this->has_notices ) {
432
- add_action( 'admin_notices', array( $this, 'notices' ) );
433
- add_action( 'admin_init', array( $this, 'admin_init' ), 1 );
434
- add_action( 'admin_enqueue_scripts', array( $this, 'thickbox' ) );
435
- }
436
}
437
438
- // If needed, filter plugin action links.
439
- add_action( 'load-plugins.php', array( $this, 'add_plugin_action_link_filters' ), 1 );
440
441
- // Make sure things get reset on switch theme.
442
- add_action( 'switch_theme', array( $this, 'flush_plugins_cache' ) );
443
444
- if ( $this->has_notices ) {
445
- add_action( 'switch_theme', array( $this, 'update_dismiss' ) );
446
- }
447
448
- // Setup the force activation hook.
449
- if ( true === $this->has_forced_activation ) {
450
- add_action( 'admin_init', array( $this, 'force_activation' ) );
451
- }
452
453
- // Setup the force deactivation hook.
454
- if ( true === $this->has_forced_deactivation ) {
455
- add_action( 'switch_theme', array( $this, 'force_deactivation' ) );
456
- }
457
}
458
459
- /**
460
- * Load translations.
461
- *
462
- * @since 2.6.0
463
- *
464
- * (@internal Uses `load_theme_textdomain()` rather than `load_plugin_textdomain()` to
465
- * get round the different ways of handling the path and deprecated notices being thrown
466
- * and such. For plugins, the actual file name will be corrected by a filter.}}
467
- *
468
- * {@internal IMPORTANT! If this function changes, review the regex in the custom TGMPA
469
- * generator on the website.}}
470
- */
471
- public function load_textdomain() {
472
- if ( is_textdomain_loaded( 'tgmpa' ) ) {
473
- return;
474
- }
475
476
- if ( false !== strpos( __FILE__, WP_PLUGIN_DIR ) || false !== strpos( __FILE__, WPMU_PLUGIN_DIR ) ) {
477
- // Plugin, we'll need to adjust the file name.
478
- add_action( 'load_textdomain_mofile', array( $this, 'correct_plugin_mofile' ), 10, 2 );
479
- load_theme_textdomain( 'tgmpa', dirname( __FILE__ ) . '/languages' );
480
- remove_action( 'load_textdomain_mofile', array( $this, 'correct_plugin_mofile' ), 10 );
481
- } else {
482
- load_theme_textdomain( 'tgmpa', dirname( __FILE__ ) . '/languages' );
483
- }
484
}
485
486
- /**
487
- * Correct the .mo file name for (must-use) plugins.
488
- *
489
- * Themese use `/path/{locale}.mo` while plugins use `/path/{text-domain}-{locale}.mo`.
490
- *
491
- * {@internal IMPORTANT! If this function changes, review the regex in the custom TGMPA
492
- * generator on the website.}}
493
- *
494
- * @since 2.6.0
495
- *
496
- * @param string $mofile Full path to the target mofile.
497
- * @param string $domain The domain for which a language file is being loaded.
498
- * @return string $mofile
499
- */
500
- public function correct_plugin_mofile( $mofile, $domain ) {
501
- // Exit early if not our domain (just in case).
502
- if ( 'tgmpa' !== $domain ) {
503
- return $mofile;
504
- }
505
- return preg_replace( '`/([a-z]{2}_[A-Z]{2}.mo) Diff to HTML by rtfpessoa

Diff to HTML by rtfpessoa

', '/tgmpa-$1', $mofile );
506
}
507
508
- /**
509
- * Potentially overload the fall-back translation file for the current language.
510
- *
511
- * WP, by default since WP 3.7, will load a local translation first and if none
512
- * can be found, will try and find a translation in the /wp-content/languages/ directory.
513
- * As this library is theme/plugin agnostic, translation files for TGMPA can exist both
514
- * in the WP_LANG_DIR /plugins/ subdirectory as well as in the /themes/ subdirectory.
515
- *
516
- * This method makes sure both directories are checked.
517
- *
518
- * {@internal IMPORTANT! If this function changes, review the regex in the custom TGMPA
519
- * generator on the website.}}
520
- *
521
- * @since 2.6.0
522
- *
523
- * @param string $mofile Full path to the target mofile.
524
- * @param string $domain The domain for which a language file is being loaded.
525
- * @return string $mofile
526
- */
527
- public function overload_textdomain_mofile( $mofile, $domain ) {
528
- // Exit early if not our domain, not a WP_LANG_DIR load or if the file exists and is readable.
529
- if ( 'tgmpa' !== $domain || false === strpos( $mofile, WP_LANG_DIR ) || @is_readable( $mofile ) ) {
530
- return $mofile;
531
- }
532
533
- // Current fallback file is not valid, let's try the alternative option.
534
- if ( false !== strpos( $mofile, '/themes/' ) ) {
535
- return str_replace( '/themes/', '/plugins/', $mofile );
536
- } elseif ( false !== strpos( $mofile, '/plugins/' ) ) {
537
- return str_replace( '/plugins/', '/themes/', $mofile );
538
- } else {
539
- return $mofile;
540
- }
541
}
542
543
- /**
544
- * Hook in plugin action link filters for the WP native plugins page.
545
- *
546
- * - Prevent activation of plugins which don't meet the minimum version requirements.
547
- * - Prevent deactivation of force-activated plugins.
548
- * - Add update notice if update available.
549
- *
550
- * @since 2.5.0
551
- */
552
- public function add_plugin_action_link_filters() {
553
- foreach ( $this->plugins as $slug => $plugin ) {
554
- if ( false === $this->can_plugin_activate( $slug ) ) {
555
- add_filter( 'plugin_action_links_' . $plugin['file_path'], array( $this, 'filter_plugin_action_links_activate' ), 20 );
556
- }
557
558
- if ( true === $plugin['force_activation'] ) {
559
- add_filter( 'plugin_action_links_' . $plugin['file_path'], array( $this, 'filter_plugin_action_links_deactivate' ), 20 );
560
- }
561
562
- if ( false !== $this->does_plugin_require_update( $slug ) ) {
563
- add_filter( 'plugin_action_links_' . $plugin['file_path'], array( $this, 'filter_plugin_action_links_update' ), 20 );
564
- }
565
}
566
}
567
568
- /**
569
- * Remove the 'Activate' link on the WP native plugins page if the plugin does not meet the
570
- * minimum version requirements.
571
- *
572
- * @since 2.5.0
573
- *
574
- * @param array $actions Action links.
575
- * @return array
576
- */
577
- public function filter_plugin_action_links_activate( $actions ) {
578
- unset( $actions['activate'] );
579
580
- return $actions;
581
- }
582
583
- /**
584
- * Remove the 'Deactivate' link on the WP native plugins page if the plugin has been set to force activate.
585
- *
586
- * @since 2.5.0
587
- *
588
- * @param array $actions Action links.
589
- * @return array
590
- */
591
- public function filter_plugin_action_links_deactivate( $actions ) {
592
- unset( $actions['deactivate'] );
593
594
- return $actions;
595
- }
596
597
- /**
598
- * Add a 'Requires update' link on the WP native plugins page if the plugin does not meet the
599
- * minimum version requirements.
600
- *
601
- * @since 2.5.0
602
- *
603
- * @param array $actions Action links.
604
- * @return array
605
- */
606
- public function filter_plugin_action_links_update( $actions ) {
607
- $actions['update'] = sprintf(
608
- '<a href="%1$s" title="%2$s" class="edit">%3$s</a>',
609
- esc_url( $this->get_tgmpa_status_url( 'update' ) ),
610
- esc_attr__( 'This plugin needs to be updated to be compatible with your theme.', 'tgmpa' ),
611
- esc_html__( 'Update Required', 'tgmpa' )
612
- );
613
614
- return $actions;
615
}
616
617
- /**
618
- * Handles calls to show plugin information via links in the notices.
619
- *
620
- * We get the links in the admin notices to point to the TGMPA page, rather
621
- * than the typical plugin-install.php file, so we can prepare everything
622
- * beforehand.
623
- *
624
- * WP does not make it easy to show the plugin information in the thickbox -
625
- * here we have to require a file that includes a function that does the
626
- * main work of displaying it, enqueue some styles, set up some globals and
627
- * finally call that function before exiting.
628
- *
629
- * Down right easy once you know how...
630
- *
631
- * Returns early if not the TGMPA page.
632
- *
633
- * @since 2.1.0
634
- *
635
- * @global string $tab Used as iframe div class names, helps with styling
636
- * @global string $body_id Used as the iframe body ID, helps with styling
637
- *
638
- * @return null Returns early if not the TGMPA page.
639
- */
640
- public function admin_init() {
641
- if ( ! $this->is_tgmpa_page() ) {
642
- return;
643
- }
644
645
- if ( isset( $_REQUEST['tab'] ) && 'plugin-information' === $_REQUEST['tab'] ) {
646
- // Needed for install_plugin_information().
647
- require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
648
649
- wp_enqueue_style( 'plugin-install' );
650
651
- global $tab, $body_id;
652
- $body_id = 'plugin-information';
653
- // @codingStandardsIgnoreStart
654
- $tab = 'plugin-information';
655
- // @codingStandardsIgnoreEnd
656
657
- install_plugin_information();
658
659
- exit;
660
- }
661
}
662
663
- /**
664
- * Enqueue thickbox scripts/styles for plugin info.
665
- *
666
- * Thickbox is not automatically included on all admin pages, so we must
667
- * manually enqueue it for those pages.
668
- *
669
- * Thickbox is only loaded if the user has not dismissed the admin
670
- * notice or if there are any plugins left to install and activate.
671
- *
672
- * @since 2.1.0
673
- */
674
- public function thickbox() {
675
- if ( ! get_user_meta( get_current_user_id(), 'tgmpa_dismissed_notice_' . $this->id, true ) ) {
676
- add_thickbox();
677
- }
678
}
679
680
- /**
681
- * Adds submenu page if there are plugin actions to take.
682
- *
683
- * This method adds the submenu page letting users know that a required
684
- * plugin needs to be installed.
685
- *
686
- * This page disappears once the plugin has been installed and activated.
687
- *
688
- * @since 1.0.0
689
- *
690
- * @see TGM_Plugin_Activation::init()
691
- * @see TGM_Plugin_Activation::install_plugins_page()
692
- *
693
- * @return null Return early if user lacks capability to install a plugin.
694
- */
695
- public function admin_menu() {
696
- // Make sure privileges are correct to see the page.
697
- if ( ! current_user_can( 'install_plugins' ) ) {
698
- return;
699
- }
700
701
- $args = apply_filters(
702
- 'tgmpa_admin_menu_args',
703
- array(
704
- 'parent_slug' => $this->parent_slug, // Parent Menu slug.
705
- 'page_title' => $this->strings['page_title'], // Page title.
706
- 'menu_title' => $this->strings['menu_title'], // Menu title.
707
- 'capability' => $this->capability, // Capability.
708
- 'menu_slug' => $this->menu, // Menu slug.
709
- 'function' => array( $this, 'install_plugins_page' ), // Callback.
710
- )
711
- );
712
713
- $this->add_admin_menu( $args );
714
}
715
716
- /**
717
- * Add the menu item.
718
- *
719
- * {@internal IMPORTANT! If this function changes, review the regex in the custom TGMPA
720
- * generator on the website.}}
721
- *
722
- * @since 2.5.0
723
- *
724
- * @param array $args Menu item configuration.
725
- */
726
- protected function add_admin_menu( array $args ) {
727
- if ( has_filter( 'tgmpa_admin_menu_use_add_theme_page' ) ) {
728
- _deprecated_function( 'The "tgmpa_admin_menu_use_add_theme_page" filter', '2.5.0', esc_html__( 'Set the parent_slug config variable instead.', 'tgmpa' ) );
729
- }
730
-
731
- if ( 'themes.php' === $this->parent_slug ) {
732
- $this->page_hook = call_user_func( 'add_theme_page', $args['page_title'], $args['menu_title'], $args['capability'], $args['menu_slug'], $args['function'] );
733
- } else {
734
- $this->page_hook = call_user_func( 'add_submenu_page', $args['parent_slug'], $args['page_title'], $args['menu_title'], $args['capability'], $args['menu_slug'], $args['function'] );
735
- }
736
}
737
738
- /**
739
- * Echoes plugin installation form.
740
- *
741
- * This method is the callback for the admin_menu method function.
742
- * This displays the admin page and form area where the user can select to install and activate the plugin.
743
- * Aborts early if we're processing a plugin installation action.
744
- *
745
- * @since 1.0.0
746
- *
747
- * @return null Aborts early if we're processing a plugin installation action.
748
- */
749
- public function install_plugins_page() {
750
- // Store new instance of plugin table in object.
751
- $plugin_table = new TGMPA_List_Table;
752
753
- // Return early if processing a plugin installation action.
754
- if ( ( ( 'tgmpa-bulk-install' === $plugin_table->current_action() || 'tgmpa-bulk-update' === $plugin_table->current_action() ) && $plugin_table->process_bulk_actions() ) || $this->do_plugin_install() ) {
755
- return;
756
- }
757
758
- // Force refresh of available plugin information so we'll know about manual updates/deletes.
759
- wp_clean_plugins_cache( false );
760
761
- ?>
762
- <div class="tgmpa wrap">
763
- <h1><?php echo esc_html( get_admin_page_title() ); ?></h1>
764
- <?php $plugin_table->prepare_items(); ?>
765
766
- <?php
767
- if ( ! empty( $this->message ) && is_string( $this->message ) ) {
768
- echo wp_kses_post( $this->message );
769
- }
770
- ?>
771
- <?php $plugin_table->views(); ?>
772
-
773
- <form id="tgmpa-plugins" action="" method="post">
774
- <input type="hidden" name="tgmpa-page" value="<?php echo esc_attr( $this->menu ); ?>" />
775
- <input type="hidden" name="plugin_status" value="<?php echo esc_attr( $plugin_table->view_context ); ?>" />
776
- <?php $plugin_table->display(); ?>
777
- </form>
778
- </div>
779
<?php
780
- }
781
-
782
- /**
783
- * Installs, updates or activates a plugin depending on the action link clicked by the user.
784
- *
785
- * Checks the $_GET variable to see which actions have been
786
- * passed and responds with the appropriate method.
787
- *
788
- * Uses WP_Filesystem to process and handle the plugin installation
789
- * method.
790
- *
791
- * @since 1.0.0
792
- *
793
- * @uses WP_Filesystem
794
- * @uses WP_Error
795
- * @uses WP_Upgrader
796
- * @uses Plugin_Upgrader
797
- * @uses Plugin_Installer_Skin
798
- * @uses Plugin_Upgrader_Skin
799
- *
800
- * @return boolean True on success, false on failure.
801
- */
802
- protected function do_plugin_install() {
803
- if ( empty( $_GET['plugin'] ) ) {
804
- return false;
805
}
806
807
- // All plugin information will be stored in an array for processing.
808
- $slug = $this->sanitize_key( urldecode( $_GET['plugin'] ) );
809
810
- if ( ! isset( $this->plugins[ $slug ] ) ) {
811
- return false;
812
- }
813
814
- // Was an install or upgrade action link clicked?
815
- if ( ( isset( $_GET['tgmpa-install'] ) && 'install-plugin' === $_GET['tgmpa-install'] ) || ( isset( $_GET['tgmpa-update'] ) && 'update-plugin' === $_GET['tgmpa-update'] ) ) {
816
817
- $install_type = 'install';
818
- if ( isset( $_GET['tgmpa-update'] ) && 'update-plugin' === $_GET['tgmpa-update'] ) {
819
- $install_type = 'update';
820
- }
821
822
- check_admin_referer( 'tgmpa-' . $install_type, 'tgmpa-nonce' );
823
824
- // Pass necessary information via URL if WP_Filesystem is needed.
825
- $url = wp_nonce_url(
826
- add_query_arg(
827
- array(
828
- 'plugin' => urlencode( $slug ),
829
- 'tgmpa-' . $install_type => $install_type . '-plugin',
830
- ),
831
- $this->get_tgmpa_url()
832
),
833
- 'tgmpa-' . $install_type,
834
- 'tgmpa-nonce'
835
- );
836
837
- $method = ''; // Leave blank so WP_Filesystem can populate it as necessary.
838
839
- if ( false === ( $creds = request_filesystem_credentials( esc_url_raw( $url ), $method, false, false, array() ) ) ) {
840
- return true;
841
- }
842
843
- if ( ! WP_Filesystem( $creds ) ) {
844
- request_filesystem_credentials( esc_url_raw( $url ), $method, true, false, array() ); // Setup WP_Filesystem.
845
- return true;
846
- }
847
848
- /* If we arrive here, we have the filesystem. */
849
850
- // Prep variables for Plugin_Installer_Skin class.
851
- $extra = array();
852
- $extra['slug'] = $slug; // Needed for potentially renaming of directory name.
853
- $source = $this->get_download_url( $slug );
854
- $api = ( 'repo' === $this->plugins[ $slug ]['source_type'] ) ? $this->get_plugins_api( $slug ) : null;
855
- $api = ( false !== $api ) ? $api : null;
856
857
- $url = add_query_arg(
858
- array(
859
- 'action' => $install_type . '-plugin',
860
- 'plugin' => urlencode( $slug ),
861
- ),
862
- 'update.php'
863
- );
864
865
- if ( ! class_exists( '\Plugin_Upgrader', false ) ) {
866
- require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
867
- }
868
869
- $title = ( 'update' === $install_type ) ? $this->strings['updating'] : $this->strings['installing'];
870
- $skin_args = array(
871
- 'type' => ( 'bundled' !== $this->plugins[ $slug ]['source_type'] ) ? 'web' : 'upload',
872
- 'title' => sprintf( $title, $this->plugins[ $slug ]['name'] ),
873
- 'url' => esc_url_raw( $url ),
874
- 'nonce' => $install_type . '-plugin_' . $slug,
875
- 'plugin' => '',
876
- 'api' => $api,
877
- 'extra' => $extra,
878
- );
879
- unset( $title );
880
881
- if ( 'update' === $install_type ) {
882
- $skin_args['plugin'] = $this->plugins[ $slug ]['file_path'];
883
- $skin = new \Plugin_Upgrader_Skin( $skin_args );
884
- } else {
885
- $skin = new \Plugin_Installer_Skin( $skin_args );
886
- }
887
888
- // Create a new instance of Plugin_Upgrader.
889
- $upgrader = new \Plugin_Upgrader( $skin );
890
891
- // Perform the action and install the plugin from the $source urldecode().
892
- add_filter( 'upgrader_source_selection', array( $this, 'maybe_adjust_source_dir' ), 1, 3 );
893
894
- if ( 'update' === $install_type ) {
895
- // Inject our info into the update transient.
896
- $to_inject = array( $slug => $this->plugins[ $slug ] );
897
- $to_inject[ $slug ]['source'] = $source;
898
- $this->inject_update_info( $to_inject );
899
900
- $upgrader->upgrade( $this->plugins[ $slug ]['file_path'] );
901
- } else {
902
- $upgrader->install( $source );
903
- }
904
905
- remove_filter( 'upgrader_source_selection', array( $this, 'maybe_adjust_source_dir' ), 1 );
906
907
- // Make sure we have the correct file path now the plugin is installed/updated.
908
- $this->populate_file_path( $slug );
909
910
- // Only activate plugins if the config option is set to true and the plugin isn't
911
- // already active (upgrade).
912
- if ( $this->is_automatic && ! $this->is_plugin_active( $slug ) ) {
913
- $plugin_activate = $upgrader->plugin_info(); // Grab the plugin info from the Plugin_Upgrader method.
914
- if ( false === $this->activate_single_plugin( $plugin_activate, $slug, true ) ) {
915
- return true; // Finish execution of the function early as we encountered an error.
916
- }
917
}
918
919
- $this->show_tgmpa_version();
920
921
- // Display message based on if all plugins are now active or not.
922
- if ( $this->is_tgmpa_complete() ) {
923
- echo '<p>', sprintf( esc_html( $this->strings['complete'] ), '<a href="' . esc_url( self_admin_url() ) . '">' . esc_html__( 'Return to the Dashboard', 'tgmpa' ) . '</a>' ), '</p>';
924
- echo '<style type="text/css">#adminmenu .wp-submenu li.current { display: none !important; }</style>';
925
- } else {
926
- echo '<p><a href="', esc_url( $this->get_tgmpa_url() ), '" target="_parent">', esc_html( $this->strings['return'] ), '</a></p>';
927
- }
928
929
- return true;
930
- } elseif ( isset( $this->plugins[ $slug ]['file_path'], $_GET['tgmpa-activate'] ) && 'activate-plugin' === $_GET['tgmpa-activate'] ) {
931
- // Activate action link was clicked.
932
- check_admin_referer( 'tgmpa-activate', 'tgmpa-nonce' );
933
934
- if ( false === $this->activate_single_plugin( $this->plugins[ $slug ]['file_path'], $slug ) ) {
935
- return true; // Finish execution of the function early as we encountered an error.
936
- }
937
}
938
-
939
- return false;
940
}
941
942
- /**
943
- * Inject information into the 'update_plugins' site transient as WP checks that before running an update.
944
- *
945
- * @since 2.5.0
946
- *
947
- * @param array $plugins The plugin information for the plugins which are to be updated.
948
- */
949
- public function inject_update_info( $plugins ) {
950
- $repo_updates = get_site_transient( 'update_plugins' );
951
952
- if ( ! is_object( $repo_updates ) ) {
953
- $repo_updates = new stdClass;
954
- }
955
956
- foreach ( $plugins as $slug => $plugin ) {
957
- $file_path = $plugin['file_path'];
958
959
- if ( empty( $repo_updates->response[ $file_path ] ) ) {
960
- $repo_updates->response[ $file_path ] = new stdClass;
961
- }
962
963
- // We only really need to set package, but let's do all we can in case WP changes something.
964
- $repo_updates->response[ $file_path ]->slug = $slug;
965
- $repo_updates->response[ $file_path ]->plugin = $file_path;
966
- $repo_updates->response[ $file_path ]->new_version = $plugin['version'];
967
- $repo_updates->response[ $file_path ]->package = $plugin['source'];
968
- if ( empty( $repo_updates->response[ $file_path ]->url ) && ! empty( $plugin['external_url'] ) ) {
969
- $repo_updates->response[ $file_path ]->url = $plugin['external_url'];
970
- }
971
}
972
973
- set_site_transient( 'update_plugins', $repo_updates );
974
}
975
976
- /**
977
- * Adjust the plugin directory name if necessary.
978
- *
979
- * The final destination directory of a plugin is based on the subdirectory name found in the
980
- * (un)zipped source. In some cases - most notably GitHub repository plugin downloads -, this
981
- * subdirectory name is not the same as the expected slug and the plugin will not be recognized
982
- * as installed. This is fixed by adjusting the temporary unzipped source subdirectory name to
983
- * the expected plugin slug.
984
- *
985
- * @since 2.5.0
986
- *
987
- * @param string $source Path to upgrade/zip-file-name.tmp/subdirectory/.
988
- * @param string $remote_source Path to upgrade/zip-file-name.tmp.
989
- * @param \WP_Upgrader $upgrader Instance of the upgrader which installs the plugin.
990
- * @return string $source
991
- */
992
- public function maybe_adjust_source_dir( $source, $remote_source, $upgrader ) {
993
- if ( ! $this->is_tgmpa_page() || ! is_object( $GLOBALS['wp_filesystem'] ) ) {
994
- return $source;
995
- }
996
997
- // Check for single file plugins.
998
- $source_files = array_keys( $GLOBALS['wp_filesystem']->dirlist( $remote_source ) );
999
- if ( 1 === count( $source_files ) && false === $GLOBALS['wp_filesystem']->is_dir( $source ) ) {
1000
- return $source;
1001
- }
1002
1003
- // Multi-file plugin, let's see if the directory is correctly named.
1004
- $desired_slug = '';
1005
1006
- // Figure out what the slug is supposed to be.
1007
- if ( false === $upgrader->bulk && ! empty( $upgrader->skin->options['extra']['slug'] ) ) {
1008
- $desired_slug = $upgrader->skin->options['extra']['slug'];
1009
- } else {
1010
- // Bulk installer contains less info, so fall back on the info registered here.
1011
- foreach ( $this->plugins as $slug => $plugin ) {
1012
- if ( ! empty( $upgrader->skin->plugin_names[ $upgrader->skin->i ] ) && $plugin['name'] === $upgrader->skin->plugin_names[ $upgrader->skin->i ] ) {
1013
- $desired_slug = $slug;
1014
- break;
1015
- }
1016
}
1017
- unset( $slug, $plugin );
1018
}
1019
1020
- if ( ! empty( $desired_slug ) ) {
1021
- $subdir_name = untrailingslashit( str_replace( trailingslashit( $remote_source ), '', $source ) );
1022
1023
- if ( ! empty( $subdir_name ) && $subdir_name !== $desired_slug ) {
1024
- $from_path = untrailingslashit( $source );
1025
- $to_path = trailingslashit( $remote_source ) . $desired_slug;
1026
1027
- if ( true === $GLOBALS['wp_filesystem']->move( $from_path, $to_path ) ) {
1028
- return trailingslashit( $to_path );
1029
- } else {
1030
- 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.', 'tgmpa' ) . ' ' . esc_html__( 'Please contact the plugin provider and ask them to package their plugin according to the WordPress guidelines.', 'tgmpa' ), array( 'found' => $subdir_name, 'expected' => $desired_slug ) );
1031
- }
1032
- } elseif ( empty( $subdir_name ) ) {
1033
- 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.', 'tgmpa' ) . ' ' . esc_html__( 'Please contact the plugin provider and ask them to package their plugin according to the WordPress guidelines.', 'tgmpa' ), array( 'found' => $subdir_name, 'expected' => $desired_slug ) );
1034
}
1035
}
1036
-
1037
- return $source;
1038
}
1039
1040
- /**
1041
- * Activate a single plugin and send feedback about the result to the screen.
1042
- *
1043
- * @since 2.5.0
1044
- *
1045
- * @param string $file_path Path within wp-plugins/ to main plugin file.
1046
- * @param string $slug Plugin slug.
1047
- * @param bool $automatic Whether this is an automatic activation after an install. Defaults to false.
1048
- * This determines the styling of the output messages.
1049
- * @return bool False if an error was encountered, true otherwise.
1050
- */
1051
- protected function activate_single_plugin( $file_path, $slug, $automatic = false ) {
1052
- if ( $this->can_plugin_activate( $slug ) ) {
1053
- $activate = activate_plugin( $file_path );
1054
1055
- if ( is_wp_error( $activate ) ) {
1056
- echo '<div id="message" class="error"><p>', wp_kses_post( $activate->get_error_message() ), '</p></div>',
1057
- '<p><a href="', esc_url( $this->get_tgmpa_url() ), '" target="_parent">', esc_html( $this->strings['return'] ), '</a></p>';
1058
1059
- return false; // End it here if there is an error with activation.
1060
- } else {
1061
- if ( ! $automatic ) {
1062
- // Make sure message doesn't display again if bulk activation is performed
1063
- // immediately after a single activation.
1064
- if ( ! isset( $_POST['action'] ) ) { // WPCS: CSRF OK.
1065
- echo '<div id="message" class="updated"><p>', esc_html( $this->strings['activated_successfully'] ), ' <strong>', esc_html( $this->plugins[ $slug ]['name'] ), '.</strong></p></div>';
1066
- }
1067
- } else {
1068
- // Simpler message layout for use on the plugin install page.
1069
- echo '<p>', esc_html( $this->strings['plugin_activated'] ), '</p>';
1070
- }
1071
- }
1072
- } elseif ( $this->is_plugin_active( $slug ) ) {
1073
- // No simpler message format provided as this message should never be encountered
1074
- // on the plugin install page.
1075
- echo '<div id="message" class="error"><p>',
1076
- sprintf(
1077
- esc_html( $this->strings['plugin_already_active'] ),
1078
- '<strong>' . esc_html( $this->plugins[ $slug ]['name'] ) . '</strong>'
1079
- ),
1080
- '</p></div>';
1081
- } elseif ( $this->does_plugin_require_update( $slug ) ) {
1082
if ( ! $automatic ) {
1083
// Make sure message doesn't display again if bulk activation is performed
1084
// immediately after a single activation.
1085
if ( ! isset( $_POST['action'] ) ) { // WPCS: CSRF OK.
1086
- echo '<div id="message" class="error"><p>',
1087
- sprintf(
1088
- esc_html( $this->strings['plugin_needs_higher_version'] ),
1089
- '<strong>' . esc_html( $this->plugins[ $slug ]['name'] ) . '</strong>'
1090
- ),
1091
- '</p></div>';
1092
}
1093
} else {
1094
// Simpler message layout for use on the plugin install page.
1095
- echo '<p>', sprintf( esc_html( $this->strings['plugin_needs_higher_version'] ), esc_html( $this->plugins[ $slug ]['name'] ) ), '</p>';
1096
}
1097
}
1098
1099
- return true;
1100
}
1101
1102
- /**
1103
- * Echoes required plugin notice.
1104
- *
1105
- * Outputs a message telling users that a specific plugin is required for
1106
- * their theme. If appropriate, it includes a link to the form page where
1107
- * users can install and activate the plugin.
1108
- *
1109
- * Returns early if we're on the Install page.
1110
- *
1111
- * @since 1.0.0
1112
- *
1113
- * @global object $current_screen
1114
- *
1115
- * @return null Returns early if we're on the Install page.
1116
- */
1117
- public function notices() {
1118
- // Remove nag on the install page / Return early if the nag message has been dismissed or user < author.
1119
- 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' ) ) ) {
1120
- return;
1121
- }
1122
1123
- // Store for the plugin slugs by message type.
1124
- $message = array();
1125
1126
- // Initialize counters used to determine plurality of action link texts.
1127
- $install_link_count = 0;
1128
- $update_link_count = 0;
1129
- $activate_link_count = 0;
1130
- $total_required_action_count = 0;
1131
1132
- foreach ( $this->plugins as $slug => $plugin ) {
1133
- if ( $this->is_plugin_active( $slug ) && false === $this->does_plugin_have_update( $slug ) ) {
1134
- continue;
1135
- }
1136
1137
- if ( ! $this->is_plugin_installed( $slug ) ) {
1138
- if ( current_user_can( 'install_plugins' ) ) {
1139
- $install_link_count++;
1140
1141
if ( true === $plugin['required'] ) {
1142
- $message['notice_can_install_required'][] = $slug;
1143
} else {
1144
- $message['notice_can_install_recommended'][] = $slug;
1145
}
1146
}
1147
if ( true === $plugin['required'] ) {
1148
$total_required_action_count++;
1149
}
1150
- } else {
1151
- if ( ! $this->is_plugin_active( $slug ) && $this->can_plugin_activate( $slug ) ) {
1152
- if ( current_user_can( 'activate_plugins' ) ) {
1153
- $activate_link_count++;
1154
-
1155
- if ( true === $plugin['required'] ) {
1156
- $message['notice_can_activate_required'][] = $slug;
1157
- } else {
1158
- $message['notice_can_activate_recommended'][] = $slug;
1159
- }
1160
- }
1161
- if ( true === $plugin['required'] ) {
1162
- $total_required_action_count++;
1163
- }
1164
- }
1165
1166
- if ( $this->does_plugin_require_update( $slug ) || false !== $this->does_plugin_have_update( $slug ) ) {
1167
1168
- if ( current_user_can( 'update_plugins' ) ) {
1169
- $update_link_count++;
1170
1171
- if ( $this->does_plugin_require_update( $slug ) ) {
1172
- $message['notice_ask_to_update'][] = $slug;
1173
- } elseif ( false !== $this->does_plugin_have_update( $slug ) ) {
1174
- $message['notice_ask_to_update_maybe'][] = $slug;
1175
- }
1176
- }
1177
- if ( true === $plugin['required'] ) {
1178
- $total_required_action_count++;
1179
}
1180
}
1181
}
1182
}
1183
- unset( $slug, $plugin );
1184
-
1185
- // If we have notices to display, we move forward.
1186
- if ( ! empty( $message ) || $total_required_action_count > 0 ) {
1187
- krsort( $message ); // Sort messages.
1188
- $rendered = '';
1189
1190
- // As add_settings_error() wraps the final message in a <p> and as the final message can't be
1191
- // filtered, using <p>'s in our html would render invalid html output.
1192
- $line_template = '<span style="display: block; margin: 0.5em 0.5em 0 0; clear: both;">%s</span>' . "\n";
1193
1194
- if ( ! current_user_can( 'activate_plugins' ) && ! current_user_can( 'install_plugins' ) && ! current_user_can( 'update_plugins' ) ) {
1195
- $rendered = esc_html( $this->strings['notice_cannot_install_activate'] ) . ' ' . esc_html( $this->strings['contact_admin'] );
1196
- $rendered .= $this->create_user_action_links_for_notice( 0, 0, 0, $line_template );
1197
- } else {
1198
1199
- // If dismissable is false and a message is set, output it now.
1200
- if ( ! $this->dismissable && ! empty( $this->dismiss_msg ) ) {
1201
- $rendered .= sprintf( $line_template, wp_kses_post( $this->dismiss_msg ) );
1202
- }
1203
1204
- // Render the individual message lines for the notice.
1205
- foreach ( $message as $type => $plugin_group ) {
1206
- $linked_plugins = array();
1207
1208
- // Get the external info link for a plugin if one is available.
1209
- foreach ( $plugin_group as $plugin_slug ) {
1210
- $linked_plugins[] = $this->get_info_link( $plugin_slug );
1211
- }
1212
- unset( $plugin_slug );
1213
-
1214
- $count = count( $plugin_group );
1215
- $linked_plugins = array_map( array( 'WPMailSMTP\TGMPA_Utils', 'wrap_in_em' ), $linked_plugins );
1216
- $last_plugin = array_pop( $linked_plugins ); // Pop off last name to prep for readability.
1217
- $imploded = empty( $linked_plugins ) ? $last_plugin : ( implode( ', ', $linked_plugins ) . ' ' . esc_html_x( 'and', 'plugin A *and* plugin B', 'tgmpa' ) . ' ' . $last_plugin );
1218
-
1219
- $rendered .= sprintf(
1220
- $line_template,
1221
- sprintf(
1222
- translate_nooped_plural( $this->strings[ $type ], $count, 'tgmpa' ),
1223
- $imploded,
1224
- $count
1225
- )
1226
- );
1227
1228
}
1229
- unset( $type, $plugin_group, $linked_plugins, $count, $last_plugin, $imploded );
1230
1231
- $rendered .= $this->create_user_action_links_for_notice( $install_link_count, $update_link_count, $activate_link_count, $line_template );
1232
}
1233
1234
- // Register the nag messages and prepare them to be processed.
1235
- add_settings_error( 'tgmpa', 'tgmpa', $rendered, $this->get_admin_notice_class() );
1236
}
1237
1238
- // Admin options pages already output settings_errors, so this is to avoid duplication.
1239
- if ( 'options-general' !== $GLOBALS['current_screen']->parent_base ) {
1240
- $this->display_settings_errors();
1241
- }
1242
}
1243
1244
- /**
1245
- * Generate the user action links for the admin notice.
1246
- *
1247
- * @since 2.6.0
1248
- *
1249
- * @param int $install_count Number of plugins to install.
1250
- * @param int $update_count Number of plugins to update.
1251
- * @param int $activate_count Number of plugins to activate.
1252
- * @param int $line_template Template for the HTML tag to output a line.
1253
- * @return string Action links.
1254
- */
1255
- protected function create_user_action_links_for_notice( $install_count, $update_count, $activate_count, $line_template ) {
1256
- // Setup action links.
1257
- $action_links = array(
1258
- 'install' => '',
1259
- 'update' => '',
1260
- 'activate' => '',
1261
- '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>' : '',
1262
- );
1263
1264
- $link_template = '<a href="%2$s">%1$s</a>';
1265
1266
- if ( current_user_can( 'install_plugins' ) ) {
1267
- if ( $install_count > 0 ) {
1268
- $action_links['install'] = sprintf(
1269
- $link_template,
1270
- translate_nooped_plural( $this->strings['install_link'], $install_count, 'tgmpa' ),
1271
- esc_url( $this->get_tgmpa_status_url( 'install' ) )
1272
- );
1273
- }
1274
- if ( $update_count > 0 ) {
1275
- $action_links['update'] = sprintf(
1276
- $link_template,
1277
- translate_nooped_plural( $this->strings['update_link'], $update_count, 'tgmpa' ),
1278
- esc_url( $this->get_tgmpa_status_url( 'update' ) )
1279
- );
1280
- }
1281
}
1282
-
1283
- if ( current_user_can( 'activate_plugins' ) && $activate_count > 0 ) {
1284
- $action_links['activate'] = sprintf(
1285
$link_template,
1286
- translate_nooped_plural( $this->strings['activate_link'], $activate_count, 'tgmpa' ),
1287
- esc_url( $this->get_tgmpa_status_url( 'activate' ) )
1288
);
1289
}
1290
1291
- $action_links = apply_filters( 'tgmpa_notice_action_links', $action_links );
1292
1293
- $action_links = array_filter( (array) $action_links ); // Remove any empty array items.
1294
1295
- if ( ! empty( $action_links ) ) {
1296
- $action_links = sprintf( $line_template, implode( ' | ', $action_links ) );
1297
- return apply_filters( 'tgmpa_notice_rendered_action_links', $action_links );
1298
- } else {
1299
- return '';
1300
- }
1301
}
1302
1303
- /**
1304
- * Get admin notice class.
1305
- *
1306
- * Work around all the changes to the various admin notice classes between WP 4.4 and 3.7
1307
- * (lowest supported version by TGMPA).
1308
- *
1309
- * @since 2.6.0
1310
- *
1311
- * @return string
1312
- */
1313
- protected function get_admin_notice_class() {
1314
- if ( ! empty( $this->strings['nag_type'] ) ) {
1315
- return sanitize_html_class( strtolower( $this->strings['nag_type'] ) );
1316
} else {
1317
- if ( version_compare( $this->wp_version, '4.2', '>=' ) ) {
1318
- return 'notice-warning';
1319
- } elseif ( version_compare( $this->wp_version, '4.1', '>=' ) ) {
1320
- return 'notice';
1321
- } else {
1322
- return 'updated';
1323
- }
1324
}
1325
}
1326
1327
- /**
1328
- * Display settings errors and remove those which have been displayed to avoid duplicate messages showing
1329
- *
1330
- * @since 2.5.0
1331
- */
1332
- protected function display_settings_errors() {
1333
- global $wp_settings_errors;
1334
1335
- settings_errors( 'tgmpa' );
1336
1337
- foreach ( (array) $wp_settings_errors as $key => $details ) {
1338
- if ( 'tgmpa' === $details['setting'] ) {
1339
- unset( $wp_settings_errors[ $key ] );
1340
- break;
1341
- }
1342
}
1343
}
1344
1345
- /**
1346
- * Register dismissal of admin notices.
1347
- *
1348
- * Acts on the dismiss link in the admin nag messages.
1349
- * If clicked, the admin notice disappears and will no longer be visible to this user.
1350
- *
1351
- * @since 2.1.0
1352
- */
1353
- public function dismiss() {
1354
- if ( isset( $_GET['tgmpa-dismiss'] ) && check_admin_referer( 'tgmpa-dismiss-' . get_current_user_id() ) ) {
1355
- update_user_meta( get_current_user_id(), 'tgmpa_dismissed_notice_' . $this->id, 1 );
1356
- }
1357
}
1358
1359
- /**
1360
- * Add individual plugin to our collection of plugins.
1361
- *
1362
- * If the required keys are not set or the plugin has already
1363
- * been registered, the plugin is not added.
1364
- *
1365
- * @since 2.0.0
1366
- *
1367
- * @param array|null $plugin Array of plugin arguments or null if invalid argument.
1368
- * @return null Return early if incorrect argument.
1369
- */
1370
- public function register( $plugin ) {
1371
- if ( empty( $plugin['slug'] ) || empty( $plugin['name'] ) ) {
1372
- return;
1373
- }
1374
1375
- if ( empty( $plugin['slug'] ) || ! is_string( $plugin['slug'] ) || isset( $this->plugins[ $plugin['slug'] ] ) ) {
1376
- return;
1377
- }
1378
1379
- $defaults = array(
1380
- 'name' => '', // String
1381
- 'slug' => '', // String
1382
- 'source' => 'repo', // String
1383
- 'required' => false, // Boolean
1384
- 'version' => '', // String
1385
- 'force_activation' => false, // Boolean
1386
- 'force_deactivation' => false, // Boolean
1387
- 'external_url' => '', // String
1388
- 'is_callable' => '', // String|Array.
1389
- );
1390
1391
- // Prepare the received data.
1392
- $plugin = wp_parse_args( $plugin, $defaults );
1393
1394
- // Standardize the received slug.
1395
- $plugin['slug'] = $this->sanitize_key( $plugin['slug'] );
1396
1397
- // Forgive users for using string versions of booleans or floats for version number.
1398
- $plugin['version'] = (string) $plugin['version'];
1399
- $plugin['source'] = empty( $plugin['source'] ) ? 'repo' : $plugin['source'];
1400
- $plugin['required'] = TGMPA_Utils::validate_bool( $plugin['required'] );
1401
- $plugin['force_activation'] = TGMPA_Utils::validate_bool( $plugin['force_activation'] );
1402
- $plugin['force_deactivation'] = TGMPA_Utils::validate_bool( $plugin['force_deactivation'] );
1403
1404
- // Enrich the received data.
1405
- $plugin['file_path'] = $this->_get_plugin_basename_from_slug( $plugin['slug'] );
1406
- $plugin['source_type'] = $this->get_plugin_source_type( $plugin['source'] );
1407
1408
- // Set the class properties.
1409
- $this->plugins[ $plugin['slug'] ] = $plugin;
1410
- $this->sort_order[ $plugin['slug'] ] = $plugin['name'];
1411
1412
- // Should we add the force activation hook ?
1413
- if ( true === $plugin['force_activation'] ) {
1414
- $this->has_forced_activation = true;
1415
- }
1416
1417
- // Should we add the force deactivation hook ?
1418
- if ( true === $plugin['force_deactivation'] ) {
1419
- $this->has_forced_deactivation = true;
1420
- }
1421
}
1422
1423
- /**
1424
- * Determine what type of source the plugin comes from.
1425
- *
1426
- * @since 2.5.0
1427
- *
1428
- * @param string $source The source of the plugin as provided, either empty (= WP repo), a file path
1429
- * (= bundled) or an external URL.
1430
- * @return string 'repo', 'external', or 'bundled'
1431
- */
1432
- protected function get_plugin_source_type( $source ) {
1433
- if ( 'repo' === $source || preg_match( self::WP_REPO_REGEX, $source ) ) {
1434
- return 'repo';
1435
- } elseif ( preg_match( self::IS_URL_REGEX, $source ) ) {
1436
- return 'external';
1437
- } else {
1438
- return 'bundled';
1439
- }
1440
}
1441
1442
/**
1443
- * Sanitizes a string key.
1444
- *
1445
- * Near duplicate of WP Core `sanitize_key()`. The difference is that uppercase characters *are*
1446
- * allowed, so as not to break upgrade paths from non-standard bundled plugins using uppercase
1447
- * characters in the plugin directory path/slug. Silly them.
1448
- *
1449
- * @see https://developer.wordpress.org/reference/hooks/sanitize_key/
1450
*
1451
* @since 2.5.0
1452
*
1453
- * @param string $key String key.
1454
- * @return string Sanitized key
1455
*/
1456
- public function sanitize_key( $key ) {
1457
- $raw_key = $key;
1458
- $key = preg_replace( '`[^A-Za-z0-9_-]`', '', $key );
1459
-
1460
- /**
1461
- * Filter a sanitized key string.
1462
- *
1463
- * @since 2.5.0
1464
- *
1465
- * @param string $key Sanitized key.
1466
- * @param string $raw_key The key prior to sanitization.
1467
- */
1468
- return apply_filters( 'tgmpa_sanitize_key', $key, $raw_key );
1469
- }
1470
1471
- /**
1472
- * Amend default configuration settings.
1473
- *
1474
- * @since 2.0.0
1475
- *
1476
- * @param array $config Array of config options to pass as class properties.
1477
- */
1478
- public function config( $config ) {
1479
- $keys = array(
1480
- 'id',
1481
- 'default_path',
1482
- 'has_notices',
1483
- 'dismissable',
1484
- 'dismiss_msg',
1485
- 'menu',
1486
- 'parent_slug',
1487
- 'capability',
1488
- 'is_automatic',
1489
- 'message',
1490
- 'strings',
1491
- );
1492
1493
- foreach ( $keys as $key ) {
1494
- if ( isset( $config[ $key ] ) ) {
1495
- if ( is_array( $config[ $key ] ) ) {
1496
- $this->$key = array_merge( $this->$key, $config[ $key ] );
1497
- } else {
1498
- $this->$key = $config[ $key ];
1499
- }
1500
}
1501
}
1502
}
1503
1504
- /**
1505
- * Amend action link after plugin installation.
1506
- *
1507
- * @since 2.0.0
1508
- *
1509
- * @param array $install_actions Existing array of actions.
1510
- * @return false|array Amended array of actions.
1511
- */
1512
- public function actions( $install_actions ) {
1513
- // Remove action links on the TGMPA install page.
1514
- if ( $this->is_tgmpa_page() ) {
1515
- return false;
1516
- }
1517
-
1518
- return $install_actions;
1519
- }
1520
-
1521
- /**
1522
- * Flushes the plugins cache on theme switch to prevent stale entries
1523
- * from remaining in the plugin table.
1524
- *
1525
- * @since 2.4.0
1526
- *
1527
- * @param bool $clear_update_cache Optional. Whether to clear the Plugin updates cache.
1528
- * Parameter added in v2.5.0.
1529
- */
1530
- public function flush_plugins_cache( $clear_update_cache = true ) {
1531
- wp_clean_plugins_cache( $clear_update_cache );
1532
}
1533
1534
- /**
1535
- * Set file_path key for each installed plugin.
1536
- *
1537
- * @since 2.1.0
1538
- *
1539
- * @param string $plugin_slug Optional. If set, only (re-)populates the file path for that specific plugin.
1540
- * Parameter added in v2.5.0.
1541
- */
1542
- public function populate_file_path( $plugin_slug = '' ) {
1543
- if ( ! empty( $plugin_slug ) && is_string( $plugin_slug ) && isset( $this->plugins[ $plugin_slug ] ) ) {
1544
- $this->plugins[ $plugin_slug ]['file_path'] = $this->_get_plugin_basename_from_slug( $plugin_slug );
1545
- } else {
1546
- // Add file_path key for all plugins.
1547
- foreach ( $this->plugins as $slug => $values ) {
1548
- $this->plugins[ $slug ]['file_path'] = $this->_get_plugin_basename_from_slug( $slug );
1549
- }
1550
- }
1551
- }
1552
1553
- /**
1554
- * Helper function to extract the file path of the plugin file from the
1555
- * plugin slug, if the plugin is installed.
1556
- *
1557
- * @since 2.0.0
1558
- *
1559
- * @param string $slug Plugin slug (typically folder name) as provided by the developer.
1560
- * @return string Either file path for plugin if installed, or just the plugin slug.
1561
- */
1562
- protected function _get_plugin_basename_from_slug( $slug ) {
1563
- $keys = array_keys( $this->get_plugins() );
1564
1565
- foreach ( $keys as $key ) {
1566
- if ( preg_match( '|^' . $slug . '/|', $key ) ) {
1567
- return $key;
1568
- }
1569
}
1570
-
1571
- return $slug;
1572
}
1573
1574
- /**
1575
- * Retrieve plugin data, given the plugin name.
1576
- *
1577
- * Loops through the registered plugins looking for $name. If it finds it,
1578
- * it returns the $data from that plugin. Otherwise, returns false.
1579
- *
1580
- * @since 2.1.0
1581
- *
1582
- * @param string $name Name of the plugin, as it was registered.
1583
- * @param string $data Optional. Array key of plugin data to return. Default is slug.
1584
- * @return string|boolean Plugin slug if found, false otherwise.
1585
- */
1586
- public function _get_plugin_data_from_name( $name, $data = 'slug' ) {
1587
- foreach ( $this->plugins as $values ) {
1588
- if ( $name === $values['name'] && isset( $values[ $data ] ) ) {
1589
- return $values[ $data ];
1590
- }
1591
- }
1592
1593
- return false;
1594
}
1595
1596
- /**
1597
- * Retrieve the download URL for a package.
1598
- *
1599
- * @since 2.5.0
1600
- *
1601
- * @param string $slug Plugin slug.
1602
- * @return string Plugin download URL or path to local file or empty string if undetermined.
1603
- */
1604
- public function get_download_url( $slug ) {
1605
- $dl_source = '';
1606
1607
- switch ( $this->plugins[ $slug ]['source_type'] ) {
1608
- case 'repo':
1609
- return $this->get_wp_repo_download_url( $slug );
1610
- case 'external':
1611
- return $this->plugins[ $slug ]['source'];
1612
- case 'bundled':
1613
- return $this->default_path . $this->plugins[ $slug ]['source'];
1614
}
1615
-
1616
- return $dl_source; // Should never happen.
1617
}
1618
1619
- /**
1620
- * Retrieve the download URL for a WP repo package.
1621
- *
1622
- * @since 2.5.0
1623
- *
1624
- * @param string $slug Plugin slug.
1625
- * @return string Plugin download URL.
1626
- */
1627
- protected function get_wp_repo_download_url( $slug ) {
1628
- $source = '';
1629
- $api = $this->get_plugins_api( $slug );
1630
1631
- if ( false !== $api && isset( $api->download_link ) ) {
1632
- $source = $api->download_link;
1633
- }
1634
1635
- return $source;
1636
}
1637
1638
- /**
1639
- * Try to grab information from WordPress API.
1640
- *
1641
- * @since 2.5.0
1642
- *
1643
- * @param string $slug Plugin slug.
1644
- * @return object Plugins_api response object on success, WP_Error on failure.
1645
- */
1646
- protected function get_plugins_api( $slug ) {
1647
- static $api = array(); // Cache received responses.
1648
1649
- if ( ! isset( $api[ $slug ] ) ) {
1650
- if ( ! function_exists( 'plugins_api' ) ) {
1651
- require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
1652
- }
1653
1654
- $response = plugins_api( 'plugin_information', array( 'slug' => $slug, 'fields' => array( 'sections' => false ) ) );
1655
1656
- $api[ $slug ] = false;
1657
1658
- if ( is_wp_error( $response ) ) {
1659
- wp_die( esc_html( $this->strings['oops'] ) );
1660
- } else {
1661
- $api[ $slug ] = $response;
1662
- }
1663
- }
1664
1665
- return $api[ $slug ];
1666
- }
1667
1668
- /**
1669
- * Retrieve a link to a plugin information page.
1670
- *
1671
- * @since 2.5.0
1672
- *
1673
- * @param string $slug Plugin slug.
1674
- * @return string Fully formed html link to a plugin information page if available
1675
- * or the plugin name if not.
1676
- */
1677
- public function get_info_link( $slug ) {
1678
- if ( ! empty( $this->plugins[ $slug ]['external_url'] ) && preg_match( self::IS_URL_REGEX, $this->plugins[ $slug ]['external_url'] ) ) {
1679
- $link = sprintf(
1680
- '<a href="%1$s" target="_blank">%2$s</a>',
1681
- esc_url( $this->plugins[ $slug ]['external_url'] ),
1682
- esc_html( $this->plugins[ $slug ]['name'] )
1683
- );
1684
- } elseif ( 'repo' === $this->plugins[ $slug ]['source_type'] ) {
1685
- $url = add_query_arg(
1686
- array(
1687
- 'tab' => 'plugin-information',
1688
- 'plugin' => urlencode( $slug ),
1689
- 'TB_iframe' => 'true',
1690
- 'width' => '640',
1691
- 'height' => '500',
1692
),
1693
- self_admin_url( 'plugin-install.php' )
1694
- );
1695
1696
- $link = sprintf(
1697
- '<a href="%1$s" class="thickbox">%2$s</a>',
1698
- esc_url( $url ),
1699
- esc_html( $this->plugins[ $slug ]['name'] )
1700
- );
1701
} else {
1702
- $link = esc_html( $this->plugins[ $slug ]['name'] ); // No hyperlink.
1703
}
1704
-
1705
- return $link;
1706
}
1707
1708
- /**
1709
- * Determine if we're on the TGMPA Install page.
1710
- *
1711
- * @since 2.1.0
1712
- *
1713
- * @return boolean True when on the TGMPA page, false otherwise.
1714
- */
1715
- protected function is_tgmpa_page() {
1716
- return isset( $_GET['page'] ) && $this->menu === $_GET['page'];
1717
- }
1718
1719
- /**
1720
- * Determine if we're on a WP Core installation/upgrade page.
1721
- *
1722
- * @since 2.6.0
1723
- *
1724
- * @return boolean True when on a WP Core installation/upgrade page, false otherwise.
1725
- */
1726
- protected function is_core_update_page() {
1727
- // Current screen is not always available, most notably on the customizer screen.
1728
- if ( ! function_exists( 'get_current_screen' ) ) {
1729
- return false;
1730
- }
1731
1732
- $screen = get_current_screen();
1733
1734
- if ( 'update-core' === $screen->base ) {
1735
- // Core update screen.
1736
- return true;
1737
- } elseif ( 'plugins' === $screen->base && ! empty( $_POST['action'] ) ) { // WPCS: CSRF ok.
1738
- // Plugins bulk update screen.
1739
- return true;
1740
- } elseif ( 'update' === $screen->base && ! empty( $_POST['action'] ) ) { // WPCS: CSRF ok.
1741
- // Individual updates (ajax call).
1742
- return true;
1743
- }
1744
1745
return false;
1746
}
1747
1748
- /**
1749
- * Retrieve the URL to the TGMPA Install page.
1750
- *
1751
- * I.e. depending on the config settings passed something along the lines of:
1752
- * http://example.com/wp-admin/themes.php?page=tgmpa-install-plugins
1753
- *
1754
- * @since 2.5.0
1755
- *
1756
- * @return string Properly encoded URL (not escaped).
1757
- */
1758
- public function get_tgmpa_url() {
1759
- static $url;
1760
-
1761
- if ( ! isset( $url ) ) {
1762
- $parent = $this->parent_slug;
1763
- if ( false === strpos( $parent, '.php' ) ) {
1764
- $parent = 'admin.php';
1765
- }
1766
- $url = add_query_arg(
1767
- array(
1768
- 'page' => urlencode( $this->menu ),
1769
- ),
1770
- self_admin_url( $parent )
1771
- );
1772
- }
1773
1774
- return $url;
1775
}
1776
1777
- /**
1778
- * Retrieve the URL to the TGMPA Install page for a specific plugin status (view).
1779
- *
1780
- * I.e. depending on the config settings passed something along the lines of:
1781
- * http://example.com/wp-admin/themes.php?page=tgmpa-install-plugins&plugin_status=install
1782
- *
1783
- * @since 2.5.0
1784
- *
1785
- * @param string $status Plugin status - either 'install', 'update' or 'activate'.
1786
- * @return string Properly encoded URL (not escaped).
1787
- */
1788
- public function get_tgmpa_status_url( $status ) {
1789
- return add_query_arg(
1790
array(
1791
- 'plugin_status' => urlencode( $status ),
1792
),
1793
- $this->get_tgmpa_url()
1794
);
1795
}
1796
1797
- /**
1798
- * Determine whether there are open actions for plugins registered with TGMPA.
1799
- *
1800
- * @since 2.5.0
1801
- *
1802
- * @return bool True if complete, i.e. no outstanding actions. False otherwise.
1803
- */
1804
- public function is_tgmpa_complete() {
1805
- $complete = true;
1806
- foreach ( $this->plugins as $slug => $plugin ) {
1807
- if ( ! $this->is_plugin_active( $slug ) || false !== $this->does_plugin_have_update( $slug ) ) {
1808
- $complete = false;
1809
- break;
1810
- }
1811
- }
1812
-
1813
- return $complete;
1814
- }
1815
1816
- /**
1817
- * Check if a plugin is installed. Does not take must-use plugins into account.
1818
- *
1819
- * @since 2.5.0
1820
- *
1821
- * @param string $slug Plugin slug.
1822
- * @return bool True if installed, false otherwise.
1823
- */
1824
- public function is_plugin_installed( $slug ) {
1825
- $installed_plugins = $this->get_plugins(); // Retrieve a list of all installed plugins (WP cached).
1826
1827
- return ( ! empty( $installed_plugins[ $this->plugins[ $slug ]['file_path'] ] ) );
1828
}
1829
1830
- /**
1831
- * Check if a plugin is active.
1832
- *
1833
- * @since 2.5.0
1834
- *
1835
- * @param string $slug Plugin slug.
1836
- * @return bool True if active, false otherwise.
1837
- */
1838
- public function is_plugin_active( $slug ) {
1839
- return ( ( ! empty( $this->plugins[ $slug ]['is_callable'] ) && is_callable( $this->plugins[ $slug ]['is_callable'] ) ) || is_plugin_active( $this->plugins[ $slug ]['file_path'] ) );
1840
- }
1841
1842
- /**
1843
- * Check if a plugin can be updated, i.e. if we have information on the minimum WP version required
1844
- * available, check whether the current install meets them.
1845
- *
1846
- * @since 2.5.0
1847
- *
1848
- * @param string $slug Plugin slug.
1849
- * @return bool True if OK to update, false otherwise.
1850
- */
1851
- public function can_plugin_update( $slug ) {
1852
- // We currently can't get reliable info on non-WP-repo plugins - issue #380.
1853
- if ( 'repo' !== $this->plugins[ $slug ]['source_type'] ) {
1854
- return true;
1855
- }
1856
1857
- $api = $this->get_plugins_api( $slug );
1858
1859
- if ( false !== $api && isset( $api->requires ) ) {
1860
- return version_compare( $this->wp_version, $api->requires, '>=' );
1861
- }
1862
1863
- // No usable info received from the plugins API, presume we can update.
1864
return true;
1865
}
1866
1867
- /**
1868
- * Check to see if the plugin is 'updatetable', i.e. installed, with an update available
1869
- * and no WP version requirements blocking it.
1870
- *
1871
- * @since 2.6.0
1872
- *
1873
- * @param string $slug Plugin slug.
1874
- * @return bool True if OK to proceed with update, false otherwise.
1875
- */
1876
- public function is_plugin_updatetable( $slug ) {
1877
- if ( ! $this->is_plugin_installed( $slug ) ) {
1878
- return false;
1879
- } else {
1880
- return ( false !== $this->does_plugin_have_update( $slug ) && $this->can_plugin_update( $slug ) );
1881
- }
1882
- }
1883
1884
- /**
1885
- * Check if a plugin can be activated, i.e. is not currently active and meets the minimum
1886
- * plugin version requirements set in TGMPA (if any).
1887
- *
1888
- * @since 2.5.0
1889
- *
1890
- * @param string $slug Plugin slug.
1891
- * @return bool True if OK to activate, false otherwise.
1892
- */
1893
- public function can_plugin_activate( $slug ) {
1894
- return ( ! $this->is_plugin_active( $slug ) && ! $this->does_plugin_require_update( $slug ) );
1895
}
1896
1897
- /**
1898
- * Retrieve the version number of an installed plugin.
1899
- *
1900
- * @since 2.5.0
1901
- *
1902
- * @param string $slug Plugin slug.
1903
- * @return string Version number as string or an empty string if the plugin is not installed
1904
- * or version unknown (plugins which don't comply with the plugin header standard).
1905
- */
1906
- public function get_installed_version( $slug ) {
1907
- $installed_plugins = $this->get_plugins(); // Retrieve a list of all installed plugins (WP cached).
1908
-
1909
- if ( ! empty( $installed_plugins[ $this->plugins[ $slug ]['file_path'] ]['Version'] ) ) {
1910
- return $installed_plugins[ $this->plugins[ $slug ]['file_path'] ]['Version'];
1911
- }
1912
1913
- return '';
1914
}
1915
1916
- /**
1917
- * Check whether a plugin complies with the minimum version requirements.
1918
- *
1919
- * @since 2.5.0
1920
- *
1921
- * @param string $slug Plugin slug.
1922
- * @return bool True when a plugin needs to be updated, otherwise false.
1923
- */
1924
- public function does_plugin_require_update( $slug ) {
1925
- $installed_version = $this->get_installed_version( $slug );
1926
- $minimum_version = $this->plugins[ $slug ]['version'];
1927
1928
- return version_compare( $minimum_version, $installed_version, '>' );
1929
}
1930
1931
- /**
1932
- * Check whether there is an update available for a plugin.
1933
- *
1934
- * @since 2.5.0
1935
- *
1936
- * @param string $slug Plugin slug.
1937
- * @return false|string Version number string of the available update or false if no update available.
1938
- */
1939
- public function does_plugin_have_update( $slug ) {
1940
- // Presume bundled and external plugins will point to a package which meets the minimum required version.
1941
- if ( 'repo' !== $this->plugins[ $slug ]['source_type'] ) {
1942
- if ( $this->does_plugin_require_update( $slug ) ) {
1943
- return $this->plugins[ $slug ]['version'];
1944
- }
1945
1946
- return false;
1947
- }
1948
1949
- $repo_updates = get_site_transient( 'update_plugins' );
1950
1951
- if ( isset( $repo_updates->response[ $this->plugins[ $slug ]['file_path'] ]->new_version ) ) {
1952
- return $repo_updates->response[ $this->plugins[ $slug ]['file_path'] ]->new_version;
1953
}
1954
1955
return false;
1956
}
1957
1958
- /**
1959
- * Retrieve potential upgrade notice for a plugin.
1960
- *
1961
- * @since 2.5.0
1962
- *
1963
- * @param string $slug Plugin slug.
1964
- * @return string The upgrade notice or an empty string if no message was available or provided.
1965
- */
1966
- public function get_upgrade_notice( $slug ) {
1967
- // We currently can't get reliable info on non-WP-repo plugins - issue #380.
1968
- if ( 'repo' !== $this->plugins[ $slug ]['source_type'] ) {
1969
- return '';
1970
- }
1971
1972
- $repo_updates = get_site_transient( 'update_plugins' );
1973
1974
- if ( ! empty( $repo_updates->response[ $this->plugins[ $slug ]['file_path'] ]->upgrade_notice ) ) {
1975
- return $repo_updates->response[ $this->plugins[ $slug ]['file_path'] ]->upgrade_notice;
1976
- }
1977
1978
return '';
1979
}
1980
1981
- /**
1982
- * Wrapper around the core WP get_plugins function, making sure it's actually available.
1983
- *
1984
- * @since 2.5.0
1985
- *
1986
- * @param string $plugin_folder Optional. Relative path to single plugin folder.
1987
- * @return array Array of installed plugins with plugin information.
1988
- */
1989
- public function get_plugins( $plugin_folder = '' ) {
1990
- if ( ! function_exists( 'get_plugins' ) ) {
1991
- require_once ABSPATH . 'wp-admin/includes/plugin.php';
1992
- }
1993
1994
- return get_plugins( $plugin_folder );
1995
}
1996
1997
- /**
1998
- * Delete dismissable nag option when theme is switched.
1999
- *
2000
- * This ensures that the user(s) is/are again reminded via nag of required
2001
- * and/or recommended plugins if they re-activate the theme.
2002
- *
2003
- * @since 2.1.1
2004
- */
2005
- public function update_dismiss() {
2006
- delete_metadata( 'user', null, 'tgmpa_dismissed_notice_' . $this->id, null, true );
2007
- }
2008
2009
- /**
2010
- * Forces plugin activation if the parameter 'force_activation' is
2011
- * set to true.
2012
- *
2013
- * This allows theme authors to specify certain plugins that must be
2014
- * active at all times while using the current theme.
2015
- *
2016
- * Please take special care when using this parameter as it has the
2017
- * potential to be harmful if not used correctly. Setting this parameter
2018
- * to true will not allow the specified plugin to be deactivated unless
2019
- * the user switches themes.
2020
- *
2021
- * @since 2.2.0
2022
- */
2023
- public function force_activation() {
2024
- foreach ( $this->plugins as $slug => $plugin ) {
2025
- if ( true === $plugin['force_activation'] ) {
2026
- if ( ! $this->is_plugin_installed( $slug ) ) {
2027
- // Oops, plugin isn't there so iterate to next condition.
2028
- continue;
2029
- } elseif ( $this->can_plugin_activate( $slug ) ) {
2030
- // There we go, activate the plugin.
2031
- activate_plugin( $plugin['file_path'] );
2032
- }
2033
- }
2034
- }
2035
}
2036
2037
- /**
2038
- * Forces plugin deactivation if the parameter 'force_deactivation'
2039
- * is set to true and adds the plugin to the 'recently active' plugins list.
2040
- *
2041
- * This allows theme authors to specify certain plugins that must be
2042
- * deactivated upon switching from the current theme to another.
2043
- *
2044
- * Please take special care when using this parameter as it has the
2045
- * potential to be harmful if not used correctly.
2046
- *
2047
- * @since 2.2.0
2048
- */
2049
- public function force_deactivation() {
2050
- $deactivated = array();
2051
2052
- foreach ( $this->plugins as $slug => $plugin ) {
2053
- /*
2054
- * Only proceed forward if the parameter is set to true and plugin is active
2055
- * as a 'normal' (not must-use) plugin.
2056
- */
2057
- if ( true === $plugin['force_deactivation'] && is_plugin_active( $plugin['file_path'] ) ) {
2058
- deactivate_plugins( $plugin['file_path'] );
2059
- $deactivated[ $plugin['file_path'] ] = time();
2060
- }
2061
- }
2062
2063
- if ( ! empty( $deactivated ) ) {
2064
- update_option( 'recently_activated', $deactivated + (array) get_option( 'recently_activated' ) );
2065
}
2066
}
2067
2068
- /**
2069
- * Echo the current TGMPA version number to the page.
2070
- *
2071
- * @since 2.5.0
2072
- */
2073
- public function show_tgmpa_version() {
2074
- echo '<p style="float: right; padding: 0em 1.5em 0.5em 0;"><strong><small>',
2075
- esc_html(
2076
- sprintf(
2077
- /* translators: %s: version number */
2078
- __( 'TGMPA v%s', 'tgmpa' ),
2079
- self::TGMPA_VERSION
2080
- )
2081
- ),
2082
- '</small></strong></p>';
2083
- }
2084
2085
- /**
2086
- * Returns the singleton instance of the class.
2087
- *
2088
- * @since 2.4.0
2089
- *
2090
- * @return \TGM_Plugin_Activation The TGM_Plugin_Activation object.
2091
- */
2092
- public static function get_instance() {
2093
- if ( ! isset( self::$instance ) && ! ( self::$instance instanceof self ) ) {
2094
- self::$instance = new self();
2095
}
2096
-
2097
- return self::$instance;
2098
}
2099
- }
2100
2101
- if ( ! function_exists( 'load_tgm_plugin_activation' ) ) {
2102
- /**
2103
- * Ensure only one instance of the class is ever invoked.
2104
- *
2105
- * @since 2.5.0
2106
- */
2107
- function load_tgm_plugin_activation() {
2108
- $GLOBALS['wp_mail_smtp_tgmpa'] = TGM_Plugin_Activation::get_instance();
2109
}
2110
}
2111
2112
- if ( did_action( 'plugins_loaded' ) ) {
2113
- load_tgm_plugin_activation();
2114
- } else {
2115
- add_action( 'plugins_loaded', 'WPMailSMTP\load_tgm_plugin_activation' );
2116
}
2117
- }
2118
2119
- if ( ! function_exists( 'tgmpa' ) ) {
2120
/**
2121
- * Helper function to register a collection of required plugins.
2122
*
2123
- * @since 2.0.0
2124
- * @api
2125
*
2126
- * @param array $plugins An array of plugin arrays.
2127
- * @param array $config Optional. An array of configuration values.
2128
*/
2129
- function tgmpa( $plugins, $config = array() ) {
2130
- $instance = call_user_func( array( get_class( $GLOBALS['wp_mail_smtp_tgmpa'] ), 'get_instance' ) );
2131
-
2132
- foreach ( $plugins as $plugin ) {
2133
- call_user_func( array( $instance, 'register' ), $plugin );
2134
}
2135
2136
- if ( ! empty( $config ) && is_array( $config ) ) {
2137
- // Send out notices for deprecated arguments passed.
2138
- if ( isset( $config['notices'] ) ) {
2139
- _deprecated_argument( __FUNCTION__, '2.2.0', 'The `notices` config parameter was renamed to `has_notices` in TGMPA 2.2.0. Please adjust your configuration.' );
2140
- if ( ! isset( $config['has_notices'] ) ) {
2141
- $config['has_notices'] = $config['notices'];
2142
- }
2143
- }
2144
2145
- if ( isset( $config['parent_menu_slug'] ) ) {
2146
- _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.' );
2147
- }
2148
- if ( isset( $config['parent_url_slug'] ) ) {
2149
- _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.' );
2150
}
2151
2152
- call_user_func( array( $instance, 'config' ), $config );
2153
}
2154
}
2155
}
2156
@@ -2160,982 +2161,972 @@ if ( ! function_exists( 'tgmpa' ) ) {
2160
*
2161
* @since 2.2.0
2162
*/
2163
- if ( ! class_exists( 'WP_List_Table' ) ) {
2164
require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
2165
}
2166
2167
- if ( ! class_exists( 'TGMPA_List_Table' ) ) {
2168
-
2169
/**
2170
- * List table class for handling plugins.
2171
*
2172
- * Extends the WP_List_Table class to provide a future-compatible
2173
- * way of listing out all required/recommended plugins.
2174
- *
2175
- * Gives users an interface similar to the Plugin Administration
2176
- * area with similar (albeit stripped down) capabilities.
2177
*
2178
- * This class also allows for the bulk install of plugins.
2179
*
2180
- * @since 2.2.0
2181
*
2182
- * @package TGM-Plugin-Activation
2183
- * @author Thomas Griffin
2184
- * @author Gary Jones
2185
*/
2186
- class TGMPA_List_Table extends \WP_List_Table {
2187
- /**
2188
- * TGMPA instance.
2189
- *
2190
- * @since 2.5.0
2191
- *
2192
- * @var object
2193
- */
2194
- protected $tgmpa;
2195
2196
- /**
2197
- * The currently chosen view.
2198
- *
2199
- * @since 2.5.0
2200
- *
2201
- * @var string One of: 'all', 'install', 'update', 'activate'
2202
- */
2203
- public $view_context = 'all';
2204
2205
- /**
2206
- * The plugin counts for the various views.
2207
- *
2208
- * @since 2.5.0
2209
- *
2210
- * @var array
2211
- */
2212
- protected $view_totals = array(
2213
- 'all' => 0,
2214
- 'install' => 0,
2215
- 'update' => 0,
2216
- 'activate' => 0,
2217
);
2218
2219
- /**
2220
- * References parent constructor and sets defaults for class.
2221
- *
2222
- * @since 2.2.0
2223
- */
2224
- public function __construct() {
2225
- $this->tgmpa = call_user_func( array( get_class( $GLOBALS['wp_mail_smtp_tgmpa'] ), 'get_instance' ) );
2226
-
2227
- parent::__construct(
2228
- array(
2229
- 'singular' => 'plugin',
2230
- 'plural' => 'plugins',
2231
- 'ajax' => false,
2232
- )
2233
- );
2234
-
2235
- if ( isset( $_REQUEST['plugin_status'] ) && in_array( $_REQUEST['plugin_status'], array( 'install', 'update', 'activate' ), true ) ) {
2236
- $this->view_context = sanitize_key( $_REQUEST['plugin_status'] );
2237
- }
2238
-
2239
- add_filter( 'tgmpa_table_data_items', array( $this, 'sort_table_items' ) );
2240
- }
2241
-
2242
- /**
2243
- * Get a list of CSS classes for the <table> tag.
2244
- *
2245
- * Overruled to prevent the 'plural' argument from being added.
2246
- *
2247
- * @since 2.5.0
2248
- *
2249
- * @return array CSS classnames.
2250
- */
2251
- public function get_table_classes() {
2252
- return array( 'widefat', 'fixed' );
2253
- }
2254
-
2255
- /**
2256
- * Gathers and renames all of our plugin information to be used by WP_List_Table to create our table.
2257
- *
2258
- * @since 2.2.0
2259
- *
2260
- * @return array $table_data Information for use in table.
2261
- */
2262
- protected function _gather_plugin_data() {
2263
- // Load thickbox for plugin links.
2264
- $this->tgmpa->admin_init();
2265
- $this->tgmpa->thickbox();
2266
-
2267
- // Categorize the plugins which have open actions.
2268
- $plugins = $this->categorize_plugins_to_views();
2269
-
2270
- // Set the counts for the view links.
2271
- $this->set_view_totals( $plugins );
2272
-
2273
- // Prep variables for use and grab list of all installed plugins.
2274
- $table_data = array();
2275
- $i = 0;
2276
-
2277
- // Redirect to the 'all' view if no plugins were found for the selected view context.
2278
- if ( empty( $plugins[ $this->view_context ] ) ) {
2279
- $this->view_context = 'all';
2280
- }
2281
-
2282
- foreach ( $plugins[ $this->view_context ] as $slug => $plugin ) {
2283
- $table_data[ $i ]['sanitized_plugin'] = $plugin['name'];
2284
- $table_data[ $i ]['slug'] = $slug;
2285
- $table_data[ $i ]['plugin'] = '<strong>' . $this->tgmpa->get_info_link( $slug ) . '</strong>';
2286
- $table_data[ $i ]['source'] = $this->get_plugin_source_type_text( $plugin['source_type'] );
2287
- $table_data[ $i ]['type'] = $this->get_plugin_advise_type_text( $plugin['required'] );
2288
- $table_data[ $i ]['status'] = $this->get_plugin_status_text( $slug );
2289
- $table_data[ $i ]['installed_version'] = $this->tgmpa->get_installed_version( $slug );
2290
- $table_data[ $i ]['minimum_version'] = $plugin['version'];
2291
- $table_data[ $i ]['available_version'] = $this->tgmpa->does_plugin_have_update( $slug );
2292
-
2293
- // Prep the upgrade notice info.
2294
- $upgrade_notice = $this->tgmpa->get_upgrade_notice( $slug );
2295
- if ( ! empty( $upgrade_notice ) ) {
2296
- $table_data[ $i ]['upgrade_notice'] = $upgrade_notice;
2297
-
2298
- add_action( "tgmpa_after_plugin_row_{$slug}", array( $this, 'wp_plugin_update_row' ), 10, 2 );
2299
- }
2300
-
2301
- $table_data[ $i ] = apply_filters( 'tgmpa_table_data_item', $table_data[ $i ], $plugin );
2302
-
2303
- $i++;
2304
- }
2305
-
2306
- return $table_data;
2307
- }
2308
-
2309
- /**
2310
- * Categorize the plugins which have open actions into views for the TGMPA page.
2311
- *
2312
- * @since 2.5.0
2313
- */
2314
- protected function categorize_plugins_to_views() {
2315
- $plugins = array(
2316
- 'all' => array(), // Meaning: all plugins which still have open actions.
2317
- 'install' => array(),
2318
- 'update' => array(),
2319
- 'activate' => array(),
2320
- );
2321
-
2322
- foreach ( $this->tgmpa->plugins as $slug => $plugin ) {
2323
- if ( $this->tgmpa->is_plugin_active( $slug ) && false === $this->tgmpa->does_plugin_have_update( $slug ) ) {
2324
- // No need to display plugins if they are installed, up-to-date and active.
2325
- continue;
2326
- } else {
2327
- $plugins['all'][ $slug ] = $plugin;
2328
-
2329
- if ( ! $this->tgmpa->is_plugin_installed( $slug ) ) {
2330
- $plugins['install'][ $slug ] = $plugin;
2331
- } else {
2332
- if ( false !== $this->tgmpa->does_plugin_have_update( $slug ) ) {
2333
- $plugins['update'][ $slug ] = $plugin;
2334
- }
2335
-
2336
- if ( $this->tgmpa->can_plugin_activate( $slug ) ) {
2337
- $plugins['activate'][ $slug ] = $plugin;
2338
- }
2339
- }
2340
- }
2341
- }
2342
-
2343
- return $plugins;
2344
- }
2345
-
2346
- /**
2347
- * Set the counts for the view links.
2348
- *
2349
- * @since 2.5.0
2350
- *
2351
- * @param array $plugins Plugins order by view.
2352
- */
2353
- protected function set_view_totals( $plugins ) {
2354
- foreach ( $plugins as $type => $list ) {
2355
- $this->view_totals[ $type ] = count( $list );
2356
- }
2357
}
2358
2359
- /**
2360
- * Get the plugin required/recommended text string.
2361
- *
2362
- * @since 2.5.0
2363
- *
2364
- * @param string $required Plugin required setting.
2365
- * @return string
2366
- */
2367
- protected function get_plugin_advise_type_text( $required ) {
2368
- if ( true === $required ) {
2369
- return __( 'Required', 'tgmpa' );
2370
- }
2371
-
2372
- return __( 'Recommended', 'tgmpa' );
2373
- }
2374
2375
- /**
2376
- * Get the plugin source type text string.
2377
- *
2378
- * @since 2.5.0
2379
- *
2380
- * @param string $type Plugin type.
2381
- * @return string
2382
- */
2383
- protected function get_plugin_source_type_text( $type ) {
2384
- $string = '';
2385
2386
- switch ( $type ) {
2387
- case 'repo':
2388
- $string = __( 'WordPress Repository', 'tgmpa' );
2389
- break;
2390
- case 'external':
2391
- $string = __( 'External Source', 'tgmpa' );
2392
- break;
2393
- case 'bundled':
2394
- $string = __( 'Pre-Packaged', 'tgmpa' );
2395
- break;
2396
- }
2397
2398
- return $string;
2399
- }
2400
2401
- /**
2402
- * Determine the plugin status message.
2403
- *
2404
- * @since 2.5.0
2405
- *
2406
- * @param string $slug Plugin slug.
2407
- * @return string
2408
- */
2409
- protected function get_plugin_status_text( $slug ) {
2410
- if ( ! $this->tgmpa->is_plugin_installed( $slug ) ) {
2411
- return __( 'Not Installed', 'tgmpa' );
2412
- }
2413
2414
- if ( ! $this->tgmpa->is_plugin_active( $slug ) ) {
2415
- $install_status = __( 'Installed But Not Activated', 'tgmpa' );
2416
- } else {
2417
- $install_status = __( 'Active', 'tgmpa' );
2418
- }
2419
2420
- $update_status = '';
2421
2422
- if ( $this->tgmpa->does_plugin_require_update( $slug ) && false === $this->tgmpa->does_plugin_have_update( $slug ) ) {
2423
- $update_status = __( 'Required Update not Available', 'tgmpa' );
2424
2425
- } elseif ( $this->tgmpa->does_plugin_require_update( $slug ) ) {
2426
- $update_status = __( 'Requires Update', 'tgmpa' );
2427
2428
- } elseif ( false !== $this->tgmpa->does_plugin_have_update( $slug ) ) {
2429
- $update_status = __( 'Update recommended', 'tgmpa' );
2430
}
2431
2432
- if ( '' === $update_status ) {
2433
- return $install_status;
2434
- }
2435
2436
- return sprintf(
2437
- /* translators: 1: install status, 2: update status */
2438
- _x( '%1$s, %2$s', 'Install/Update Status', 'tgmpa' ),
2439
- $install_status,
2440
- $update_status
2441
- );
2442
}
2443
2444
- /**
2445
- * Sort plugins by Required/Recommended type and by alphabetical plugin name within each type.
2446
- *
2447
- * @since 2.5.0
2448
- *
2449
- * @param array $items Prepared table items.
2450
- * @return array Sorted table items.
2451
- */
2452
- public function sort_table_items( $items ) {
2453
- $type = array();
2454
- $name = array();
2455
2456
- foreach ( $items as $i => $plugin ) {
2457
- $type[ $i ] = $plugin['type']; // Required / recommended.
2458
- $name[ $i ] = $plugin['sanitized_plugin'];
2459
- }
2460
2461
- array_multisort( $type, SORT_DESC, $name, SORT_ASC, $items );
2462
2463
- return $items;
2464
}
2465
2466
- /**
2467
- * Get an associative array ( id => link ) of the views available on this table.
2468
- *
2469
- * @since 2.5.0
2470
- *
2471
- * @return array
2472
- */
2473
- public function get_views() {
2474
- $status_links = array();
2475
2476
- foreach ( $this->view_totals as $type => $count ) {
2477
- if ( $count < 1 ) {
2478
- continue;
2479
- }
2480
2481
- switch ( $type ) {
2482
- case 'all':
2483
- /* translators: 1: number of plugins. */
2484
- $text = _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $count, 'plugins', 'tgmpa' );
2485
- break;
2486
- case 'install':
2487
- /* translators: 1: number of plugins. */
2488
- $text = _n( 'To Install <span class="count">(%s)</span>', 'To Install <span class="count">(%s)</span>', $count, 'tgmpa' );
2489
- break;
2490
- case 'update':
2491
- /* translators: 1: number of plugins. */
2492
- $text = _n( 'Update Available <span class="count">(%s)</span>', 'Update Available <span class="count">(%s)</span>', $count, 'tgmpa' );
2493
- break;
2494
- case 'activate':
2495
- /* translators: 1: number of plugins. */
2496
- $text = _n( 'To Activate <span class="count">(%s)</span>', 'To Activate <span class="count">(%s)</span>', $count, 'tgmpa' );
2497
- break;
2498
- default:
2499
- $text = '';
2500
- break;
2501
- }
2502
2503
- if ( ! empty( $text ) ) {
2504
2505
- $status_links[ $type ] = sprintf(
2506
- '<a href="%s"%s>%s</a>',
2507
- esc_url( $this->tgmpa->get_tgmpa_status_url( $type ) ),
2508
- ( $type === $this->view_context ) ? ' class="current"' : '',
2509
- sprintf( $text, number_format_i18n( $count ) )
2510
- );
2511
- }
2512
- }
2513
2514
- return $status_links;
2515
}
2516
2517
- /**
2518
- * Create default columns to display important plugin information
2519