wp_version = $wp_version; // Announce that the class is ready, and pass the object (for advanced use). do_action_ref_array( 'generator_init', array( $this ) ); // When the rest of WP has loaded, kick-start the rest of the class. add_action( 'init', array( $this, 'init' ) ); } /* Initialise the interactions between this class and WordPress.*/ public function init() { // Load class strings. $this->strings = array( 'page_title' => __( 'Install Required Plugins', 'generator' ), 'menu_title' => __( 'Install Plugins', 'generator' ), 'installing' => __( 'Installing Plugin: %s', 'generator' ), 'oops' => __( 'Something went wrong.', 'generator' ), 'notice_can_install_required' => _n_noop( 'This theme requires the following plugin: %1$s.', 'This theme requires the following plugins: %1$s.', 'generator' ), 'notice_can_install_recommended' => _n_noop( 'This theme recommends the following plugin: %1$s.', 'This theme recommends the following plugins: %1$s.', 'generator' ), 'notice_cannot_install' => _n_noop( 'Sorry, but you do not have the correct permissions to install the %s plugin. Contact the administrator of this site for help on getting the plugin installed.', 'Sorry, but you do not have the correct permissions to install the %s plugins. Contact the administrator of this site for help on getting the plugins installed.', 'generator' ), 'notice_can_activate_required' => _n_noop( 'The following required plugin is currently inactive: %1$s.', 'The following required plugins are currently inactive: %1$s.', 'generator' ), 'notice_can_activate_recommended'=> _n_noop( 'The following recommended plugin is currently inactive: %1$s.', 'The following recommended plugins are currently inactive: %1$s.', 'generator' ), 'notice_cannot_activate' => _n_noop( 'Sorry, but you do not have the correct permissions to activate the %s plugin. Contact the administrator of this site for help on getting the plugin activated.', 'Sorry, but you do not have the correct permissions to activate the %s plugins. Contact the administrator of this site for help on getting the plugins activated.', 'generator' ), '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.', 'generator' ), 'notice_cannot_update' => _n_noop( 'Sorry, but you do not have the correct permissions to update the %s plugin. Contact the administrator of this site for help on getting the plugin updated.', 'Sorry, but you do not have the correct permissions to update the %s plugins. Contact the administrator of this site for help on getting the plugins updated.', 'generator' ), 'install_link' => _n_noop( 'Begin installing plugin', 'Begin installing plugins', 'generator' ), 'activate_link' => _n_noop( 'Begin activating plugin', 'Begin activating plugins', 'generator' ), 'return' => __( 'Return to Required Plugins Installer', 'generator' ), 'dashboard' => __( 'Return to the dashboard', 'generator' ), 'plugin_activated' => __( 'Plugin activated successfully.', 'generator' ), 'activated_successfully' => __( 'The following plugin was activated successfully:', 'generator' ), 'complete' => __( 'All plugins installed and activated successfully. %1$s', 'generator' ), 'dismiss' => __( 'Dismiss this notice', 'generator' ), ); do_action( 'generator_register' ); // After this point, the plugins should be registered and the configuration set. if ( $this->plugins ) { $sorted = array(); foreach ( $this->plugins as $plugin ) { $sorted[] = $plugin['name']; } array_multisort( $sorted, 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_action( 'switch_theme', array( $this, 'flush_plugins_cache' ) ); // Load admin bar in the header to remove flash when installing plugins. if ( $this->is_generator_page() ) { remove_action( 'wp_footer', 'wp_admin_bar_render', 1000 ); remove_action( 'admin_footer', 'wp_admin_bar_render', 1000 ); add_action( 'wp_head', 'wp_admin_bar_render', 1000 ); add_action( 'admin_head', 'wp_admin_bar_render', 1000 ); } 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( 'switch_theme', array( $this, 'update_dismiss' ) ); } // Setup the force activation hook. foreach ( $this->plugins as $plugin ) { if ( isset( $plugin['force_activation'] ) && true === $plugin['force_activation'] ) { add_action( 'admin_init', array( $this, 'force_activation' ) ); break; } } // Setup the force deactivation hook. foreach ( $this->plugins as $plugin ) { if ( isset( $plugin['force_deactivation'] ) && true === $plugin['force_deactivation'] ) { add_action( 'switch_theme', array( $this, 'force_deactivation' ) ); break; } } } } /* Handles calls to show plugin information via links in the notices.*/ public function admin_init() { if ( ! $this->is_generator_page() ) { return; } if ( isset( $_REQUEST['tab'] ) && 'plugin-information' == $_REQUEST['tab'] ) { require_once ABSPATH . 'wp-admin/includes/plugin-install.php'; // Need for install_plugin_information(). wp_enqueue_style( 'plugin-install' ); global $tab, $body_id; $body_id = $tab = 'plugin-information'; install_plugin_information(); exit; } } /* Enqueues thickbox scripts/styles for plugin info. */ public function thickbox() { if ( ! get_user_meta( get_current_user_id(), 'generator_dismissed_notice_' . $this->id, true ) ) { add_thickbox(); } } /* Adds submenu page under 'Appearance' tab. */ public function admin_menu() { // Make sure privileges are correct to see the page if ( ! current_user_can( 'install_plugins' ) ) { return; } $this->populate_file_path(); foreach ( $this->plugins as $plugin ) { if ( ! is_plugin_active( $plugin['file_path'] ) ) { add_theme_page( $this->strings['page_title'], // Page title. $this->strings['menu_title'], // Menu title. 'edit_theme_options', // Capability. $this->menu, // Menu slug. array( $this, 'install_plugins_page' ) // Callback. ); break; } } } /* Echoes plugin installation form.*/ public function install_plugins_page() { // Store new instance of plugin table in object. $plugin_table = new generatorPA_List_Table; // Return early if processing a plugin installation action. if ( isset( $_POST['action'] ) && 'generator-bulk-install' == $_POST['action'] && $plugin_table->process_bulk_actions() || $this->do_plugin_install() ) { return; } ?>
' . $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; } 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', 'generator' ) . '' ) . '
'; echo ''; } return true; } // Checks for actions from hover links to process the activation. elseif ( isset( $_GET['plugin'] ) && ( isset( $_GET['generator-activate'] ) && 'activate-plugin' == $_GET['generator-activate'] ) ) { check_admin_referer( 'generator-activate', 'generator-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', ), 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, 'generator' ), $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, 'generator' ) . '' : ''; $show_activate_link = $activate_link ? '' . translate_nooped_plural( $this->strings['activate_link'], $activate_link_count, 'generator' ) . '' : ''; // Define all of the action links. $action_links = apply_filters( 'generator_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( 'generator', 'generator', $rendered, sanitize_html_class( strtolower( $this->strings['nag_type'] ) ) ); } else { add_settings_error( 'generator', 'generator', $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( 'generator' ); } } /* Add dismissable admin notices. */ public function dismiss() { if ( isset( $_GET['generator-dismiss'] ) ) { update_user_meta( get_current_user_id(), 'generator_dismissed_notice_' . $this->id, 1 ); } } /* Add individual plugin to our collection of plugins. */ 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.*/ public function config( $config ) { $keys = array( 'id', '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. */ public function actions( $install_actions ) { // Remove action links on the generatorPA install page. if ( $this->is_generator_page() ) { return false; } return $install_actions; } /* Flushes the plugins cache on theme switch to prevent stale entries */ public function flush_plugins_cache() { wp_cache_flush(); } /* Set file_path key for each installed plugin. */ 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. */ 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. */ 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 generatorPA Install page. */ protected function is_generator_page() { if ( isset( $_GET['page'] ) && $this->menu === $_GET['page'] ) { return true; } return false; } /* Delete dismissable nag option when theme is switched. */ public function update_dismiss() { delete_user_meta( get_current_user_id(), 'generator_dismissed_notice_' . $this->id ); } /* Forces plugin activation if the parameter 'force_activation' is set to true.*/ 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.*/ 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 parameter 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. */ public static function get_instance() { if ( ! isset( self::$instance ) && ! ( self::$instance instanceof generator_Plugin_Activation ) ) { self::$instance = new generator_Plugin_Activation(); } return self::$instance; } } // Ensure only one instance of the class is ever invoked. $generator = generator_Plugin_Activation::get_instance(); } if ( ! function_exists( 'generator' ) ) { /* Helper function to register a collection of required plugins. */ function generator( $plugins, $config = array() ) { foreach ( $plugins as $plugin ) { generator_Plugin_Activation::$instance->register( $plugin ); } if ( $config ) { generator_Plugin_Activation::$instance->config( $config ); } } } /* WP_List_Table isn't always available. If it isn't available, we load it here. */ if ( ! class_exists( 'WP_List_Table' ) ) { require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' ); } if ( ! class_exists( 'generatorPA_List_Table' ) ) { /* List table class for handling plugins. */ class generatorPA_List_Table extends WP_List_Table { /* References parent constructor and sets defaults for class.*/ public function __construct() { parent::__construct( array( 'singular' => 'plugin', 'plural' => 'plugins', 'ajax' => false, ) ); } /* Gathers and renames all of our plugin information to be used by WP_List_Table to create our table.*/ protected function _gather_plugin_data() { // Load thickbox for plugin links. generator_Plugin_Activation::$instance->admin_init(); generator_Plugin_Activation::$instance->thickbox(); // Prep variables for use and grab list of all installed plugins. $table_data = array(); $i = 0; $installed_plugins = get_plugins(); foreach ( generator_Plugin_Activation::$instance->plugins as $plugin ) { if ( is_plugin_active( $plugin['file_path'] ) ) { continue; // No need to display plugins if they are installed and activated. } $table_data[$i]['sanitized_plugin'] = $plugin['name']; $table_data[$i]['slug'] = $this->_get_plugin_data_from_name( $plugin['name'] ); $external_url = $this->_get_plugin_data_from_name( $plugin['name'], 'external_url' ); $source = $this->_get_plugin_data_from_name( $plugin['name'], 'source' ); if ( $external_url && preg_match( '|^http(s)?://|', $external_url ) ) { $table_data[$i]['plugin'] = '' . $plugin['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['name'] ), 'TB_iframe' => 'true', 'width' => '640', 'height' => '500', ), admin_url( 'plugin-install.php' ) ); $table_data[$i]['plugin'] = '' . $plugin['name'] . ''; } else { $table_data[$i]['plugin'] = '' . $plugin['name'] . ''; } if ( isset( $table_data[$i]['plugin'] ) && (array) $table_data[$i]['plugin'] ) { $plugin['name'] = $table_data[$i]['plugin']; } if ( ! empty( $plugin['source'] ) ) { // The plugin must be from a private repository. if ( preg_match( '|^http(s)?://|', $plugin['source'] ) ) { $table_data[$i]['source'] = __( 'Private Repository', 'generator' ); // The plugin is pre-packaged with the theme. } else { $table_data[$i]['source'] = __( 'Pre-Packaged', 'generator' ); } } else { $table_data[$i]['source'] = __( 'WordPress Repository', 'generator' ); } $table_data[$i]['type'] = isset( $plugin['required'] ) && $plugin['required'] ? __( 'Required', 'generator' ) : __( 'Recommended', 'generator' ); if ( ! isset( $installed_plugins[$plugin['file_path']] ) ) { $table_data[$i]['status'] = sprintf( '%1$s', __( 'Not Installed', 'generator' ) ); } elseif ( is_plugin_inactive( $plugin['file_path'] ) ) { $table_data[$i]['status'] = sprintf( '%1$s', __( 'Installed But Not Activated', 'generator' ) ); } $table_data[$i]['file_path'] = $plugin['file_path']; $table_data[$i]['url'] = isset( $plugin['source'] ) ? $plugin['source'] : 'repo'; $i++; } // Sort plugins by Required/Recommended type and by alphabetical listing within each type. $resort = array(); $req = array(); $rec = array(); // Grab all the plugin types. foreach ( $table_data as $plugin ) { $resort[] = $plugin['type']; } // Sort each plugin by type. foreach ( $resort as $type ) { if ( 'Required' == $type ) { $req[] = $type; } else { $rec[] = $type; } } // Sort alphabetically each plugin type array, merge them and then sort in reverse (lists Required plugins first). sort( $req ); sort( $rec ); array_merge( $resort, $req, $rec ); array_multisort( $resort, SORT_DESC, $table_data ); return $table_data; } /* Retrieve plugin data, given the plugin name. Taken from the generator_Plugin_Activation class.*/ protected function _get_plugin_data_from_name( $name, $data = 'slug' ) { foreach ( generator_Plugin_Activation::$instance->plugins as $plugin => $values ) { if ( $name == $values['name'] && isset( $values[$data] ) ) { return $values[$data]; } } return false; } /* Create default columns to display important plugin information */ public function column_default( $item, $column_name ) { return $item[$column_name]; } /* Create default title column along with action links of 'Install' */ public function column_plugin( $item ) { $installed_plugins = get_plugins(); // No need to display any hover links. if ( is_plugin_active( $item['file_path'] ) ) { $actions = array(); } // We need to display the 'Install' hover link. if ( ! isset( $installed_plugins[$item['file_path']] ) ) { $actions = array( 'install' => sprintf( '' . __( 'Install', 'generator' ) . '', wp_nonce_url( add_query_arg( array( 'page' => generator_Plugin_Activation::$instance->menu, 'plugin' => $item['slug'], 'plugin_name' => $item['sanitized_plugin'], 'plugin_source' => $item['url'], 'generator-install' => 'install-plugin', ), admin_url( 'themes.php' ) ), 'generator-install' ), $item['sanitized_plugin'] ),); } // We need to display the 'Activate' hover link. elseif ( is_plugin_inactive( $item['file_path'] ) ) { $actions = array( 'activate' => sprintf( '' . __( 'Activate', 'generator' ) . '', add_query_arg( array( 'page' => generator_Plugin_Activation::$instance->menu, 'plugin' => $item['slug'], 'plugin_name' => $item['sanitized_plugin'], 'plugin_source' => $item['url'], 'generator-activate' => 'activate-plugin', 'generator-activate-nonce' => wp_create_nonce( 'generator-activate' ), ), admin_url( 'themes.php' ) ), $item['sanitized_plugin'] ), ); } return sprintf( '%1$s %2$s', $item['plugin'], $this->row_actions( $actions ) ); } /* Required for bulk installing. */ public function column_cb( $item ) { $value = $item['file_path'] . ',' . $item['url'] . ',' . $item['sanitized_plugin']; return sprintf( '', $this->_args['singular'], $value, $item['sanitized_plugin'] ); } /* Sets default message within the plugins table if no plugins */ public function no_items() { printf( __( 'No plugins to install or activate. Return to the Dashboard', 'generator' ), admin_url() ); echo ''; } /* Output all the column information within the table.*/ public function get_columns() { $columns = array( 'cb' => '', 'plugin' => __( 'Plugin', 'generator' ), 'source' => __( 'Source', 'generator' ), 'type' => __( 'Type', 'generator' ), 'status' => __( 'Status', 'generator' ) ); return $columns; } /* Defines all types of bulk actions for handling*/ public function get_bulk_actions() { $actions = array( 'generator-bulk-install' => __( 'Install', 'generator' ), 'generator-bulk-activate' => __( 'Activate', 'generator' ), ); return $actions; } /* Processes bulk installation and activation actions. */ public function process_bulk_actions() { // Bulk installation process. if ( 'generator-bulk-install' === $this->current_action() ) { check_admin_referer( 'bulk-' . $this->_args['plural'] ); // Prep variables to be populated. $plugins_to_install = array(); $plugin_installs = array(); $plugin_path = array(); $plugin_name = array(); // Look first to see if information has been passed via WP_Filesystem. if ( isset( $_GET['plugins'] ) ) { $plugins = explode( ',', stripslashes( $_GET['plugins'] ) ); } // Looks like the user can use the direct method, take from $_POST. elseif ( isset( $_POST['plugin'] ) ) { $plugins = (array) $_POST['plugin']; } // Nothing has been submitted. else { $plugins = array(); } // Grab information from $_POST if available. if ( isset( $_POST['plugin'] ) ) { foreach ( $plugins as $plugin_data ) { $plugins_to_install[] = explode( ',', $plugin_data ); } foreach ( $plugins_to_install as $plugin_data ) { $plugin_installs[] = $plugin_data[0]; $plugin_path[] = $plugin_data[1]; $plugin_name[] = $plugin_data[2]; } } // Information has been passed via $_GET. else { foreach ( $plugins as $key => $value ) { // Grab plugin slug for each plugin. if ( 0 == $key % 3 || 0 == $key ) { $plugins_to_install[] = $value; $plugin_installs[] = $value; } } } // Look first to see if information has been passed via WP_Filesystem. if ( isset( $_GET['plugin_paths'] ) ) { $plugin_paths = explode( ',', stripslashes( $_GET['plugin_paths'] ) ); } // Looks like the user doesn't need to enter his FTP creds. elseif ( isset( $_POST['plugin'] ) ) { $plugin_paths = (array) $plugin_path; } // Nothing has been submitted. else { $plugin_paths = array(); } // Look first to see if information has been passed via WP_Filesystem. if ( isset( $_GET['plugin_names'] ) ) { $plugin_names = explode( ',', stripslashes( $_GET['plugin_names'] ) ); } // Looks like the user doesn't need to enter his FTP creds. elseif ( isset( $_POST['plugin'] ) ) { $plugin_names = (array) $plugin_name; } // Nothing has been submitted. else { $plugin_names = array(); } // Loop through plugin slugs and remove already installed plugins from the list. $i = 0; foreach ( $plugin_installs as $key => $plugin ) { if ( preg_match( '|.php$|', $plugin ) ) { unset( $plugin_installs[$key] ); // If the plugin path isn't in the $_GET variable, we can unset the corresponding path. if ( ! isset( $_GET['plugin_paths'] ) ) unset( $plugin_paths[$i] ); // If the plugin name isn't in the $_GET variable, we can unset the corresponding name. if ( ! isset( $_GET['plugin_names'] ) ) unset( $plugin_names[$i] ); } $i++; } // No need to proceed further if we have no plugins to install. if ( empty( $plugin_installs ) ) { echo '' . __( 'No plugins are available to be installed at this time.', 'generator' ) . '
' . __( 'No plugins are available to be activated at this time.', 'generator' ) . '
' . $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;' ) . '
' . generator_Plugin_Activation::$instance->strings['return'] . '
'; $complete[] = $plugin; break; } 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( generator_Plugin_Activation::$instance->strings['complete'], '' . __( 'Return to the Dashboard', 'generator' ) . '' ) . '
'; echo ''; } } /* Flush header output buffer. */ public function before_flush_output() { wp_ob_end_flush_all(); flush(); } /* Flush footer output buffer and iterate $this->i to make sure the*/ public function after_flush_output() { wp_ob_end_flush_all(); flush(); $this->i++; } } } } }