Update TGM Plugin Activation library

This commit is contained in:
Brian Miyaji
2021-11-05 19:57:42 +09:00
parent 2b0253be42
commit bb78dca699
2 changed files with 3778 additions and 3540 deletions

481
includes/libraries/class-tgm-plugin-activation.php Executable file → Normal file
View File

@@ -8,22 +8,11 @@
* or theme author for support.
*
* @package TGM-Plugin-Activation
* @version 2.5.2
* @version 2.6.1
* @link http://tgmpluginactivation.com/
* @author Thomas Griffin, Gary Jones, Juliette Reinders Folmer
* @copyright Copyright (c) 2011, Thomas Griffin
* @license GPL-2.0+
*
* @wordpress-plugin
* Plugin Name: TGM Plugin Activation
* Plugin URI:
* Description: Plugin installation and activation for WordPress themes.
* Version: 2.5.2
* Author: Thomas Griffin, Gary Jones, Juliette Reinders Folmer
* Author URI: http://tgmpluginactivation.com/
* Text Domain: tgmpa
* Domain Path: /languages/
* Copyright: 2011, Thomas Griffin
*/
/*
@@ -66,7 +55,7 @@ if ( ! class_exists( 'TGM_Plugin_Activation' ) ) {
*
* @const string Version number.
*/
const TGMPA_VERSION = '2.5.2';
const TGMPA_VERSION = '2.6.1';
/**
* Regular expression to test if a URL is a WP plugin repo URL.
@@ -99,7 +88,6 @@ if ( ! class_exists( 'TGM_Plugin_Activation' ) ) {
* Holds arrays of plugin details.
*
* @since 1.0.0
*
* @since 2.5.0 the array has the plugin slug as an associative key.
*
* @var array
@@ -256,9 +244,9 @@ if ( ! class_exists( '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
*
@@ -271,6 +259,15 @@ if ( ! class_exists( 'TGM_Plugin_Activation' ) ) {
// Announce that the class is ready, and pass the object (for advanced use).
do_action_ref_array( 'tgmpa_init', array( $this ) );
/*
* Load our text domain and allow for overloading the fall-back file.
*
* {@internal IMPORTANT! If this code changes, review the regex in the custom TGMPA
* generator on the website.}}
*/
add_action( 'init', array( $this, 'load_textdomain' ), 5 );
add_filter( 'load_textdomain_mofile', array( $this, 'overload_textdomain_mofile' ), 10, 2 );
// When the rest of WP has loaded, kick-start the rest of the class.
add_action( 'init', array( $this, 'init' ) );
}
@@ -278,12 +275,14 @@ if ( ! class_exists( 'TGM_Plugin_Activation' ) ) {
/**
* 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
*
* @since 2.5.2
*
* @param string $name Name of an inaccessible property.
* @param mixed $value Value to assign to the property.
* @return void Silently fail to set the property when this is tried from outside of this class context.
@@ -296,6 +295,8 @@ if ( ! class_exists( 'TGM_Plugin_Activation' ) ) {
/**
* Magic method to get the value of a protected property outside of this class context.
*
* @since 2.5.2
*
* @param string $name Name of an inaccessible property.
* @return mixed The property value.
*/
@@ -332,53 +333,47 @@ if ( ! class_exists( 'TGM_Plugin_Activation' ) ) {
$this->strings = array(
'page_title' => __( 'Install Required Plugins', 'tgmpa' ),
'menu_title' => __( 'Install Plugins', 'tgmpa' ),
/* translators: %s: plugin name. */
'installing' => __( 'Installing Plugin: %s', 'tgmpa' ),
/* translators: %s: plugin name. */
'updating' => __( 'Updating Plugin: %s', 'tgmpa' ),
'oops' => __( 'Something went wrong with the plugin API.', 'tgmpa' ),
'notice_can_install_required' => _n_noop(
/* translators: 1: plugin name(s). */
'This theme requires the following plugin: %1$s.',
'This theme requires the following plugins: %1$s.',
'tgmpa'
),
'notice_can_install_recommended' => _n_noop(
/* translators: 1: plugin name(s). */
'This theme recommends the following plugin: %1$s.',
'This theme recommends the following plugins: %1$s.',
'tgmpa'
),
'notice_cannot_install' => _n_noop(
'Sorry, but you do not have the correct permissions to install the %1$s plugin.',
'Sorry, but you do not have the correct permissions to install the %1$s plugins.',
'tgmpa'
),
'notice_ask_to_update' => _n_noop(
/* translators: 1: plugin name(s). */
'The following plugin needs to be updated to its latest version to ensure maximum compatibility with this theme: %1$s.',
'The following plugins need to be updated to their latest version to ensure maximum compatibility with this theme: %1$s.',
'tgmpa'
),
'notice_ask_to_update_maybe' => _n_noop(
/* translators: 1: plugin name(s). */
'There is an update available for: %1$s.',
'There are updates available for the following plugins: %1$s.',
'tgmpa'
),
'notice_cannot_update' => _n_noop(
'Sorry, but you do not have the correct permissions to update the %1$s plugin.',
'Sorry, but you do not have the correct permissions to update the %1$s plugins.',
'tgmpa'
),
'notice_can_activate_required' => _n_noop(
/* translators: 1: plugin name(s). */
'The following required plugin is currently inactive: %1$s.',
'The following required plugins are currently inactive: %1$s.',
'tgmpa'
),
'notice_can_activate_recommended' => _n_noop(
/* translators: 1: plugin name(s). */
'The following recommended plugin is currently inactive: %1$s.',
'The following recommended plugins are currently inactive: %1$s.',
'tgmpa'
),
'notice_cannot_activate' => _n_noop(
'Sorry, but you do not have the correct permissions to activate the %1$s plugin.',
'Sorry, but you do not have the correct permissions to activate the %1$s plugins.',
'tgmpa'
),
'install_link' => _n_noop(
'Begin installing plugin',
'Begin installing plugins',
@@ -395,13 +390,17 @@ if ( ! class_exists( 'TGM_Plugin_Activation' ) ) {
'tgmpa'
),
'return' => __( 'Return to Required Plugins Installer', 'tgmpa' ),
'dashboard' => __( 'Return to the dashboard', 'tgmpa' ),
'dashboard' => __( 'Return to the Dashboard', 'tgmpa' ),
'plugin_activated' => __( 'Plugin activated successfully.', 'tgmpa' ),
'activated_successfully' => __( 'The following plugin was activated successfully:', 'tgmpa' ),
/* translators: 1: plugin name. */
'plugin_already_active' => __( 'No action taken. Plugin %1$s was already active.', 'tgmpa' ),
/* translators: 1: plugin name. */
'plugin_needs_higher_version' => __( 'Plugin not activated. A higher version of %s is needed for this theme. Please update the plugin.', 'tgmpa' ),
/* translators: 1: dashboard link. */
'complete' => __( 'All plugins installed and activated successfully. %1$s', 'tgmpa' ),
'dismiss' => __( 'Dismiss this notice', 'tgmpa' ),
'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' ),
);
@@ -431,10 +430,11 @@ if ( ! class_exists( 'TGM_Plugin_Activation' ) ) {
add_action( 'admin_init', array( $this, 'admin_init' ), 1 );
add_action( 'admin_enqueue_scripts', array( $this, 'thickbox' ) );
}
add_action( 'load-plugins.php', array( $this, 'add_plugin_action_link_filters' ), 1 );
}
// If needed, filter plugin action links.
add_action( 'load-plugins.php', array( $this, 'add_plugin_action_link_filters' ), 1 );
// Make sure things get reset on switch theme.
add_action( 'switch_theme', array( $this, 'flush_plugins_cache' ) );
@@ -454,8 +454,95 @@ if ( ! class_exists( 'TGM_Plugin_Activation' ) ) {
}
/**
* Prevent activation of plugins which don't meet the minimum version requirement from the
* WP native plugins page.
* Load translations.
*
* @since 2.6.0
*
* (@internal Uses `load_theme_textdomain()` rather than `load_plugin_textdomain()` to
* get round the different ways of handling the path and deprecated notices being thrown
* and such. For plugins, the actual file name will be corrected by a filter.}}
*
* {@internal IMPORTANT! If this function changes, review the regex in the custom TGMPA
* generator on the website.}}
*/
public function load_textdomain() {
if ( is_textdomain_loaded( 'tgmpa' ) ) {
return;
}
if ( false !== strpos( __FILE__, WP_PLUGIN_DIR ) || false !== strpos( __FILE__, WPMU_PLUGIN_DIR ) ) {
// Plugin, we'll need to adjust the file name.
add_action( 'load_textdomain_mofile', array( $this, 'correct_plugin_mofile' ), 10, 2 );
load_theme_textdomain( 'tgmpa', dirname( __FILE__ ) . '/languages' );
remove_action( 'load_textdomain_mofile', array( $this, 'correct_plugin_mofile' ), 10 );
} else {
load_theme_textdomain( 'tgmpa', dirname( __FILE__ ) . '/languages' );
}
}
/**
* Correct the .mo file name for (must-use) plugins.
*
* Themese use `/path/{locale}.mo` while plugins use `/path/{text-domain}-{locale}.mo`.
*
* {@internal IMPORTANT! If this function changes, review the regex in the custom TGMPA
* generator on the website.}}
*
* @since 2.6.0
*
* @param string $mofile Full path to the target mofile.
* @param string $domain The domain for which a language file is being loaded.
* @return string $mofile
*/
public function correct_plugin_mofile( $mofile, $domain ) {
// Exit early if not our domain (just in case).
if ( 'tgmpa' !== $domain ) {
return $mofile;
}
return preg_replace( '`/([a-z]{2}_[A-Z]{2}.mo)$`', '/tgmpa-$1', $mofile );
}
/**
* Potentially overload the fall-back translation file for the current language.
*
* WP, by default since WP 3.7, will load a local translation first and if none
* can be found, will try and find a translation in the /wp-content/languages/ directory.
* As this library is theme/plugin agnostic, translation files for TGMPA can exist both
* in the WP_LANG_DIR /plugins/ subdirectory as well as in the /themes/ subdirectory.
*
* This method makes sure both directories are checked.
*
* {@internal IMPORTANT! If this function changes, review the regex in the custom TGMPA
* generator on the website.}}
*
* @since 2.6.0
*
* @param string $mofile Full path to the target mofile.
* @param string $domain The domain for which a language file is being loaded.
* @return string $mofile
*/
public function overload_textdomain_mofile( $mofile, $domain ) {
// Exit early if not our domain, not a WP_LANG_DIR load or if the file exists and is readable.
if ( 'tgmpa' !== $domain || false === strpos( $mofile, WP_LANG_DIR ) || @is_readable( $mofile ) ) {
return $mofile;
}
// Current fallback file is not valid, let's try the alternative option.
if ( false !== strpos( $mofile, '/themes/' ) ) {
return str_replace( '/themes/', '/plugins/', $mofile );
} elseif ( false !== strpos( $mofile, '/plugins/' ) ) {
return str_replace( '/plugins/', '/themes/', $mofile );
} else {
return $mofile;
}
}
/**
* Hook in plugin action link filters for the WP native plugins page.
*
* - Prevent activation of plugins which don't meet the minimum version requirements.
* - Prevent deactivation of force-activated plugins.
* - Add update notice if update available.
*
* @since 2.5.0
*/
@@ -582,7 +669,7 @@ if ( ! class_exists( 'TGM_Plugin_Activation' ) ) {
* @since 2.1.0
*/
public function thickbox() {
if ( ! get_user_meta( get_current_user_id(), 'sp_dismissed_notice_' . $this->id, true ) ) {
if ( ! get_user_meta( get_current_user_id(), 'tgmpa_dismissed_notice_' . $this->id, true ) ) {
add_thickbox();
}
}
@@ -626,6 +713,9 @@ if ( ! class_exists( 'TGM_Plugin_Activation' ) ) {
/**
* Add the menu item.
*
* {@internal IMPORTANT! If this function changes, review the regex in the custom TGMPA
* generator on the website.}}
*
* @since 2.5.0
*
* @param array $args Menu item configuration.
@@ -667,7 +757,7 @@ if ( ! class_exists( 'TGM_Plugin_Activation' ) ) {
?>
<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
@@ -773,15 +863,17 @@ if ( ! class_exists( 'TGM_Plugin_Activation' ) ) {
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
}
$title = ( 'update' === $install_type ) ? $this->strings['updating'] : $this->strings['installing'];
$skin_args = array(
'type' => ( 'bundled' !== $this->plugins[ $slug ]['source_type'] ) ? 'web' : 'upload',
'title' => sprintf( $this->strings['installing'], $this->plugins[ $slug ]['name'] ),
'title' => sprintf( $title, $this->plugins[ $slug ]['name'] ),
'url' => esc_url_raw( $url ),
'nonce' => $install_type . '-plugin_' . $slug,
'plugin' => '',
'api' => $api,
'extra' => $extra,
);
unset( $title );
if ( 'update' === $install_type ) {
$skin_args['plugin'] = $this->plugins[ $slug ]['file_path'];
@@ -807,7 +899,7 @@ if ( ! class_exists( 'TGM_Plugin_Activation' ) ) {
$upgrader->install( $source );
}
remove_filter( 'upgrader_source_selection', array( $this, 'maybe_adjust_source_dir' ), 1, 3 );
remove_filter( 'upgrader_source_selection', array( $this, 'maybe_adjust_source_dir' ), 1 );
// Make sure we have the correct file path now the plugin is installed/updated.
$this->populate_file_path( $slug );
@@ -926,11 +1018,11 @@ if ( ! class_exists( 'TGM_Plugin_Activation' ) ) {
$subdir_name = untrailingslashit( str_replace( trailingslashit( $remote_source ), '', $source ) );
if ( ! empty( $subdir_name ) && $subdir_name !== $desired_slug ) {
$from = untrailingslashit( $source );
$to = trailingslashit( $remote_source ) . $desired_slug;
$from_path = untrailingslashit( $source );
$to_path = trailingslashit( $remote_source ) . $desired_slug;
if ( true === $GLOBALS['wp_filesystem']->move( $from, $to ) ) {
return trailingslashit( $to );
if ( true === $GLOBALS['wp_filesystem']->move( $from_path, $to_path ) ) {
return trailingslashit( $to_path );
} else {
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 ) );
}
@@ -1020,8 +1112,8 @@ if ( ! class_exists( 'TGM_Plugin_Activation' ) ) {
* @return null Returns early if we're on the Install page.
*/
public function notices() {
// Remove nag on the install page / Return early if the nag message has been dismissed.
if ( $this->is_tgmpa_page() || get_user_meta( get_current_user_id(), 'sp_dismissed_notice_' . $this->id, true ) ) {
// Remove nag on the install page / Return early if the nag message has been dismissed or user < author.
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' ) ) ) {
return;
}
@@ -1032,6 +1124,7 @@ if ( ! class_exists( 'TGM_Plugin_Activation' ) ) {
$install_link_count = 0;
$update_link_count = 0;
$activate_link_count = 0;
$total_required_action_count = 0;
foreach ( $this->plugins as $slug => $plugin ) {
if ( $this->is_plugin_active( $slug ) && false === $this->does_plugin_have_update( $slug ) ) {
@@ -1047,9 +1140,9 @@ if ( ! class_exists( 'TGM_Plugin_Activation' ) ) {
} else {
$message['notice_can_install_recommended'][] = $slug;
}
} else {
// Need higher privileges to install the plugin.
$message['notice_cannot_install'][] = $slug;
}
if ( true === $plugin['required'] ) {
$total_required_action_count++;
}
} else {
if ( ! $this->is_plugin_active( $slug ) && $this->can_plugin_activate( $slug ) ) {
@@ -1061,15 +1154,15 @@ if ( ! class_exists( 'TGM_Plugin_Activation' ) ) {
} else {
$message['notice_can_activate_recommended'][] = $slug;
}
} else {
// Need higher privileges to activate the plugin.
$message['notice_cannot_activate'][] = $slug;
}
if ( true === $plugin['required'] ) {
$total_required_action_count++;
}
}
if ( $this->does_plugin_require_update( $slug ) || false !== $this->does_plugin_have_update( $slug ) ) {
if ( current_user_can( 'install_plugins' ) ) {
if ( current_user_can( 'update_plugins' ) ) {
$update_link_count++;
if ( $this->does_plugin_require_update( $slug ) ) {
@@ -1077,9 +1170,9 @@ if ( ! class_exists( 'TGM_Plugin_Activation' ) ) {
} elseif ( false !== $this->does_plugin_have_update( $slug ) ) {
$message['notice_ask_to_update_maybe'][] = $slug;
}
} else {
// Need higher privileges to update the plugin.
$message['notice_cannot_update'][] = $slug;
}
if ( true === $plugin['required'] ) {
$total_required_action_count++;
}
}
}
@@ -1087,7 +1180,7 @@ if ( ! class_exists( 'TGM_Plugin_Activation' ) ) {
unset( $slug, $plugin );
// If we have notices to display, we move forward.
if ( ! empty( $message ) ) {
if ( ! empty( $message ) || $total_required_action_count > 0 ) {
krsort( $message ); // Sort messages.
$rendered = '';
@@ -1095,6 +1188,11 @@ if ( ! class_exists( 'TGM_Plugin_Activation' ) ) {
// filtered, using <p>'s in our html would render invalid html output.
$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'] ) . ' ' . esc_html( $this->strings['contact_admin'] );
$rendered .= $this->create_user_action_links_for_notice( 0, 0, 0, $line_template );
} else {
// If dismissable is false and a message is set, output it now.
if ( ! $this->dismissable && ! empty( $this->dismiss_msg ) ) {
$rendered .= sprintf( $line_template, wp_kses_post( $this->dismiss_msg ) );
@@ -1124,43 +1222,65 @@ if ( ! class_exists( 'TGM_Plugin_Activation' ) ) {
)
);
if ( 0 === strpos( $type, 'notice_cannot' ) ) {
$rendered .= $this->strings['contact_admin'];
}
}
unset( $type, $plugin_group, $linked_plugins, $count, $last_plugin, $imploded );
$rendered .= $this->create_user_action_links_for_notice( $install_link_count, $update_link_count, $activate_link_count, $line_template );
}
// Register the nag messages and prepare them to be processed.
add_settings_error( 'tgmpa', 'tgmpa', $rendered, $this->get_admin_notice_class() );
}
// Admin options pages already output settings_errors, so this is to avoid duplication.
if ( 'options-general' !== $GLOBALS['current_screen']->parent_base ) {
$this->display_settings_errors();
}
}
/**
* Generate the user action links for the admin notice.
*
* @since 2.6.0
*
* @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_count, $update_count, $activate_count, $line_template ) {
// Setup action links.
$action_links = array(
'install' => '',
'update' => '',
'activate' => '',
'dismiss' => $this->dismissable ? '<a href="' . esc_url( add_query_arg( 'tgmpa-dismiss', 'dismiss_admin_notices' ) ) . '" class="dismiss-notice" target="_parent">' . esc_html( $this->strings['dismiss'] ) . '</a>' : '',
'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>' : '',
);
$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' ) )
);
}
@@ -1169,23 +1289,35 @@ if ( ! class_exists( 'TGM_Plugin_Activation' ) ) {
$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 ) );
$rendered .= apply_filters( 'tgmpa_notice_rendered_action_links', $action_links );
}
// Register the nag messages and prepare them to be processed.
if ( ! empty( $this->strings['nag_type'] ) ) {
add_settings_error( 'tgmpa', 'tgmpa', $rendered, sanitize_html_class( strtolower( $this->strings['nag_type'] ) ) );
return apply_filters( 'tgmpa_notice_rendered_action_links', $action_links );
} else {
$nag_class = version_compare( $this->wp_version, '3.8', '<' ) ? 'updated' : 'update-nag';
add_settings_error( 'tgmpa', 'tgmpa', $rendered, $nag_class );
return '';
}
}
// Admin options pages already output settings_errors, so this is to avoid duplication.
if ( 'options-general' !== $GLOBALS['current_screen']->parent_base ) {
$this->display_settings_errors();
/**
* Get admin notice class.
*
* Work around all the changes to the various admin notice classes between WP 4.4 and 3.7
* (lowest supported version by TGMPA).
*
* @since 2.6.0
*
* @return string
*/
protected function get_admin_notice_class() {
if ( ! empty( $this->strings['nag_type'] ) ) {
return sanitize_html_class( strtolower( $this->strings['nag_type'] ) );
} else {
if ( version_compare( $this->wp_version, '4.2', '>=' ) ) {
return 'notice-warning';
} elseif ( version_compare( $this->wp_version, '4.1', '>=' ) ) {
return 'notice';
} else {
return 'updated';
}
}
}
@@ -1208,15 +1340,16 @@ if ( ! class_exists( 'TGM_Plugin_Activation' ) ) {
}
/**
* Add dismissable admin notices.
* Register dismissal of admin notices.
*
* Appends a link to the admin nag messages. If clicked, the admin notice disappears and no longer is visible to users.
* Acts on the dismiss link in the admin nag messages.
* If clicked, the admin notice disappears and will no longer be visible to this user.
*
* @since 2.1.0
*/
public function dismiss() {
if ( isset( $_GET['tgmpa-dismiss'] ) ) {
update_user_meta( get_current_user_id(), 'sp_dismissed_notice_' . $this->id, 1 );
if ( isset( $_GET['tgmpa-dismiss'] ) && check_admin_referer( 'tgmpa-dismiss-' . get_current_user_id() ) ) {
update_user_meta( get_current_user_id(), 'tgmpa_dismissed_notice_' . $this->id, 1 );
}
}
@@ -1324,7 +1457,7 @@ if ( ! class_exists( 'TGM_Plugin_Activation' ) ) {
/**
* Filter a sanitized key string.
*
* @since 3.0.0
* @since 2.5.0
*
* @param string $key Sanitized key.
* @param string $raw_key The key prior to sanitization.
@@ -1371,7 +1504,7 @@ if ( ! class_exists( 'TGM_Plugin_Activation' ) ) {
* @since 2.0.0
*
* @param array $install_actions Existing array of actions.
* @return array Amended array of actions.
* @return false|array Amended array of actions.
*/
public function actions( $install_actions ) {
// Remove action links on the TGMPA install page.
@@ -1580,6 +1713,35 @@ if ( ! class_exists( 'TGM_Plugin_Activation' ) ) {
return isset( $_GET['page'] ) && $this->menu === $_GET['page'];
}
/**
* Determine if we're on a WP Core installation/upgrade page.
*
* @since 2.6.0
*
* @return boolean True when on a WP Core installation/upgrade page, false otherwise.
*/
protected function is_core_update_page() {
// Current screen is not always available, most notably on the customizer screen.
if ( ! function_exists( 'get_current_screen' ) ) {
return false;
}
$screen = get_current_screen();
if ( 'update-core' === $screen->base ) {
// Core update screen.
return true;
} elseif ( 'plugins' === $screen->base && ! empty( $_POST['action'] ) ) { // WPCS: CSRF ok.
// Plugins bulk update screen.
return true;
} elseif ( 'update' === $screen->base && ! empty( $_POST['action'] ) ) { // WPCS: CSRF ok.
// Individual updates (ajax call).
return true;
}
return false;
}
/**
* Retrieve the URL to the TGMPA Install page.
*
@@ -1692,13 +1854,30 @@ if ( ! class_exists( 'TGM_Plugin_Activation' ) ) {
$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.
return true;
}
/**
* Check to see if the plugin is 'updatetable', i.e. installed, with an update available
* and no WP version requirements blocking it.
*
* @since 2.6.0
*
* @param string $slug Plugin slug.
* @return bool True if OK to proceed with update, false otherwise.
*/
public function is_plugin_updatetable( $slug ) {
if ( ! $this->is_plugin_installed( $slug ) ) {
return false;
} else {
return ( false !== $this->does_plugin_have_update( $slug ) && $this->can_plugin_update( $slug ) );
}
}
/**
* Check if a plugin can be activated, i.e. is not currently active and meets the minimum
* plugin version requirements set in TGMPA (if any).
@@ -1821,7 +2000,7 @@ if ( ! class_exists( 'TGM_Plugin_Activation' ) ) {
* @since 2.1.1
*/
public function update_dismiss() {
delete_metadata( 'user', null, 'sp_dismissed_notice_' . $this->id, null, true );
delete_metadata( 'user', null, 'tgmpa_dismissed_notice_' . $this->id, null, true );
}
/**
@@ -1854,7 +2033,7 @@ if ( ! class_exists( 'TGM_Plugin_Activation' ) ) {
/**
* Forces plugin deactivation if the parameter 'force_deactivation'
* is set to true.
* is set to true and adds the plugin to the 'recently active' plugins list.
*
* This allows theme authors to specify certain plugins that must be
* deactivated upon switching from the current theme to another.
@@ -1865,20 +2044,38 @@ if ( ! class_exists( 'TGM_Plugin_Activation' ) ) {
* @since 2.2.0
*/
public function force_deactivation() {
$deactivated = array();
foreach ( $this->plugins as $slug => $plugin ) {
// Only proceed forward if the parameter is set to true and plugin is active.
if ( true === $plugin['force_deactivation'] && $this->is_plugin_active( $slug ) ) {
/*
* Only proceed forward if the parameter is set to true and plugin is active
* as a 'normal' (not must-use) plugin.
*/
if ( true === $plugin['force_deactivation'] && is_plugin_active( $plugin['file_path'] ) ) {
deactivate_plugins( $plugin['file_path'] );
$deactivated[ $plugin['file_path'] ] = time();
}
}
if ( ! empty( $deactivated ) ) {
update_option( 'recently_activated', $deactivated + (array) get_option( 'recently_activated' ) );
}
}
/**
* Echo the current TGMPA version number to the page.
*
* @since 2.5.0
*/
public function show_tgmpa_version() {
echo '<p style="float: right; padding: 0em 1.5em 0.5em 0;"><strong><small>',
esc_html( sprintf( _x( 'TGMPA v%s', '%s = version number', 'tgmpa' ), self::TGMPA_VERSION ) ),
esc_html(
sprintf(
/* translators: %s: version number */
__( 'TGMPA v%s', 'tgmpa' ),
self::TGMPA_VERSION
)
),
'</small></strong></p>';
}
@@ -1887,7 +2084,7 @@ if ( ! class_exists( 'TGM_Plugin_Activation' ) ) {
*
* @since 2.4.0
*
* @return object The TGM_Plugin_Activation object.
* @return \TGM_Plugin_Activation The TGM_Plugin_Activation object.
*/
public static function get_instance() {
if ( ! isset( self::$instance ) && ! ( self::$instance instanceof self ) ) {
@@ -1901,6 +2098,8 @@ if ( ! class_exists( 'TGM_Plugin_Activation' ) ) {
if ( ! function_exists( 'load_tgm_plugin_activation' ) ) {
/**
* Ensure only one instance of the class is ever invoked.
*
* @since 2.5.0
*/
function load_tgm_plugin_activation() {
$GLOBALS['tgmpa'] = TGM_Plugin_Activation::get_instance();
@@ -2093,7 +2292,7 @@ if ( ! class_exists( 'TGMPA_List_Table' ) ) {
if ( ! empty( $upgrade_notice ) ) {
$table_data[ $i ]['upgrade_notice'] = $upgrade_notice;
add_action( "tgmpa_after_plugin_row_$slug", array( $this, 'wp_plugin_update_row' ), 10, 2 );
add_action( "tgmpa_after_plugin_row_{$slug}", array( $this, 'wp_plugin_update_row' ), 10, 2 );
}
$table_data[ $i ] = apply_filters( 'tgmpa_table_data_item', $table_data[ $i ], $plugin );
@@ -2232,7 +2431,8 @@ if ( ! class_exists( 'TGMPA_List_Table' ) ) {
}
return sprintf(
_x( '%1$s, %2$s', '%1$s = install status, %2$s = update status', 'tgmpa' ),
/* translators: 1: install status, 2: update status */
_x( '%1$s, %2$s', 'Install/Update Status', 'tgmpa' ),
$install_status,
$update_status
);
@@ -2277,15 +2477,19 @@ if ( ! class_exists( 'TGMPA_List_Table' ) ) {
switch ( $type ) {
case 'all':
/* translators: 1: number of plugins. */
$text = _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $count, 'plugins', 'tgmpa' );
break;
case 'install':
/* translators: 1: number of plugins. */
$text = _n( 'To Install <span class="count">(%s)</span>', 'To Install <span class="count">(%s)</span>', $count, 'tgmpa' );
break;
case 'update':
/* translators: 1: number of plugins. */
$text = _n( 'Update Available <span class="count">(%s)</span>', 'Update Available <span class="count">(%s)</span>', $count, 'tgmpa' );
break;
case 'activate':
/* translators: 1: number of plugins. */
$text = _n( 'To Activate <span class="count">(%s)</span>', 'To Activate <span class="count">(%s)</span>', $count, 'tgmpa' );
break;
default:
@@ -2419,7 +2623,7 @@ if ( ! class_exists( 'TGMPA_List_Table' ) ) {
* @since 2.2.0
*/
public function no_items() {
printf( wp_kses_post( __( 'No plugins to install, update or activate. <a href="%1$s">Return to the Dashboard</a>', 'tgmpa' ) ), esc_url( self_admin_url() ) );
echo esc_html__( 'No plugins to install, update or activate.', 'tgmpa' ) . ' <a href="' . esc_url( self_admin_url() ) . '"> ' . esc_html__( 'Return to the Dashboard', 'tgmpa' ) . '</a>';
echo '<style type="text/css">#adminmenu .wp-submenu li.current { display: none !important; }</style>';
}
@@ -2488,16 +2692,19 @@ if ( ! class_exists( 'TGMPA_List_Table' ) ) {
// Display the 'Install' action link if the plugin is not yet available.
if ( ! $this->tgmpa->is_plugin_installed( $item['slug'] ) ) {
$actions['install'] = _x( 'Install %2$s', '%2$s = plugin name in screen reader markup', 'tgmpa' );
/* translators: %2$s: plugin name in screen reader markup */
$actions['install'] = __( 'Install %2$s', 'tgmpa' );
} else {
// Display the 'Update' action link if an update is available and WP complies with plugin minimum.
if ( false !== $this->tgmpa->does_plugin_have_update( $item['slug'] ) && $this->tgmpa->can_plugin_update( $item['slug'] ) ) {
$actions['update'] = _x( 'Update %2$s', '%2$s = plugin name in screen reader markup', 'tgmpa' );
/* translators: %2$s: plugin name in screen reader markup */
$actions['update'] = __( 'Update %2$s', 'tgmpa' );
}
// Display the 'Activate' action link, but only if the plugin meets the minimum version.
if ( $this->tgmpa->can_plugin_activate( $item['slug'] ) ) {
$actions['activate'] = _x( 'Activate %2$s', '%2$s = plugin name in screen reader markup', 'tgmpa' );
/* translators: %2$s: plugin name in screen reader markup */
$actions['activate'] = __( 'Activate %2$s', 'tgmpa' );
}
}
@@ -2516,7 +2723,7 @@ if ( ! class_exists( 'TGMPA_List_Table' ) ) {
);
$action_links[ $action ] = sprintf(
'<a href="%1$s">' . esc_html( $text ) . '</a>',
'<a href="%1$s">' . esc_html( $text ) . '</a>', // $text contains the second placeholder.
esc_url( $nonce_url ),
'<span class="screen-reader-text">' . esc_html( $item['sanitized_plugin'] ) . '</span>'
);
@@ -2669,8 +2876,13 @@ if ( ! class_exists( 'TGMPA_List_Table' ) ) {
continue;
}
// For install: make sure this is a plugin we *can* install and not one already installed.
if ( 'install' === $install_type && true === $this->tgmpa->is_plugin_installed( $slug ) ) {
unset( $plugins_to_install[ $key ] );
}
// For updates: make sure this is a plugin we *can* update (update available and WP version ok).
if ( 'update' === $install_type && ( $this->tgmpa->is_plugin_installed( $slug ) && ( false === $this->tgmpa->does_plugin_have_update( $slug ) || ! $this->tgmpa->can_plugin_update( $slug ) ) ) ) {
if ( 'update' === $install_type && false === $this->tgmpa->is_plugin_updatetable( $slug ) ) {
unset( $plugins_to_install[ $key ] );
}
}
@@ -2757,8 +2969,9 @@ if ( ! class_exists( 'TGMPA_List_Table' ) ) {
);
// Wrap the install process with the appropriate HTML.
echo '<div class="tgmpa wrap">',
'<h2>', esc_html( get_admin_page_title() ), '</h2>';
echo '<div class="tgmpa">',
'<h2 style="font-size: 23px; font-weight: 400; line-height: 29px; margin: 0; padding: 9px 15px 4px 0;">', esc_html( get_admin_page_title() ), '</h2>
<div class="update-php" style="width: 100%; height: 98%; min-height: 850px; padding-top: 1px;">';
// Process the bulk installation submissions.
add_filter( 'upgrader_source_selection', array( $this->tgmpa, 'maybe_adjust_source_dir' ), 1, 3 );
@@ -2772,9 +2985,9 @@ if ( ! class_exists( 'TGMPA_List_Table' ) ) {
$installer->bulk_install( $sources );
}
remove_filter( 'upgrader_source_selection', array( $this->tgmpa, 'maybe_adjust_source_dir' ), 1, 3 );
remove_filter( 'upgrader_source_selection', array( $this->tgmpa, 'maybe_adjust_source_dir' ), 1 );
echo '</div>';
echo '</div></div>';
return true;
}
@@ -2898,6 +3111,11 @@ if ( ! class_exists( 'TGM_Bulk_Installer' ) ) {
/**
* Hack: Prevent TGMPA v2.4.1- bulk installer class from being loaded if 2.4.1- is loaded after 2.5+.
*
* @since 2.5.2
*
* {@internal The TGMPA_Bulk_Installer class was originally called TGM_Bulk_Installer.
* For more information, see that class.}}
*/
class TGM_Bulk_Installer {
}
@@ -2906,6 +3124,11 @@ if ( ! class_exists( 'TGM_Bulk_Installer_Skin' ) ) {
/**
* Hack: Prevent TGMPA v2.4.1- bulk installer skin class from being loaded if 2.4.1- is loaded after 2.5+.
*
* @since 2.5.2
*
* {@internal The TGMPA_Bulk_Installer_Skin class was originally called TGM_Bulk_Installer_Skin.
* For more information, see that class.}}
*/
class TGM_Bulk_Installer_Skin {
}
@@ -2950,9 +3173,9 @@ if ( ! function_exists( '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
@@ -3059,17 +3282,19 @@ if ( ! function_exists( 'tgmpa_load_bulk_installer' ) ) {
*
* @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.
* @return string|bool Install confirmation messages on success, false on failure.
* @return array|false Install confirmation messages on success, false on failure.
*/
public function bulk_install( $plugins, $args = array() ) {
// [TGMPA + ] Hook auto-activation in.
@@ -3095,16 +3320,17 @@ if ( ! function_exists( 'tgmpa_load_bulk_installer' ) ) {
$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 ) );
/*
@@ -3136,13 +3362,14 @@ if ( ! function_exists( 'tgmpa_load_bulk_installer' ) ) {
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);
*/
$result = $this->run( array(
$result = $this->run(
array(
'package' => $plugin, // [TGMPA + ] adjusted.
'destination' => WP_PLUGIN_DIR,
'clear_destination' => false, // [TGMPA + ] adjusted.
@@ -3151,7 +3378,8 @@ if ( ! function_exists( 'tgmpa_load_bulk_installer' ) ) {
'hook_extra' => array(
'plugin' => $plugin,
),
) );
)
);
$results[ $plugin ] = $this->result;
@@ -3274,9 +3502,9 @@ if ( ! function_exists( 'tgmpa_load_bulk_installer' ) ) {
*
* @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
*
@@ -3359,22 +3587,29 @@ if ( ! function_exists( 'tgmpa_load_bulk_installer' ) ) {
public function add_strings() {
if ( 'update' === $this->options['install_type'] ) {
parent::add_strings();
/* translators: 1: plugin name, 2: action number 3: total number of actions. */
$this->upgrader->strings['skin_before_update_header'] = __( 'Updating Plugin %1$s (%2$d/%3$d)', 'tgmpa' );
} else {
/* translators: 1: plugin name, 2: error message. */
$this->upgrader->strings['skin_update_failed_error'] = __( 'An error occurred while installing %1$s: <strong>%2$s</strong>.', 'tgmpa' );
/* translators: 1: plugin name. */
$this->upgrader->strings['skin_update_failed'] = __( 'The installation of %1$s failed.', 'tgmpa' );
if ( $this->tgmpa->is_automatic ) {
// Automatic activation strings.
$this->upgrader->strings['skin_upgrade_start'] = __( 'The installation and activation process is starting. This process may take a while on some hosts, so please be patient.', 'tgmpa' );
/* translators: 1: plugin name. */
$this->upgrader->strings['skin_update_successful'] = __( '%1$s installed and activated successfully.', 'tgmpa' ) . ' <a href="#" class="hide-if-no-js" onclick="%2$s"><span>' . esc_html__( 'Show Details', 'tgmpa' ) . '</span><span class="hidden">' . esc_html__( 'Hide Details', 'tgmpa' ) . '</span>.</a>';
$this->upgrader->strings['skin_upgrade_end'] = __( 'All installations and activations have been completed.', 'tgmpa' );
/* translators: 1: plugin name, 2: action number 3: total number of actions. */
$this->upgrader->strings['skin_before_update_header'] = __( 'Installing and Activating Plugin %1$s (%2$d/%3$d)', 'tgmpa' );
} else {
// Default installation strings.
$this->upgrader->strings['skin_upgrade_start'] = __( 'The installation process is starting. This process may take a while on some hosts, so please be patient.', 'tgmpa' );
/* translators: 1: plugin name. */
$this->upgrader->strings['skin_update_successful'] = esc_html__( '%1$s installed successfully.', 'tgmpa' ) . ' <a href="#" class="hide-if-no-js" onclick="%2$s"><span>' . esc_html__( 'Show Details', 'tgmpa' ) . '</span><span class="hidden">' . esc_html__( 'Hide Details', 'tgmpa' ) . '</span>.</a>';
$this->upgrader->strings['skin_upgrade_end'] = __( 'All installations have been completed.', 'tgmpa' );
/* translators: 1: plugin name, 2: action number 3: total number of actions. */
$this->upgrader->strings['skin_before_update_header'] = __( 'Installing Plugin %1$s (%2$d/%3$d)', 'tgmpa' );
}
}

View File

@@ -394,8 +394,11 @@ final class SportsPress {
endswitch;
$config = array(
'id' => 'sportspress',
'default_path' => '',
'menu' => 'tgmpa-install-plugins',
'parent_slug' => 'plugins.php',
'capability' => 'manage_options',
'has_notices' => true,
'dismissable' => true,
'is_automatic' => true,