Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 36 additions & 33 deletions class-tgm-plugin-activation.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,9 @@ class TGM_Plugin_Activation {
* Adds a reference of this object to $instance, populates default strings,
* does the tgmpa_init action hook, and hooks in the interactions to init.
*
* @internal This method should be `protected`, but as too many TGMPA implementations
* {@internal This method should be `protected`, but as too many TGMPA implementations
* haven't upgraded beyond v2.3.6 yet, this gives backward compatibility issues.
* Reverted back to public for the time being.
* Reverted back to public for the time being.}}
*
* @since 1.0.0
*
Expand All @@ -267,9 +267,9 @@ public function __construct() {
/**
* Magic method to (not) set protected properties from outside of this class.
*
* @internal hackedihack... There is a serious bug in v2.3.2 - 2.3.6 where the `menu` property
* {@internal hackedihack... There is a serious bug in v2.3.2 - 2.3.6 where the `menu` property
* is being assigned rather than tested in a conditional, effectively rendering it useless.
* This 'hack' prevents this from happening.
* This 'hack' prevents this from happening.}}
*
* @see https://github.com/TGMPA/TGM-Plugin-Activation/blob/2.3.6/tgm-plugin-activation/class-tgm-plugin-activation.php#L1593
*
Expand Down Expand Up @@ -647,7 +647,7 @@ public function install_plugins_page() {

?>
<div class="tgmpa wrap">
<h2><?php echo esc_html( get_admin_page_title() ); ?></h2>
<h1><?php echo esc_html( get_admin_page_title() ); ?></h1>
<?php $plugin_table->prepare_items(); ?>

<?php
Expand Down Expand Up @@ -1077,7 +1077,7 @@ public function notices() {
$line_template = '<span style="display: block; margin: 0.5em 0.5em 0 0; clear: both;">%s</span>' . "\n";

if ( ! current_user_can( 'activate_plugins' ) && ! current_user_can( 'install_plugins' ) && ! current_user_can( 'update_plugins' ) ) {
$rendered = esc_html__( $this->strings['notice_cannot_install_activate'] . ' ' . $this->strings['contact_admin'] );
$rendered = esc_html__( $this->strings['notice_cannot_install_activate'] ) . ' ' . esc_html__( $this->strings['contact_admin'] );
$rendered .= $this->create_user_action_links_for_notice( 0, 0, 0, $line_template );
} else {

Expand Down Expand Up @@ -1131,13 +1131,13 @@ public function notices() {
*
* @since 2.x.x
*
* @param int $install_link_count Number of plugins to install.
* @param int $update_link_count Number of plugins to update.
* @param int $activate_link_count Number of plugins to activate.
* @param int $line_template Template for the HTML tag to output a line.
* @param int $install_count Number of plugins to install.
* @param int $update_count Number of plugins to update.
* @param int $activate_count Number of plugins to activate.
* @param int $line_template Template for the HTML tag to output a line.
* @return string Action links.
*/
protected function create_user_action_links_for_notice( $install_link_count, $update_link_count, $activate_link_count, $line_template ) {
protected function create_user_action_links_for_notice( $install_count, $update_count, $activate_count, $line_template ) {
// Setup action links.
$action_links = array(
'install' => '',
Expand All @@ -1149,26 +1149,26 @@ protected function create_user_action_links_for_notice( $install_link_count, $up
$link_template = '<a href="%2$s">%1$s</a>';

if ( current_user_can( 'install_plugins' ) ) {
if ( $install_link_count > 0 ) {
if ( $install_count > 0 ) {
$action_links['install'] = sprintf(
$link_template,
translate_nooped_plural( $this->strings['install_link'], $install_link_count, 'tgmpa' ),
translate_nooped_plural( $this->strings['install_link'], $install_count, 'tgmpa' ),
esc_url( $this->get_tgmpa_status_url( 'install' ) )
);
}
if ( $update_link_count > 0 ) {
if ( $update_count > 0 ) {
$action_links['update'] = sprintf(
$link_template,
translate_nooped_plural( $this->strings['update_link'], $update_link_count, 'tgmpa' ),
translate_nooped_plural( $this->strings['update_link'], $update_count, 'tgmpa' ),
esc_url( $this->get_tgmpa_status_url( 'update' ) )
);
}
}

if ( current_user_can( 'activate_plugins' ) && $activate_link_count > 0 ) {
if ( current_user_can( 'activate_plugins' ) && $activate_count > 0 ) {
$action_links['activate'] = sprintf(
$link_template,
translate_nooped_plural( $this->strings['activate_link'], $activate_link_count, 'tgmpa' ),
translate_nooped_plural( $this->strings['activate_link'], $activate_count, 'tgmpa' ),
esc_url( $this->get_tgmpa_status_url( 'activate' ) )
);
}
Expand All @@ -1177,7 +1177,7 @@ protected function create_user_action_links_for_notice( $install_link_count, $up

$action_links = array_filter( (array) $action_links ); // Remove any empty array items.

if ( ! empty( $action_links ) && is_array( $action_links ) ) {
if ( ! empty( $action_links ) ) {
$action_links = sprintf( $line_template, implode( ' | ', $action_links ) );
return apply_filters( 'tgmpa_notice_rendered_action_links', $action_links );
} else {
Expand Down Expand Up @@ -1712,7 +1712,7 @@ public function can_plugin_update( $slug ) {
$api = $this->get_plugins_api( $slug );

if ( false !== $api && isset( $api->requires ) ) {
return version_compare( $GLOBALS['wp_version'], $api->requires, '>=' );
return version_compare( $this->wp_version, $api->requires, '>=' );
}

// No usable info received from the plugins API, presume we can update.
Expand Down Expand Up @@ -2992,9 +2992,9 @@ function tgmpa_load_bulk_installer() {
*
* @since 2.2.0
*
* @internal Since 2.5.0 the class is an extension of Plugin_Upgrader rather than WP_Upgrader
* @internal Since 2.5.2 the class has been renamed from TGM_Bulk_Installer to TGMPA_Bulk_Installer.
* This was done to prevent backward compatibility issues with v2.3.6.
* {@internal Since 2.5.0 the class is an extension of Plugin_Upgrader rather than WP_Upgrader.}}
* {@internal Since 2.5.2 the class has been renamed from TGM_Bulk_Installer to TGMPA_Bulk_Installer.
* This was done to prevent backward compatibility issues with v2.3.6.}}
*
* @package TGM-Plugin-Activation
* @author Thomas Griffin
Expand Down Expand Up @@ -3101,13 +3101,15 @@ public function run( $options ) {
*
* @since 2.2.0
*
* @internal This is basically a near identical copy of the WP Core Plugin_Upgrader::bulk_upgrade()
* method, with minor adjustments to deal with new installs instead of upgrades.
* {@internal This is basically a near identical copy of the WP Core
* Plugin_Upgrader::bulk_upgrade() method, with minor adjustments to deal with
* new installs instead of upgrades.
* For ease of future synchronizations, the adjustments are clearly commented, but no other
* comments are added. Code style has been made to comply.
* comments are added. Code style has been made to comply.}}
*
* @see Plugin_Upgrader::bulk_upgrade()
* @see https://core.trac.wordpress.org/browser/tags/4.2.1/src/wp-admin/includes/class-wp-upgrader.php#L838
* (@internal Last synced: Dec 31st 2015 against https://core.trac.wordpress.org/browser/trunk?rev=36134}}
*
* @param array $plugins The plugin sources needed for installation.
* @param array $args Arbitrary passed extra arguments.
Expand Down Expand Up @@ -3137,16 +3139,17 @@ public function bulk_install( $plugins, $args = array() ) {
$res = $this->fs_connect( array( WP_CONTENT_DIR, WP_PLUGIN_DIR ) );
if ( ! $res ) {
$this->skin->footer();

return false;
}

$this->skin->bulk_header();

// Only start maintenance mode if:
// - running Multisite and there are one or more plugins specified, OR
// - a plugin with an update available is currently active.
// @TODO: For multisite, maintenance mode should only kick in for individual sites if at all possible.
/*
* Only start maintenance mode if:
* - running Multisite and there are one or more plugins specified, OR
* - a plugin with an update available is currently active.
* @TODO: For multisite, maintenance mode should only kick in for individual sites if at all possible.
*/
$maintenance = ( is_multisite() && ! empty( $plugins ) );

/*
Expand Down Expand Up @@ -3178,7 +3181,7 @@ public function bulk_install( $plugins, $args = array() ) {
continue;
}

// Get the URL to the zip file
// Get the URL to the zip file.
$r = $current->response[ $plugin ];

$this->skin->plugin_active = is_plugin_active($plugin);
Expand Down Expand Up @@ -3318,9 +3321,9 @@ public function auto_activate( $bool ) {
*
* @since 2.2.0
*
* @internal Since 2.5.2 the class has been renamed from TGM_Bulk_Installer_Skin to
* {@internal Since 2.5.2 the class has been renamed from TGM_Bulk_Installer_Skin to
* TGMPA_Bulk_Installer_Skin.
* This was done to prevent backward compatibility issues with v2.3.6.
* This was done to prevent backward compatibility issues with v2.3.6.}}
*
* @see https://core.trac.wordpress.org/browser/trunk/src/wp-admin/includes/class-wp-upgrader-skins.php
*
Expand Down
15 changes: 9 additions & 6 deletions example.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,14 @@
* - two from an external source, one from an arbitrary source, one from a GitHub repository
* - two from the .org repo, where one demonstrates the use of the `is_callable` argument
*
* The variable passed to tgmpa_register_plugins() should be an array of plugin
* arrays.
* The variables passed to the `tgmpa()` function should be:
* - an array of plugin arrays;
* - optionally a configuration array.
* If you are not changing anything in the configuration array, you can remove the array and remove the
* variable from the function call: `tgmpa( $plugins );`.
* In that case, the TGMPA default settings will be used.
*
* This function is hooked into tgmpa_init, which is fired within the
* TGM_Plugin_Activation class constructor.
* This function is hooked into `tgmpa_register`, which is fired on the WP `init` action on priority 10.
*/
function my_theme_register_required_plugins() {
/*
Expand Down Expand Up @@ -186,8 +189,8 @@ function my_theme_register_required_plugins() {
'plugin_already_active' => __( 'No action taken. Plugin %1$s was already active.', 'theme-slug' ), // %1$s = plugin name(s).
'plugin_needs_higher_version' => __( 'Plugin not activated. A higher version of %s is needed for this theme. Please update the plugin.', 'theme-slug' ), // %1$s = plugin name(s).
'complete' => __( 'All plugins installed and activated successfully. %1$s', 'theme-slug' ), // %s = dashboard link.
'notice_cannot_install_activate' => __( 'There are one or more required or recommended plugins to install, update or activate.', 'tgmpa' ),
'contact_admin' => __( 'Please contact the administrator of this site for help.', 'tgmpa' ),
'notice_cannot_install_activate' => __( 'There are one or more required or recommended plugins to install, update or activate.', 'theme-slug' ),
'contact_admin' => __( 'Please contact the administrator of this site for help.', 'theme-slug' ),

'nag_type' => '', // Determines admin notice type - can only be one of the typical WP notice classes, such as 'updated', 'update-nag', 'notice-warning', 'notice-info' or 'error'. Some of which may not work as expected in older WP versions.
),
Expand Down