OS : Linux
PHP Version : 7.4.33
Software : wp_version = $GLOBALS['wp_version'];
// Announce that the class is ready, and pass the object (for advanced use).
do_action_ref_array( 'tgmpa_init', array( $this ) );
// When the rest of WP has loaded, kick-start the rest of the class.
add_action( 'init', array( $this, 'init' ) );
}
/**
* 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
* is being assigned rather than tested in a conditional, effectively rendering it useless.
* 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.
* (Inside this class context, the __set() method if not used as there is direct access.)
*/
public function __set( $name, $value ) {
return;
}
/**
* 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.
*/
public function __get( $name ) {
return $this->{$name};
}
/**
* Initialise the interactions between this class and WordPress.
*
* Hooks in three new methods for the class: admin_menu, notices and styles.
*
* @since 2.0.0
*
* @see TGM_Plugin_Activation::admin_menu()
* @see TGM_Plugin_Activation::notices()
* @see TGM_Plugin_Activation::styles()
*/
public function init() {
/**
* By default TGMPA only loads on the WP back-end and not in an Ajax call. Using this filter
* you can overrule that behaviour.
*
* @since 2.5.0
*
* @param bool $load Whether or not TGMPA should load.
* Defaults to the return of `is_admin() && ! defined( 'DOING_AJAX' )`.
*/
if ( true !== apply_filters( 'tgmpa_load', ( is_admin() && ! defined( 'DOING_AJAX' ) ) ) ) {
return;
}
// Load class strings.
$this->strings = array(
'page_title' => esc_html__( 'Install Required Plugins', 'total-school' ),
'menu_title' => esc_html__( 'Install Plugins', 'total-school' ),
/* translators: %s: plugin name. */
'installing' => esc_html__( 'Installing Plugin: %s', 'total-school' ),
/* translators: %s: plugin name. */
'updating' => esc_html__( 'Updating Plugin: %s', 'total-school' ),
'oops' => esc_html__( 'Something went wrong with the plugin API.', 'total-school' ),
'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.',
'total-school'
),
'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.',
'total-school'
),
'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.',
'total-school'
),
'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.',
'total-school'
),
'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.',
'total-school'
),
'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.',
'total-school'
),
'install_link' => _n_noop(
'Begin installing plugin',
'Begin installing plugins',
'total-school'
),
'update_link' => _n_noop(
'Begin updating plugin',
'Begin updating plugins',
'total-school'
),
'activate_link' => _n_noop(
'Begin activating plugin',
'Begin activating plugins',
'total-school'
),
'return' => esc_html__( 'Return to Required Plugins Installer', 'total-school' ),
'dashboard' => esc_html__( 'Return to the Dashboard', 'total-school' ),
'plugin_activated' => esc_html__( 'Plugin activated successfully.', 'total-school' ),
'activated_successfully' => esc_html__( 'The following plugin was activated successfully:', 'total-school' ),
/* translators: 1: plugin name. */
'plugin_already_active' => esc_html__( 'No action taken. Plugin %1$s was already active.', 'total-school' ),
/* translators: 1: plugin name. */
'plugin_needs_higher_version' => esc_html__( 'Plugin not activated. A higher version of %s is needed for this theme. Please update the plugin.', 'total-school' ),
/* translators: 1: dashboard link. */
'complete' => esc_html__( 'All plugins installed and activated successfully. %1$s', 'total-school' ),
'dismiss' => esc_html__( 'Dismiss this notice', 'total-school' ),
'notice_cannot_install_activate' => esc_html__( 'There are one or more required or recommended plugins to install, update or activate.', 'total-school' ),
'contact_admin' => esc_html__( 'Please contact the administrator of this site for help.', 'total-school' ),
);
do_action( 'tgmpa_register' );
/* After this point, the plugins should be registered and the configuration set. */
// Proceed only if we have plugins to handle.
if ( empty( $this->plugins ) || ! is_array( $this->plugins ) ) {
return;
}
// Set up the menu and notices if we still have outstanding actions.
if ( true !== $this->is_tgmpa_complete() ) {
// Sort the plugins.
array_multisort( $this->sort_order, SORT_ASC, $this->plugins );
add_action( 'admin_menu', array( $this, 'admin_menu' ) );
add_action( 'admin_head', array( $this, 'dismiss' ) );
// Prevent the normal links from showing underneath a single install/update page.
add_filter( 'install_plugin_complete_actions', array( $this, 'actions' ) );
add_filter( 'update_plugin_complete_actions', array( $this, 'actions' ) );
if ( $this->has_notices ) {
add_action( 'admin_notices', array( $this, 'notices' ) );
add_action( 'admin_init', array( $this, 'admin_init' ), 1 );
add_action( 'admin_enqueue_scripts', array( $this, 'thickbox' ) );
}
}
// 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' ) );
if ( $this->has_notices ) {
add_action( 'switch_theme', array( $this, 'update_dismiss' ) );
}
// Setup the force activation hook.
if ( true === $this->has_forced_activation ) {
add_action( 'admin_init', array( $this, 'force_activation' ) );
}
// Setup the force deactivation hook.
if ( true === $this->has_forced_deactivation ) {
add_action( 'switch_theme', array( $this, 'force_deactivation' ) );
}
}
/**
* 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
*/
public function add_plugin_action_link_filters() {
foreach ( $this->plugins as $slug => $plugin ) {
if ( false === $this->can_plugin_activate( $slug ) ) {
add_filter( 'plugin_action_links_' . $plugin['file_path'], array( $this, 'filter_plugin_action_links_activate' ), 20 );
}
if ( true === $plugin['force_activation'] ) {
add_filter( 'plugin_action_links_' . $plugin['file_path'], array( $this, 'filter_plugin_action_links_deactivate' ), 20 );
}
if ( false !== $this->does_plugin_require_update( $slug ) ) {
add_filter( 'plugin_action_links_' . $plugin['file_path'], array( $this, 'filter_plugin_action_links_update' ), 20 );
}
}
}
/**
* Remove the 'Activate' link on the WP native plugins page if the plugin does not meet the
* minimum version requirements.
*
* @since 2.5.0
*
* @param array $actions Action links.
* @return array
*/
public function filter_plugin_action_links_activate( $actions ) {
unset( $actions['activate'] );
return $actions;
}
/**
* Remove the 'Deactivate' link on the WP native plugins page if the plugin has been set to force activate.
*
* @since 2.5.0
*
* @param array $actions Action links.
* @return array
*/
public function filter_plugin_action_links_deactivate( $actions ) {
unset( $actions['deactivate'] );
return $actions;
}
/**
* Add a 'Requires update' link on the WP native plugins page if the plugin does not meet the
* minimum version requirements.
*
* @since 2.5.0
*
* @param array $actions Action links.
* @return array
*/
public function filter_plugin_action_links_update( $actions ) {
$actions['update'] = sprintf(
'%3$s',
esc_url( $this->get_tgmpa_status_url( 'update' ) ),
esc_attr__( 'This plugin needs to be updated to be compatible with your theme.', 'total-school' ),
esc_html__( 'Update Required', 'total-school' )
);
return $actions;
}
/**
* Handles calls to show plugin information via links in the notices.
*
* We get the links in the admin notices to point to the TGMPA page, rather
* than the typical plugin-install.php file, so we can prepare everything
* beforehand.
*
* WP does not make it easy to show the plugin information in the thickbox -
* here we have to require a file that includes a function that does the
* main work of displaying it, enqueue some styles, set up some globals and
* finally call that function before exiting.
*
* Down right easy once you know how...
*
* Returns early if not the TGMPA page.
*
* @since 2.1.0
*
* @global string $tab Used as iframe div class names, helps with styling
* @global string $body_id Used as the iframe body ID, helps with styling
*
* @return null Returns early if not the TGMPA page.
*/
public function admin_init() {
if ( ! $this->is_tgmpa_page() ) {
return;
}
if ( isset( $_REQUEST['tab'] ) && 'plugin-information' === $_REQUEST['tab'] ) {
// Needed for install_plugin_information().
require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
wp_enqueue_style( 'plugin-install' );
global $tab, $body_id;
$body_id = 'plugin-information';
// @codingStandardsIgnoreStart
$tab = 'plugin-information';
// @codingStandardsIgnoreEnd
install_plugin_information();
exit;
}
}
/**
* Enqueue thickbox scripts/styles for plugin info.
*
* Thickbox is not automatically included on all admin pages, so we must
* manually enqueue it for those pages.
*
* Thickbox is only loaded if the user has not dismissed the admin
* notice or if there are any plugins left to install and activate.
*
* @since 2.1.0
*/
public function thickbox() {
if ( ! get_user_meta( get_current_user_id(), 'tgmpa_dismissed_notice_' . $this->id, true ) ) {
add_thickbox();
}
}
/**
* Adds submenu page if there are plugin actions to take.
*
* This method adds the submenu page letting users know that a required
* plugin needs to be installed.
*
* This page disappears once the plugin has been installed and activated.
*
* @since 1.0.0
*
* @see TGM_Plugin_Activation::init()
* @see TGM_Plugin_Activation::install_plugins_page()
*
* @return null Return early if user lacks capability to install a plugin.
*/
public function admin_menu() {
// Make sure privileges are correct to see the page.
if ( ! current_user_can( 'install_plugins' ) ) {
return;
}
$args = apply_filters(
'tgmpa_admin_menu_args',
array(
'parent_slug' => $this->parent_slug, // Parent Menu slug.
'page_title' => $this->strings['page_title'], // Page title.
'menu_title' => $this->strings['menu_title'], // Menu title.
'capability' => $this->capability, // Capability.
'menu_slug' => $this->menu, // Menu slug.
'function' => array( $this, 'install_plugins_page' ), // Callback.
)
);
$this->add_admin_menu( $args );
}
/**
* 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.
*/
protected function add_admin_menu( array $args ) {
$this->page_hook = add_theme_page( $args['page_title'], $args['menu_title'], $args['capability'], $args['menu_slug'], $args['function'] );
}
/**
* Echoes plugin installation form.
*
* This method is the callback for the admin_menu method function.
* This displays the admin page and form area where the user can select to install and activate the plugin.
* Aborts early if we're processing a plugin installation action.
*
* @since 1.0.0
*
* @return null Aborts early if we're processing a plugin installation action.
*/
public function install_plugins_page() {
// Store new instance of plugin table in object.
$plugin_table = new TGMPA_List_Table;
// Return early if processing a plugin installation action.
if ( ( ( 'tgmpa-bulk-install' === $plugin_table->current_action() || 'tgmpa-bulk-update' === $plugin_table->current_action() ) && $plugin_table->process_bulk_actions() ) || $this->do_plugin_install() ) {
return;
}
// Force refresh of available plugin information so we'll know about manual updates/deletes.
wp_clean_plugins_cache( false );
?>
', sprintf( esc_html( $this->strings['complete'] ), '' . esc_html__( 'Return to the Dashboard', 'total-school' ) . '' ), ' ', esc_html( $this->strings['return'] ), ' ', wp_kses_post( $activate->get_error_message() ), ' ', esc_html( $this->strings['return'] ), ' ', esc_html( $this->strings['activated_successfully'] ), ' ', esc_html( $this->plugins[ $slug ]['name'] ), '. ', esc_html( $this->strings['plugin_activated'] ), ' ',
sprintf(
esc_html( $this->strings['plugin_already_active'] ),
'' . esc_html( $this->plugins[ $slug ]['name'] ) . ''
),
' ',
sprintf(
esc_html( $this->strings['plugin_needs_higher_version'] ),
'' . esc_html( $this->plugins[ $slug ]['name'] ) . ''
),
' ', sprintf( esc_html( $this->strings['plugin_needs_higher_version'] ), esc_html( $this->plugins[ $slug ]['name'] ) ), ' and as the final message can't be
// filtered, using 's in our html would render invalid html output.
$line_template = '%s' . "\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 ) );
}
// Render the individual message lines for the notice.
foreach ( $message as $type => $plugin_group ) {
$linked_plugins = array();
// Get the external info link for a plugin if one is available.
foreach ( $plugin_group as $plugin_slug ) {
$linked_plugins[] = $this->get_info_link( $plugin_slug );
}
unset( $plugin_slug );
$count = count( $plugin_group );
$linked_plugins = array_map( array( 'TGMPA_Utils', 'wrap_in_em' ), $linked_plugins );
$last_plugin = array_pop( $linked_plugins ); // Pop off last name to prep for readability.
$imploded = empty( $linked_plugins ) ? $last_plugin : ( implode( ', ', $linked_plugins ) . ' ' . esc_html_x( 'and', 'plugin A *and* plugin B', 'total-school' ) . ' ' . $last_plugin );
$rendered .= sprintf(
$line_template,
sprintf(
translate_nooped_plural( $this->strings[ $type ], $count, 'total-school' ),
$imploded,
$count
)
);
}
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 ? '' . esc_html( $this->strings['dismiss'] ) . '' : '',
);
$link_template = '%1$s';
if ( current_user_can( 'install_plugins' ) ) {
if ( $install_count > 0 ) {
$action_links['install'] = sprintf(
$link_template,
translate_nooped_plural( $this->strings['install_link'], $install_count, 'total-school' ),
esc_url( $this->get_tgmpa_status_url( 'install' ) )
);
}
if ( $update_count > 0 ) {
$action_links['update'] = sprintf(
$link_template,
translate_nooped_plural( $this->strings['update_link'], $update_count, 'total-school' ),
esc_url( $this->get_tgmpa_status_url( 'update' ) )
);
}
}
if ( current_user_can( 'activate_plugins' ) && $activate_count > 0 ) {
$action_links['activate'] = sprintf(
$link_template,
translate_nooped_plural( $this->strings['activate_link'], $activate_count, 'total-school' ),
esc_url( $this->get_tgmpa_status_url( 'activate' ) )
);
}
$action_links = apply_filters( 'tgmpa_notice_action_links', $action_links );
$action_links = array_filter( (array) $action_links ); // Remove any empty array items.
if ( ! empty( $action_links ) ) {
$action_links = sprintf( $line_template, implode( ' | ', $action_links ) );
return apply_filters( 'tgmpa_notice_rendered_action_links', $action_links );
} else {
return '';
}
}
/**
* 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';
}
}
}
/**
* Display settings errors and remove those which have been displayed to avoid duplicate messages showing
*
* @since 2.5.0
*/
protected function display_settings_errors() {
global $wp_settings_errors;
settings_errors( 'tgmpa' );
foreach ( (array) $wp_settings_errors as $key => $details ) {
if ( 'tgmpa' === $details['setting'] ) {
unset( $wp_settings_errors[ $key ] );
break;
}
}
}
/**
* Register dismissal of admin notices.
*
* 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'] ) && check_admin_referer( 'tgmpa-dismiss-' . get_current_user_id() ) ) {
update_user_meta( get_current_user_id(), 'tgmpa_dismissed_notice_' . $this->id, 1 );
}
}
/**
* Add individual plugin to our collection of plugins.
*
* If the required keys are not set or the plugin has already
* been registered, the plugin is not added.
*
* @since 2.0.0
*
* @param array|null $plugin Array of plugin arguments or null if invalid argument.
* @return null Return early if incorrect argument.
*/
public function register( $plugin ) {
if ( empty( $plugin['slug'] ) || empty( $plugin['name'] ) ) {
return;
}
if ( empty( $plugin['slug'] ) || ! is_string( $plugin['slug'] ) || isset( $this->plugins[ $plugin['slug'] ] ) ) {
return;
}
$defaults = array(
'name' => '', // String
'slug' => '', // String
'source' => 'repo', // String
'required' => false, // Boolean
'version' => '', // String
'force_activation' => false, // Boolean
'force_deactivation' => false, // Boolean
'external_url' => '', // String
'is_callable' => '', // String|Array.
);
// Prepare the received data.
$plugin = wp_parse_args( $plugin, $defaults );
// Standardize the received slug.
$plugin['slug'] = $this->sanitize_key( $plugin['slug'] );
// Forgive users for using string versions of booleans or floats for version number.
$plugin['version'] = (string) $plugin['version'];
$plugin['source'] = empty( $plugin['source'] ) ? 'repo' : $plugin['source'];
$plugin['required'] = TGMPA_Utils::validate_bool( $plugin['required'] );
$plugin['force_activation'] = TGMPA_Utils::validate_bool( $plugin['force_activation'] );
$plugin['force_deactivation'] = TGMPA_Utils::validate_bool( $plugin['force_deactivation'] );
// Enrich the received data.
$plugin['file_path'] = $this->_get_plugin_basename_from_slug( $plugin['slug'] );
$plugin['source_type'] = $this->get_plugin_source_type( $plugin['source'] );
// Set the class properties.
$this->plugins[ $plugin['slug'] ] = $plugin;
$this->sort_order[ $plugin['slug'] ] = $plugin['name'];
// Should we add the force activation hook ?
if ( true === $plugin['force_activation'] ) {
$this->has_forced_activation = true;
}
// Should we add the force deactivation hook ?
if ( true === $plugin['force_deactivation'] ) {
$this->has_forced_deactivation = true;
}
}
/**
* Determine what type of source the plugin comes from.
*
* @since 2.5.0
*
* @param string $source The source of the plugin as provided, either empty (= WP repo), a file path
* (= bundled) or an external URL.
* @return string 'repo', 'external', or 'bundled'
*/
protected function get_plugin_source_type( $source ) {
if ( 'repo' === $source || preg_match( self::WP_REPO_REGEX, $source ) ) {
return 'repo';
} elseif ( preg_match( self::IS_URL_REGEX, $source ) ) {
return 'external';
} else {
return 'bundled';
}
}
/**
* Sanitizes a string key.
*
* Near duplicate of WP Core `sanitize_key()`. The difference is that uppercase characters *are*
* allowed, so as not to break upgrade paths from non-standard bundled plugins using uppercase
* characters in the plugin directory path/slug. Silly them.
*
* @see https://developer.wordpress.org/reference/hooks/sanitize_key/
*
* @since 2.5.0
*
* @param string $key String key.
* @return string Sanitized key
*/
public function sanitize_key( $key ) {
$raw_key = $key;
$key = preg_replace( '`[^A-Za-z0-9_-]`', '', $key );
/**
* Filter a sanitized key string.
*
* @since 2.5.0
*
* @param string $key Sanitized key.
* @param string $raw_key The key prior to sanitization.
*/
return apply_filters( 'tgmpa_sanitize_key', $key, $raw_key );
}
/**
* Amend default configuration settings.
*
* @since 2.0.0
*
* @param array $config Array of config options to pass as class properties.
*/
public function config( $config ) {
$keys = array(
'id',
'default_path',
'has_notices',
'dismissable',
'dismiss_msg',
'menu',
'parent_slug',
'capability',
'is_automatic',
'message',
'strings',
);
foreach ( $keys as $key ) {
if ( isset( $config[ $key ] ) ) {
if ( is_array( $config[ $key ] ) ) {
$this->$key = array_merge( $this->$key, $config[ $key ] );
} else {
$this->$key = $config[ $key ];
}
}
}
}
/**
* Amend action link after plugin installation.
*
* @since 2.0.0
*
* @param array $install_actions Existing array of actions.
* @return false|array Amended array of actions.
*/
public function actions( $install_actions ) {
// Remove action links on the TGMPA install page.
if ( $this->is_tgmpa_page() ) {
return false;
}
return $install_actions;
}
/**
* Flushes the plugins cache on theme switch to prevent stale entries
* from remaining in the plugin table.
*
* @since 2.4.0
*
* @param bool $clear_update_cache Optional. Whether to clear the Plugin updates cache.
* Parameter added in v2.5.0.
*/
public function flush_plugins_cache( $clear_update_cache = true ) {
wp_clean_plugins_cache( $clear_update_cache );
}
/**
* Set file_path key for each installed plugin.
*
* @since 2.1.0
*
* @param string $plugin_slug Optional. If set, only (re-)populates the file path for that specific plugin.
* Parameter added in v2.5.0.
*/
public function populate_file_path( $plugin_slug = '' ) {
if ( ! empty( $plugin_slug ) && is_string( $plugin_slug ) && isset( $this->plugins[ $plugin_slug ] ) ) {
$this->plugins[ $plugin_slug ]['file_path'] = $this->_get_plugin_basename_from_slug( $plugin_slug );
} else {
// Add file_path key for all plugins.
foreach ( $this->plugins as $slug => $values ) {
$this->plugins[ $slug ]['file_path'] = $this->_get_plugin_basename_from_slug( $slug );
}
}
}
/**
* Helper function to extract the file path of the plugin file from the
* plugin slug, if the plugin is installed.
*
* @since 2.0.0
*
* @param string $slug Plugin slug (typically folder name) as provided by the developer.
* @return string Either file path for plugin if installed, or just the plugin slug.
*/
protected function _get_plugin_basename_from_slug( $slug ) {
$keys = array_keys( $this->get_plugins() );
foreach ( $keys as $key ) {
if ( preg_match( '|^' . $slug . '/|', $key ) ) {
return $key;
}
}
return $slug;
}
/**
* Retrieve plugin data, given the plugin name.
*
* Loops through the registered plugins looking for $name. If it finds it,
* it returns the $data from that plugin. Otherwise, returns false.
*
* @since 2.1.0
*
* @param string $name Name of the plugin, as it was registered.
* @param string $data Optional. Array key of plugin data to return. Default is slug.
* @return string|boolean Plugin slug if found, false otherwise.
*/
public function _get_plugin_data_from_name( $name, $data = 'slug' ) {
foreach ( $this->plugins as $values ) {
if ( $name === $values['name'] && isset( $values[ $data ] ) ) {
return $values[ $data ];
}
}
return false;
}
/**
* Retrieve the download URL for a package.
*
* @since 2.5.0
*
* @param string $slug Plugin slug.
* @return string Plugin download URL or path to local file or empty string if undetermined.
*/
public function get_download_url( $slug ) {
$dl_source = '';
switch ( $this->plugins[ $slug ]['source_type'] ) {
case 'repo':
return $this->get_wp_repo_download_url( $slug );
case 'external':
return $this->plugins[ $slug ]['source'];
case 'bundled':
return $this->default_path . $this->plugins[ $slug ]['source'];
}
return $dl_source; // Should never happen.
}
/**
* Retrieve the download URL for a WP repo package.
*
* @since 2.5.0
*
* @param string $slug Plugin slug.
* @return string Plugin download URL.
*/
protected function get_wp_repo_download_url( $slug ) {
$source = '';
$api = $this->get_plugins_api( $slug );
if ( false !== $api && isset( $api->download_link ) ) {
$source = $api->download_link;
}
return $source;
}
/**
* Try to grab information from WordPress API.
*
* @since 2.5.0
*
* @param string $slug Plugin slug.
* @return object Plugins_api response object on success, WP_Error on failure.
*/
protected function get_plugins_api( $slug ) {
static $api = array(); // Cache received responses.
if ( ! isset( $api[ $slug ] ) ) {
if ( ! function_exists( 'plugins_api' ) ) {
require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
}
$response = plugins_api( 'plugin_information', array( 'slug' => $slug, 'fields' => array( 'sections' => false ) ) );
$api[ $slug ] = false;
if ( is_wp_error( $response ) ) {
wp_die( esc_html( $this->strings['oops'] ) );
} else {
$api[ $slug ] = $response;
}
}
return $api[ $slug ];
}
/**
* Retrieve a link to a plugin information page.
*
* @since 2.5.0
*
* @param string $slug Plugin slug.
* @return string Fully formed html link to a plugin information page if available
* or the plugin name if not.
*/
public function get_info_link( $slug ) {
if ( ! empty( $this->plugins[ $slug ]['external_url'] ) && preg_match( self::IS_URL_REGEX, $this->plugins[ $slug ]['external_url'] ) ) {
$link = sprintf(
'%2$s',
esc_url( $this->plugins[ $slug ]['external_url'] ),
esc_html( $this->plugins[ $slug ]['name'] )
);
} elseif ( 'repo' === $this->plugins[ $slug ]['source_type'] ) {
$url = add_query_arg(
array(
'tab' => 'plugin-information',
'plugin' => urlencode( $slug ),
'TB_iframe' => 'true',
'width' => '640',
'height' => '500',
),
self_admin_url( 'plugin-install.php' )
);
$link = sprintf(
'%2$s',
esc_url( $url ),
esc_html( $this->plugins[ $slug ]['name'] )
);
} else {
$link = esc_html( $this->plugins[ $slug ]['name'] ); // No hyperlink.
}
return $link;
}
/**
* Determine if we're on the TGMPA Install page.
*
* @since 2.1.0
*
* @return boolean True when on the TGMPA page, false otherwise.
*/
protected function is_tgmpa_page() {
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.
*
* I.e. depending on the config settings passed something along the lines of:
* http://example.com/wp-admin/themes.php?page=tgmpa-install-plugins
*
* @since 2.5.0
*
* @return string Properly encoded URL (not escaped).
*/
public function get_tgmpa_url() {
static $url;
if ( ! isset( $url ) ) {
$parent = $this->parent_slug;
if ( false === strpos( $parent, '.php' ) ) {
$parent = 'admin.php';
}
$url = add_query_arg(
array(
'page' => urlencode( $this->menu ),
),
self_admin_url( $parent )
);
}
return $url;
}
/**
* Retrieve the URL to the TGMPA Install page for a specific plugin status (view).
*
* I.e. depending on the config settings passed something along the lines of:
* http://example.com/wp-admin/themes.php?page=tgmpa-install-plugins&plugin_status=install
*
* @since 2.5.0
*
* @param string $status Plugin status - either 'install', 'update' or 'activate'.
* @return string Properly encoded URL (not escaped).
*/
public function get_tgmpa_status_url( $status ) {
return add_query_arg(
array(
'plugin_status' => urlencode( $status ),
),
$this->get_tgmpa_url()
);
}
/**
* Determine whether there are open actions for plugins registered with TGMPA.
*
* @since 2.5.0
*
* @return bool True if complete, i.e. no outstanding actions. False otherwise.
*/
public function is_tgmpa_complete() {
$complete = true;
foreach ( $this->plugins as $slug => $plugin ) {
if ( ! $this->is_plugin_active( $slug ) || false !== $this->does_plugin_have_update( $slug ) ) {
$complete = false;
break;
}
}
return $complete;
}
/**
* Check if a plugin is installed. Does not take must-use plugins into account.
*
* @since 2.5.0
*
* @param string $slug Plugin slug.
* @return bool True if installed, false otherwise.
*/
public function is_plugin_installed( $slug ) {
$installed_plugins = $this->get_plugins(); // Retrieve a list of all installed plugins (WP cached).
return ( ! empty( $installed_plugins[ $this->plugins[ $slug ]['file_path'] ] ) );
}
/**
* Check if a plugin is active.
*
* @since 2.5.0
*
* @param string $slug Plugin slug.
* @return bool True if active, false otherwise.
*/
public function is_plugin_active( $slug ) {
return ( ( ! empty( $this->plugins[ $slug ]['is_callable'] ) && is_callable( $this->plugins[ $slug ]['is_callable'] ) ) || is_plugin_active( $this->plugins[ $slug ]['file_path'] ) );
}
/**
* Check if a plugin can be updated, i.e. if we have information on the minimum WP version required
* available, check whether the current install meets them.
*
* @since 2.5.0
*
* @param string $slug Plugin slug.
* @return bool True if OK to update, false otherwise.
*/
public function can_plugin_update( $slug ) {
// We currently can't get reliable info on non-WP-repo plugins - issue #380.
if ( 'repo' !== $this->plugins[ $slug ]['source_type'] ) {
return true;
}
$api = $this->get_plugins_api( $slug );
if ( false !== $api && isset( $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).
*
* @since 2.5.0
*
* @param string $slug Plugin slug.
* @return bool True if OK to activate, false otherwise.
*/
public function can_plugin_activate( $slug ) {
return ( ! $this->is_plugin_active( $slug ) && ! $this->does_plugin_require_update( $slug ) );
}
/**
* Retrieve the version number of an installed plugin.
*
* @since 2.5.0
*
* @param string $slug Plugin slug.
* @return string Version number as string or an empty string if the plugin is not installed
* or version unknown (plugins which don't comply with the plugin header standard).
*/
public function get_installed_version( $slug ) {
$installed_plugins = $this->get_plugins(); // Retrieve a list of all installed plugins (WP cached).
if ( ! empty( $installed_plugins[ $this->plugins[ $slug ]['file_path'] ]['Version'] ) ) {
return $installed_plugins[ $this->plugins[ $slug ]['file_path'] ]['Version'];
}
return '';
}
/**
* Check whether a plugin complies with the minimum version requirements.
*
* @since 2.5.0
*
* @param string $slug Plugin slug.
* @return bool True when a plugin needs to be updated, otherwise false.
*/
public function does_plugin_require_update( $slug ) {
$installed_version = $this->get_installed_version( $slug );
$minimum_version = $this->plugins[ $slug ]['version'];
return version_compare( $minimum_version, $installed_version, '>' );
}
/**
* Check whether there is an update available for a plugin.
*
* @since 2.5.0
*
* @param string $slug Plugin slug.
* @return false|string Version number string of the available update or false if no update available.
*/
public function does_plugin_have_update( $slug ) {
// Presume bundled and external plugins will point to a package which meets the minimum required version.
if ( 'repo' !== $this->plugins[ $slug ]['source_type'] ) {
if ( $this->does_plugin_require_update( $slug ) ) {
return $this->plugins[ $slug ]['version'];
}
return false;
}
$repo_updates = get_site_transient( 'update_plugins' );
if ( isset( $repo_updates->response[ $this->plugins[ $slug ]['file_path'] ]->new_version ) ) {
return $repo_updates->response[ $this->plugins[ $slug ]['file_path'] ]->new_version;
}
return false;
}
/**
* Retrieve potential upgrade notice for a plugin.
*
* @since 2.5.0
*
* @param string $slug Plugin slug.
* @return string The upgrade notice or an empty string if no message was available or provided.
*/
public function get_upgrade_notice( $slug ) {
// We currently can't get reliable info on non-WP-repo plugins - issue #380.
if ( 'repo' !== $this->plugins[ $slug ]['source_type'] ) {
return '';
}
$repo_updates = get_site_transient( 'update_plugins' );
if ( ! empty( $repo_updates->response[ $this->plugins[ $slug ]['file_path'] ]->upgrade_notice ) ) {
return $repo_updates->response[ $this->plugins[ $slug ]['file_path'] ]->upgrade_notice;
}
return '';
}
/**
* Wrapper around the core WP get_plugins function, making sure it's actually available.
*
* @since 2.5.0
*
* @param string $plugin_folder Optional. Relative path to single plugin folder.
* @return array Array of installed plugins with plugin information.
*/
public function get_plugins( $plugin_folder = '' ) {
if ( ! function_exists( 'get_plugins' ) ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
return get_plugins( $plugin_folder );
}
/**
* Delete dismissable nag option when theme is switched.
*
* This ensures that the user(s) is/are again reminded via nag of required
* and/or recommended plugins if they re-activate the theme.
*
* @since 2.1.1
*/
public function update_dismiss() {
delete_metadata( 'user', null, 'tgmpa_dismissed_notice_' . $this->id, null, true );
}
/**
* Forces plugin activation if the parameter 'force_activation' is
* set to true.
*
* This allows theme authors to specify certain plugins that must be
* active at all times while using the current theme.
*
* Please take special care when using this parameter as it has the
* potential to be harmful if not used correctly. Setting this parameter
* to true will not allow the specified plugin to be deactivated unless
* the user switches themes.
*
* @since 2.2.0
*/
public function force_activation() {
foreach ( $this->plugins as $slug => $plugin ) {
if ( true === $plugin['force_activation'] ) {
if ( ! $this->is_plugin_installed( $slug ) ) {
// Oops, plugin isn't there so iterate to next condition.
continue;
} elseif ( $this->can_plugin_activate( $slug ) ) {
// There we go, activate the plugin.
activate_plugin( $plugin['file_path'] );
}
}
}
}
/**
* Forces plugin deactivation if the parameter 'force_deactivation'
* 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.
*
* Please take special care when using this parameter as it has the
* potential to be harmful if not used correctly.
*
* @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
* 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 ' ',
esc_html(
sprintf(
/* translators: %s: version number */
esc_html__( 'TGMPA v%s', 'total-school' ),
self::TGMPA_VERSION
)
),
' %2$s' . esc_html__( 'Installed version:', 'total-school' ) . ' %1$s' . esc_html__( 'Minimum required version:', 'total-school' ) . ' %2$s' . esc_html__( 'Available version:', 'total-school' ) . ' ', esc_html( $message ), ' ', esc_html( $message ), ' ', esc_html__( 'No plugins were selected to be activated. No action taken.', 'total-school' ), ' ', esc_html__( 'No plugins are available to be activated at this time.', 'total-school' ), ' ', wp_kses_post( $activate->get_error_message() ), ' %1$s %2$s. tag.
*
* Overruled to prevent the 'plural' argument from being added.
*
* @since 2.5.0
*
* @return array CSS classnames.
*/
public function get_table_classes() {
return array( 'widefat', 'fixed' );
}
/**
* Gathers and renames all of our plugin information to be used by WP_List_Table to create our table.
*
* @since 2.2.0
*
* @return array $table_data Information for use in table.
*/
protected function _gather_plugin_data() {
// Load thickbox for plugin links.
$this->tgmpa->admin_init();
$this->tgmpa->thickbox();
// Categorize the plugins which have open actions.
$plugins = $this->categorize_plugins_to_views();
// Set the counts for the view links.
$this->set_view_totals( $plugins );
// Prep variables for use and grab list of all installed plugins.
$table_data = array();
$i = 0;
// Redirect to the 'all' view if no plugins were found for the selected view context.
if ( empty( $plugins[ $this->view_context ] ) ) {
$this->view_context = 'all';
}
foreach ( $plugins[ $this->view_context ] as $slug => $plugin ) {
$table_data[ $i ]['sanitized_plugin'] = $plugin['name'];
$table_data[ $i ]['slug'] = $slug;
$table_data[ $i ]['plugin'] = '' . $this->tgmpa->get_info_link( $slug ) . '';
$table_data[ $i ]['source'] = $this->get_plugin_source_type_text( $plugin['source_type'] );
$table_data[ $i ]['type'] = $this->get_plugin_advise_type_text( $plugin['required'] );
$table_data[ $i ]['status'] = $this->get_plugin_status_text( $slug );
$table_data[ $i ]['installed_version'] = $this->tgmpa->get_installed_version( $slug );
$table_data[ $i ]['minimum_version'] = $plugin['version'];
$table_data[ $i ]['available_version'] = $this->tgmpa->does_plugin_have_update( $slug );
// Prep the upgrade notice info.
$upgrade_notice = $this->tgmpa->get_upgrade_notice( $slug );
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 );
}
$table_data[ $i ] = apply_filters( 'tgmpa_table_data_item', $table_data[ $i ], $plugin );
$i++;
}
return $table_data;
}
/**
* Categorize the plugins which have open actions into views for the TGMPA page.
*
* @since 2.5.0
*/
protected function categorize_plugins_to_views() {
$plugins = array(
'all' => array(), // Meaning: all plugins which still have open actions.
'install' => array(),
'update' => array(),
'activate' => array(),
);
foreach ( $this->tgmpa->plugins as $slug => $plugin ) {
if ( $this->tgmpa->is_plugin_active( $slug ) && false === $this->tgmpa->does_plugin_have_update( $slug ) ) {
// No need to display plugins if they are installed, up-to-date and active.
continue;
} else {
$plugins['all'][ $slug ] = $plugin;
if ( ! $this->tgmpa->is_plugin_installed( $slug ) ) {
$plugins['install'][ $slug ] = $plugin;
} else {
if ( false !== $this->tgmpa->does_plugin_have_update( $slug ) ) {
$plugins['update'][ $slug ] = $plugin;
}
if ( $this->tgmpa->can_plugin_activate( $slug ) ) {
$plugins['activate'][ $slug ] = $plugin;
}
}
}
}
return $plugins;
}
/**
* Set the counts for the view links.
*
* @since 2.5.0
*
* @param array $plugins Plugins order by view.
*/
protected function set_view_totals( $plugins ) {
foreach ( $plugins as $type => $list ) {
$this->view_totals[ $type ] = count( $list );
}
}
/**
* Get the plugin required/recommended text string.
*
* @since 2.5.0
*
* @param string $required Plugin required setting.
* @return string
*/
protected function get_plugin_advise_type_text( $required ) {
if ( true === $required ) {
return esc_attr__( 'Required', 'total-school' );
}
return esc_attr__( 'Recommended', 'total-school' );
}
/**
* Get the plugin source type text string.
*
* @since 2.5.0
*
* @param string $type Plugin type.
* @return string
*/
protected function get_plugin_source_type_text( $type ) {
$string = '';
switch ( $type ) {
case 'repo':
$string = esc_html__( 'WordPress Repository', 'total-school' );
break;
case 'external':
$string = esc_html__( 'External Source', 'total-school' );
break;
case 'bundled':
$string = esc_html__( 'Pre-Packaged', 'total-school' );
break;
}
return $string;
}
/**
* Determine the plugin status message.
*
* @since 2.5.0
*
* @param string $slug Plugin slug.
* @return string
*/
protected function get_plugin_status_text( $slug ) {
if ( ! $this->tgmpa->is_plugin_installed( $slug ) ) {
return esc_attr__( 'Not Installed', 'total-school' );
}
if ( ! $this->tgmpa->is_plugin_active( $slug ) ) {
$install_status = esc_attr__( 'Installed But Not Activated', 'total-school' );
} else {
$install_status = esc_attr__( 'Active', 'total-school' );
}
$update_status = '';
if ( $this->tgmpa->does_plugin_require_update( $slug ) && false === $this->tgmpa->does_plugin_have_update( $slug ) ) {
$update_status = esc_attr__( 'Required Update not Available', 'total-school' );
} elseif ( $this->tgmpa->does_plugin_require_update( $slug ) ) {
$update_status = esc_attr__( 'Requires Update', 'total-school' );
} elseif ( false !== $this->tgmpa->does_plugin_have_update( $slug ) ) {
$update_status = esc_attr__( 'Update recommended', 'total-school' );
}
if ( '' === $update_status ) {
return $install_status;
}
return sprintf(
/* translators: 1: install status, 2: update status */
_x( '%1$s, %2$s', 'Install/Update Status', 'total-school' ),
$install_status,
$update_status
);
}
/**
* Sort plugins by Required/Recommended type and by alphabetical plugin name within each type.
*
* @since 2.5.0
*
* @param array $items Prepared table items.
* @return array Sorted table items.
*/
public function sort_table_items( $items ) {
$type = array();
$name = array();
foreach ( $items as $i => $plugin ) {
$type[ $i ] = $plugin['type']; // Required / recommended.
$name[ $i ] = $plugin['sanitized_plugin'];
}
array_multisort( $type, SORT_DESC, $name, SORT_ASC, $items );
return $items;
}
/**
* Get an associative array ( id => link ) of the views available on this table.
*
* @since 2.5.0
*
* @return array
*/
public function get_views() {
$status_links = array();
foreach ( $this->view_totals as $type => $count ) {
if ( $count < 1 ) {
continue;
}
switch ( $type ) {
case 'all':
/* translators: 1: number of plugins. */
$text = _nx( 'All (%s)', 'All (%s)', $count, 'plugins', 'total-school' );
break;
case 'install':
/* translators: 1: number of plugins. */
$text = _n( 'To Install (%s)', 'To Install (%s)', $count, 'total-school' );
break;
case 'update':
/* translators: 1: number of plugins. */
$text = _n( 'Update Available (%s)', 'Update Available (%s)', $count, 'total-school' );
break;
case 'activate':
/* translators: 1: number of plugins. */
$text = _n( 'To Activate (%s)', 'To Activate (%s)', $count, 'total-school' );
break;
default:
$text = '';
break;
}
if ( ! empty( $text ) ) {
$status_links[ $type ] = sprintf(
'%s',
esc_url( $this->tgmpa->get_tgmpa_status_url( $type ) ),
( $type === $this->view_context ) ? ' class="current"' : '',
sprintf( $text, number_format_i18n( $count ) )
);
}
}
return $status_links;
}
/**
* Create default columns to display important plugin information
* like type, action and status.
*
* @since 2.2.0
*
* @param array $item Array of item data.
* @param string $column_name The name of the column.
* @return string
*/
public function column_default( $item, $column_name ) {
return $item[ $column_name ];
}
/**
* Required for bulk installing.
*
* Adds a checkbox for each plugin.
*
* @since 2.2.0
*
* @param array $item Array of item data.
* @return string The input checkbox with all necessary info.
*/
public function column_cb( $item ) {
return sprintf(
'',
esc_attr( $this->_args['singular'] ),
esc_attr( $item['slug'] ),
esc_attr( $item['sanitized_plugin'] )
);
}
/**
* Create default title column along with the action links.
*
* @since 2.2.0
*
* @param array $item Array of item data.
* @return string The plugin name and action links.
*/
public function column_plugin( $item ) {
return sprintf(
'%1$s %2$s',
$item['plugin'],
$this->row_actions( $this->get_row_actions( $item ), true )
);
}
/**
* Create version information column.
*
* @since 2.5.0
*
* @param array $item Array of item data.
* @return string HTML-formatted version information.
*/
public function column_version( $item ) {
$output = array();
if ( $this->tgmpa->is_plugin_installed( $item['slug'] ) ) {
$installed = ! empty( $item['installed_version'] ) ? $item['installed_version'] : _x( 'unknown', 'as in: "version nr unknown"', 'total-school' );
$color = '';
if ( ! empty( $item['minimum_version'] ) && $this->tgmpa->does_plugin_require_update( $item['slug'] ) ) {
$color = ' color: #ff0000; font-weight: bold;';
}
$output[] = sprintf(
'
';
}
/**
* Extra controls to be displayed between bulk actions and pagination.
*
* @since 2.5.0
*
* @param string $which 'top' or 'bottom' table navigation.
*/
public function extra_tablenav( $which ) {
if ( 'bottom' === $which ) {
$this->tgmpa->show_tgmpa_version();
}
}
/**
* Defines the bulk actions for handling registered plugins.
*
* @since 2.2.0
*
* @return array $actions The bulk actions for the plugin install table.
*/
public function get_bulk_actions() {
$actions = array();
if ( 'update' !== $this->view_context && 'activate' !== $this->view_context ) {
if ( current_user_can( 'install_plugins' ) ) {
$actions['tgmpa-bulk-install'] = esc_attr__( 'Install', 'total-school' );
}
}
if ( 'install' !== $this->view_context ) {
if ( current_user_can( 'update_plugins' ) ) {
$actions['tgmpa-bulk-update'] = esc_attr__( 'Update', 'total-school' );
}
if ( current_user_can( 'activate_plugins' ) ) {
$actions['tgmpa-bulk-activate'] = esc_attr__( 'Activate', 'total-school' );
}
}
return $actions;
}
/**
* Processes bulk installation and activation actions.
*
* The bulk installation process looks for the $_POST information and passes that
* through if a user has to use WP_Filesystem to enter their credentials.
*
* @since 2.2.0
*/
public function process_bulk_actions() {
// Bulk installation process.
if ( 'tgmpa-bulk-install' === $this->current_action() || 'tgmpa-bulk-update' === $this->current_action() ) {
check_admin_referer( 'bulk-' . $this->_args['plural'] );
$install_type = 'install';
if ( 'tgmpa-bulk-update' === $this->current_action() ) {
$install_type = 'update';
}
$plugins_to_install = array();
// Did user actually select any plugins to install/update ?
if ( empty( $_POST['plugin'] ) ) {
if ( 'install' === $install_type ) {
$message = esc_html__( 'No plugins were selected to be installed. No action taken.', 'total-school' );
} else {
$message = esc_html__( 'No plugins were selected to be updated. No action taken.', 'total-school' );
}
echo '
', esc_html( get_admin_page_title() ), '
\n";
if ( is_wp_error( $activate ) ) {
$this->skin->error( $activate );
$this->strings['process_success'] .= $this->strings['activation_failed'];
} else {
$this->strings['process_success'] .= $this->strings['activation_success'];
}
}
}
return $bool;
}
}
}
if ( ! class_exists( 'TGMPA_Bulk_Installer_Skin' ) ) {
/**
* Installer skin to set strings for the bulk plugin installations..
*
* Extends Bulk_Upgrader_Skin and customizes to suit the installation of multiple
* plugins.
*
* @since 2.2.0
*
* {@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.}}
*
* @see https://core.trac.wordpress.org/browser/trunk/src/wp-admin/includes/class-wp-upgrader-skins.php
*
* @package TGM-Plugin-Activation
* @author Thomas Griffin
* @author Gary Jones
*/
class TGMPA_Bulk_Installer_Skin extends Bulk_Upgrader_Skin {
/**
* Holds plugin info for each individual plugin installation.
*
* @since 2.2.0
*
* @var array
*/
public $plugin_info = array();
/**
* Holds names of plugins that are undergoing bulk installations.
*
* @since 2.2.0
*
* @var array
*/
public $plugin_names = array();
/**
* Integer to use for iteration through each plugin installation.
*
* @since 2.2.0
*
* @var integer
*/
public $i = 0;
/**
* TGMPA instance
*
* @since 2.5.0
*
* @var object
*/
protected $tgmpa;
/**
* Constructor. Parses default args with new ones and extracts them for use.
*
* @since 2.2.0
*
* @param array $args Arguments to pass for use within the class.
*/
public function __construct( $args = array() ) {
// Get TGMPA class instance.
$this->tgmpa = call_user_func( array( get_class( $GLOBALS['tgmpa'] ), 'get_instance' ) );
// Parse default and new args.
$defaults = array(
'url' => '',
'nonce' => '',
'names' => array(),
'install_type' => 'install',
);
$args = wp_parse_args( $args, $defaults );
// Set plugin names to $this->plugin_names property.
$this->plugin_names = $args['names'];
// Extract the new args.
parent::__construct( $args );
}
/**
* Sets install skin strings for each individual plugin.
*
* Checks to see if the automatic activation flag is set and uses the
* the proper strings accordingly.
*
* @since 2.2.0
*/
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'] = esc_html__( 'Updating Plugin %1$s (%2$d/%3$d)', 'total-school' );
} else {
/* translators: 1: plugin name, 2: error message. */
$this->upgrader->strings['skin_update_failed_error'] = esc_html__( 'An error occurred while installing %1$s: %2$s.', 'total-school' );
/* translators: 1: plugin name. */
$this->upgrader->strings['skin_update_failed'] = esc_html__( 'The installation of %1$s failed.', 'total-school' );
if ( $this->tgmpa->is_automatic ) {
// Automatic activation strings.
$this->upgrader->strings['skin_upgrade_start'] = esc_html__( 'The installation and activation process is starting. This process may take a while on some hosts, so please be patient.', 'total-school' );
/* translators: 1: plugin name. */
$this->upgrader->strings['skin_update_successful'] = esc_html__( '%1$s installed and activated successfully.', 'total-school' ) . ' ';
$this->upgrader->strings['skin_upgrade_end'] = esc_html__( 'All installations and activations have been completed.', 'total-school' );
/* translators: 1: plugin name, 2: action number 3: total number of actions. */
$this->upgrader->strings['skin_before_update_header'] = esc_html__( 'Installing and Activating Plugin %1$s (%2$d/%3$d)', 'total-school' );
} else {
// Default installation strings.
$this->upgrader->strings['skin_upgrade_start'] = esc_html__( 'The installation process is starting. This process may take a while on some hosts, so please be patient.', 'total-school' );
/* translators: 1: plugin name. */
$this->upgrader->strings['skin_update_successful'] = esc_html__( '%1$s installed successfully.', 'total-school' ) . ' ';
$this->upgrader->strings['skin_upgrade_end'] = esc_html__( 'All installations have been completed.', 'total-school' );
/* translators: 1: plugin name, 2: action number 3: total number of actions. */
$this->upgrader->strings['skin_before_update_header'] = esc_html__( 'Installing Plugin %1$s (%2$d/%3$d)', 'total-school' );
}
}
}
/**
* Outputs the header strings and necessary JS before each plugin installation.
*
* @since 2.2.0
*
* @param string $title Unused in this implementation.
*/
public function before( $title = '' ) {
if ( empty( $title ) ) {
$title = esc_html( $this->plugin_names[ $this->i ] );
}
parent::before( $title );
}
/**
* Outputs the footer strings and necessary JS after each plugin installation.
*
* Checks for any errors and outputs them if they exist, else output
* success strings.
*
* @since 2.2.0
*
* @param string $title Unused in this implementation.
*/
public function after( $title = '' ) {
if ( empty( $title ) ) {
$title = esc_html( $this->plugin_names[ $this->i ] );
}
parent::after( $title );
$this->i++;
}
/**
* Outputs links after bulk plugin installation is complete.
*
* @since 2.2.0
*/
public function bulk_footer() {
// Serve up the string to say installations (and possibly activations) are complete.
parent::bulk_footer();
// Flush plugins cache so we can make sure that the installed plugins list is always up to date.
wp_clean_plugins_cache();
$this->tgmpa->show_tgmpa_version();
// Display message based on if all plugins are now active or not.
$update_actions = array();
if ( $this->tgmpa->is_tgmpa_complete() ) {
// All plugins are active, so we display the complete string and hide the menu to protect users.
echo '';
$update_actions['dashboard'] = sprintf(
esc_html( $this->tgmpa->strings['complete'] ),
'' . esc_html__( 'Return to the Dashboard', 'total-school' ) . ''
);
} else {
$update_actions['tgmpa_page'] = '' . esc_html( $this->tgmpa->strings['return'] ) . '';
}
/**
* Filter the list of action links available following bulk plugin installs/updates.
*
* @since 2.5.0
*
* @param array $update_actions Array of plugin action links.
* @param array $plugin_info Array of information for the last-handled plugin.
*/
$update_actions = apply_filters( 'tgmpa_update_bulk_plugins_complete_actions', $update_actions, $this->plugin_info );
if ( ! empty( $update_actions ) ) {
$this->feedback( implode( ' | ', (array) $update_actions ) );
}
}
/* *********** DEPRECATED METHODS *********** */
/**
* Flush header output buffer.
*
* @since 2.2.0
* @deprecated 2.5.0 use {@see Bulk_Upgrader_Skin::flush_output()} instead
* @see Bulk_Upgrader_Skin::flush_output()
*/
public function before_flush_output() {
_deprecated_function( __FUNCTION__, 'TGMPA 2.5.0', 'Bulk_Upgrader_Skin::flush_output()' );
$this->flush_output();
}
/**
* Flush footer output buffer and iterate $this->i to make sure the
* installation strings reference the correct plugin.
*
* @since 2.2.0
* @deprecated 2.5.0 use {@see Bulk_Upgrader_Skin::flush_output()} instead
* @see Bulk_Upgrader_Skin::flush_output()
*/
public function after_flush_output() {
_deprecated_function( __FUNCTION__, 'TGMPA 2.5.0', 'Bulk_Upgrader_Skin::flush_output()' );
$this->flush_output();
$this->i++;
}
}
}
}
}
}
if ( ! class_exists( 'TGMPA_Utils' ) ) {
/**
* Generic utilities for TGMPA.
*
* All methods are static, poor-dev name-spacing class wrapper.
*
* Class was called TGM_Utils in 2.5.0 but renamed TGMPA_Utils in 2.5.1 as this was conflicting with Soliloquy.
*
* @since 2.5.0
*
* @package TGM-Plugin-Activation
* @author Juliette Reinders Folmer
*/
class TGMPA_Utils {
/**
* Whether the PHP filter extension is enabled.
*
* @see http://php.net/book.filter
*
* @since 2.5.0
*
* @static
*
* @var bool $has_filters True is the extension is enabled.
*/
public static $has_filters;
/**
* Wrap an arbitrary string in tags. Meant to be used in combination with array_map().
*
* @since 2.5.0
*
* @static
*
* @param string $string Text to be wrapped.
* @return string
*/
public static function wrap_in_em( $string ) {
return '' . wp_kses_post( $string ) . '';
}
/**
* Wrap an arbitrary string in tags. Meant to be used in combination with array_map().
*
* @since 2.5.0
*
* @static
*
* @param string $string Text to be wrapped.
* @return string
*/
public static function wrap_in_strong( $string ) {
return '' . wp_kses_post( $string ) . '';
}
/**
* Helper function: Validate a value as boolean
*
* @since 2.5.0
*
* @static
*
* @param mixed $value Arbitrary value.
* @return bool
*/
public static function validate_bool( $value ) {
if ( ! isset( self::$has_filters ) ) {
self::$has_filters = extension_loaded( 'filter' );
}
if ( self::$has_filters ) {
return filter_var( $value, FILTER_VALIDATE_BOOLEAN );
} else {
return self::emulate_filter_bool( $value );
}
}
/**
* Helper function: Cast a value to bool
*
* @since 2.5.0
*
* @static
*
* @param mixed $value Value to cast.
* @return bool
*/
protected static function emulate_filter_bool( $value ) {
// @codingStandardsIgnoreStart
static $true = array(
'1',
'true', 'True', 'TRUE',
'y', 'Y',
'yes', 'Yes', 'YES',
'on', 'On', 'ON',
);
static $false = array(
'0',
'false', 'False', 'FALSE',
'n', 'N',
'no', 'No', 'NO',
'off', 'Off', 'OFF',
);
// @codingStandardsIgnoreEnd
if ( is_bool( $value ) ) {
return $value;
} elseif ( is_int( $value ) && ( 0 === $value || 1 === $value ) ) {
return (bool) $value;
} elseif ( ( is_float( $value ) && ! is_nan( $value ) ) && ( (float) 0 === $value || (float) 1 === $value ) ) {
return (bool) $value;
} elseif ( is_string( $value ) ) {
$value = trim( $value );
if ( in_array( $value, $true, true ) ) {
return true;
} elseif ( in_array( $value, $false, true ) ) {
return false;
} else {
return false;
}
}
return false;
}
} // End of class TGMPA_Utils
} // End of class_exists wrapper