' . $activate->get_error_message() . '
' . $this->strings['return'] . '
'; + return true; // End it here if there is an error with automatic activation + } + else { + echo '' . $this->strings['plugin_activated'] . '
'; + } + } + + // Display message based on if all plugins are now active or not. + $complete = array(); + foreach ( $this->plugins as $plugin ) { + if ( ! is_plugin_active( $plugin['file_path'] ) ) { + echo '' . $this->strings['return'] . '
'; + $complete[] = $plugin; + break; + } + // Nothing to store. + else { + $complete[] = ''; + } + } + + // Filter out any empty entries. + $complete = array_filter( $complete ); + + // All plugins are active, so we display the complete string and hide the plugin menu. + if ( empty( $complete ) ) { + echo '' . sprintf( $this->strings['complete'], '' . __( 'Return to the Dashboard', 'tgmpa' ) . '' ) . '
'; + echo ''; + } + + return true; + } + // Checks for actions from hover links to process the activation. + elseif ( isset( $_GET['plugin'] ) && ( isset( $_GET['tgmpa-activate'] ) && 'activate-plugin' == $_GET['tgmpa-activate'] ) ) { + check_admin_referer( 'tgmpa-activate', 'tgmpa-activate-nonce' ); + + // Populate $plugin array with necessary information. + $plugin['name'] = $_GET['plugin_name']; + $plugin['slug'] = $_GET['plugin']; + $plugin['source'] = $_GET['plugin_source']; + + $plugin_data = get_plugins( '/' . $plugin['slug'] ); // Retrieve all plugins. + $plugin_file = array_keys( $plugin_data ); // Retrieve all plugin files from installed plugins. + $plugin_to_activate = $plugin['slug'] . '/' . $plugin_file[0]; // Match plugin slug with appropriate plugin file. + $activate = activate_plugin( $plugin_to_activate ); // Activate the plugin. + + if ( is_wp_error( $activate ) ) { + echo '' . $activate->get_error_message() . '
' . $this->strings['return'] . '
'; + return true; // End it here if there is an error with activation. + } + else { + // Make sure message doesn't display again if bulk activation is performed immediately after a single activation. + if ( ! isset( $_POST['action'] ) ) { + $msg = $this->strings['activated_successfully'] . ' ' . $plugin['name'] . ''; + echo '' . $msg . '
' . wp_kses_post( $this->dismiss_msg ) . '
'; + } + + // Grab all plugin names. + foreach ( $message as $type => $plugin_groups ) { + $linked_plugin_groups = array(); + + // Count number of plugins in each message group to calculate singular/plural message. + $count = count( $plugin_groups ); + + // Loop through the plugin names to make the ones pulled from the .org repo linked. + foreach ( $plugin_groups as $plugin_group_single_name ) { + $external_url = $this->_get_plugin_data_from_name( $plugin_group_single_name, 'external_url' ); + $source = $this->_get_plugin_data_from_name( $plugin_group_single_name, 'source' ); + + if ( $external_url && preg_match( '|^http(s)?://|', $external_url ) ) { + $linked_plugin_groups[] = '' . $plugin_group_single_name . ''; + } + elseif ( ! $source || preg_match( '|^http://wordpress.org/extend/plugins/|', $source ) ) { + $url = add_query_arg( + array( + 'tab' => 'plugin-information', + 'plugin' => $this->_get_plugin_data_from_name( $plugin_group_single_name ), + 'TB_iframe' => 'true', + 'width' => '640', + 'height' => '500', + ), + network_admin_url( 'plugin-install.php' ) + ); + + $linked_plugin_groups[] = '' . $plugin_group_single_name . ''; + } + else { + $linked_plugin_groups[] = $plugin_group_single_name; // No hyperlink. + } + + if ( isset( $linked_plugin_groups ) && (array) $linked_plugin_groups ) { + $plugin_groups = $linked_plugin_groups; + } + } + + $last_plugin = array_pop( $plugin_groups ); // Pop off last name to prep for readability. + $imploded = empty( $plugin_groups ) ? '' . $last_plugin . '' : '' . ( implode( ', ', $plugin_groups ) . ' and ' . $last_plugin . '' ); + + $rendered .= '' . sprintf( translate_nooped_plural( $this->strings[$type], $count, 'tgmpa' ), $imploded, $count ) . '
'; + } + + // Setup variables to determine if action links are needed. + $show_install_link = $install_link ? '' . translate_nooped_plural( $this->strings['install_link'], $install_link_count, 'tgmpa' ) . '' : ''; + $show_activate_link = $activate_link ? '' . translate_nooped_plural( $this->strings['activate_link'], $activate_link_count, 'tgmpa' ) . '' : ''; + + // Define all of the action links. + $action_links = apply_filters( + 'tgmpa_notice_action_links', + array( + 'install' => ( current_user_can( 'install_plugins' ) ) ? $show_install_link : '', + 'activate' => ( current_user_can( 'activate_plugins' ) ) ? $show_activate_link : '', + 'dismiss' => $this->dismissable ? '' . $this->strings['dismiss'] . '' : '', + ) + ); + + $action_links = array_filter( $action_links ); // Remove any empty array items. + if ( $action_links ) { + $rendered .= '' . implode( ' | ', $action_links ) . '
'; + } + + // Register the nag messages and prepare them to be processed. + $nag_class = version_compare( $this->wp_version, '3.8', '<' ) ? 'updated' : 'update-nag'; + if ( ! empty( $this->strings['nag_type'] ) ) { + add_settings_error( 'tgmpa', 'tgmpa', $rendered, sanitize_html_class( strtolower( $this->strings['nag_type'] ) ) ); + } else { + add_settings_error( 'tgmpa', 'tgmpa', $rendered, $nag_class ); + } + } + + // Admin options pages already output settings_errors, so this is to avoid duplication. + if ( 'options-general' !== $current_screen->parent_base ) { + settings_errors( 'tgmpa' ); + } + + } + + /** + * Add dismissable admin notices. + * + * Appends a link to the admin nag messages. If clicked, the admin notice disappears and no longer is visible to users. + * + * @since 2.1.0 + */ + public function dismiss() { + + if ( isset( $_GET['tgmpa-dismiss'] ) ) { + update_user_meta( get_current_user_id(), 'tgmpa_dismissed_notice', 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 $plugin Array of plugin arguments. + */ + public function register( $plugin ) { + + if ( ! isset( $plugin['slug'] ) || ! isset( $plugin['name'] ) ) { + return; + } + + foreach ( $this->plugins as $registered_plugin ) { + if ( $plugin['slug'] == $registered_plugin['slug'] ) { + return; + } + } + + $this->plugins[] = $plugin; + + } + + /** + * 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( 'default_path', 'has_notices', 'dismissable', 'dismiss_msg', 'menu', 'is_automatic', 'message', 'strings' ); + + foreach ( $keys as $key ) { + if ( isset( $config[$key] ) ) { + if ( is_array( $config[$key] ) ) { + foreach ( $config[$key] as $subkey => $value ) { + $this->{$key}[$subkey] = $value; + } + } else { + $this->$key = $config[$key]; + } + } + } + + } + + /** + * Amend action link after plugin installation. + * + * @since 2.0.0 + * + * @param array $install_actions Existing array of actions. + * @return 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 + */ + public function flush_plugins_cache() { + + wp_cache_flush(); + + } + + /** + * Set file_path key for each installed plugin. + * + * @since 2.1.0 + */ + public function populate_file_path() { + + // Add file_path key for all plugins. + foreach ( $this->plugins as $plugin => $values ) { + $this->plugins[$plugin]['file_path'] = $this->_get_plugin_basename_from_slug( $values['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( 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. + */ + protected function _get_plugin_data_from_name( $name, $data = 'slug' ) { + + foreach ( $this->plugins as $plugin => $values ) { + if ( $name == $values['name'] && isset( $values[$data] ) ) { + return $values[$data]; + } + } + + return false; + + } + + /** + * 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() { + + if ( isset( $_GET['page'] ) && $this->menu === $_GET['page'] ) { + return true; + } + + return false; + + } + + /** + * Delete dismissable nag option when theme is switched. + * + * This ensures that the user is 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_user_meta( get_current_user_id(), 'tgmpa_dismissed_notice' ); + + } + + /** + * 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() { + + // Set file_path parameter for any installed plugins. + $this->populate_file_path(); + + $installed_plugins = get_plugins(); + + foreach ( $this->plugins as $plugin ) { + // Oops, plugin isn't there so iterate to next condition. + if ( isset( $plugin['force_activation'] ) && $plugin['force_activation'] && ! isset( $installed_plugins[$plugin['file_path']] ) ) { + continue; + } + // There we go, activate the plugin. + elseif ( isset( $plugin['force_activation'] ) && $plugin['force_activation'] && is_plugin_inactive( $plugin['file_path'] ) ) { + activate_plugin( $plugin['file_path'] ); + } + } + + } + + /** + * Forces plugin deactivation if the parameter 'force_deactivation' + * is set to true. + * + * This allows theme authors to specify certain plugins that must be + * deactived 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() { + + // Set file_path parameter for any installed plugins. + $this->populate_file_path(); + + foreach ( $this->plugins as $plugin ) { + // Only proceed forward if the paramter is set to true and plugin is active. + if ( isset( $plugin['force_deactivation'] ) && $plugin['force_deactivation'] && is_plugin_active( $plugin['file_path'] ) ) { + deactivate_plugins( $plugin['file_path'] ); + } + } + + } + + /** + * Returns the singleton instance of the class. + * + * @since 2.4.0 + * + * @return object The TGM_Plugin_Activation object. + */ + public static function get_instance() { + + if ( ! isset( self::$instance ) && ! ( self::$instance instanceof TGM_Plugin_Activation ) ) { + self::$instance = new TGM_Plugin_Activation(); + } + + return self::$instance; + + } + + } + + // Ensure only one instance of the class is ever invoked. + $tgmpa = TGM_Plugin_Activation::get_instance(); + +} + +if ( ! function_exists( 'tgmpa' ) ) { + /** + * Helper function to register a collection of required plugins. + * + * @since 2.0.0 + * @api + * + * @param array $plugins An array of plugin arrays. + * @param array $config Optional. An array of configuration values. + */ + function tgmpa( $plugins, $config = array() ) { + + foreach ( $plugins as $plugin ) { + TGM_Plugin_Activation::$instance->register( $plugin ); + } + + if ( $config ) { + TGM_Plugin_Activation::$instance->config( $config ); + } + + } +} + +/** + * WP_List_Table isn't always available. If it isn't available, + * we load it here. + * + * @since 2.2.0 + */ +if ( ! class_exists( 'WP_List_Table' ) ) { + require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' ); +} + +if ( ! class_exists( 'TGMPA_List_Table' ) ) { + /** + * List table class for handling plugins. + * + * Extends the WP_List_Table class to provide a future-compatible + * way of listing out all required/recommended plugins. + * + * Gives users an interface similar to the Plugin Administration + * area with similar (albeit stripped down) capabilities. + * + * This class also allows for the bulk install of plugins. + * + * @since 2.2.0 + * + * @package TGM-Plugin-Activation + * @author Thomas Griffin' . $activate->get_error_message() . '
%1$s %2$s
' . sprintf( $this->upgrader->strings['skin_update_failed_error'], $this->plugin_names[$this->i], $this->error ) . '
' . sprintf( $this->upgrader->strings['skin_update_failed'], $this->plugin_names[$this->i] ) . '
' . sprintf( $this->upgrader->strings['skin_update_successful'], $this->plugin_names[$this->i], 'jQuery(\'#progress-' . esc_js( $this->upgrader->update_current ) . '\').toggle();jQuery(\'span\', this).toggle(); return false;' ) . '
' . TGM_Plugin_Activation::$instance->strings['return'] . '
'; + $complete[] = $plugin; + break; + } + // Nothing to store. + else { + $complete[] = ''; + } + } + + // Filter out any empty entries. + $complete = array_filter( $complete ); + + // All plugins are active, so we display the complete string and hide the menu to protect users. + if ( empty( $complete ) ) { + echo '' . sprintf( TGM_Plugin_Activation::$instance->strings['complete'], '' . __( 'Return to the Dashboard', 'tgmpa' ) . '' ) . '
'; + echo ''; + } + + } + + /** + * Flush header output buffer. + * + * @since 2.2.0 + */ + public function before_flush_output() { + + wp_ob_end_flush_all(); + flush(); + + } + + /** + * Flush footer output buffer and iterate $this->i to make sure the + * installation strings reference the correct plugin. + * + * @since 2.2.0 + */ + public function after_flush_output() { + + wp_ob_end_flush_all(); + flush(); + $this->i++; + + } + + } + } +} \ No newline at end of file diff --git a/scratch-parent/TGM-Plugin-Activation/example.php b/scratch-parent/TGM-Plugin-Activation/example.php new file mode 100755 index 0000000..f2eb586 --- /dev/null +++ b/scratch-parent/TGM-Plugin-Activation/example.php @@ -0,0 +1,114 @@ + + * @author Gary JonesGet started here.', 'unyson' ), admin_url( 'post-new.php' ) ); ?>
+ + + + + + + + + + + + +
+ +
+ + 1 && get_option( 'page_comments' ) ) : ?> + + + ++ 'ol', + 'short_ping' => true, + 'avatar_size'=> 34, + ) ); + ?> +
+ + 1 && get_option( 'page_comments' ) ) : ?> + + + + + + + + + + + +