wp_version = $GLOBALS['wp_version']; do_action_ref_array( 'tgmpa_init', array( $this ) ); add_action( 'init', array( $this, 'init' ) ); } public function __set( $name, $value ) { return; } public function __get( $name ) { return $this->{$name}; } public function init() { if ( true !== apply_filters( 'tgmpa_load', ( is_admin() && !defined( 'DOING_AJAX' ) ) ) ) { return; } $this->strings = array( 'page_title' => __( 'Install Required Plugins', 'bands' ), 'menu_title' => __( 'Install Plugins', 'bands' ), 'installing' => __( 'Installing Plugin: %s', 'bands' ), 'updating' => __( 'Updating Plugin: %s', 'bands' ), 'oops' => __( 'Something went wrong with the plugin API.', 'bands' ), 'notice_can_install_required' => _n_noop( 'This theme requires the following plugin: %1$s.', 'This theme requires the following plugins: %1$s.', 'bands' ), 'notice_can_install_recommended' => _n_noop( 'This theme recommends the following plugin: %1$s.', 'This theme recommends the following plugins: %1$s.', 'bands' ), 'notice_ask_to_update' => _n_noop( '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.', 'bands' ), 'notice_ask_to_update_maybe' => _n_noop( 'There is an update available for: %1$s.', 'There are updates available for the following plugins: %1$s.', 'bands' ), 'notice_can_activate_required' => _n_noop( 'The following required plugin is currently inactive: %1$s.', 'The following required plugins are currently inactive: %1$s.', 'bands' ), 'notice_can_activate_recommended' => _n_noop( 'The following recommended plugin is currently inactive: %1$s.', 'The following recommended plugins are currently inactive: %1$s.', 'bands' ), 'install_link' => _n_noop( 'Begin installing plugin', 'Begin installing plugins', 'bands' ), 'update_link' => _n_noop( 'Begin updating plugin', 'Begin updating plugins', 'bands' ), 'activate_link' => _n_noop( 'Begin activating plugin', 'Begin activating plugins', 'bands' ), 'return' => __( 'Return to Required Plugins Installer', 'bands' ), 'dashboard' => __( 'Return to the Dashboard', 'bands' ), 'plugin_activated' => __( 'Plugin activated successfully.', 'bands' ), 'activated_successfully' => __( 'The following plugin was activated successfully:', 'bands' ), 'plugin_already_active' => __( 'No action taken. Plugin %1$s was already active.', 'bands' ), 'plugin_needs_higher_version' => __( 'Plugin not activated. A higher version of %s is needed for this theme. Please update the plugin.', 'bands' ), 'complete' => __( 'All plugins installed and activated successfully. %1$s', 'bands' ), 'dismiss' => __( 'Dismiss this notice', 'bands' ), 'notice_cannot_install_activate' => __( 'There are one or more required or recommended plugins to install, update or activate.', 'bands' ), 'contact_admin' => __( 'Please contact the administrator of this site for help.', 'bands' ), ); do_action( 'tgmpa_register' ); if ( empty( $this->plugins ) || !is_array( $this->plugins ) ) { return; } if ( true !== $this->is_tgmpa_complete() ) { array_multisort( $this->sort_order, SORT_ASC, $this->plugins ); add_action( 'admin_menu', array( $this, 'admin_menu' ) ); add_action( 'admin_head', array( $this, 'dismiss' ) ); 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' ) ); } } add_action( 'load-plugins.php', array( $this, 'add_plugin_action_link_filters' ), 1 ); add_action( 'switch_theme', array( $this, 'flush_plugins_cache' ) ); if ( $this->has_notices ) { add_action( 'switch_theme', array( $this, 'update_dismiss' ) ); } if ( true === $this->has_forced_activation ) { add_action( 'admin_init', array( $this, 'force_activation' ) ); } if ( true === $this->has_forced_deactivation ) { add_action( 'switch_theme', array( $this, 'force_deactivation' ) ); } } 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 ); } } } public function filter_plugin_action_links_activate( $actions ) { unset( $actions['activate'] ); return $actions; } public function filter_plugin_action_links_deactivate( $actions ) { unset( $actions['deactivate'] ); return $actions; } 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.', 'bands' ), esc_html__( 'Update Required', 'bands' ) ); return $actions; } public function admin_init() { if ( !$this->is_tgmpa_page() ) { return; } if ( isset( $_REQUEST['tab'] ) && 'plugin-information' === $_REQUEST['tab'] ) { require_once ABSPATH . 'wp-admin/includes/plugin-install.php'; wp_enqueue_style( 'plugin-install' ); global $tab, $body_id; $body_id = 'plugin-information'; $tab = 'plugin-information'; install_plugin_information(); exit; } } public function thickbox() { if ( !get_user_meta( get_current_user_id(), 'tgmpa_dismissed_notice_' . $this->id, true ) ) { add_thickbox(); } } public function admin_menu() { if ( !current_user_can( 'install_plugins' ) ) { return; } $args = apply_filters( 'tgmpa_admin_menu_args', array( 'parent_slug' => $this->parent_slug, 'page_title' => $this->strings['page_title'], 'menu_title' => $this->strings['menu_title'], 'capability' => $this->capability, 'menu_slug' => $this->menu, 'function' => array( $this, 'install_plugins_page' ), ) ); $this->add_admin_menu( $args ); } 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'] ); } public function install_plugins_page() { $plugin_table = new TGMPA_List_Table; 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; } wp_clean_plugins_cache( false ); ?>
', sprintf( esc_html( $this->strings['complete'] ), '' . esc_html__( 'Return to the Dashboard', 'bands' ) . '' ), '
'; echo ''; } else { echo '', esc_html( $this->strings['return'] ), '
'; } return true; } elseif ( isset( $this->plugins[ $slug ]['file_path'], $_GET['tgmpa-activate'] ) && 'activate-plugin' === $_GET['tgmpa-activate'] ) { check_admin_referer( 'tgmpa-activate', 'tgmpa-nonce' ); if ( false === $this->activate_single_plugin( $this->plugins[ $slug ]['file_path'], $slug ) ) { return true; } } return false; } public function inject_update_info( $plugins ) { $repo_updates = get_site_transient( 'update_plugins' ); if ( !is_object( $repo_updates ) ) { $repo_updates = new stdClass; } foreach ( $plugins as $slug => $plugin ) { $file_path = $plugin['file_path']; if ( empty( $repo_updates->response[ $file_path ] ) ) { $repo_updates->response[ $file_path ] = new stdClass; } $repo_updates->response[ $file_path ]->slug = $slug; $repo_updates->response[ $file_path ]->plugin = $file_path; $repo_updates->response[ $file_path ]->new_version = $plugin['version']; $repo_updates->response[ $file_path ]->package = $plugin['source']; if ( empty( $repo_updates->response[ $file_path ]->url ) && !empty( $plugin['external_url'] ) ) { $repo_updates->response[ $file_path ]->url = $plugin['external_url']; } } set_site_transient( 'update_plugins', $repo_updates ); } public function maybe_adjust_source_dir( $source, $remote_source, $upgrader ) { if ( !$this->is_tgmpa_page() || !is_object( $GLOBALS['wp_filesystem'] ) ) { return $source; } $source_files = array_keys( $GLOBALS['wp_filesystem']->dirlist( $remote_source ) ); if ( 1 === count( $source_files ) && false === $GLOBALS['wp_filesystem']->is_dir( $source ) ) { return $source; } $desired_slug = ''; if ( false === $upgrader->bulk && !empty( $upgrader->skin->options['extra']['slug'] ) ) { $desired_slug = $upgrader->skin->options['extra']['slug']; } else { foreach ( $this->plugins as $slug => $plugin ) { if ( !empty( $upgrader->skin->plugin_names[ $upgrader->skin->i ] ) && $plugin['name'] === $upgrader->skin->plugin_names[ $upgrader->skin->i ] ) { $desired_slug = $slug; break; } } unset( $slug, $plugin ); } if ( !empty( $desired_slug ) ) { $subdir_name = untrailingslashit( str_replace( trailingslashit( $remote_source ), '', $source ) ); if ( !empty( $subdir_name ) && $subdir_name !== $desired_slug ) { $from_path = untrailingslashit( $source ); $to_path = trailingslashit( $remote_source ) . $desired_slug; 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.', 'bands' ) . ' ' . esc_html__( 'Please contact the plugin provider and ask them to package their plugin according to the WordPress guidelines.', 'bands' ), array( 'found' => $subdir_name, 'expected' => $desired_slug ) ); } } elseif ( empty( $subdir_name ) ) { return new WP_Error( 'packaged_wrong', esc_html__( 'The remote plugin package consists of more than one file, but the files are not packaged in a folder.', 'bands' ) . ' ' . esc_html__( 'Please contact the plugin provider and ask them to package their plugin according to the WordPress guidelines.', 'bands' ), array( 'found' => $subdir_name, 'expected' => $desired_slug ) ); } } return $source; } protected function activate_single_plugin( $file_path, $slug, $automatic = false ) { if ( $this->can_plugin_activate( $slug ) ) { $activate = activate_plugin( $file_path ); if ( is_wp_error( $activate ) ) { echo '', wp_kses_post( $activate->get_error_message() ), '
', esc_html( $this->strings['return'] ), '
'; return false; } else { if ( !$automatic ) { if ( !isset( $_POST['action'] ) ) { echo '', esc_html( $this->strings['activated_successfully'] ), ' ', esc_html( $this->plugins[ $slug ]['name'] ), '.
', esc_html( $this->strings['plugin_activated'] ), '
'; } } } elseif ( $this->is_plugin_active( $slug ) ) { echo '', 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'] ) ), '
'; } } return true; } public function notices() { 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; } $message = array(); $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 ) ) { continue; } if ( !$this->is_plugin_installed( $slug ) ) { if ( current_user_can( 'install_plugins' ) ) { $install_link_count++; if ( true === $plugin['required'] ) { $message['notice_can_install_required'][] = $slug; } else { $message['notice_can_install_recommended'][] = $slug; } } if ( true === $plugin['required'] ) { $total_required_action_count++; } } else { if ( !$this->is_plugin_active( $slug ) && $this->can_plugin_activate( $slug ) ) { if ( current_user_can( 'activate_plugins' ) ) { $activate_link_count++; if ( true === $plugin['required'] ) { $message['notice_can_activate_required'][] = $slug; } else { $message['notice_can_activate_recommended'][] = $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( 'update_plugins' ) ) { $update_link_count++; if ( $this->does_plugin_require_update( $slug ) ) { $message['notice_ask_to_update'][] = $slug; } elseif ( false !== $this->does_plugin_have_update( $slug ) ) { $message['notice_ask_to_update_maybe'][] = $slug; } } if ( true === $plugin['required'] ) { $total_required_action_count++; } } } } unset( $slug, $plugin ); if ( !empty( $message ) || $total_required_action_count > 0 ) { krsort( $message ); $rendered = ''; $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 ( $this->dismissable && !empty( $this->dismiss_msg ) ) { $rendered .= sprintf( $line_template, wp_kses_post( $this->dismiss_msg ) ); } foreach ( $message as $type => $plugin_group ) { $linked_plugins = array(); 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 ); $imploded = empty( $linked_plugins ) ? $last_plugin : ( implode( ', ', $linked_plugins ) . ' ' . esc_html_x( 'and', 'plugin A *and* plugin B', 'bands' ) . ' ' . $last_plugin ); $rendered .= sprintf( $line_template, sprintf( translate_nooped_plural( $this->strings[ $type ], $count, 'bands' ), $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 ); } add_settings_error( 'tgmpa', 'tgmpa', $rendered, $this->get_admin_notice_class() ); } if ( 'options-general' !== $GLOBALS['current_screen']->parent_base ) { $this->display_settings_errors(); } } protected function create_user_action_links_for_notice( $install_count, $update_count, $activate_count, $line_template ) { $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, 'bands' ), 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, 'bands' ), 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, 'bands' ), 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 ); if ( !empty( $action_links ) ) { $action_links = sprintf( $line_template, implode( ' | ', $action_links ) ); return apply_filters( 'tgmpa_notice_rendered_action_links', $action_links ); } else { return ''; } } 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'; } } } 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; } } } 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 ); } } 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' => '', 'slug' => '', 'source' => 'repo', 'required' => false, 'version' => '', 'force_activation' => false, 'force_deactivation' => false, 'external_url' => '', 'is_callable' => '', ); $plugin = wp_parse_args( $plugin, $defaults ); $plugin['slug'] = $this->sanitize_key( $plugin['slug'] ); $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'] ); $plugin['file_path'] = $this->_get_plugin_basename_from_slug( $plugin['slug'] ); $plugin['source_type'] = $this->get_plugin_source_type( $plugin['source'] ); $this->plugins[ $plugin['slug'] ] = $plugin; $this->sort_order[ $plugin['slug'] ] = $plugin['name']; if ( true === $plugin['force_activation'] ) { $this->has_forced_activation = true; } if ( true === $plugin['force_deactivation'] ) { $this->has_forced_deactivation = true; } } 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'; } } public function sanitize_key( $key ) { $raw_key = $key; $key = preg_replace( '`[^A-Za-z0-9_-]`', '', $key ); return apply_filters( 'tgmpa_sanitize_key', $key, $raw_key ); } 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 ]; } } } } public function actions( $install_actions ) { if ( $this->is_tgmpa_page() ) { return false; } return $install_actions; } public function flush_plugins_cache( $clear_update_cache = true ) { wp_clean_plugins_cache( $clear_update_cache ); } 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 { foreach ( $this->plugins as $slug => $values ) { $this->plugins[ $slug ]['file_path'] = $this->_get_plugin_basename_from_slug( $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; } 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; } 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; } 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; } protected function get_plugins_api( $slug ) { static $api = array(); 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 ]; } 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'] ); } return $link; } protected function is_tgmpa_page() { return isset( $_GET['page'] ) && $this->menu === $_GET['page']; } protected function is_core_update_page() { if ( !function_exists( 'get_current_screen' ) ) { return false; } $screen = get_current_screen(); if ( 'update-core' === $screen->base ) { return true; } elseif ( 'plugins' === $screen->base && !empty( $_POST['action'] ) ) { return true; } elseif ( 'update' === $screen->base && !empty( $_POST['action'] ) ) { return true; } return false; } 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; } public function get_tgmpa_status_url( $status ) { return add_query_arg( array( 'plugin_status' => urlencode( $status ), ), $this->get_tgmpa_url() ); } 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; } public function is_plugin_installed( $slug ) { $installed_plugins = $this->get_plugins(); return ( !empty( $installed_plugins[ $this->plugins[ $slug ]['file_path'] ] ) ); } 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'] ) ); } public function can_plugin_update( $slug ) { 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, '>=' ); } return true; } 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 ) ); } } public function can_plugin_activate( $slug ) { return ( !$this->is_plugin_active( $slug ) && !$this->does_plugin_require_update( $slug ) ); } public function get_installed_version( $slug ) { $installed_plugins = $this->get_plugins(); if ( !empty( $installed_plugins[ $this->plugins[ $slug ]['file_path'] ]['Version'] ) ) { return $installed_plugins[ $this->plugins[ $slug ]['file_path'] ]['Version']; } return ''; } 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, '>' ); } public function does_plugin_have_update( $slug ) { 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; } public function get_upgrade_notice( $slug ) { 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 ''; } public function get_plugins( $plugin_folder = '' ) { if ( !function_exists( 'get_plugins' ) ) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } return get_plugins( $plugin_folder ); } public function update_dismiss() { delete_metadata( 'user', null, 'tgmpa_dismissed_notice_' . $this->id, null, true ); } public function force_activation() { foreach ( $this->plugins as $slug => $plugin ) { if ( true === $plugin['force_activation'] ) { if ( !$this->is_plugin_installed( $slug ) ) { continue; } elseif ( $this->can_plugin_activate( $slug ) ) { activate_plugin( $plugin['file_path'] ); } } } } public function force_deactivation() { $deactivated = array(); foreach ( $this->plugins as $slug => $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' ) ); } } public function show_tgmpa_version() { echo '', esc_html( sprintf( __( 'TGMPA v%s', 'bands' ), self::TGMPA_VERSION ) ), '
'; } public static function get_instance() { if ( !isset( self::$instance ) && !( self::$instance instanceof self ) ) { self::$instance = new self(); } return self::$instance; } } if ( !function_exists( 'load_tgm_plugin_activation' ) ) { function load_tgm_plugin_activation() { $GLOBALS['tgmpa'] = TGM_Plugin_Activation::get_instance(); } } if ( did_action( 'plugins_loaded' ) ) { load_tgm_plugin_activation(); } else { add_action( 'plugins_loaded', 'load_tgm_plugin_activation' ); } } if ( !function_exists( 'tgmpa' ) ) { function tgmpa( $plugins, $config = array() ) { $instance = call_user_func( array( get_class( $GLOBALS['tgmpa'] ), 'get_instance' ) ); foreach ( $plugins as $plugin ) { call_user_func( array( $instance, 'register' ), $plugin ); } if ( !empty( $config ) && is_array( $config ) ) { if ( isset( $config['notices'] ) ) { _deprecated_argument( __FUNCTION__, '2.2.0', 'The `notices` config parameter was renamed to `has_notices` in TGMPA 2.2.0. Please adjust your configuration.' ); if ( !isset( $config['has_notices'] ) ) { $config['has_notices'] = $config['notices']; } } if ( isset( $config['parent_menu_slug'] ) ) { _deprecated_argument( __FUNCTION__, '2.4.0', 'The `parent_menu_slug` config parameter was removed in TGMPA 2.4.0. In TGMPA 2.5.0 an alternative was (re-)introduced. Please adjust your configuration. For more information visit the website: http://tgmpluginactivation.com/configuration/#h-configuration-options.' ); } if ( isset( $config['parent_url_slug'] ) ) { _deprecated_argument( __FUNCTION__, '2.4.0', 'The `parent_url_slug` config parameter was removed in TGMPA 2.4.0. In TGMPA 2.5.0 an alternative was (re-)introduced. Please adjust your configuration. For more information visit the website: http://tgmpluginactivation.com/configuration/#h-configuration-options.' ); } call_user_func( array( $instance, 'config' ), $config ); } } } if ( !class_exists( 'WP_List_Table' ) ) { require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; } if ( !class_exists( 'TGMPA_List_Table' ) ) { class TGMPA_List_Table extends WP_List_Table { protected $tgmpa; public $view_context = 'all'; protected $view_totals = array( 'all' => 0, 'install' => 0, 'update' => 0, 'activate' => 0, ); public function __construct() { $this->tgmpa = call_user_func( array( get_class( $GLOBALS['tgmpa'] ), 'get_instance' ) ); parent::__construct( array( 'singular' => 'plugin', 'plural' => 'plugins', 'ajax' => false, ) ); if ( isset( $_REQUEST['plugin_status'] ) && in_array( $_REQUEST['plugin_status'], array( 'install', 'update', 'activate' ), true ) ) { $this->view_context = sanitize_key( $_REQUEST['plugin_status'] ); } add_filter( 'tgmpa_table_data_items', array( $this, 'sort_table_items' ) ); } public function get_table_classes() { return array( 'widefat', 'fixed' ); } protected function _gather_plugin_data() { $this->tgmpa->admin_init(); $this->tgmpa->thickbox(); $plugins = $this->categorize_plugins_to_views(); $this->set_view_totals( $plugins ); $table_data = array(); $i = 0; 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 ); $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; } protected function categorize_plugins_to_views() { $plugins = array( 'all' => array(), '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 ) ) { 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; } protected function set_view_totals( $plugins ) { foreach ( $plugins as $type => $list ) { $this->view_totals[ $type ] = count( $list ); } } protected function get_plugin_advise_type_text( $required ) { if ( true === $required ) { return __( 'Required', 'bands' ); } return __( 'Recommended', 'bands' ); } protected function get_plugin_source_type_text( $type ) { $string = ''; switch ( $type ) { case 'repo': $string = __( 'WordPress Repository', 'bands' ); break; case 'external': $string = __( 'External Source', 'bands' ); break; case 'bundled': $string = __( 'Pre-Packaged', 'bands' ); break; } return $string; } protected function get_plugin_status_text( $slug ) { if ( !$this->tgmpa->is_plugin_installed( $slug ) ) { return __( 'Not Installed', 'bands' ); } if ( !$this->tgmpa->is_plugin_active( $slug ) ) { $install_status = __( 'Installed But Not Activated', 'bands' ); } else { $install_status = __( 'Active', 'bands' ); } $update_status = ''; if ( $this->tgmpa->does_plugin_require_update( $slug ) && false === $this->tgmpa->does_plugin_have_update( $slug ) ) { $update_status = __( 'Required Update not Available', 'bands' ); } elseif ( $this->tgmpa->does_plugin_require_update( $slug ) ) { $update_status = __( 'Requires Update', 'bands' ); } elseif ( false !== $this->tgmpa->does_plugin_have_update( $slug ) ) { $update_status = __( 'Update recommended', 'bands' ); } if ( '' === $update_status ) { return $install_status; } return sprintf( _x( '%1$s, %2$s', 'Install/Update Status', 'bands' ), $install_status, $update_status ); } public function sort_table_items( $items ) { $type = array(); $name = array(); foreach ( $items as $i => $plugin ) { $type[ $i ] = $plugin['type']; $name[ $i ] = $plugin['sanitized_plugin']; } array_multisort( $type, SORT_DESC, $name, SORT_ASC, $items ); return $items; } public function get_views() { $status_links = array(); foreach ( $this->view_totals as $type => $count ) { if ( $count < 1 ) { continue; } switch ( $type ) { case 'all': $text = _nx( 'All (%s)', 'All (%s)', $count, 'plugins', 'bands' ); break; case 'install': $text = _n( 'To Install (%s)', 'To Install (%s)', $count, 'bands' ); break; case 'update': $text = _n( 'Update Available (%s)', 'Update Available (%s)', $count, 'bands' ); break; case 'activate': $text = _n( 'To Activate (%s)', 'To Activate (%s)', $count, 'bands' ); 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; } public function column_default( $item, $column_name ) { return $item[ $column_name ]; } public function column_cb( $item ) { return sprintf( '', esc_attr( $this->_args['singular'] ), esc_attr( $item['slug'] ), esc_attr( $item['sanitized_plugin'] ) ); } public function column_plugin( $item ) { return sprintf( '%1$s %2$s', $item['plugin'], $this->row_actions( $this->get_row_actions( $item ), true ) ); } 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"', 'bands' ); $color = ''; if ( !empty( $item['minimum_version'] ) && $this->tgmpa->does_plugin_require_update( $item['slug'] ) ) { $color = ' color: #ff0000; font-weight: bold;'; } $output[] = sprintf( '%2$s' . __( 'Installed version:', 'bands' ) . '
', $color, $installed ); } if ( !empty( $item['minimum_version'] ) ) { $output[] = sprintf( '%1$s' . __( 'Minimum required version:', 'bands' ) . '
', $item['minimum_version'] ); } if ( !empty( $item['available_version'] ) ) { $color = ''; if ( !empty( $item['minimum_version'] ) && version_compare( $item['available_version'], $item['minimum_version'], '>=' ) ) { $color = ' color: #71C671; font-weight: bold;'; } $output[] = sprintf( '%2$s' . __( 'Available version:', 'bands' ) . '
', $color, $item['available_version'] ); } if ( empty( $output ) ) { return ' '; } else { return implode( "\n", $output ); } } public function no_items() { echo esc_html__( 'No plugins to install, update or activate.', 'bands' ) . ' ' . esc_html__( 'Return to the Dashboard', 'bands' ) . ''; echo ''; } public function get_columns() { $columns = array( 'cb' => '', 'plugin' => __( 'Plugin', 'bands' ), 'source' => __( 'Source', 'bands' ), 'type' => __( 'Type', 'bands' ), ); if ( 'all' === $this->view_context || 'update' === $this->view_context ) { $columns['version'] = __( 'Version', 'bands' ); $columns['status'] = __( 'Status', 'bands' ); } return apply_filters( 'tgmpa_table_columns', $columns ); } protected function get_default_primary_column_name() { return 'plugin'; } protected function get_primary_column_name() { if ( method_exists( 'WP_List_Table', 'get_primary_column_name' ) ) { return parent::get_primary_column_name(); } else { return $this->get_default_primary_column_name(); } } protected function get_row_actions( $item ) { $actions = array(); $action_links = array(); if ( !$this->tgmpa->is_plugin_installed( $item['slug'] ) ) { $actions['install'] = __( 'Install %2$s', 'bands' ); } else { if ( false !== $this->tgmpa->does_plugin_have_update( $item['slug'] ) && $this->tgmpa->can_plugin_update( $item['slug'] ) ) { $actions['update'] = __( 'Update %2$s', 'bands' ); } if ( $this->tgmpa->can_plugin_activate( $item['slug'] ) ) { $actions['activate'] = __( 'Activate %2$s', 'bands' ); } } foreach ( $actions as $action => $text ) { $nonce_url = wp_nonce_url( add_query_arg( array( 'plugin' => urlencode( $item['slug'] ), 'tgmpa-' . $action => $action . '-plugin', ), $this->tgmpa->get_tgmpa_url() ), 'tgmpa-' . $action, 'tgmpa-nonce' ); $action_links[ $action ] = sprintf( '' . esc_html( $text ) . '', esc_url( $nonce_url ), '' . esc_html( $item['sanitized_plugin'] ) . '' ); } $prefix = ( defined( 'WP_NETWORK_ADMIN' ) && WP_NETWORK_ADMIN ) ? 'network_admin_' : ''; return apply_filters( "tgmpa_{$prefix}plugin_action_links", array_filter( $action_links ), $item['slug'], $item, $this->view_context ); } public function single_row( $item ) { parent::single_row( $item ); do_action( "tgmpa_after_plugin_row_{$item['slug']}", $item['slug'], $item, $this->view_context ); } public function wp_plugin_update_row( $slug, $item ) { if ( empty( $item['upgrade_notice'] ) ) { return; } echo '', esc_html( $message ), '
', esc_html( $message ), '
', esc_html__( 'No plugins were selected to be activated. No action taken.', 'bands' ), '
', esc_html__( 'No plugins are available to be activated at this time.', 'bands' ), '
', wp_kses_post( $activate->get_error_message() ), '
%1$s %2$s.