/** * Install plugin from a URL. * * A mix of install-plugin and upload-plugin actions from wp-admin/update.php:93. */ public function download_plugin() { if (!current_user_can('upload_plugins')) { wp_die(__('You do not have sufficient permissions to install plugins on this site.')); } check_admin_referer('plugin-download'); require_once ABSPATH . 'wp-admin/admin-header.php'; $download_url = esc_url_raw($_REQUEST['pluginurl']); // Remove "-master" from GitHub URL-s if (false !== strstr($download_url, '//github.com/')) { add_filter('upgrader_source_selection', array($this, 'remove_github_master'), 9, 3); } $type = 'web'; $title = sprintf(__('Installing Plugin from URL: %s'), esc_html($download_url)); $url = 'update.php?action=install-plugin'; $nonce = 'plugin-download'; $upgrader = new Plugin_Upgrader(new Plugin_Installer_Skin(compact('type', 'title', 'url', 'nonce'))); $upgrader->install($download_url); include ABSPATH . 'wp-admin/admin-footer.php'; }
protected function install() { foreach ($this->plugins as $index => $slug) { $skin = new Jetpack_Automatic_Install_Skin(); $upgrader = new Plugin_Upgrader($skin); $zip_url = self::generate_wordpress_org_plugin_download_link($slug); $result = $upgrader->install($zip_url); if (!$this->bulk && is_wp_error($result)) { return $result; } $plugin = self::get_plugin_id_by_slug($slug); $error_code = 'install_error'; if (!$plugin) { $error = $this->log[$slug]['error'] = __('There was an error installing your plugin', 'jetpack'); } if (!$this->bulk && !$result) { $error_code = $upgrader->skin->get_main_error_code(); $message = $upgrader->skin->get_main_error_message(); $error = $this->log[$slug]['error'] = $message ? $message : __('An unknown error occurred during installation', 'jetpack'); } $this->log[$plugin][] = $upgrader->skin->get_upgrade_messages(); } if (!$this->bulk && isset($error)) { if ('download_failed' === $error_code) { // For backwards compatibility: versions prior to 3.9 would return no_package instead of download_failed. $error_code = 'no_package'; } return new WP_Error($error_code, $this->log[$slug]['error'], 400); } // replace the slug with the actual plugin id $this->plugins[$index] = $plugin; return true; }
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())); } }
protected function install() { foreach ($this->plugins as $index => $slug) { $skin = new Automatic_Upgrader_Skin(); $upgrader = new Plugin_Upgrader($skin); $result = $upgrader->install($this->download_links[$slug]); if (!$this->bulk && is_wp_error($result)) { return $result; } $plugin = $this::get_plugin_id_by_slug($slug); if (!$plugin) { $error = $this->log[$slug]['error'] = __('There was an error installing your plugin', 'jetpack'); } if (!$this->bulk && !$result) { $error = $this->log[$slug]['error'] = __('An unknown error occurred during installation', 'jetpack'); } $this->log[$plugin][] = $upgrader->skin->get_upgrade_messages(); } if (!$this->bulk && isset($error)) { return new WP_Error('install_error', $this->log[$slug]['error'], 400); } // replace the slug with the actual plugin id $this->plugins[$index] = $plugin; return true; }
function mpi_plugin_handle_download($plugin_name, $package, $mpi_action, $whform) { global $wp_version; if (version_compare($wp_version, '3.0', '<')) { include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; $upgrader = new Plugin_Upgrader(); $upgrader->install($package); if ($upgrader->plugin_info()) { echo '<a href="' . wp_nonce_url('plugins.php?action=activate&plugin=' . $upgrader->plugin_info(), 'activate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Activate this plugin') . '" target="_parent">' . __('Activate Plugin') . '</a>'; } } else { include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; $upgrader = new Plugin_Upgrader(new Plugin_Installer_Skin(compact('type', 'title', 'nonce', 'url'))); $res = $upgrader->install($package); //remove temp files if ($whform == "upload_locFiles") { @unlink($package); } if (!$upgrader->plugin_info()) { echo $res; } elseif ($mpi_action == "activate") { $mpiplugins = get_option('active_plugins'); if ($mpiplugins) { $puginsToActiv = array($upgrader->plugin_info()); foreach ($puginsToActiv as $mpiplugin) { if (!in_array($mpiplugin, $mpiplugins)) { array_push($mpiplugins, $mpiplugin); update_option('active_plugins', $mpiplugins); } } } _e('<b class="mpi_act">Plugin activated successfully.</b><br/>', 'mpi'); } } }
function pl_ui_build_body($obj) { if (isset($_GET['install_faves']) && 'true' == $_GET['install_faves'] || isset($_GET['install_multi']) && 'true' == $_GET['install_multi']) { if (isset($_GET['install_multi'])) { $mode = 'multi'; } else { $mode = 'fav'; } if ('multi' == $mode) { $banner = 'Installing Selected Products'; $favs = explode(',', $_GET['slugs']); foreach ($favs as $k => $fav) { $favs[$fav] = $fav; unset($favs[$k]); } } else { $banner = 'Installing Favourite Products'; $favs = (array) get_user_meta(wp_get_current_user()->ID, '_card_fav', true); } printf('<h2>%s</2>', $banner); // lets go! if (!empty($favs)) { include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; $upgrader = new Plugin_Upgrader(new Plugin_Installer_Skin(compact('type', 'title', 'nonce', 'url'))); $data = PL_Platform()->functions->cache_get('connect_updates'); foreach ($data as $k => $prod) { $data[$prod->slug] = $prod; unset($data[$k]); } foreach ($favs as $slug => $k) { $path = sprintf('%s/%s.php', $slug, $slug); if (PL_Platform()->extend->is_plugin_installed($path)) { printf('<p>%s is already installed, skipping.</p>', $data[$slug]->post_title); } else { printf('<p><i class="%s-spinner fa fa-cog fa-spin"></i><div style="display:none">', $slug); $link = PL_Platform_Updater::get_download_link($data[$slug]->download_data); $res = $upgrader->install($link); printf('</div></p><script>jQuery(".%s-spinner").hide()</script>', $slug); if ($upgrader->plugin_info()) { $result = activate_plugin($path); printf('<p><strong>%s</strong> has been installed successfully and is activated.</p>', $data[$slug]->post_title); } else { echo $res; break; } } } echo '</p><h3>All Done!</h3></p><script>localStorage.clear();setTimeout(function(){window.location.href=window.PLAdmin.extendURL},3000)</script>'; } } else { $obj->build_body(); } }
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); }
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)); } }
/** * Install a plugin */ function siteorigin_plugin_activation_do_plugin_install() { /** All plugin information will be stored in an array for processing */ $plugin = array(); /** Checks for actions from hover links to process the installation */ if (isset($_GET[sanitize_key('plugin')]) && (isset($_GET[sanitize_key('siteorigin-pa-install')]) && 'install-plugin' == $_GET[sanitize_key('siteorigin-pa-install')]) && current_user_can('install_plugins')) { check_admin_referer('siteorigin-pa-install'); $plugin['name'] = $_GET['plugin_name']; // Plugin name $plugin['slug'] = $_GET['plugin']; // Plugin slug if (!empty($_GET['plugin_source'])) { $plugin['source'] = $_GET['plugin_source']; } else { $plugin['source'] = false; } /** Pass all necessary information via URL if WP_Filesystem is needed */ $url = wp_nonce_url(add_query_arg(array('page' => 'siteorigin_plugin_activation', 'plugin' => $plugin['slug'], 'plugin_name' => $plugin['name'], 'plugin_source' => $plugin['source'], 'siteorigin-pa-install' => 'install-plugin'), admin_url('themes.php')), 'siteorigin-pa-install'); $method = ''; // Leave blank so WP_Filesystem can populate it as necessary $fields = array(sanitize_key('siteorigin-pa-install')); // 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 /** Prep variables for Plugin_Installer_Skin class */ $title = sprintf(__('Installing %s', 'vantage'), $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']; // Find the source of the plugin $source = !empty($plugin['source']) ? $plugin['source'] : 'http://downloads.wordpress.org/plugin/' . urlencode($plugin['slug']) . '.zip'; /** Create a new instance of Plugin_Upgrader */ $upgrader = new Plugin_Upgrader($skin = new Plugin_Installer_Skin(compact('type', 'title', 'url', 'nonce', 'plugin', 'api'))); /** Perform the action and install the plugin from the $source urldecode() */ $upgrader->install($source); /** Flush plugins cache so we can make sure that the installed plugins list is always up to date */ wp_cache_flush(); } }
/** * @usage Single click add-on install */ function installAddon() { if (isset($_POST['updateurl']) && current_user_can(WPDM_ADMIN_CAP)) { include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; include_once ABSPATH . 'wp-admin/includes/plugin-install.php'; $upgrader = new \Plugin_Upgrader(new \Plugin_Installer_Skin(compact('title', 'url', 'nonce', 'plugin', 'api'))); $downloadlink = $_POST['updateurl'] . '&preact=login&user='******'__wpdm_suname') . '&pass='******'__wpdm_supass'); $upgrader->install($downloadlink); $plugininfo = wpdm_plugin_data($_POST['plugin']); if (file_exists(dirname(WPDM_BASE_DIR) . '/' . $plugininfo['plugin_index_file'])) { activate_plugin($plugininfo['plugin_index_file']); } die("Installed Successfully"); } else { die("Only site admin is authorized to install add-on"); } }
function install() { $args = $this->input(); if (isset($args['zip'][0]['id'])) { $plugin_attachment_id = $args['zip'][0]['id']; $local_file = get_attached_file($plugin_attachment_id); if (!$local_file) { return new WP_Error('local-file-does-not-exist'); } $skin = new Jetpack_Automatic_Install_Skin(); $upgrader = new Plugin_Upgrader($skin); $pre_install_plugin_list = get_plugins(); $result = $upgrader->install($local_file); // clean up. wp_delete_attachment($plugin_attachment_id, true); if (is_wp_error($result)) { return $result; } $after_install_plugin_list = get_plugins(); $plugin = array_values(array_diff(array_keys($after_install_plugin_list), array_keys($pre_install_plugin_list))); if (!$result) { $error_code = $upgrader->skin->get_main_error_code(); $message = $upgrader->skin->get_main_error_message(); if (empty($message)) { $message = __('An unknown error occurred during installation', 'jetpack'); } if ('download_failed' === $error_code) { $error_code = 'no_package'; } return new WP_Error($error_code, $message, 400); } if (empty($plugin)) { return new WP_Error('plugin_already_installed'); } $this->plugins = $plugin; $this->log[$plugin[0]] = $upgrader->skin->get_upgrade_messages(); return true; } return new WP_Error('no_plugin_installed'); }
function handle_download($plugin_name, $package) { global $wp_version; if (version_compare($wp_version, '2.8', '<')) { $this->update_plugin_advanced($plugin_name, $package); } else { if (version_compare($wp_version, '3.0', '<')) { include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; $upgrader = new Plugin_Upgrader(); $upgrader->install($package); if ($upgrader->plugin_info()) { echo '<a href="' . wp_nonce_url('plugins.php?action=activate&plugin=' . $upgrader->plugin_info(), 'activate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Activate this plugin') . '" target="_parent">' . __('Activate Plugin') . '</a>'; } } else { include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; $upgrader = new Plugin_Upgrader(new Plugin_Installer_Skin(compact('type', 'title', 'nonce', 'url'))); $res = $upgrader->install($package); if (!$upgrader->plugin_info()) { echo $res; } } } }
/** * Installs a plugin or activates a plugin depending on the hover * link clicked by the user. * * Checks the $_GET variable to see which actions have been * passed and responds with the appropriate method. * * Uses WP_Filesystem to process and handle the plugin installation * method. * * @since 1.0.0 * * @uses WP_Filesystem * @uses WP_Error * @uses WP_Upgrader * @uses Plugin_Upgrader * @uses Plugin_Installer_Skin * * @return boolean True on success, false on failure */ protected function do_plugin_install() { /** All plugin information will be stored in an array for processing */ $plugin = array(); /** Checks for actions from hover links to process the installation */ if (isset($_GET[sanitize_key('plugin')]) && (isset($_GET[sanitize_key('tgmpa-install')]) && 'install-plugin' == $_GET[sanitize_key('tgmpa-install')] || isset($_GET[sanitize_key('tgmpa-update')]) && 'update-plugin' == $_GET[sanitize_key('tgmpa-update')])) { check_admin_referer('tgmpa-install'); $plugin['name'] = $_GET[sanitize_key('plugin_name')]; // Plugin name $plugin['slug'] = $_GET[sanitize_key('plugin')]; // Plugin slug $plugin['source'] = $_GET[sanitize_key('plugin_source')]; // Plugin source $plugin['version'] = isset($_GET[sanitize_key('version')]) ? $_GET[sanitize_key('version')] : ''; // Plugin source $install_type = isset($_GET[sanitize_key('tgmpa-update')]) ? $_GET[sanitize_key('tgmpa-update')] : ''; // Install type /** Pass all necessary information via URL if WP_Filesystem is needed */ $url = wp_nonce_url(add_query_arg(array('page' => $this->menu, 'plugin' => $plugin['slug'], 'plugin_name' => $plugin['name'], 'plugin_source' => $plugin['source'], 'tgmpa-install' => 'install-plugin'), admin_url($this->parent_url_slug)), 'tgmpa-install'); $method = ''; // Leave blank so WP_Filesystem can populate it as necessary $fields = array(sanitize_key('tgmpa-install')); // 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 /** Set plugin source to WordPress API link if available */ if (isset($plugin['source']) && 'repo' == $plugin['source']) { $api = plugins_api('plugin_information', array('slug' => $plugin['slug'], 'fields' => array('sections' => false))); if (is_wp_error($api)) { wp_die($this->strings['oops'] . var_dump($api)); } if (isset($api->download_link)) { $plugin['source'] = $api->download_link; } } /** 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($this->strings['installing'], $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']; /** Prefix a default path to pre-packaged plugins */ $source = 'upload' == $type ? $this->default_path . $plugin['source'] : $plugin['source']; /** Create a new instance of Plugin_Upgrader */ $upgrader = new Plugin_Upgrader($skin = new Plugin_Installer_Skin(compact('type', 'title', 'url', 'nonce', 'plugin', 'api'))); /** Perform the action and install the plugin from the $source urldecode() */ if ($install_type == 'update-plugin') { delete_site_transient('update_plugins'); $data = get_site_transient('update_plugins'); if (!is_object($data)) { $data = new stdClass(); } $data->response[$plugin['slug']]->package = $source; $data->response[$plugin['slug']]->version = $plugin['version']; set_site_transient('update_plugins', $data); $upgrader->upgrade($plugin['slug']); } else { $upgrader->install($source); } /** Flush plugins cache so we can make sure that the installed plugins list is always up to date */ wp_cache_flush(); /** Only activate plugins if the config option is set to true */ if ($this->is_automatic) { $plugin_activate = $upgrader->plugin_info(); // Grab the plugin info from the Plugin_Upgrader method $activate = activate_plugin($plugin_activate); // Activate the plugin $this->populate_file_path(); // Re-populate the file path now that the plugin has been installed and activated if (is_wp_error($activate)) { echo '<div id="message" class="error"><p>' . $activate->get_error_message() . '</p></div>'; echo '<p><a href="' . add_query_arg('page', $this->menu, admin_url($this->parent_url_slug)) . '" title="' . esc_attr($this->strings['return']) . '" target="_parent">' . __('Return to Required Plugins Installer', THEMENAME) . '</a></p>'; return true; // End it here if there is an error with automatic activation } else { echo '<p>' . $this->strings['plugin_activated'] . '</p>'; } } /** 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 '<p><a href="' . add_query_arg('page', $this->menu, admin_url($this->parent_url_slug)) . '" title="' . esc_attr($this->strings['return']) . '" target="_parent">' . $this->strings['return'] . '</a></p>'; $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 '<p>' . sprintf($this->strings['complete'], '<a href="' . admin_url() . '" title="' . __('Return to the Dashboard', THEMENAME) . '">' . __('Return to the Dashboard', THEMENAME) . '</a>') . '</p>'; echo '<style type="text/css">#adminmenu .wp-submenu li.current { display: none !important; }</style>'; } return true; } elseif (isset($_GET[sanitize_key('plugin')]) && (isset($_GET[sanitize_key('tgmpa-activate')]) && 'activate-plugin' == $_GET[sanitize_key('tgmpa-activate')])) { check_admin_referer('tgmpa-activate', 'tgmpa-activate-nonce'); /** Populate $plugin array with necessary information */ $plugin['name'] = $_GET[sanitize_key('plugin_name')]; $plugin['slug'] = $_GET[sanitize_key('plugin')]; $plugin['source'] = $_GET[sanitize_key('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 '<div id="message" class="error"><p>' . $activate->get_error_message() . '</p></div>'; echo '<p><a href="' . add_query_arg('page', $this->menu, admin_url($this->parent_url_slug)) . '" title="' . esc_attr($this->strings['return']) . '" target="_parent">' . $this->strings['return'] . '</a></p>'; 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[sanitize_key('action')])) { $msg = sprintf(__('The following plugin was activated successfully: %s.', THEMENAME), '<strong>' . $plugin['name'] . '</strong>'); echo '<div id="message" class="updated"><p>' . $msg . '</p></div>'; } } } return false; }
echo sprintf(__('Please contact your administrator (%1s) to activate the plugin "Maps Marker Pro".', 'lmm'), '<a href="mailto:' . get_bloginfo('admin_email') . '?subject=' . esc_attr__('Please activate the plugin "Maps Marker Pro"', 'lmm') . '">' . get_bloginfo('admin_email') . '</a>'); } } } } else { if (!wp_verify_nonce($_POST['_wpnonce'], 'pro-upgrade-nonce')) { wp_die('<br/>' . __('Security check failed - please call this function from the according admin page!', 'lmm') . ''); } if ($action == 'upgrade_to_pro_version') { include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; add_filter('https_ssl_verify', '__return_false'); //info: otherwise SSL error on localhost installs. add_filter('https_local_ssl_verify', '__return_false'); //info: not sure if needed, added to be sure $upgrader = new Plugin_Upgrader(new Plugin_Upgrader_Skin()); $dl = 'https://www.mapsmarker.com/upgrade-pro'; $upgrader->install($dl); //info: check if download was successful $lmm_pro_readme = WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'leaflet-maps-marker-pro' . DIRECTORY_SEPARATOR . 'readme.txt'; if (file_exists($lmm_pro_readme)) { echo '<p>' . __('Please activate the plugin by clicking the link above', 'lmm') . '</p>'; } else { $dl_l = 'https://www.mapsmarker.com/upgrade-pro'; $dl_lt = 'www.mapsmarker.com/upgrade-pro'; echo '<p>' . sprintf(__('The pro plugin package could not be downloaded automatically. Please download the plugin from <a href="%1s">%2s</a> and upload it to the directory /wp-content/plugins on your server manually', 'lmm'), $dl_l, $dl_lt) . '</p>'; } } } ?> </div> <!--wrap-->
/** * Installs and activates the plugin. * * This method actually installs the plugins. It instantiates the * WP_Filesystem Abstraction class to do the heavy lifting. * * Any errors are displayed using the WP_Error class. * * @since 1.0.0 * * @uses WP_Filesystem * @uses WP_Error * @uses WP_Upgrader * @uses Plugin_Upgrader * @uses Plugin_Installer_Skin * * @return boolean True on success, false on failure */ protected function do_plugin_install() { if (empty($_POST)) { // Bail out if the global $_POST is empty return false; } check_admin_referer('tgmpa'); // Security check foreach ($this->plugins as $plugin) { // Iterate and perform the action for each plugin in the array $fields = array(sanitize_key($plugin['name'])); $method = ''; // Leave blank so WP_Filesystem can populate it as necessary if (isset($_POST[sanitize_key($plugin['name'])])) { // Don't do anything if the form has not been submitted $url = wp_nonce_url('themes.php?page=' . $this->menu, 'tgmpa'); // Make sure we are coming from the right page 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 $api = plugins_api('plugin_information', array('slug' => $plugin['slug'], 'fields' => array('sections' => false))); if (is_wp_error($api)) { wp_die($this->strings['oops'] . var_dump($api)); } // Prep variables for Plugin_Installer_Skin class $title = sprintf($this->strings['installing'], $plugin['name']); $nonce = 'install-plugin_' . $plugin['slug']; $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); } if (!isset($plugin['source']) && isset($api->download_link)) { $plugin['source'] = $api->download_link; } /** Set type, based on whether the source starts with http:// or https:// */ $type = preg_match('|^http(s)?://|', $plugin['source']) ? 'web' : 'upload'; /** Prefix a default path to pre-packaged plugins */ $source = 'upload' == $type ? $this->default_path . $plugin['source'] : $plugin['source']; $upgrader = new Plugin_Upgrader(new Plugin_Installer_Skin(compact('title', 'url', 'nonce', 'plugin', 'api'))); // Create a new instance of Plugin_Upgrader $upgrader->install($source); // Perform the action and install the plugin from the $source urldecode() $plugin_activate = $upgrader->plugin_info(); // Grab the plugin info from the Plugin_Upgrader method wp_cache_flush(); // Flush the cache to remove plugin header errors $activate = activate_plugin($plugin_activate); // Activate the plugin $this->populate_file_path(); // Re-populate the file path now that the plugin has been installed and activated if (is_wp_error($activate)) { echo '<div id="message" class="error"><p>' . $activate->get_error_message() . '</p></div>'; echo '<p><a href="' . add_query_arg('page', $this->menu, admin_url('themes.php')) . '" title="' . esc_attr($this->strings['return']) . '" target="_parent">' . __('Return to Required Plugins Installer', $this->domain) . '</a></p>'; return true; // End it here if there is an error with automatic activation } else { echo '<p>' . $this->strings['plugin_activated'] . '</p>'; foreach ($this->plugins as $plugin) { if (!is_plugin_active($plugin['file_path'])) { echo '<p><a href="' . add_query_arg('page', $this->menu, admin_url('themes.php')) . '" title="' . esc_attr($this->strings['return']) . '" target="_parent">' . __('Return to Required Plugins Installer', $this->domain) . '</a></p>'; break; } } } } } return true; }
/** * Install and active a plugin from slug name * * @param $slug * @return array */ function learn_press_install_and_active_add_on($slug) { learn_press_require_plugins_api(); if (!class_exists('Plugin_Upgrader', false)) { require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; } $api = plugins_api('plugin_information', array('slug' => $slug, 'fields' => array('sections' => false))); $title = sprintf(__('Installing Plugin: %s', 'learn_press'), $api->name . ' ' . $api->version); $nonce = 'install-plugin_' . $slug; $url = 'update.php?action=install-plugin&plugin=' . urlencode($slug); $plugin = learn_press_plugin_basename_from_slug($slug); $return = array(); if (!learn_press_is_plugin_install($plugin)) { $upgrader = new Plugin_Upgrader(new Plugin_Installer_Skin(compact('title', 'url', 'nonce', 'plugin', 'api'))); $result = $upgrader->install($api->download_link); if (is_wp_error($result)) { $return['error'] = $result; $return['status'] = 'not_install'; $return['status_text'] = __('Not install', 'learn_press'); } else { $return['result'] = $result; $return['status'] = 'installed'; $return['status_text'] = __('Installed', 'learn_press'); } } $plugin = learn_press_plugin_basename_from_slug($slug); //echo "[$plugin]"; if (learn_press_is_plugin_install($plugin)) { activate_plugin($plugin, false, is_network_admin()); // ensure that plugin is enabled $is_activate = is_plugin_active($plugin); $return['status'] = $is_activate ? 'activate' : 'deactivate'; $return['status_text'] = $is_activate ? __('Enabled', 'learn_press') : __('Disabled', 'learn_press'); } $return['plugin_file'] = $plugin; return $return; }
/** * Install and activate dependency. * * @param string $slug Plugin slug. * * @return bool|array false or Message. */ public function install($slug) { if ($this->is_installed($slug) || !current_user_can('update_plugins')) { return false; } $this->current_slug = $slug; add_filter('upgrader_source_selection', array($this, 'upgrader_source_selection'), 10, 2); $skin = new WPDI_Plugin_Installer_Skin(array('type' => 'plugin', 'nonce' => wp_nonce_url($this->config[$slug]['download_link']))); $upgrader = new Plugin_Upgrader($skin); $result = $upgrader->install($this->config[$slug]['download_link']); if (is_wp_error($result)) { return array('status' => 'error', 'message' => $result->get_error_message()); } wp_cache_flush(); if (!$this->config[$slug]['optional']) { $result = $this->activate($slug); return array('status' => 'updated', 'slug' => $slug, 'message' => sprintf(__('%s has been installed and activated.'), $this->config[$slug]['name'])); } if ('error' == $result['status']) { return $result; } return array('status' => 'updated', 'message' => sprintf(__('%s has been installed.'), $this->config[$slug]['name'])); }
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(); }
public function download_plugin($slug, $url) { require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; require_once $this->plugin_path() . '/includes/installer-upgrader-skins.php'; $upgrader_skins = new Installer_Upgrader_Skins(); //use our custom (mute) Skin $upgrader = new Plugin_Upgrader($upgrader_skins); remove_action('upgrader_process_complete', array('Language_Pack_Upgrader', 'async_upgrade'), 20); $plugins = get_plugins(); $plugin_id = false; //upgrade or install? foreach ($plugins as $id => $plugin) { $wp_plugin_slug = dirname($id); if ($wp_plugin_slug == $slug) { $plugin_id = $id; break; } } if ($plugin_id) { //upgrade $plugin_is_active = is_plugin_active($plugin_id); $ret = $upgrader->upgrade($plugin_id); if ($plugin_is_active) { activate_plugin($plugin_id); } } else { //install $ret = $upgrader->install($url); } return $ret; }
/** * Installs a plugin or activates a plugin depending on the hover * link clicked by the user. * * Checks the $_GET variable to see which actions have been * passed and responds with the appropriate method. * * Uses WP_Filesystem to process and handle the plugin installation * method. * * @since 1.0.0 * * @uses WP_Filesystem * @uses WP_Error * @uses WP_Upgrader * @uses Plugin_Upgrader * @uses Plugin_Installer_Skin * * @return boolean True on success, false on failure */ protected function do_plugin_install() { // All plugin information will be stored in an array for processing. $plugin = array(); // Checks for actions from hover links to process the installation. if (isset($_GET['plugin']) && (isset($_GET['tgmpa-install']) && 'install-plugin' === $_GET['tgmpa-install'])) { check_admin_referer('tgmpa-install'); $plugin['name'] = $_GET['plugin_name']; // Plugin name. // @todo needs sanitizing, figure out how $plugin['slug'] = sanitize_title($_GET['plugin']); // Plugin slug. $plugin['source'] = $_GET['plugin_source']; // Plugin source. // @todo needs sanitizing, figure out how // Pass all necessary information via URL if WP_Filesystem is needed. $url = wp_nonce_url(add_query_arg(array('page' => urlencode($this->menu), 'plugin' => urlencode($plugin['slug']), 'plugin_name' => urlencode($plugin['name']), 'plugin_source' => urlencode($plugin['source']), 'tgmpa-install' => 'install-plugin'), self_admin_url($this->parent_slug)), 'tgmpa-install'); $method = ''; // Leave blank so WP_Filesystem can populate it as necessary. $fields = array('tgmpa-install'); // 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. // Set plugin source to WordPress API link if available. if (isset($plugin['source']) && 'repo' === $plugin['source']) { $api = plugins_api('plugin_information', array('slug' => $plugin['slug'], 'fields' => array('sections' => false))); if (is_wp_error($api)) { if (WP_DEBUG === true) { wp_die(esc_html($this->strings['oops']) . var_dump($api)); // wpcs: xss ok } else { wp_die(esc_html($this->strings['oops'])); } } if (isset($api->download_link)) { $plugin['source'] = $api->download_link; } } // 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($this->strings['installing'], $plugin['name']); $url = add_query_arg(array('action' => 'install-plugin', 'plugin' => urlencode($plugin['slug'])), 'update.php'); if (isset($_GET['from'])) { $url .= add_query_arg('from', urlencode(stripslashes($_GET['from'])), $url); } $url = esc_url_raw($url); $nonce = 'install-plugin_' . $plugin['slug']; // Prefix a default path to pre-packaged plugins. $source = 'upload' === $type ? $this->default_path . $plugin['source'] : $plugin['source']; // Create a new instance of Plugin_Upgrader. $upgrader = new Plugin_Upgrader($skin = new Plugin_Installer_Skin(compact('type', 'title', 'url', 'nonce', 'plugin', 'api'))); // Perform the action and install the plugin from the $source urldecode(). $upgrader->install($source); // Flush plugins cache so we can make sure that the installed plugins list is always up to date. wp_cache_flush(); // Only activate plugins if the config option is set to true. if ($this->is_automatic) { $plugin_activate = $upgrader->plugin_info(); // Grab the plugin info from the Plugin_Upgrader method. $activate = activate_plugin($plugin_activate); // Activate the plugin. $this->populate_file_path(); // Re-populate the file path now that the plugin has been installed and activated. if (is_wp_error($activate)) { echo '<div id="message" class="error"><p>', wp_kses_post($activate->get_error_message()), '</p></div>', '<p><a href="', esc_url(add_query_arg('page', urlencode($this->menu), self_admin_url('themes.php'))), '" target="_parent">', esc_html($this->strings['return']), '</a></p>'; return true; // End it here if there is an error with automatic activation } else { echo '<p>', esc_html($this->strings['plugin_activated']), '</p>'; } } // 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 '<p><a href="', esc_url(add_query_arg('page', urlencode($this->menu), self_admin_url($this->parent_slug))), '" target="_parent">', esc_html($this->strings['return']), '</a></p>'; $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 '<p>', sprintf(esc_html($this->strings['complete']), '<a href="' . esc_url(self_admin_url()) . '">' . esc_html__('Return to the Dashboard', 'tgmpa') . '</a>'), '</p>'; echo '<style type="text/css">#adminmenu .wp-submenu li.current { display: none !important; }</style>'; } return true; } 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']; // @todo needs sanitizing, figure out how $plugin['slug'] = sanitize_title($_GET['plugin']); $plugin['source'] = $_GET['plugin_source']; // @todo needs sanitizing, figure out how $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 '<div id="message" class="error"><p>', wp_kses_post($activate->get_error_message()), '</p></div>'; echo '<p><a href="', esc_url(add_query_arg('page', urlencode($this->menu), self_admin_url($this->parent_slug))), '" target="_parent">', esc_html($this->strings['return']), '</a></p>'; 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'])) { echo '<div id="message" class="updated"><p>', esc_html($this->strings['activated_successfully']), ' <strong>', esc_html($plugin['name']), '.</strong></p></div>'; } } } return false; }
/** * Install the plugin. * * @since 1.0.0 * * @return true|null|WP_Error */ public function install() { if ($this->is_installed()) { return new WP_Error('cannot_reinstall', esc_html__('The plugin is already installed.', 'audiotheme-agent')); } if (!current_user_can('install_plugins')) { return new WP_Error('unauthorized', esc_html__('You do not have sufficient permissions to install plugins on this site.', 'audiotheme-agent')); } $upgrader = new Plugin_Upgrader(new Automatic_Upgrader_Skin()); $result = $upgrader->install($this->get_download_url()); if (true === $result) { $plugins = get_plugins('/' . $this->get_slug()); $plugin_file = $this->get_slug() . '/' . key($plugins); $this->set_file($plugin_file)->set_installed(true)->set_installed_version($this->get_current_version()); } return $result; }
/** * Added from v4.1.1 * WPDM add-on installer */ function wpdm_install_addon() { if (isset($_REQUEST['addon']) && current_user_can('manage_options')) { include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; include_once ABSPATH . 'wp-admin/includes/plugin-install.php'; $upgrader = new Plugin_Upgrader(new Plugin_Installer_Skin(compact('title', 'url', 'nonce', 'plugin', 'api'))); if (strpos($_REQUEST['addon'], '.zip')) { $downloadlink = $_REQUEST['addon']; } else { $downloadlink = 'http://www.wpdownloadmanager.com/?wpdmdl=' . $_REQUEST['addon']; } $upgrader->install($downloadlink); die; } else { die("Only site admin is authorized to install add-on"); } }
/** * Installs a plugin or activates a plugin depending on the hover * link clicked by the user. * * Checks the $_GET variable to see which actions have been * passed and responds with the appropriate method. * * Uses WP_Filesystem to process and handle the plugin installation * method. * * @since 1.0.0 * * @uses WP_Filesystem * @uses WP_Error * @uses WP_Upgrader * @uses Plugin_Upgrader * @uses Plugin_Installer_Skin * * @return boolean True on success, false on failure. */ protected function do_plugin_install() { if (!isset($_GET['plugin'])) { return false; } // All plugin information will be stored in an array for processing. $plugin = array(); $slug = sanitize_key($_GET['plugin']); // Checks for actions from hover links to process the installation. if (isset($this->plugins[$slug], $_GET['tgmpa-install']) && 'install-plugin' === $_GET['tgmpa-install']) { check_admin_referer('tgmpa-install'); // Pass necessary information via URL if WP_Filesystem is needed. $url = wp_nonce_url(add_query_arg(array('plugin' => urlencode($slug), 'tgmpa-install' => 'install-plugin'), $this->get_tgmpa_url()), 'tgmpa-install'); $method = ''; // Leave blank so WP_Filesystem can populate it as necessary. if (false === ($creds = request_filesystem_credentials(esc_url_raw($url), $method, false, false, array()))) { return true; } if (!WP_Filesystem($creds)) { request_filesystem_credentials(esc_url_raw($url), $method, true, false, array()); // Setup WP_Filesystem. return true; } // If we arrive here, we have the filesystem require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; // Need for upgrade classes. $plugin['slug'] = $slug; // Needed for potentially renaming of directory name $plugin['name'] = $this->plugins[$slug]['name']; $source = $this->get_download_url($slug); // Prep variables for Plugin_Installer_Skin class. $url = add_query_arg(array('action' => 'install-plugin', 'plugin' => urlencode($slug)), 'update.php'); // Create a new instance of Plugin_Upgrader. $upgrader = new Plugin_Upgrader(new Plugin_Installer_Skin(array('type' => preg_match(self::IS_URL_REGEX, $source) ? 'web' : 'upload', 'title' => sprintf($this->strings['installing'], $plugin['name']), 'url' => esc_url_raw($url), 'nonce' => 'install-plugin_' . $slug, 'plugin' => $plugin))); // Perform the action and install the plugin from the $source urldecode(). add_filter('upgrader_source_selection', array($this, 'maybe_adjust_source_dir'), 1, 3); $upgrader->install($source); remove_filter('upgrader_source_selection', array($this, 'maybe_adjust_source_dir'), 1, 3); // Flush plugins cache so we can make sure that the installed plugins list is always up to date. $this->flush_plugins_cache(); // Only activate plugins if the config option is set to true. if ($this->is_automatic) { $plugin_activate = $upgrader->plugin_info(); // Grab the plugin info from the Plugin_Upgrader method. if (false === $this->activate_single_plugin($plugin_activate, $slug, true)) { return true; // Finish execution of the function early as we encountered an error } // Re-populate the file path now that the plugin has been installed and activated. $this->populate_file_path($slug); } // Display message based on if all plugins are now active or not. $complete = true; foreach ($this->plugins as $plugin) { if (!is_plugin_active($plugin['file_path'])) { echo '<p><a href="', esc_url($this->get_tgmpa_url()), '" target="_parent">', esc_html($this->strings['return']), '</a></p>'; $complete = false; break; } } // All plugins are active, so we display the complete string and hide the plugin menu. if (true === $complete) { echo '<p>', sprintf(esc_html($this->strings['complete']), '<a href="' . esc_url(self_admin_url()) . '">' . esc_html__('Return to the Dashboard', 'tgmpa') . '</a>'), '</p>'; echo '<style type="text/css">#adminmenu .wp-submenu li.current { display: none !important; }</style>'; } return true; } elseif (isset($this->plugins[$slug]['file_path'], $_GET['tgmpa-activate']) && 'activate-plugin' === $_GET['tgmpa-activate']) { check_admin_referer('tgmpa-activate', 'tgmpa-activate-nonce'); if (false === $this->activate_single_plugin($this->plugins[$slug]['file_path'], $slug)) { return true; // Finish execution of the function early as we encountered an error } } return false; }
function wpdm_activate_shop() { if (current_user_can('manage_options')) { include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; include_once ABSPATH . 'wp-admin/includes/plugin-install.php'; $upgrader = new Plugin_Upgrader(new Plugin_Installer_Skin(compact('title', 'url', 'nonce', 'plugin', 'api'))); $downloadlink = 'http://www.wpdownloadmanager.com/?wpdmdl=15671'; ob_start(); echo "<div id='acto'>"; if (file_exists(dirname(dirname(__FILE__)) . '/wpdm-premium-packages/')) { $upgrader->upgrade($downloadlink); } else { $upgrader->install($downloadlink); } echo '</div><style>#acto .wrap { display: none; }</style>'; @ob_clean(); activate_plugin('wpdm-premium-packages/wpdm-premium-packages.php'); echo "Congratulation! Your Digital Store is Activated. <a href='' class='btn btn-warning'>Refresh The Page!</a>"; die; } else { die("Only site admin is authorized to install add-on"); } }
/** * Ajax handler for installing a plugin. * * @since 4.6.0 * * @see Plugin_Upgrader */ function wp_ajax_install_plugin() { check_ajax_referer('updates'); if (empty($_POST['slug'])) { wp_send_json_error(array('slug' => '', 'errorCode' => 'no_plugin_specified', 'errorMessage' => __('No plugin specified.'))); } $status = array('install' => 'plugin', 'slug' => sanitize_key(wp_unslash($_POST['slug']))); if (!current_user_can('install_plugins')) { $status['errorMessage'] = __('Sorry, you are not allowed to install plugins on this site.'); wp_send_json_error($status); } include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; include_once ABSPATH . 'wp-admin/includes/plugin-install.php'; $api = plugins_api('plugin_information', array('slug' => sanitize_key(wp_unslash($_POST['slug'])), 'fields' => array('sections' => false))); if (is_wp_error($api)) { $status['errorMessage'] = $api->get_error_message(); wp_send_json_error($status); } $status['pluginName'] = $api->name; $skin = new WP_Ajax_Upgrader_Skin(); $upgrader = new Plugin_Upgrader($skin); $result = $upgrader->install($api->download_link); if (defined('WP_DEBUG') && WP_DEBUG) { $status['debug'] = $skin->get_upgrade_messages(); } if (is_wp_error($result)) { $status['errorCode'] = $result->get_error_code(); $status['errorMessage'] = $result->get_error_message(); wp_send_json_error($status); } elseif (is_wp_error($skin->result)) { $status['errorCode'] = $skin->result->get_error_code(); $status['errorMessage'] = $skin->result->get_error_message(); wp_send_json_error($status); } elseif ($skin->get_errors()->get_error_code()) { $status['errorMessage'] = $skin->get_error_messages(); wp_send_json_error($status); } elseif (is_null($result)) { global $wp_filesystem; $status['errorCode'] = 'unable_to_connect_to_filesystem'; $status['errorMessage'] = __('Unable to connect to the filesystem. Please confirm your credentials.'); // Pass through the error from WP_Filesystem if one was raised. if ($wp_filesystem instanceof WP_Filesystem_Base && is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code()) { $status['errorMessage'] = esc_html($wp_filesystem->errors->get_error_message()); } wp_send_json_error($status); } $install_status = install_plugin_install_status($api); $pagenow = isset($_POST['pagenow']) ? sanitize_key($_POST['pagenow']) : ''; // If install request is coming from import page, do not return network activation link. $plugins_url = 'import' === $pagenow ? admin_url('plugins.php') : network_admin_url('plugins.php'); if (current_user_can('activate_plugins') && is_plugin_inactive($install_status['file'])) { $status['activateUrl'] = add_query_arg(array('_wpnonce' => wp_create_nonce('activate-plugin_' . $install_status['file']), 'action' => 'activate', 'plugin' => $install_status['file']), $plugins_url); } if (is_multisite() && current_user_can('manage_network_plugins') && 'import' !== $pagenow) { $status['activateUrl'] = add_query_arg(array('networkwide' => 1), $status['activateUrl']); } wp_send_json_success($status); }
/** * Manipulate addon. * * @param string $addon Addon to manipulate. * @param string $action Action to execute. * * @return array */ protected static function execute($addon, $action) { // Check capabilities foreach (self::$actions as $do => $capability) { if ($action == $do && !empty($capability) && !current_user_can($capability)) { throw new Exception(__('You do not have sufficient permissions to either add or delete plugins for this site.')); } } // Check if addon should be updated or removed if ('update' == $action || 'uninstall' == $action) { // Get plugin slug $plugin = self::check($addon, false); if (empty($plugin)) { throw new Exception(__('update' == $action ? 'Cannot detect plugin to be updated.' : 'Cannot detect plugin to be removed.', IG_LIBRARY_TEXTDOMAIN)); } } // Check if addon should be removed if ('uninstall' == $action) { $result = delete_plugins(array($plugin)); // Verify uninstallation result if (is_wp_error($result)) { throw new Exception($result->get_error_message()); } } else { // Verify authentication data $authentication = (bool) $_GET['authentication']; $username = isset($_POST['username']) ? $_POST['username'] : ''; $password = isset($_POST['password']) ? $_POST['password'] : ''; if ($authentication && (empty($username) || empty($password))) { // Check if user has customer account saved $customer_account = get_option('ig_customer_account', null); if (is_array($customer_account) && !@empty($customer_account['username']) && !@empty($customer_account['password'])) { $username = $customer_account['username']; $password = $customer_account['password']; } else { throw new Exception(null); } } // Try to authenticate or download addon installation package try { $package = self::download($addon, $authentication, $username, $password, 'authenticate' == $action); } catch (Exception $e) { throw $e; } // Get WordPress's WordPress Filesystem Abstraction object $wp_filesystem = IG_Init_File_System::get_instance(); // Check if addon should be installed or updated if ('authenticate' != $action) { // Verify core and add-on compatibility if (isset($_GET['core']) && ($core = self::get($_GET['core']))) { // Extract downloaded add-on package $tmp_dir = substr($package, 0, -4); $result = unzip_file($package, $tmp_dir); if (is_wp_error($result)) { throw new Exception($result->get_error_message()); } // Find constant definition file if (@is_file("{$tmp_dir}/defines.php")) { include "{$tmp_dir}/defines.php"; } elseif (count($defines = glob("{$tmp_dir}/*/defines.php"))) { include current($defines); } // Get minimum core version required for this add-on if (defined($core_version = strtoupper($addon) . '_CORE_VERSION')) { eval('$core_version = ' . $core_version . ';'); } if ($core_version && version_compare($core_version, $core['Version'], '>')) { // Delete downloaded add-on package and clean-up temporary directory $wp_filesystem->delete($package); $wp_filesystem->delete($tmp_dir, true); // Skip add-on installation throw new Exception(sprintf(__("Cannot install %1\$s v%2\$s.\nThis version requires %3\$s v%4\$s while you are using %5\$s v%6\$s.", IG_LIBRARY_TEXTDOMAIN), $core['Addons'][$addon]->name, $core['Addons'][$addon]->version, $core['Name'], $core_version, $core['Name'], $core['Version'])); } // Verification done, clean-up temporary directory $wp_filesystem->delete($tmp_dir, true); } // Init WordPress Plugin Upgrader class_exists('Plugin_Upgrader') || (include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'); function_exists('screen_icon') || (include_once ABSPATH . 'wp-admin/includes/screen.php'); function_exists('show_message') || (include_once ABSPATH . 'wp-admin/includes/misc.php'); function_exists('get_plugin_data') || (include_once ABSPATH . 'wp-admin/includes/plugin.php'); // Either install or update add-on $upgrader = new Plugin_Upgrader(); if ('install' == $action) { // Install plugin $result = $upgrader->install($package); // Verify installation result if (is_wp_error($result)) { throw new Exception($result->get_error_message()); } } else { // Update plugin add_filter('upgrader_pre_install', array($upgrader, 'deactivate_plugin_before_upgrade'), 10, 2); add_filter('upgrader_clear_destination', array($upgrader, 'delete_old_plugin'), 10, 4); $upgrader->run(array('package' => $package, 'destination' => WP_PLUGIN_DIR, 'clear_destination' => true, 'clear_working' => true, 'hook_extra' => array('plugin' => $plugin, 'type' => 'plugin', 'action' => 'update'))); remove_filter('upgrader_pre_install', array($upgrader, 'deactivate_plugin_before_upgrade')); remove_filter('upgrader_clear_destination', array($upgrader, 'delete_old_plugin')); if (is_wp_error($upgrader->result)) { throw new Exception($upgrader->result->get_error_message()); } // Force refresh of plugin update information if (function_exists('wp_clean_plugins_cache')) { wp_clean_plugins_cache(true); } } // Try to activate plugin try { $result = self::activate($addon, $action); } catch (Exception $e) { throw $e; } // Remove downloaded add-on installation package $wp_filesystem->delete($package); } else { // Check if user want to save customer account if (isset($_POST['remember']) && (bool) $_POST['remember']) { update_option('ig_customer_account', array('username' => $username, 'password' => $password)); } } } // Return data return is_array($result) ? $result : array('success' => true, 'addon' => $addon, 'action' => $action, 'message' => 'authenticate' == $action ? json_decode($wp_filesystem->get_contents($package)) : null); }
if (!current_user_can('upload_plugins')) { wp_die(__('You do not have sufficient permissions to install plugins on this site.')); } check_admin_referer('plugin-upload'); $file_upload = new File_Upload_Upgrader('pluginzip', 'package'); $title = __('Upload Plugin'); $parent_file = 'plugins.php'; $submenu_file = 'plugin-install.php'; require_once ABSPATH . 'wp-admin/admin-header.php'; $title = sprintf(__('Installing Plugin from uploaded file: %s'), esc_html(basename($file_upload->filename))); $nonce = 'plugin-upload'; $url = add_query_arg(array('package' => $file_upload->id), 'update.php?action=upload-plugin'); $type = 'upload'; //Install plugin type, From Web or an Upload. $upgrader = new Plugin_Upgrader(new Plugin_Installer_Skin(compact('type', 'title', 'nonce', 'url'))); $result = $upgrader->install($file_upload->package); if ($result || is_wp_error($result)) { $file_upload->cleanup(); } include ABSPATH . 'wp-admin/admin-footer.php'; } elseif ('upgrade-theme' == $action) { if (!current_user_can('update_themes')) { wp_die(__('You do not have sufficient permissions to update themes for this site.')); } check_admin_referer('upgrade-theme_' . $theme); wp_enqueue_script('customize-loader'); wp_enqueue_script('updates'); $title = __('Update Theme'); $parent_file = 'themes.php'; $submenu_file = 'themes.php'; require_once ABSPATH . 'wp-admin/admin-header.php';
/** * Install GHU */ function install() { add_filter('upgrader_source_selection', array($this, 'upgrader_source_selection'), 10, 2); $skin = new IGU_Plugin_Installer_Skin(array('type' => 'plugin', 'nonce' => wp_nonce_url($this->zip))); $upgrader = new Plugin_Upgrader($skin); $result = $upgrader->install($this->zip); if (is_wp_error($result)) { return array('status' => 'error', 'message' => $result->get_error_message()); } wp_cache_flush(); $result = $this->activate(); if ('error' == $result['status']) { return $result; } return array('status' => 'ok', 'message' => __('GitHub Updater has been installed and activated.')); }
/** * Installs, updates or activates a plugin depending on the action link clicked by the user. * * Checks the $_GET variable to see which actions have been * passed and responds with the appropriate method. * * Uses WP_Filesystem to process and handle the plugin installation * method. * * @since 1.0.0 * * @uses WP_Filesystem * @uses WP_Error * @uses WP_Upgrader * @uses Plugin_Upgrader * @uses Plugin_Installer_Skin * @uses Plugin_Upgrader_Skin * * @return boolean True on success, false on failure. */ protected function do_plugin_install() { if (empty($_GET['plugin'])) { return false; } // All plugin information will be stored in an array for processing. $slug = $this->sanitize_key(urldecode($_GET['plugin'])); if (!isset($this->plugins[$slug])) { return false; } // Was an install or upgrade action link clicked? if (isset($_GET['tgmpa-install']) && 'install-plugin' === $_GET['tgmpa-install'] || isset($_GET['tgmpa-update']) && 'update-plugin' === $_GET['tgmpa-update']) { $install_type = 'install'; if (isset($_GET['tgmpa-update']) && 'update-plugin' === $_GET['tgmpa-update']) { $install_type = 'update'; } check_admin_referer('tgmpa-' . $install_type, 'tgmpa-nonce'); // Pass necessary information via URL if WP_Filesystem is needed. $url = wp_nonce_url(add_query_arg(array('plugin' => urlencode($slug), 'tgmpa-' . $install_type => $install_type . '-plugin'), $this->get_tgmpa_url()), 'tgmpa-' . $install_type, 'tgmpa-nonce'); $method = ''; // Leave blank so WP_Filesystem can populate it as necessary. if (false === ($creds = request_filesystem_credentials(esc_url_raw($url), $method, false, false, array()))) { return true; } if (!WP_Filesystem($creds)) { request_filesystem_credentials(esc_url_raw($url), $method, true, false, array()); // Setup WP_Filesystem. return true; } /* If we arrive here, we have the filesystem. */ // Prep variables for Plugin_Installer_Skin class. $extra = array(); $extra['slug'] = $slug; // Needed for potentially renaming of directory name. $source = $this->get_download_url($slug); $api = 'repo' === $this->plugins[$slug]['source_type'] ? $this->get_plugins_api($slug) : null; $api = false !== $api ? $api : null; $url = add_query_arg(array('action' => $install_type . '-plugin', 'plugin' => urlencode($slug)), 'update.php'); if (!class_exists('Plugin_Upgrader', false)) { require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; } $skin_args = array('type' => 'bundled' !== $this->plugins[$slug]['source_type'] ? 'web' : 'upload', 'title' => sprintf($this->strings['installing'], $this->plugins[$slug]['name']), 'url' => esc_url_raw($url), 'nonce' => $install_type . '-plugin_' . $slug, 'plugin' => '', 'api' => $api, 'extra' => $extra); if ('update' === $install_type) { $skin_args['plugin'] = $this->plugins[$slug]['file_path']; $skin = new Plugin_Upgrader_Skin($skin_args); } else { $skin = new Plugin_Installer_Skin($skin_args); } // Create a new instance of Plugin_Upgrader. $upgrader = new Plugin_Upgrader($skin); // Perform the action and install the plugin from the $source urldecode(). add_filter('upgrader_source_selection', array($this, 'maybe_adjust_source_dir'), 1, 3); if ('update' === $install_type) { // Inject our info into the update transient. $to_inject = array($slug => $this->plugins[$slug]); $to_inject[$slug]['source'] = $source; $this->inject_update_info($to_inject); $upgrader->upgrade($this->plugins[$slug]['file_path']); } else { $upgrader->install($source); } remove_filter('upgrader_source_selection', array($this, 'maybe_adjust_source_dir'), 1, 3); // Make sure we have the correct file path now the plugin is installed/updated. $this->populate_file_path($slug); // Only activate plugins if the config option is set to true and the plugin isn't // already active (upgrade). if ($this->is_automatic && !$this->is_plugin_active($slug)) { $plugin_activate = $upgrader->plugin_info(); // Grab the plugin info from the Plugin_Upgrader method. if (false === $this->activate_single_plugin($plugin_activate, $slug, true)) { return true; // Finish execution of the function early as we encountered an error. } } $this->show_tgmpa_version(); // Display message based on if all plugins are now active or not. if ($this->is_tgmpa_complete()) { echo '<p>', sprintf(esc_html($this->strings['complete']), '<a href="' . esc_url(self_admin_url()) . '">' . esc_html__('Return to the Dashboard', 'tgmpa') . '</a>'), '</p>'; echo '<style type="text/css">#adminmenu .wp-submenu li.current { display: none !important; }</style>'; } else { echo '<p><a href="', esc_url($this->get_tgmpa_url()), '" target="_parent">', esc_html($this->strings['return']), '</a></p>'; } return true; } elseif (isset($this->plugins[$slug]['file_path'], $_GET['tgmpa-activate']) && 'activate-plugin' === $_GET['tgmpa-activate']) { // Activate action link was clicked. check_admin_referer('tgmpa-activate', 'tgmpa-nonce'); if (false === $this->activate_single_plugin($this->plugins[$slug]['file_path'], $slug)) { return true; // Finish execution of the function early as we encountered an error. } } return false; }
public function ajax_handler($action) { $action = isset($_POST['action']) ? $_POST['action'] : $action; switch ($action) { case 'a8c_developer_lightbox_step_1': check_ajax_referer('a8c_developer_lightbox_step_1'); if (empty($_POST['a8c_developer_project_type'])) { die('-1'); } $this->save_project_type($_POST['a8c_developer_project_type']); $to_install_or_enable = 0; $recommended_plugins = $this->get_recommended_plugins(); foreach ($recommended_plugins as $plugin_slug => $plugin_details) { if (!$plugin_details['active']) { $to_install_or_enable++; } } // If no plugins to take action on, head to the settings page if (!$to_install_or_enable) { die('redirect'); } echo '<strong>' . esc_html__('Plugins', 'a8c-developer') . '</strong>'; echo '<p>' . esc_html__('We recommend that you also install and activate the following plugins:', 'a8c-developer') . '</p>'; echo '<table class="recommended-plugins">'; foreach ($recommended_plugins as $plugin_slug => $plugin_details) { if ($plugin_details['active']) { continue; } echo '<tr>'; $details = $this->get_plugin_details($plugin_slug); if (is_wp_error($details)) { $details = array(); } $plugin_details = array_merge((array) $details, array('slug' => $plugin_slug), $plugin_details); echo '<td><strong>' . $plugin_details['name'] . '</strong></td>'; echo '<td>'; if ($this->is_recommended_plugin_installed($plugin_slug)) { $path = $this->get_path_for_recommended_plugin($plugin_slug); echo '<button type="button" class="a8c-developer-button-activate" data-path="' . esc_attr($path) . '" data-nonce="' . wp_create_nonce('a8c_developer_activate_plugin_' . $path) . '">' . esc_html__('Activate', 'a8c-developer') . '</button>'; } else { echo '<button type="button" class="a8c-developer-button-install" data-pluginslug="' . esc_attr($plugin_slug) . '" data-nonce="' . wp_create_nonce('a8c_developer_install_plugin_' . $plugin_slug) . '">' . esc_html__('Install', 'a8c-developer') . '</button>'; } if (!empty($plugin_details['short_description'])) { echo '<br /><span class="description">' . esc_html__($plugin_details['short_description']) . '</span>'; } echo '</td>'; echo '</tr>'; } echo '<tr><td colspan="2"><button type="button" class="button button-primary a8c-developer-button-close">' . esc_html__('Get Developing!', 'a8c-developer') . '</button></td></tr>'; echo '</table>'; echo '<script type="text/javascript">a8c_developer_bind_events();</script>'; exit; case 'a8c_developer_install_plugin': if (empty($_POST['plugin_slug'])) { die(__('ERROR: No slug was passed to the AJAX callback.', 'a8c-developer')); } check_ajax_referer('a8c_developer_install_plugin_' . $_POST['plugin_slug']); if (!current_user_can('install_plugins') || !current_user_can('activate_plugins')) { die(__('ERROR: You lack permissions to install and/or activate plugins.', 'a8c-developer')); } include_once ABSPATH . 'wp-admin/includes/plugin-install.php'; $api = plugins_api('plugin_information', array('slug' => $_POST['plugin_slug'], 'fields' => array('sections' => false))); if (is_wp_error($api)) { die(sprintf(__('ERROR: Error fetching plugin information: %s', 'a8c-developer'), $api->get_error_message())); } $upgrader = new Plugin_Upgrader(new Automattic_Developer_Empty_Upgrader_Skin(array('nonce' => 'install-plugin_' . $_POST['plugin_slug'], 'plugin' => $_POST['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', 'a8c-developer'); if (is_wp_error($install_result)) { $error_message = $install_result->get_error_message(); } die(sprintf(__('ERROR: Failed to install plugin: %s', 'a8c-developer'), $error_message)); } $activate_result = activate_plugin($this->get_path_for_recommended_plugin($_POST['plugin_slug'])); if (is_wp_error($activate_result)) { die(sprintf(__('ERROR: Failed to activate plugin: %s', 'a8c-developer'), $activate_result->get_error_message())); } exit('1'); case 'a8c_developer_activate_plugin': if (empty($_POST['path'])) { die(__('ERROR: No slug was passed to the AJAX callback.', 'a8c-developer')); } check_ajax_referer('a8c_developer_activate_plugin_' . $_POST['path']); if (!current_user_can('activate_plugins')) { die(__('ERROR: You lack permissions to activate plugins.', 'a8c-developer')); } $activate_result = activate_plugin($_POST['path']); if (is_wp_error($activate_result)) { die(sprintf(__('ERROR: Failed to activate plugin: %s', 'a8c-developer'), $activate_result->get_error_message())); } exit('1'); } // Unknown action die('-1'); }