public function rtbiz_install_plugin($plugin_slug) { include_once ABSPATH . 'wp-admin/includes/plugin-install.php'; $api = plugins_api('plugin_information', array('slug' => $plugin_slug, 'fields' => array('sections' => false))); if (is_wp_error($api)) { die(sprintf(__('ERROR: Error fetching plugin information: %s', RTBIZ_TEXT_DOMAIN), $api->get_error_message())); } if (!class_exists('Plugin_Upgrader')) { require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; } if (!class_exists('Rtbiz_Plugin_Upgrader_Skin')) { require_once RTBIZ_PATH . 'admin/abstract/class-rtbiz-plugin-upgrader-skin.php'; } $upgrader = new Plugin_Upgrader(new Rtbiz_Plugin_Upgrader_Skin(array('nonce' => 'install-plugin_' . $plugin_slug, 'plugin' => $plugin_slug, 'api' => $api))); $install_result = $upgrader->install($api->download_link); if (!$install_result || is_wp_error($install_result)) { // $install_result can be false if the file system isn't writeable. $error_message = __('Please ensure the file system is writeable', RTBIZ_TEXT_DOMAIN); if (is_wp_error($install_result)) { $error_message = $install_result->get_error_message(); } die(sprintf(__('ERROR: Failed to install plugin: %s', RTBIZ_TEXT_DOMAIN), $error_message)); } $activate_result = activate_plugin($this->rtbiz_get_path_for_plugin($plugin_slug)); if (is_wp_error($activate_result)) { die(sprintf(__('ERROR: Failed to activate plugin: %s', RTBIZ_TEXT_DOMAIN), $activate_result->get_error_message())); } }
/** * Add Contextual Help to Backups tools page. * * Help is pulled from the readme FAQ. * * @return null */ function hmbkp_contextual_help() { // Pre WordPress 3.3 compat if (!method_exists(get_current_screen(), 'add_help_tab')) { return; } require_once ABSPATH . 'wp-admin/includes/plugin-install.php'; if (!($plugin = get_transient('hmbkp_plugin_data'))) { $plugin = plugins_api('plugin_information', array('slug' => HMBKP_PLUGIN_SLUG)); // Cache for one day set_transient('hmbkp_plugin_data', $plugin, 1 * DAY_IN_SECONDS); } $warning = ''; // Check if help is for the right version. if (!empty($plugin->version) && version_compare(HMBKP_VERSION, $plugin->version, '!=')) { $warning = sprintf('<div id="message" class="updated inline"><p><strong>' . __('You are not using the latest stable version of BackUpWordPress', 'hmbkp') . '</strong> — ' . __('The information below is for version %1$s. View the %2$s file for help specific to version %3$s.', 'hmbkp') . '</p></div>', '<code>' . esc_attr($plugin->version) . '</code>', '<code>readme.txt</code>', '<code>' . esc_attr(HMBKP_VERSION) . '</code>'); } ob_start(); require_once HMBKP_PLUGIN_PATH . 'admin/constants.php'; $constants = ob_get_clean(); ob_start(); include_once HMBKP_PLUGIN_PATH . 'admin/faq.php'; $faq = ob_get_clean(); get_current_screen()->add_help_tab(array('title' => __('FAQ', 'hmbkp'), 'id' => 'hmbkp_faq', 'content' => wp_kses_post($faq))); get_current_screen()->add_help_tab(array('title' => __('Constants', 'hmbkp'), 'id' => 'hmbkp_constants', 'content' => wp_kses_post($constants))); get_current_screen()->set_help_sidebar('<p><strong>' . __('For more information:', 'hmbkp') . '</strong></p>' . '<p><a href="https://github.com/humanmade/backupwordpress" target="_blank">GitHub</a></p>' . '<p><a href="http://wordpress.org/tags/backupwordpress?forum_id=10" target="_blank">' . __('Support Forums', 'hmbkp') . '</a></p>' . '<p><a href="http://translate.hmn.md/" target="_blank">' . __('Help with translation', 'hmbkp') . '</a></p>'); }
public function manage() { if (!function_exists('plugins_api')) { require_once ABSPATH . '/wp-admin/includes/plugin-install.php'; } preg_match_all('/####([\\d\\w\\-]{1,})####/', $this->template, $plugin_list); if (isset($plugin_list[1]) && is_array($plugin_list[1])) { $search = array(); foreach ($plugin_list[1] as $plugin) { $api = plugins_api('plugin_information', array('slug' => stripslashes($plugin))); $status = install_plugin_install_status($api); switch ($status['status']) { case 'install': $search["####{$plugin}####"] = isset($status['url']) ? $status['url'] : 'javascript:void();'; $search["###{$plugin}-install-text###"] = __('Install Now'); break; case 'update_available': $search["####{$plugin}####"] = isset($status['url']) ? $status['url'] : 'javascript:void();'; $search["###{$plugin}-install-text###"] = __('Install Update Now'); break; case 'newer_installed': $search["####{$plugin}####"] = 'javascript:void();'; $search["###{$plugin}-install-text###"] = sprintf(__('Newer Version (%s) Installed'), $status['version']); break; case 'latest_installed': $search["####{$plugin}####"] = 'javascript:void();'; $search["###{$plugin}-install-text###"] = __('Latest Version Installed'); break; } } $this->template = str_replace(array_keys($search), $search, $this->template); } echo $this->template; }
function prepare_items() { include ABSPATH . 'wp-admin/includes/plugin-install.php'; global $tabs, $tab, $paged, $type, $term; wp_reset_vars(array('tab')); $paged = $this->get_pagenum(); $per_page = 30; // These are the tabs which are shown on the page $tabs = array(); $tabs['dashboard'] = __('Search'); if ('search' == $tab) { $tabs['search'] = __('Search Results'); } $tabs['featured'] = _x('Featured', 'Plugin Installer'); $tabs['popular'] = _x('Popular', 'Plugin Installer'); $tabs['new'] = _x('Newest', 'Plugin Installer'); $nonmenu_tabs = array('plugin-information'); //Valid actions to perform which do not have a Menu item. $tabs = apply_filters('install_plugins_tabs', $tabs); $nonmenu_tabs = apply_filters('install_plugins_nonmenu_tabs', $nonmenu_tabs); // If a non-valid menu tab has been selected, And its not a non-menu action. if (empty($tab) || !isset($tabs[$tab]) && !in_array($tab, (array) $nonmenu_tabs)) { $tab = key($tabs); } $args = array('page' => $paged, 'per_page' => $per_page); switch ($tab) { case 'search': $type = isset($_REQUEST['type']) ? stripslashes($_REQUEST['type']) : 'term'; $term = isset($_REQUEST['s']) ? stripslashes($_REQUEST['s']) : ''; switch ($type) { case 'tag': $args['tag'] = sanitize_title_with_dashes($term); break; case 'term': $args['search'] = $term; break; case 'author': $args['author'] = $term; break; } add_action('install_plugins_table_header', 'install_search_form', 10, 0); break; case 'featured': case 'popular': case 'new': $args['browse'] = $tab; break; default: $args = false; } if (!$args) { return; } $api = plugins_api('query_plugins', $args); if (is_wp_error($api)) { wp_die($api->get_error_message() . '</p> <p class="hide-if-no-js"><a href="#" onclick="document.location.reload(); return false;">' . __('Try again') . '</a>'); } $this->items = $api->plugins; $this->set_pagination_args(array('total_items' => $api->info['results'], 'per_page' => $per_page)); }
function install() { $plugin = array('name' => 'Clef', 'slug' => 'wpclef'); require_once ABSPATH . 'wp-admin/includes/plugin-install.php'; // Need for plugins_api require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; // Need for upgrade classes require_once 'plugin-install.php'; $api = plugins_api('plugin_information', array('slug' => $plugin['slug'], 'fields' => array('sections' => false))); if (is_wp_error($api)) { $this->clef_install_errors = array($api->get_error_message()); add_action('admin_notices', array(&$this, 'clef_install_errors')); return; } elseif (isset($api->download_link)) { $plugin['source'] = $api->download_link; } else { $this->clef_install_errors = array('Error trying to download Clef'); add_action('admin_notices', array(&$this, 'clef_install_errors')); return; } /** Pass all necessary information via URL if WP_Filesystem is needed */ $url = wp_nonce_url(add_query_arg(array('page' => 'bruteprotect-clef', 'bruteprotect-clef-action' => 'install'), admin_url('admin.php')), 'bruteprotect-clef-install'); $method = ''; // Leave blank so WP_Filesystem can populate it as necessary $fields = array(sanitize_key('bruteprotect-clef-install')); // Extra fields to pass to WP_Filesystem if (false === ($creds = request_filesystem_credentials($url, $method, false, false, $fields))) { return; } if (!WP_Filesystem($creds)) { request_filesystem_credentials($url, $method, true, false, $fields); // Setup WP_Filesystem return; } /** Set type, based on whether the source starts with http:// or https:// */ $type = preg_match('|^http(s)?://|', $plugin['source']) ? 'web' : 'upload'; /** Prep variables for Plugin_Installer_Skin class */ $title = sprintf('Installing %s', $plugin['name']); $url = add_query_arg(array('action' => 'install-plugin', 'plugin' => $plugin['slug']), 'update.php'); if (isset($_GET['from'])) { $url .= add_query_arg('from', urlencode(stripslashes($_GET['from'])), $url); } $nonce = 'install-plugin_' . $plugin['slug']; $source = $plugin['source']; /** Create a new instance of Plugin_Upgrader */ $upgrader = new Plugin_Upgrader($skin = new Silent_Plugin_Installer_Skin(compact('type', 'title', 'url', 'nonce', 'plugin', 'api'))); /** Perform the action and install the plugin from the $source urldecode() */ $upgrader->install($source); if (!empty($skin->errors)) { $this->clef_install_errors = $skin->errors; add_action('admin_notices', array(&$this, 'clef_install_errors')); return; } /** Flush plugins cache so we can make sure that the installed plugins list is always up to date */ wp_cache_flush(); }
/** * List plugins a user has favorited in the WordPress.org plugins directory. * * ## OPTIONS * * <user> * : The username of the wordpress.org account whose favorite plugins you are listing. * * [--slug] * : Only return plugin slugs. Can be combined with `wp plugin install` (see examples). * * [--verbose] * : Display more information about the plugins. * * ## EXAMPLES * * wp plugin favorites matt * wp plugin favorites matt --verbose * wp plugin favorites matt --slug | xargs wp plugin install --activate * wp plugin favorites matt --slug | grep -vwE "(hello-dolly|bbpress)" | xargs wp plugin install --activate * * @synopsis <user> [--slug] [--verbose] */ public function __invoke($args, $assoc_args) { // prepare variables list($user) = $args; extract($assoc_args = wp_parse_args($assoc_args, array('slug' => false, 'verbose' => false))); // get access to plugins_api require_once ABSPATH . 'wp-admin/includes/plugin-install.php'; // query wordpress.org $api = plugins_api('query_plugins', array('user' => $user, 'fields' => array('last_updated' => true, 'active_installs' => true))); // only return slug? if ($slug) { foreach ($api->plugins as $plugin) { WP_CLI::log($plugin->slug); } return; } // get table columns $props = array('name', 'last_updated', 'rating', 'num_ratings', 'active_installs'); if ($verbose) { $props = array_merge($props, array('author', 'version', 'requires', 'tested', 'short_description')); } // pull object properties into an array $plugins = array(); foreach ($api->plugins as $plugin) { $args = array(); foreach ($props as $prop) { $args[$prop] = ''; if (isset($plugin->{$prop})) { $args[$prop] = $plugin->{$prop}; // clean up some fields for output switch ($prop) { case 'rating': $args[$prop] = (int) $args['rating'] / 100 * 5 . '/5'; break; case 'author': $args[$prop] = strip_tags($args['author']); break; case 'last_updated': $args[$prop] = date('Y-m-d', strtotime($args['last_updated'])); break; case 'active_installs': $args[$prop] = number_format($args['active_installs']); break; } } } $plugins[$plugin->slug] = $args; } if (!$plugins) { WP_CLI::log('No favorite plugins found.'); return; } // output as list table $formatter = new \WP_CLI\Formatter($assoc_args, $props, 'plugin'); $formatter->display_items($plugins); }
public function get_information() { if (!function_exists('plugins_api')) { require ABSPATH . 'wp-admin/includes/plugin-install.php'; } $fields = array('short_description' => true, 'screenshots' => false, 'changelog' => false, 'installation' => false, 'description' => false); $args = array('slug' => $this->slug, 'fields' => $fields); $this->information = plugins_api('plugin_information', $args); return $this->information; }
function install_link() { include_once ABSPATH . 'wp-admin/includes/plugin-install.php'; $info = plugins_api('plugin_information', array('slug' => $this->slug)); if (is_wp_error($info)) { return false; } // plugin not available from wordpress.org return wp_nonce_url(self_admin_url('update.php?action=install-plugin&plugin=' . $this->slug), 'install-plugin_' . $this->slug); }
protected function get_plugin_data_from_api() { $data = plugins_api('plugin_information', array('slug' => $this->slug, 'is_ssl' => is_ssl(), 'fields' => self::$fields)); if (!is_wp_error($data)) { return $this->transform_plugin_data($data); } else { $this->_error = $data; } return false; }
/** * @access protected * * @return bool */ public function _retrieve_data() { require_once ABSPATH . 'wp-admin/includes/plugin-install.php'; $args = array('author' => $this->options['username'], 'per_page' => 100, 'fields' => array('description' => false, 'compatibility' => false, 'icons' => true, 'downloaded' => true, 'last_updated' => true)); $data = plugins_api('query_plugins', $args); if ($data && isset($data->plugins)) { $data = array('data' => $data->plugins, 'expiration' => time() + $this->expiration); update_post_meta($this->post->ID, '_plugins', $data); return $data; } return false; }
protected function execute(InputInterface $input, OutputInterface $output) { $env = Validators::validateEnv($input->getOption('env')); $root = $this->skeleton->getWebRoot(); $plugins = $this->skeleton->get(sprintf('wordpress.%s.plugins', $env)); require $root . '/wp-load.php'; require ABSPATH . 'wp-admin/includes/admin.php'; require ABSPATH . 'wp-admin/includes/plugin-install.php'; foreach ($plugins as $slug => $version) { $plugin = plugins_api('plugin_information', array('slug' => $slug)); if (is_wp_error($plugin)) { throw new \Exception('Could not get plugin information for ' . $slug); } if ($version) { list($prefix) = explode($slug, $plugin->download_link); $link = sprintf('%s%s.%s.zip', $prefix, $slug, $version); $response = wp_remote_head($link); if (!isset($response['response']['code']) || $response['response']['code'] != 200) { throw new \Exception('Unable to verify ' . $link); } $plugin->download_link = $link; $plugin->version = $version; } require ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; $status = install_plugin_install_status($plugin); $upgrader = new \Plugin_Upgrader(new UpgraderSkin($output)); $current = current(get_plugins("/{$slug}")); switch ($status['status']) { case 'install': $output->write(sprintf('Installing <info>%s</info> v<comment>%s</comment>', $plugin->name, $plugin->version)); $upgrader->install($plugin->download_link); break; case 'update_available': if ($plugin->version == $current['Version']) { $output->writeln(sprintf('<info>%s</info> v<comment>%s</comment> is already installed!', $plugin->name, $plugin->version)); } else { $output->write(sprintf('Upgrading <info>%s</info> from <comment>%s</comment> to <comment>%s</comment>', $plugin->name, $current['Version'], $plugin->version)); $file = sprintf('%s/%s', $slug, key(get_plugins("/{$slug}"))); $upgrader->upgrade($file); } break; case 'latest_installed': $output->writeln(sprintf('<info>%s</info> v<comment>%s</comment> is already installed!', $plugin->name, $current['Version'])); break; case 'newer_installed': $output->writeln(sprintf('<info>%s</info> v<comment>%s</comment> is installed & newer than <comment>%s</comment>', $plugin->name, $current['Version'], $plugin->version)); break; } } if ($plugins) { $output->writeln(sprintf('<info>Activate plugins in the WordPress Admin</info>', $plugin->name)); } }
function install_wp_super_cache() { require_once ABSPATH . 'wp-admin/includes/plugin-install.php'; require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; // code from wp-admin/update.php $api = plugins_api('plugin_information', array('slug' => 'wp-super-cache', 'fields' => array('short_description' => false, 'sections' => false, 'requires' => false, 'rating' => false, 'ratings' => false, 'downloaded' => false, 'last_updated' => false, 'added' => false, 'tags' => false, 'compatibility' => false, 'homepage' => false, 'donate_link' => false))); if (is_wp_error($api)) { wp_die($api); } $upgrader = new Plugin_Upgrader(new Plugin_Installer_Skin(compact('title', 'url', 'nonce', 'plugin', 'api'))); $upgrader->install($api->download_link); }
function check_plugins() { require_once ABSPATH . 'wp-admin/includes/plugin-install.php'; $plugins = get_plugin_updates(); if (!empty($plugins)) { foreach ((array) $plugins as $plugin_file => $plugin_data) { plugins_api('plugin_information', array('slug' => $plugin_data->update->slug)); } WP_CLI::success('Plugin updates refreshed.'); } else { WP_CLI::log('All plugins are up to date.'); } }
public function get_information() { $key = str_replace('_', '_', $this->slug) . '_information'; if (false === ($this->information = get_transient($key))) { if (!function_exists('plugins_api')) { require ABSPATH . 'wp-admin/includes/plugin-install.php'; } $fields = array('short_description' => true, 'screenshots' => false, 'changelog' => false, 'installation' => false, 'description' => false); $args = array('slug' => $this->slug, 'fields' => $fields); $this->information = plugins_api('plugin_information', $args); set_transient($key, $this->information, DAY_IN_SECONDS); } return $this->information; }
function rkv_plugin_favorites() { /** If plugins_api isn't available, load the file that holds the function */ if (!function_exists('plugins_api')) { require_once ABSPATH . 'wp-admin/includes/plugin-install.php'; } /** Prepare our query */ $api = plugins_api('query_plugins', array('user' => 'norcross')); /** Display the results */ if (is_wp_error($api)) { echo 'Something went wrong!'; } else { $favorites = $api->plugins; } shuffle($favorites); // grab the first one after randomizing the array $plugin_name = $favorites[0]->name; $plugin_slug = $favorites[0]->slug; $plugin_link = $favorites[0]->homepage; $plugin_text = $favorites[0]->short_description; $author_name = $favorites[0]->author; $author_link = $favorites[0]->author_profile; echo '<div class="widget plugin-details plugin-favorite">'; echo '<h4 class="nav-header">Other Favorites <i class="icon icon-tags pull-right"></i></h4>'; // first one echo '<div class="favorite-single">'; echo '<h5><a href="' . $plugin_link . '" target="_blank">' . $plugin_name . '</a></h5>'; echo '<p class="plugin-author"><em><small>by</small></em> <a href="' . $author_link . '" target="_blank">' . $author_name . '</a></p>'; echo '<p>' . $plugin_text . '</p>'; echo '<p class="more-link"><a class="btn" href="http://wordpress.org/extend/plugins/' . $plugin_slug . '/" target="_blank">Learn More →</a></p>'; echo '</div>'; // now grab the second one after randomizing the array $plugin_name = $favorites[1]->name; $plugin_slug = $favorites[1]->slug; $plugin_link = $favorites[1]->homepage; $plugin_text = $favorites[1]->short_description; $author_name = $favorites[1]->author; $author_link = $favorites[1]->author_profile; // second one echo '<div class="favorite-single">'; echo '<h5><a href="' . $plugin_link . '" target="_blank">' . $plugin_name . '</a></h5>'; echo '<p class="plugin-author"><em><small>by</small></em> <a href="' . $author_link . '" target="_blank">' . $author_name . '</a></p>'; echo '<p>' . $plugin_text . '</p>'; echo '<p class="more-link"><a class="btn" href="http://wordpress.org/extend/plugins/' . $plugin_slug . '/" target="_blank">Learn More →</a></p>'; echo '</div>'; echo '<p class="disclaimer"><strong>Note:</strong> these plugins are not developed by me.</p>'; // close it out echo '</div>'; }
public static function update_available($plugin_data, $new_plugin_data) { require_once ABSPATH . 'wp-admin/includes/plugin-install.php'; $plugin = plugins_api('plugin_information', array('slug' => $new_plugin_data->slug)); if (!$plugin || is_wp_error($plugin) || empty($plugin->sections['changelog'])) { return; } $changes = $plugin->sections['changelog']; $pos = strpos($changes, '<h4>' . preg_replace('/[^\\d\\.]/', '', $plugin_data['Version'])); if ($pos !== false) { $changes = trim(substr($changes, 0, $pos)); } piklist::render('shared/update-available'); $changes = preg_replace('/<h4>(.*)<\\/h4>.*/iU', '', $changes); $changes = strip_tags($changes, '<li>'); echo '<ul class="update-available">' . $changes . '</ul>'; }
private function get_plugin_latest_version($plugin = '') { if (!function_exists('plugins_api') && file_exists(ABSPATH . 'wp-admin/includes/plugin-install.php')) { require_once ABSPATH . 'wp-admin/includes/plugin-install.php'; } $args = array('slug' => $plugin, 'fields' => array('version' => true)); /** Prepare our query */ $call_api = plugins_api('plugin_information', $args); /** Check for Errors & Display the results */ if (is_wp_error($call_api)) { /* $api_error = $call_api->get_error_message(); */ return false; } else { if (!empty($call_api->version)) { return $call_api->version; } return false; } return false; }
/** * Add Contextual Help to Backups tools page. * * Help is pulled from the readme FAQ. * * @todo get plugin info from local readme and use plugin_updates cache to check if we are running the latest version so we don't have to do a wp_remote_get on every page load. * @return null */ function hmbkp_contextual_help() { require_once ABSPATH . 'wp-admin/includes/plugin-install.php'; $plugin = plugins_api('plugin_information', array('slug' => 'backupwordpress')); $warning = ''; // Check if help is for the right version. if (!empty($plugin->version) && version_compare(HMBKP_VERSION, $plugin->version, '!=')) { $warning = sprintf('<div id="message" class="updated inline"><p><strong>' . __('You are not using the latest stable version of BackUpWordPress', 'hmbkp') . '</strong>' . __(' — The information below is for version %s. View the readme.txt file for help specific to version %s.', 'hmbkp') . '</p></div>', '<code>' . $plugin->version . '</code>', '<code>' . HMBKP_VERSION . '</code>'); } ob_start(); require_once HMBKP_PLUGIN_PATH . '/admin.constants.php'; $constants = ob_get_clean(); // Pre WordPress 3.3 compat if (!method_exists(get_current_screen(), 'add_help_tab')) { return; } get_current_screen()->add_help_tab(array('title' => 'FAQ', 'id' => 'hmbkp_faq', 'content' => $warning . $plugin->sections['faq'])); get_current_screen()->add_help_tab(array('title' => 'Constants', 'id' => 'hmbkp_constants', 'content' => $warning . $constants)); get_current_screen()->set_help_sidebar('<p><strong>' . __('For more information:') . '</strong></p>' . '<p>' . __('<a href="http://https://github.com/humanmade/backupwordpress" target="_blank">github</a>') . '</p>' . '<p>' . __('<a href="http://wordpress.org/tags/backupwordpress?forum_id=10" target="_blank">Support Forums</a>') . '</p>'); }
function bf_add_ons_screen() { // Check that the user is allowed to update options if (!current_user_can('manage_options')) { wp_die(__('You do not have sufficient permissions to access this page.', 'buddyforms')); } ?> <div id="bf_admin_wrap" class="wrap"> <?php include 'admin-credits.php'; include_once ABSPATH . 'wp-admin/includes/plugin-install.php'; $call_api = plugins_api('query_plugins', array('search' => 'buddyforms', 'page' => '1', 'per_page' => '-1', 'fields' => array('downloaded' => true, 'active_installs' => true, 'icons' => true, 'rating' => true, 'num_ratings' => true, 'description' => false, 'short_description' => true, 'donate_link' => false, 'tags' => false, 'sections' => false, 'homepage' => false, 'added' => false, 'last_updated' => true, 'compatibility' => true, 'tested' => true, 'requires' => true, 'downloadlink' => true))); add_thickbox(); buddyforms_get_addons($call_api); ?> </div> <?php }
/** * Helper function to return the URL for installing a plugin. * * @param string $slug Plugin slug; determines which plugin to install. */ function plugin_install_url($slug) { /* * Include Plugin Install Administration API to get access to the * plugins_api() function */ include_once ABSPATH . 'wp-admin/includes/plugin-install.php'; $plugin_information = plugins_api('plugin_information', array('slug' => $slug)); if (is_wp_error($plugin_information)) { return false; } else { return wp_nonce_url(self_admin_url('update.php?action=install-plugin&plugin=' . $slug), 'install-plugin_' . $slug); } }
/** * 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]; }
exit; } if (!current_user_can('manage_options')) { header('Status: 403 Forbidden'); header('HTTP/1.1 403 Forbidden'); exit; } ?> <div class="wrap" style="margin-top:45px;"> <?php if (function_exists('get_transient')) { require_once ABSPATH . 'wp-admin/includes/plugin-install.php'; if (false === ($bps_api = get_transient('bulletproof-security_info'))) { $bps_api = plugins_api('plugin_information', array('slug' => stripslashes('bulletproof-security'))); if (!is_wp_error($bps_api)) { $bps_expire = 60 * 30; // Cache downloads data for 30 minutes $bps_downloaded = array('downloaded' => $bps_api->downloaded); maybe_serialize($bps_downloaded); set_transient('bulletproof-security_info', $bps_downloaded, $bps_expire); } } $bps_transient = get_transient('bulletproof-security_info'); echo '<div class="bps-star-container" style="float:right;position:relative;top:-40px;left:0px;margin:0px 0px -40px 0px;font-weight:bold;">'; echo '<div class="bps-star"><img src="' . plugins_url('/bulletproof-security/admin/images/star.png') . '" /></div>'; echo '<div class="bps-downloaded">'; foreach ($bps_transient as $key => $value) { echo number_format_i18n($value) . ' ' . str_replace('downloaded', "Downloads", $key); }
/** * Downloads the plugin's changelog. * * @since 3.1 * * @return array An array of changelog headers {Version X.X (Month Day, Year)} => <ul> lists of changes. */ function download_changelog() { include_once ABSPATH . 'wp-admin/includes/plugin-install.php'; $plugin = plugins_api('plugin_information', array('slug' => 'seo-ultimate')); if (is_wp_error($plugin)) { return false; } $changelog = $plugin->sections['changelog']; $entries = explode('<h4>', $changelog); $versions = array(); foreach ($entries as $entry) { $item = explode('</h4>', $entry, 2); if (count($item) == 2) { $versions[$item[0]] = $item[1]; } } return $versions; }
/** * Processes bulk installation and activation actions. * * The bulk installation process looks either for the $_POST * information or for the plugin info within the $_GET variable 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()) { 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'])); } elseif (isset($_POST['plugin'])) { $plugins = (array) $_POST['plugin']; // @todo needs sanitizing, figure out how } 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]; } } 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'])); } elseif (isset($_POST['plugin'])) { $plugin_paths = (array) $plugin_path; } 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'])); } elseif (isset($_POST['plugin'])) { $plugin_names = (array) $plugin_name; } 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 '<div id="message" class="error"><p>', esc_html__('No plugins are available to be installed at this time.', 'tgmpa'), '</p></div>'; return false; } // Reset array indexes in case we removed already installed plugins. $plugin_installs = array_values($plugin_installs); $plugin_paths = array_values($plugin_paths); $plugin_names = array_values($plugin_names); // If we grabbed our plugin info from $_GET, we need to decode it for use. $plugin_installs = array_map('urldecode', $plugin_installs); $plugin_paths = array_map('urldecode', $plugin_paths); $plugin_names = array_map('urldecode', $plugin_names); // Pass all necessary information via URL if WP_Filesystem is needed. $url = wp_nonce_url(add_query_arg(array('page' => $this->tgmpa->menu, 'tgmpa-action' => 'install-selected', 'plugins' => urlencode(implode(',', $plugins)), 'plugin_paths' => urlencode(implode(',', $plugin_paths)), 'plugin_names' => urlencode(implode(',', $plugin_names))), self_admin_url($this->admin_page_base)), 'bulk-plugins'); $method = ''; // Leave blank so WP_Filesystem can populate it as necessary. $fields = array('action', '_wp_http_referer', '_wpnonce'); // Extra fields to pass to WP_Filesystem. if (false === ($creds = request_filesystem_credentials(esc_url_raw($url), $method, false, false, $fields))) { return true; } if (!WP_Filesystem($creds)) { request_filesystem_credentials(esc_url_raw($url), $method, true, false, $fields); // Setup WP_Filesystem. return true; } require_once ABSPATH . 'wp-admin/includes/plugin-install.php'; // Need for plugins_api require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; // Need for upgrade classes // Store all information in arrays since we are processing a bulk installation. $api = array(); $sources = array(); $install_path = array(); // Loop through each plugin to install and try to grab information from WordPress API, if not create 'tgmpa-empty' scalar. $i = 0; foreach ($plugin_installs as $plugin) { $temp = plugins_api('plugin_information', array('slug' => $plugin, 'fields' => array('sections' => false))); $api[$i] = (object) 'tgmpa-empty'; if (!is_wp_error($temp)) { $api[$i] = $temp; } $i++; } unset($plugin, $temp); if (is_wp_error($api)) { if (WP_DEBUG === true) { wp_die(esc_html($this->tgmpa->strings['oops']) . var_dump($api)); // wpcs: xss ok } else { wp_die(esc_html($this->tgmpa->strings['oops'])); } } // Capture download links from $api or set install link to pre-packaged/private repo. $i = 0; foreach ($api as $object) { $sources[$i] = isset($object->download_link) && 'repo' === $plugin_paths[$i] ? $object->download_link : $plugin_paths[$i]; $i++; } // Finally, all the data is prepared to be sent to the installer. $url = esc_url_raw(add_query_arg(array('page' => $this->tgmpa->menu), self_admin_url($this->admin_page_base))); $nonce = 'bulk-plugins'; $names = $plugin_names; // Create a new instance of TGM_Bulk_Installer. $installer = new TGM_Bulk_Installer($skin = new TGM_Bulk_Installer_Skin(compact('url', 'nonce', 'names'))); // Wrap the install process with the appropriate HTML. echo '<div class="tgmpa wrap">', '<h2>', esc_html(get_admin_page_title()), '</h2>'; // Process the bulk installation submissions. $installer->bulk_install($sources); echo '</div>'; return true; } // Bulk activation process. if ('tgmpa-bulk-activate' === $this->current_action()) { check_admin_referer('bulk-' . $this->_args['plural']); // Grab plugin data from $_POST. $plugins = isset($_POST['plugin']) ? (array) $_POST['plugin'] : array(); // @todo needs sanitizing, figure out how $plugins_to_activate = array(); // Split plugin value into array with plugin file path, plugin source and plugin name. foreach ($plugins as $i => $plugin) { $plugins_to_activate[] = explode(',', $plugin); } foreach ($plugins_to_activate as $i => $array) { if (!preg_match('|.php$|', $array[0])) { unset($plugins_to_activate[$i]); } } // Return early if there are no plugins to activate. if (empty($plugins_to_activate)) { echo '<div id="message" class="error"><p>', esc_html__('No plugins are available to be activated at this time.', 'tgmpa'), '</p></div>'; return false; } $plugins = array(); $plugin_names = array(); foreach ($plugins_to_activate as $plugin_string) { $plugins[] = $plugin_string[0]; $plugin_names[] = $plugin_string[2]; } $count = count($plugin_names); // Count so we can use _n function. $last_plugin = array_pop($plugin_names); // Pop off last name to prep for readability. $imploded = empty($plugin_names) ? '<strong>' . $last_plugin . '</strong>' : '<strong>' . (implode(', ', $plugin_names) . '</strong> and <strong>' . $last_plugin . '</strong>.'); // Now we are good to go - let's start activating plugins. $activate = activate_plugins($plugins); if (is_wp_error($activate)) { echo '<div id="message" class="error"><p>', wp_kses_post($activate->get_error_message()), '</p></div>'; } else { printf('<div id="message" class="updated"><p>%1$s %2$s.</p></div>', esc_html(_n('The following plugin was activated successfully:', 'The following plugins were activated successfully:', $count, 'tgmpa')), wp_kses_post($imploded)); } // Update recently activated plugins option. $recent = (array) get_option('recently_activated'); foreach ($plugins as $plugin => $time) { if (isset($recent[$plugin])) { unset($recent[$plugin]); } } update_option('recently_activated', $recent); unset($_POST); // Reset the $_POST variable in case user wants to perform one action after another. return true; } }
echo '<p>' . __('Plugin failed to reactivate due to a fatal error.') . '</p>'; error_reporting(E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR | E_USER_WARNING | E_RECOVERABLE_ERROR); @ini_set('display_errors', true); //Ensure that Fatal errors are displayed. wp_register_plugin_realpath(WP_PLUGIN_DIR . '/' . $plugin); include WP_PLUGIN_DIR . '/' . $plugin; } iframe_footer(); } elseif ('install-plugin' == $action) { if (!current_user_can('install_plugins')) { wp_die(__('You do not have sufficient permissions to install plugins on this site.')); } include_once ABSPATH . 'wp-admin/includes/plugin-install.php'; //for plugins_api.. check_admin_referer('install-plugin_' . $plugin); $api = plugins_api('plugin_information', array('slug' => $plugin, 'fields' => array('sections' => false))); //Save on a bit of bandwidth. if (is_wp_error($api)) { wp_die($api); } $title = __('Plugin Install'); $parent_file = 'plugins.php'; $submenu_file = 'plugin-install.php'; require_once ABSPATH . 'wp-admin/admin-header.php'; $title = sprintf(__('Installing Plugin: %s'), $api->name . ' ' . $api->version); $nonce = 'install-plugin_' . $plugin; $url = 'update.php?action=install-plugin&plugin=' . urlencode($plugin); if (isset($_GET['from'])) { $url .= '&from=' . urlencode(stripslashes($_GET['from'])); } $type = 'web';
/** * Display plugin information in dialog box form. * * @since 2.7.0 */ function install_plugin_information() { global $tab; $api = plugins_api('plugin_information', array('slug' => wp_unslash($_REQUEST['plugin']))); if (is_wp_error($api)) { wp_die($api); } $plugins_allowedtags = array('a' => array('href' => array(), 'title' => array(), 'target' => array()), 'abbr' => array('title' => array()), 'acronym' => array('title' => array()), 'code' => array(), 'pre' => array(), 'em' => array(), 'strong' => array(), 'div' => array(), 'p' => array(), 'ul' => array(), 'ol' => array(), 'li' => array(), 'h1' => array(), 'h2' => array(), 'h3' => array(), 'h4' => array(), 'h5' => array(), 'h6' => array(), 'img' => array('src' => array(), 'class' => array(), 'alt' => array())); $plugins_section_titles = array('description' => _x('Description', 'Plugin installer section title'), 'installation' => _x('Installation', 'Plugin installer section title'), 'faq' => _x('FAQ', 'Plugin installer section title'), 'screenshots' => _x('Screenshots', 'Plugin installer section title'), 'changelog' => _x('Changelog', 'Plugin installer section title'), 'other_notes' => _x('Other Notes', 'Plugin installer section title')); //Sanitize HTML foreach ((array) $api->sections as $section_name => $content) { $api->sections[$section_name] = wp_kses($content, $plugins_allowedtags); } foreach (array('version', 'author', 'requires', 'tested', 'homepage', 'downloaded', 'slug') as $key) { if (isset($api->{$key})) { $api->{$key} = wp_kses($api->{$key}, $plugins_allowedtags); } } $section = isset($_REQUEST['section']) ? wp_unslash($_REQUEST['section']) : 'description'; //Default to the Description tab, Do not translate, API returns English. if (empty($section) || !isset($api->sections[$section])) { $section = array_shift($section_titles = array_keys((array) $api->sections)); } iframe_header(__('Plugin Install')); echo "<div id='{$tab}-header'>\n"; echo "<ul id='sidemenu'>\n"; foreach ((array) $api->sections as $section_name => $content) { if (isset($plugins_section_titles[$section_name])) { $title = $plugins_section_titles[$section_name]; } else { $title = ucwords(str_replace('_', ' ', $section_name)); } $class = $section_name == $section ? ' class="current"' : ''; $href = add_query_arg(array('tab' => $tab, 'section' => $section_name)); $href = esc_url($href); $san_section = esc_attr($section_name); echo "\t<li><a name='{$san_section}' href='{$href}' {$class}>{$title}</a></li>\n"; } echo "</ul>\n"; echo "</div>\n"; ?> <div class="alignright fyi"> <?php if (!empty($api->download_link) && (current_user_can('install_plugins') || current_user_can('update_plugins'))) { ?> <p class="action-button"> <?php $status = install_plugin_install_status($api); switch ($status['status']) { case 'install': if ($status['url']) { echo '<a href="' . $status['url'] . '" target="_parent">' . __('Install Now') . '</a>'; } break; case 'update_available': if ($status['url']) { echo '<a href="' . $status['url'] . '" target="_parent">' . __('Install Update Now') . '</a>'; } break; case 'newer_installed': echo '<a>' . sprintf(__('Newer Version (%s) Installed'), $status['version']) . '</a>'; break; case 'latest_installed': echo '<a>' . __('Latest Version Installed') . '</a>'; break; } ?> </p> <?php } ?> <h2 class="mainheader"><?php /* translators: For Your Information */ _e('FYI'); ?> </h2> <ul> <?php if (!empty($api->version)) { ?> <li><strong><?php _e('Version:'); ?> </strong> <?php echo $api->version; ?> </li> <?php } if (!empty($api->author)) { ?> <li><strong><?php _e('Author:'); ?> </strong> <?php echo links_add_target($api->author, '_blank'); ?> </li> <?php } if (!empty($api->last_updated)) { ?> <li><strong><?php _e('Last Updated:'); ?> </strong> <span title="<?php echo $api->last_updated; ?> "><?php printf(__('%s ago'), human_time_diff(strtotime($api->last_updated))); ?> </span></li> <?php } if (!empty($api->requires)) { ?> <li><strong><?php _e('Requires WordPress Version:'); ?> </strong> <?php printf(__('%s or higher'), $api->requires); ?> </li> <?php } if (!empty($api->tested)) { ?> <li><strong><?php _e('Compatible up to:'); ?> </strong> <?php echo $api->tested; ?> </li> <?php } if (!empty($api->downloaded)) { ?> <li><strong><?php _e('Downloaded:'); ?> </strong> <?php printf(_n('%s time', '%s times', $api->downloaded), number_format_i18n($api->downloaded)); ?> </li> <?php } if (!empty($api->slug) && empty($api->external)) { ?> <li><a target="_blank" href="http://wordpress.org/extend/plugins/<?php echo $api->slug; ?> /"><?php _e('WordPress.org Plugin Page »'); ?> </a></li> <?php } if (!empty($api->homepage)) { ?> <li><a target="_blank" href="<?php echo $api->homepage; ?> "><?php _e('Plugin Homepage »'); ?> </a></li> <?php } ?> </ul> <?php if (!empty($api->rating)) { ?> <h2><?php _e('Average Rating'); ?> </h2> <div class="star-holder" title="<?php printf(_n('(based on %s rating)', '(based on %s ratings)', $api->num_ratings), number_format_i18n($api->num_ratings)); ?> "> <div class="star star-rating" style="width: <?php echo esc_attr(str_replace(',', '.', $api->rating)); ?> px"></div> </div> <small><?php printf(_n('(based on %s rating)', '(based on %s ratings)', $api->num_ratings), number_format_i18n($api->num_ratings)); ?> </small> <?php } ?> </div> <div id="section-holder" class="wrap"> <?php if (!empty($api->tested) && version_compare(substr($GLOBALS['wp_version'], 0, strlen($api->tested)), $api->tested, '>')) { echo '<div class="updated"><p>' . __('<strong>Warning:</strong> This plugin has <strong>not been tested</strong> with your current version of WordPress.') . '</p></div>'; } else { if (!empty($api->requires) && version_compare(substr($GLOBALS['wp_version'], 0, strlen($api->requires)), $api->requires, '<')) { echo '<div class="updated"><p>' . __('<strong>Warning:</strong> This plugin has <strong>not been marked as compatible</strong> with your version of WordPress.') . '</p></div>'; } } foreach ((array) $api->sections as $section_name => $content) { if (isset($plugins_section_titles[$section_name])) { $title = $plugins_section_titles[$section_name]; } else { $title = ucwords(str_replace('_', ' ', $section_name)); } $content = links_add_base_url($content, 'http://wordpress.org/extend/plugins/' . $api->slug . '/'); $content = links_add_target($content, '_blank'); $san_section = esc_attr($section_name); $display = $section_name == $section ? 'block' : 'none'; echo "\t<div id='section-{$san_section}' class='section' style='display: {$display};'>\n"; echo "\t\t<h2 class='long-header'>{$title}</h2>"; echo $content; echo "\t</div>\n"; } echo "</div>\n"; iframe_footer(); exit; }
/** * Processes bulk installation and activation actions. * * The bulk installation process looks either for the $_POST * information or for the plugin info within the $_GET variable 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()) { 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[sanitize_key('plugins')])) { $plugins = explode(',', stripslashes($_GET[sanitize_key('plugins')])); } elseif (isset($_POST[sanitize_key('plugin')])) { $plugins = (array) $_POST[sanitize_key('plugin')]; } else { $plugins = array(); } $a = 0; // Incremental variable /** Grab information from $_POST if available */ if (isset($_POST[sanitize_key('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]; } } 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; } $a++; } } /** Look first to see if information has been passed via WP_Filesystem */ if (isset($_GET[sanitize_key('plugin_paths')])) { $plugin_paths = explode(',', stripslashes($_GET[sanitize_key('plugin_paths')])); } elseif (isset($_POST[sanitize_key('plugin')])) { $plugin_paths = (array) $plugin_path; } else { $plugin_paths = array(); } /** Look first to see if information has been passed via WP_Filesystem */ if (isset($_GET[sanitize_key('plugin_names')])) { $plugin_names = explode(',', stripslashes($_GET[sanitize_key('plugin_names')])); } elseif (isset($_POST[sanitize_key('plugin')])) { $plugin_names = (array) $plugin_name; } else { $plugin_names = array(); } $b = 0; // Incremental variable /** Loop through plugin slugs and remove already installed plugins from the list */ 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[sanitize_key('plugin_paths')])) { unset($plugin_paths[$b]); } /** If the plugin name isn't in the $_GET variable, we can unset the corresponding name */ if (!isset($_GET[sanitize_key('plugin_names')])) { unset($plugin_names[$b]); } } $b++; } /** No need to proceed further if we have no plugins to install */ if (empty($plugin_installs)) { return false; } /** Reset array indexes in case we removed already installed plugins */ $plugin_installs = array_values($plugin_installs); $plugin_paths = array_values($plugin_paths); $plugin_names = array_values($plugin_names); /** If we grabbed our plugin info from $_GET, we need to decode it for use */ $plugin_installs = array_map('urldecode', $plugin_installs); $plugin_paths = array_map('urldecode', $plugin_paths); $plugin_names = array_map('urldecode', $plugin_names); /** Pass all necessary information via URL if WP_Filesystem is needed */ $url = wp_nonce_url(add_query_arg(array('page' => TGM_Plugin_Activation::$instance->menu, 'tgmpa-action' => 'install-selected', 'plugins' => urlencode(implode(',', $plugins)), 'plugin_paths' => urlencode(implode(',', $plugin_paths)), 'plugin_names' => urlencode(implode(',', $plugin_names))), admin_url(TGM_Plugin_Activation::$instance->parent_url_slug)), 'bulk-plugins'); $method = ''; // Leave blank so WP_Filesystem can populate it as necessary $fields = array(sanitize_key('action'), sanitize_key('_wp_http_referer'), sanitize_key('_wpnonce')); // Extra fields to pass to WP_Filesystem if (false === ($creds = request_filesystem_credentials($url, $method, false, false, $fields))) { return true; } if (!WP_Filesystem($creds)) { request_filesystem_credentials($url, $method, true, false, $fields); // Setup WP_Filesystem return true; } require_once ABSPATH . 'wp-admin/includes/plugin-install.php'; // Need for plugins_api require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; // Need for upgrade classes /** Store all information in arrays since we are processing a bulk installation */ $api = array(); $sources = array(); $install_path = array(); $c = 0; // Incremental variable /** Loop through each plugin to install and try to grab information from WordPress API, if not create 'tgmpa-empty' scalar */ foreach ($plugin_installs as $plugin) { $api[$c] = plugins_api('plugin_information', array('slug' => $plugin, 'fields' => array('sections' => false))) ? plugins_api('plugin_information', array('slug' => $plugin, 'fields' => array('sections' => false))) : (object) ($api[$c] = 'tgmpa-empty'); $c++; } if (is_wp_error($api)) { wp_die(TGM_Plugin_Activation::$instance->strings['oops'] . var_dump($api)); } $d = 0; // Incremental variable /** Capture download links from $api or set install link to pre-packaged/private repo */ foreach ($api as $object) { $sources[$d] = isset($object->download_link) && 'repo' == $plugin_paths[$d] ? $object->download_link : $plugin_paths[$d]; $d++; } /** Finally, all the data is prepared to be sent to the installer */ $url = add_query_arg(array('page' => TGM_Plugin_Activation::$instance->menu), admin_url(TGM_Plugin_Activation::$instance->parent_url_slug)); $nonce = 'bulk-plugins'; $names = $plugin_names; /** Create a new instance of TGM_Bulk_Installer */ $installer = new TGM_Bulk_Installer($skin = new TGM_Bulk_Installer_Skin(compact('url', 'nonce', 'names'))); /** Wrap the install process with the appropriate HTML */ echo '<div class="tgmpa wrap">'; screen_icon(apply_filters('tgmpa_default_screen_icon', 'themes')); echo '<h2>' . esc_html(get_admin_page_title()) . '</h2>'; /** Process the bulk installation submissions */ $installer->bulk_install($sources); echo '</div>'; return true; } /** Bulk activation process */ if ('tgmpa-bulk-activate' === $this->current_action()) { check_admin_referer('bulk-' . $this->_args['plural']); /** Grab plugin data from $_POST */ $plugins = isset($_POST[sanitize_key('plugin')]) ? (array) $_POST[sanitize_key('plugin')] : array(); $plugins_to_activate = array(); /** Split plugin value into array with plugin file path, plugin source and plugin name */ foreach ($plugins as $i => $plugin) { $plugins_to_activate[] = explode(',', $plugin); } foreach ($plugins_to_activate as $i => $array) { if (!preg_match('|.php$|', $array[0])) { // Plugins that haven't been installed yet won't have the correct file path unset($plugins_to_activate[$i]); } } /** Return early if there are no plugins to activate */ if (empty($plugins_to_activate)) { return; } $plugins = array(); $plugin_names = array(); foreach ($plugins_to_activate as $plugin_string) { $plugins[] = $plugin_string[0]; $plugin_names[] = $plugin_string[2]; } $count = count($plugin_names); // Count so we can use _n function $last_plugin = array_pop($plugin_names); // Pop off last name to prep for readability $imploded = empty($plugin_names) ? '<strong>' . $last_plugin . '</strong>' : '<strong>' . (implode(', ', $plugin_names) . '</strong> and <strong>' . $last_plugin . '</strong>.'); /** Now we are good to go - let's start activating plugins */ $activate = activate_plugins($plugins); if (is_wp_error($activate)) { echo '<div id="message" class="error"><p>' . $activate->get_error_message() . '</p></div>'; } else { printf('<div id="message" class="updated"><p>%1$s %2$s</p></div>', _n('The following plugin was activated successfully:', 'The following plugins were activated successfully:', $count, TGM_Plugin_Activation::$instance->domain), $imploded); } /** Update recently activated plugins option */ $recent = (array) get_option('recently_activated'); foreach ($plugins as $plugin => $time) { if (isset($recent[$plugin])) { unset($recent[$plugin]); } } update_option('recently_activated', $recent); unset($_POST); // Reset the $_POST variable in case user wants to perform one action after another } }
/** * Install a plugin from .org in the background via a cron job (used by * installer - opt in). * @param string $plugin_to_install_id * @param array $plugin_to_install * @since 2.6.0 */ public static function background_installer($plugin_to_install_id, $plugin_to_install) { if (!empty($plugin_to_install['repo-slug'])) { require_once ABSPATH . 'wp-admin/includes/file.php'; require_once ABSPATH . 'wp-admin/includes/plugin-install.php'; require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; require_once ABSPATH . 'wp-admin/includes/plugin.php'; WP_Filesystem(); $skin = new Automatic_Upgrader_Skin(); $upgrader = new WP_Upgrader($skin); $installed_plugins = array_map(array(__CLASS__, 'format_plugin_slug'), array_keys(get_plugins())); $plugin_slug = $plugin_to_install['repo-slug']; $plugin = $plugin_slug . '/' . $plugin_slug . '.php'; $installed = false; $activate = false; // See if the plugin is installed already if (in_array($plugin_to_install['repo-slug'], $installed_plugins)) { $installed = true; $activate = !is_plugin_active($plugin); } // Install this thing! if (!$installed) { // Suppress feedback ob_start(); try { $plugin_information = plugins_api('plugin_information', array('slug' => $plugin_to_install['repo-slug'], 'fields' => array('short_description' => false, 'sections' => false, 'requires' => false, 'rating' => false, 'ratings' => false, 'downloaded' => false, 'last_updated' => false, 'added' => false, 'tags' => false, 'homepage' => false, 'donate_link' => false, 'author_profile' => false, 'author' => false))); if (is_wp_error($plugin_information)) { throw new Exception($plugin_information->get_error_message()); } $package = $plugin_information->download_link; $download = $upgrader->download_package($package); if (is_wp_error($download)) { throw new Exception($download->get_error_message()); } $working_dir = $upgrader->unpack_package($download, true); if (is_wp_error($working_dir)) { throw new Exception($working_dir->get_error_message()); } $result = $upgrader->install_package(array('source' => $working_dir, 'destination' => WP_PLUGIN_DIR, 'clear_destination' => false, 'abort_if_destination_exists' => false, 'clear_working' => true, 'hook_extra' => array('type' => 'plugin', 'action' => 'install'))); if (is_wp_error($result)) { throw new Exception($result->get_error_message()); } $activate = true; } catch (Exception $e) { WC_Admin_Notices::add_custom_notice($plugin_to_install_id . '_install_error', sprintf(__('%1$s could not be installed (%2$s). <a href="%3$s">Please install it manually by clicking here.</a>', 'woocommerce'), $plugin_to_install['name'], $e->getMessage(), esc_url(admin_url('index.php?wc-install-plugin-redirect=' . $plugin_to_install['repo-slug'])))); } // Discard feedback ob_end_clean(); } wp_clean_plugins_cache(); // Activate this thing if ($activate) { try { $result = activate_plugin($plugin); if (is_wp_error($result)) { throw new Exception($result->get_error_message()); } } catch (Exception $e) { WC_Admin_Notices::add_custom_notice($plugin_to_install_id . '_install_error', sprintf(__('%1$s was installed but could not be activated. <a href="%2$s">Please activate it manually by clicking here.</a>', 'woocommerce'), $plugin_to_install['name'], admin_url('plugins.php'))); } } } }
/** * Search wordpress.org repo. * * @param array $args A arguments array containing the search term in the first element. * @param array $assoc_args Data passed in from command. */ protected function _search($args, $assoc_args) { $term = $args[0]; $defaults = array('per-page' => 10, 'page' => 1, 'fields' => implode(',', array('name', 'slug', 'rating'))); $assoc_args = array_merge($defaults, $assoc_args); $fields = array(); foreach (explode(',', $assoc_args['fields']) as $field) { $fields[$field] = true; } $formatter = $this->get_formatter($assoc_args); $api_args = array('per_page' => (int) $assoc_args['per-page'], 'page' => (int) $assoc_args['page'], 'search' => $term, 'fields' => $fields); if ('plugin' == $this->item_type) { $api = plugins_api('query_plugins', $api_args); } else { $api = themes_api('query_themes', $api_args); } if (is_wp_error($api)) { \WP_CLI::error($api->get_error_message() . __(' Try again')); } $plural = $this->item_type . 's'; if (!isset($api->{$plural})) { \WP_CLI::error(__('API error. Try Again.')); } $items = $api->{$plural}; $count = \WP_CLI\Utils\get_flag_value($api->info, 'results', 'unknown'); \WP_CLI::success(sprintf('Showing %s of %s %s.', count($items), $count, $plural)); $formatter->display_items($items); }
/** * * @global array $tabs * @global string $tab * @global int $paged * @global string $type * @global string $term * @global string $wp_version */ public function prepare_items() { include ABSPATH . 'wp-admin/includes/plugin-install.php'; global $tabs, $tab, $paged, $type, $term; wp_reset_vars(array('tab')); $paged = $this->get_pagenum(); $per_page = 30; // These are the tabs which are shown on the page $tabs = array(); if ('search' == $tab) { $tabs['search'] = __('Search Results'); } $tabs['featured'] = _x('Featured', 'Plugin Installer'); $tabs['popular'] = _x('Popular', 'Plugin Installer'); $tabs['recommended'] = _x('Recommended', 'Plugin Installer'); $tabs['favorites'] = _x('Favorites', 'Plugin Installer'); if ($tab === 'beta' || false !== strpos($GLOBALS['wp_version'], '-')) { $tabs['beta'] = _x('Beta Testing', 'Plugin Installer'); } if (current_user_can('upload_plugins')) { // No longer a real tab. Here for filter compatibility. // Gets skipped in get_views(). $tabs['upload'] = __('Upload Plugin'); } $nonmenu_tabs = array('plugin-information'); // Valid actions to perform which do not have a Menu item. /** * Filter the tabs shown on the Plugin Install screen. * * @since 2.7.0 * * @param array $tabs The tabs shown on the Plugin Install screen. Defaults include 'featured', 'popular', * 'recommended', 'favorites', and 'upload'. */ $tabs = apply_filters('install_plugins_tabs', $tabs); /** * Filter tabs not associated with a menu item on the Plugin Install screen. * * @since 2.7.0 * * @param array $nonmenu_tabs The tabs that don't have a Menu item on the Plugin Install screen. */ $nonmenu_tabs = apply_filters('install_plugins_nonmenu_tabs', $nonmenu_tabs); // If a non-valid menu tab has been selected, And it's not a non-menu action. if (empty($tab) || !isset($tabs[$tab]) && !in_array($tab, (array) $nonmenu_tabs)) { $tab = key($tabs); } $args = array('page' => $paged, 'per_page' => $per_page, 'fields' => array('last_updated' => true, 'icons' => true, 'active_installs' => true), 'locale' => get_locale(), 'installed_plugins' => $this->get_installed_plugin_slugs()); switch ($tab) { case 'search': $type = isset($_REQUEST['type']) ? wp_unslash($_REQUEST['type']) : 'term'; $term = isset($_REQUEST['s']) ? wp_unslash($_REQUEST['s']) : ''; switch ($type) { case 'tag': $args['tag'] = sanitize_title_with_dashes($term); break; case 'term': $args['search'] = $term; break; case 'author': $args['author'] = $term; break; } break; case 'featured': $args['fields']['group'] = true; $this->orderby = 'group'; // No break! // No break! case 'popular': case 'new': case 'beta': case 'recommended': $args['browse'] = $tab; break; case 'favorites': $user = isset($_GET['user']) ? wp_unslash($_GET['user']) : get_user_option('wporg_favorites'); update_user_meta(get_current_user_id(), 'wporg_favorites', $user); if ($user) { $args['user'] = $user; } else { $args = false; } add_action('install_plugins_favorites', 'install_plugins_favorites_form', 9, 0); break; default: $args = false; break; } /** * Filter API request arguments for each Plugin Install screen tab. * * The dynamic portion of the hook name, `$tab`, refers to the plugin install tabs. * Default tabs include 'featured', 'popular', 'recommended', 'favorites', and 'upload'. * * @since 3.7.0 * * @param array|bool $args Plugin Install API arguments. */ $args = apply_filters("install_plugins_table_api_args_{$tab}", $args); if (!$args) { return; } $api = plugins_api('query_plugins', $args); if (is_wp_error($api)) { $this->error = $api; return; } $this->items = $api->plugins; if ($this->orderby) { uasort($this->items, array($this, 'order_callback')); } $this->set_pagination_args(array('total_items' => $api->info['results'], 'per_page' => $args['per_page'])); if (isset($api->info['groups'])) { $this->groups = $api->info['groups']; } }