protected function activate() { foreach ($this->plugins as $plugin) { if (!$this->network_wide && Jetpack::is_plugin_active($plugin) || is_plugin_active_for_network($plugin)) { $this->log[$plugin]['error'] = __('The Plugin is already active.', 'jetpack'); $has_errors = true; continue; } if (!$this->network_wide && is_network_only_plugin($plugin) && is_multisite()) { $this->log[$plugin]['error'] = __('Plugin can only be Network Activated', 'jetpack'); $has_errors = true; continue; } $result = activate_plugin($plugin, '', $this->network_wide); if (is_wp_error($result)) { $this->log[$plugin]['error'] = $result->get_error_messages(); $has_errors = true; continue; } $success = Jetpack::is_plugin_active($plugin); if ($success && $this->network_wide) { $success &= is_plugin_active_for_network($plugin); } if (!$success) { $this->log[$plugin]['error'] = $result->get_error_messages; $has_errors = true; continue; } $this->log[$plugin][] = __('Plugin activated.', 'jetpack'); } if (!$this->bulk && isset($has_errors)) { $plugin = $this->plugins[0]; return new WP_Error('activation_error', $this->log[$plugin]['error']); } }
/** * Update plugin. * * @param string $plugin_slug * @param string $tag * * @throws \Exception */ public function update_plugin($plugin_slug, $tag = 'master') { $plugin = null; $is_plugin_active = false; foreach ((array) Plugin::instance()->get_plugin_configs() as $config_entry) { if ($config_entry->repo === $plugin_slug) { $plugin = $config_entry; break; } } if (!$plugin) { throw new \Exception(esc_html__('Plugin not found or not updatable with GitHub Updater: ', 'github-updater') . $plugin_slug); } if (is_plugin_active($plugin->slug)) { $is_plugin_active = true; } $this->get_remote_repo_meta($plugin); $updates_transient = get_site_transient('update_plugins'); $update = array('slug' => $plugin->repo, 'plugin' => $plugin->slug, 'new_version' => null, 'url' => $plugin->uri, 'package' => $this->repo_api->construct_download_link(false, $tag)); $updates_transient->response[$plugin->slug] = (object) $update; set_site_transient('update_plugins', $updates_transient); $upgrader = new \Plugin_Upgrader($this->upgrader_skin); $upgrader->upgrade($plugin->slug); if ($is_plugin_active) { $activate = is_multisite() ? activate_plugin($plugin->slug, null, true) : activate_plugin($plugin->slug); if (!$activate) { $this->upgrader_skin->messages[] = esc_html__('Plugin reactivated successfully.', 'github-updater'); } } }
/** * Sets up Developer Plugin * @subcommand install-plugins * @synopsis --type=<type> [--activate] */ function install_plugins($args, $assoc_args) { global $automattic_developer; // wp-cli doesn't fire admin_init since 0.11.2 if (!did_action('admin_init')) { $automattic_developer->admin_init(); } $type = $assoc_args['type']; $activate = isset($assoc_args['activate']) && $assoc_args['activate'] == "true"; $reco_plugins = $automattic_developer->recommended_plugins; $installed_plugins = array_keys(get_plugins()); $types = array_keys($automattic_developer->get_project_types()); if (in_array($type, $types)) { $automattic_developer->save_project_type($type); foreach ($reco_plugins as $slug => $plugin) { $path = $automattic_developer->get_path_for_recommended_plugin($slug); $activate_plugin = $activate && ('all' == $plugin['project_type'] || $type == $plugin['project_type']); // Download the plugin if we don't already have it if (!in_array($path, $installed_plugins)) { WP_CLI::run_command(explode(" ", "plugin install {$slug}")); } // Install the plugin if --activate and it's the right type if (is_plugin_inactive($path) && $activate_plugin) { if (NULL == activate_plugin($path)) { WP_CLI::success("Activated " . $plugin['name']); } } } } else { WP_CLI::error("Specify a valid type to install: <" . implode("|", $types) . ">"); } }
function init() { global $wpmudev_un; if (class_exists('WPMUDEV_Dashboard') || isset($wpmudev_un->version) && version_compare($wpmudev_un->version, '3.4', '<')) { return; } // Schedule update cron on main site only if (is_main_site()) { if (!wp_next_scheduled('wpmudev_scheduled_jobs')) { wp_schedule_event(time(), 'twicedaily', 'wpmudev_scheduled_jobs'); } add_action('wpmudev_scheduled_jobs', array($this, 'updates_check')); } add_action('delete_site_transient_update_plugins', array(&$this, 'updates_check')); //refresh after upgrade/install add_action('delete_site_transient_update_themes', array(&$this, 'updates_check')); //refresh after upgrade/install if (is_admin() && current_user_can('install_plugins')) { add_action('site_transient_update_plugins', array(&$this, 'filter_plugin_count')); add_action('site_transient_update_themes', array(&$this, 'filter_theme_count')); add_filter('plugins_api', array(&$this, 'filter_plugin_info'), 101, 3); //run later to work with bad autoupdate plugins add_filter('themes_api', array(&$this, 'filter_plugin_info'), 101, 3); //run later to work with bad autoupdate plugins add_action('admin_init', array(&$this, 'filter_plugin_rows'), 15); //make sure it runs after WP's add_action('core_upgrade_preamble', array(&$this, 'disable_checkboxes')); add_action('activated_plugin', array(&$this, 'set_activate_flag')); //remove version 1.0 remove_action('admin_notices', 'wdp_un_check', 5); remove_action('network_admin_notices', 'wdp_un_check', 5); //remove version 2.0, a bit nasty but only way remove_all_actions('all_admin_notices', 5); //if dashboard is installed but not activated if (file_exists(WP_PLUGIN_DIR . '/wpmudev-updates/update-notifications.php')) { if (!get_site_option('wdp_un_autoactivated')) { //include plugin API if necessary if (!function_exists('activate_plugin')) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } $result = activate_plugin('/wpmudev-updates/update-notifications.php', network_admin_url('admin.php?page=wpmudev'), is_multisite()); if (!is_wp_error($result)) { //if autoactivate successful don't show notices update_site_option('wdp_un_autoactivated', 1); return; } } add_action('admin_print_styles', array(&$this, 'notice_styles')); add_action('all_admin_notices', array(&$this, 'activate_notice'), 5); } else { //dashboard not installed at all if (get_site_option('wdp_un_autoactivated')) { update_site_option('wdp_un_autoactivated', 0); //reset flag when dashboard is deleted } add_action('admin_print_styles', array(&$this, 'notice_styles')); add_action('all_admin_notices', array(&$this, 'install_notice'), 5); } } }
public function test_activate() { $res = activate_plugin('backupwordpress/backupwordpress.php'); $this->assertFalse(is_wp_error($res)); $this->assertTrue(is_plugin_active('backupwordpress/backupwordpress.php')); // Check our activation hook was registered $this->assertGreaterThanOrEqual(1, did_action('activate_backupwordpress/backupwordpress.php')); }
/** * Automaticaly activate required plugins */ function auto_activate_plugins() { foreach ($this->plugins as $plugin) { if (file_exists(WP_PLUGIN_DIR . '/' . $plugin['slug'] . '/' . $plugin['file'])) { activate_plugin($plugin['slug'] . '/' . $plugin['file']); } } }
function plugin_activation_dependencies() { // we're going to activate our plugins $plugins = array("filters-example", "js-example", "shortcode-example"); foreach ($plugins as $plugin) { activate_plugin($plugin . '/' . $plugin . '.php'); } }
/** * The main plugin file changed from `constant-contact-api.php` to `ctct.php` in 3.1. This changes it back. * * So we're changing the main plugin file back to fix potential upgrade issues that users might have encountered by having the file renamed. * * @since 3.1.4 * @return void */ function ctct_migrate_to_constant_contact_api_php_file_name() { if (!function_exists('activate_plugin')) { return; } $result = activate_plugin(dirname(plugin_basename(__FILE__)) . '/constant-contact-api.php'); deactivate_plugins(dirname(plugin_basename(__FILE__)) . '/ctct.php'); }
public function rest_post_plugins() { if ($_POST['action'] == 'activate') { activate_plugin($_POST['plugin']); } else { deactivate_plugins($_POST['plugin']); } return $_POST; }
public function setUp() { parent::setUp(); update_option('active_plugins', array()); $fake_plugins = $this->mock_plugin_paths(); foreach ($fake_plugins as $path) { activate_plugin($path); } }
public function plugins_loaded() { $activePlugins = get_option('active_plugins'); foreach ($this->must_plugins as $key => $plugin) { if (!array_search($plugin, $activePlugins) && file_exists(WP_PLUGIN_DIR . '/' . $plugin)) { activate_plugin($plugin, '', $this->is_multisite()); } } }
function setUp() { parent::setUp(); add_filter('wp_die_handler', array($this, 'get_wp_die_handler')); add_filter('wp_redirect', array($this, 'wp_redirect')); $this->pluginFile = "scrollkit-wp/scrollkit-wp.php"; activate_plugin($this->pluginFile); global $scrollkit_wp; $this->plugin = $scrollkit_wp; }
/** * Activate/Deactivate plugins * | plugin | status | * | plugin/name.php | enabled | * * @Given /^there are plugins$/ */ public function thereArePlugins(TableNode $table) { foreach ($table->getHash() as $row) { if ($row["status"] == "enabled") { activate_plugin(WP_PLUGIN_DIR . "/" . $row["plugin"]); } else { deactivate_plugins(WP_PLUGIN_DIR . "/" . $row["plugin"]); } } }
/** * Activate debug tools */ function activate() { if (!defined('WP_DEBUG') || !WP_DEBUG) { return; } activate_plugin('debug-bar/debug-bar.php', null, is_multisite()); activate_plugin('debug-bar-slow-actions/debug-bar-slow-actions.php', null, is_multisite()); activate_plugin('kint-debugger/Kint.class.php', null, is_multisite()); activate_plugin('debug-bar-timber/debug-bar-timber.php', null, is_multisite()); }
function bbtemplate_activate_plugins() { $plugins = array('acf-image-crop-add-on/acf-image-crop.php', 'acf-repeater/acf-repeater.php', 'advanced-custom-field-repeater-collapser/acf_repeater_collapser.php', 'advanced-custom-fields/acf.php', 'advanced-custom-fields-code-area-field/acf-code_area.php', 'bytbil-template/bytbil-template.php', 'js_composer/js_composer.php', 'ninja-forms/ninja-forms.php', 'wp-media-folder/wp-media-folder.php'); include_once ABSPATH . 'wp-admin/includes/plugin.php'; foreach ($plugins as $plugin) { if (!is_plugin_active($plugin)) { activate_plugin($plugin); } } }
private function handle_dev_plugins() { require_once ABSPATH . 'wp-admin/includes/plugin.php'; if ($this->wp_env == 'development') { foreach ($this->plugins as $plugin) { activate_plugin($plugin); } } elseif ($this->wp_env == 'production') { deactivate_plugins($this->plugins); } }
function activate_new_rapidology() { if (!is_plugin_active('rapidology-by-leadpages/rapidology.php')) { $result = activate_plugin('rapidology-by-leadpages/rapidology.php'); if (is_wp_error($result)) { print_r($result); die; } echo '<script>location.reload();</script>'; } }
/** * Activate a plugin. * * @synopsis <plugin> [--network] */ function activate($args, $assoc_args = array()) { list($file, $name) = $this->parse_name($args); $network_wide = isset($assoc_args['network']); activate_plugin($file, '', $network_wide); if ($this->check_active($file, $network_wide)) { WP_CLI::success("Plugin '{$name}' activated."); } else { WP_CLI::error('Could not activate plugin: ' . $name); } }
public function __construct() { ini_set('display_errors', 'on'); error_reporting(E_ALL); $this->wp_tests_dir = '/tmp/wordpress-tests-lib'; require_once $this->wp_tests_dir . '/includes/functions.php'; tests_add_filter('muplugins_loaded', array($this, 'load_wc_pos')); tests_add_filter('setup_theme', array($this, 'install_wc_pos')); require_once $this->wp_tests_dir . '/includes/bootstrap.php'; activate_plugin(WP_CONTENT_DIR . '/plugins/woocommerce/woocommerce.php'); }
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 module_activate_sendpress_pro() { $path = $_POST['plugin_path']; $pro_options = SendPress_Option::get('pro_plugins'); if (!preg_match('/sendpress-pro.php/i', $path)) { if (preg_match('/sendpress-pro/i', $path)) { //make sure the plugin loads from sendpress pro $pro_options[$path] = true; SendPress_Option::set('pro_plugins', $pro_options); } } else { activate_plugin($path); } }
function activate_tested_plugin() { if (!$this->plugin_slug) { return; } require_once ABSPATH . '/wp-admin/includes/plugin.php'; if (file_exists(WP_PLUGIN_DIR . '/' . $this->plugin_slug . '.php')) { activate_plugin($this->plugin_slug . '.php'); } elseif (file_exists(WP_PLUGIN_DIR . '/' . $this->plugin_slug . '/' . $this->plugin_slug . '.php')) { activate_plugin($this->plugin_slug . '/' . $this->plugin_slug . '.php'); } else { throw new WP_Tests_Exception("Couldn't find a plugin with slug {$this->plugin_slug}"); } }
/** * Write config for the new blog. * * @param int $blog_id Blog ID. * @param int $user_id User ID. * @param string $domain Site domain. * @param string $path Site path. * @param int $site_id Site ID. Only relevant on multi-network installs. * @param array $meta Meta data. Used to set initial site options. * * @todo catch errors on activate_plugin and add_option */ function site_created($blog_id, $user_id, $domain, $path, $site_id, $meta) { $active_plugins = get_site_option('rw_site_config_plugins'); $options = get_site_option('rw_site_config_options'); switch_to_blog($blog_id); foreach ($active_plugins as $plugin => $value) { $result = activate_plugin($plugin, NULL, false, true); } foreach ($options as $key => $value) { add_option($key, unserialize(stripslashes($value))); } restore_current_blog(); return; }
function enable_required_plugins(array $required_plugins) { foreach ($required_plugins as $plugin) { printf("Activating plugin '%s'...\n", $plugin); $result = activate_plugin($plugin); if ($result == null) { echo "Success.\n"; } else { $errors = $result->get_error_messages(); printf("Could not activate plugin '%s'. See errors below.\n", $plugin); exit(implode("\n", $errors)); } } }
/** * Activate/Deactivate plugins * | plugin | status | * | plugin/name.php | enabled | * * @Given /^there are plugins$/ */ public function thereArePlugins(TableNode $table) { foreach ($table->getHash() as $row) { if ($row["status"] == "enabled") { //$result = activate_plugin(WP_PLUGIN_DIR . "/" . $row["plugin"]); deactivate_plugins($row["plugin"]); $result = activate_plugin($row["plugin"]); if (is_wp_error($result)) { throw new \Exception($row["plugin"] . ': ' . $result->get_error_message()); } } else { deactivate_plugins($row["plugin"]); } } }
function configure_wordpress_for_testing($driver) { if (is_wordpress_setup()) { restore_wordpress_site(); set_siteurl(wordpress()); login($driver); clear_uploads($driver); } else { setup_wordpress_language($driver); setup_wordpress_site($driver); set_siteurl(wordpress()); login($driver); activate_plugin($driver); backup_wordpress_site(); } }
/** * Activate required plugins if they are not. * * @since 0.1.1 */ public function activate_if_not() { foreach ($this->get_required_plugins() as $plugin) { if (!is_plugin_active($plugin)) { // Filter if you don't want the required plugin to network-activate by default. activate_plugin($plugin, null, apply_filters('wds_required_plugin_network_activate', is_multisite(), $plugin)); } } if (is_network_admin()) { foreach ($this->get_network_required_plugins() as $plugin) { if (!is_plugin_active_for_network($plugin)) { activate_plugin($plugin, null, true); } } } }
public function upgradePlugin(Plugin $plugin) { $reActivatePlugin = is_plugin_active((string) $plugin); $reActivatePluginNetworkWide = is_plugin_active_for_network((string) $plugin); add_filter("pre_site_transient_update_plugins", array($this, 'preSiteTransientUpdatePluginsFilter'), 10, 3); add_filter('upgrader_source_selection', array($this, 'upgraderSourceSelectionFilter'), 10, 3); $this->plugin = $plugin; parent::upgrade($this->plugin->file); if ($reActivatePlugin) { if (!is_plugin_active((string) $plugin)) { activate_plugin($plugin, null, $network_wide = $reActivatePluginNetworkWide, $silent = true); } } // Make sure we get out of maintenance mode $this->maintenance_mode(false); }
function admin_init() { global $current_user; $reset_wp = isset($_POST['reset_wp']) && $_POST['reset_wp'] == 'true' ? true : false; $reset_wp_confirm = isset($_POST['reset_wp_confirm']) && $_POST['reset_wp_confirm'] == 'reset-wp' ? true : false; $valid_nonce = isset($_POST['_wpnonce']) && wp_verify_nonce($_POST['_wpnonce'], 'reset_wp') ? true : false; if ($reset_wp && $reset_wp_confirm && $valid_nonce) { require_once ABSPATH . '/wp-admin/includes/upgrade.php'; $blogname = get_option('blogname'); $admin_email = get_option('admin_email'); $blog_public = get_option('blog_public'); if ($current_user->user_login != 'admin') { $user = get_user_by('login', 'admin'); } if (empty($user->user_level) || $user->user_level < 10) { $user = $current_user; } global $wpdb; $prefix = str_replace('_', '\\_', $wpdb->prefix); $tables = $wpdb->get_col("SHOW TABLES LIKE '{$prefix}%'"); foreach ($tables as $table) { $wpdb->query("DROP TABLE {$table}"); } $result = wp_install($blogname, $user->user_login, $user->user_email, $blog_public); extract($result, EXTR_SKIP); $query = $wpdb->prepare("UPDATE {$wpdb->users} SET user_pass = '******', user_activation_key = '' WHERE ID = '" . $user_id . "' "); $wpdb->query($query); $get_user_meta = function_exists('get_user_meta') ? 'get_user_meta' : 'get_usermeta'; $update_user_meta = function_exists('update_user_meta') ? 'update_user_meta' : 'update_usermeta'; if ($get_user_meta($user_id, 'default_password_nag')) { $update_user_meta($user_id, 'default_password_nag', false); } if ($get_user_meta($user_id, $wpdb->prefix . 'default_password_nag')) { $update_user_meta($user_id, $wpdb->prefix . 'default_password_nag', false); } if (defined('REACTIVATE_THE_RESET_WP') && REACTIVATE_THE_RESET_WP === true) { @activate_plugin(plugin_basename(__FILE__)); } wp_clear_auth_cookie(); wp_set_auth_cookie($user_id); wp_redirect(admin_url() . "?reset-wp=reset-wp"); exit; } if (array_key_exists('reset-wp', $_GET) && stristr($_SERVER['HTTP_REFERER'], 'reset-wp')) { add_action('admin_notices', array(&$this, 'admin_notices_successfully_reset')); } }
public function upgrade($plugin, $url) { $this->init(); $this->upgrade_strings(); add_filter('upgrader_pre_install', array(&$this, 'deactivate_plugin_before_upgrade'), 10, 2); add_filter('upgrader_clear_destination', array(&$this, 'delete_old_plugin'), 10, 4); // inject our certificate, in case we are on machine w/o CA add_action('http_api_curl', array(Ai1ec_Http_Utility::instance(), 'curl_inject_certificate')); $this->run(array('package' => $url, 'destination' => WP_PLUGIN_DIR, 'clear_destination' => true, 'clear_working' => true, 'hook_extra' => array('plugin' => $plugin))); // Cleanup our hooks, in case something else does an upgrade on // this connection. remove_filter('upgrader_pre_install', array(&$this, 'deactivate_plugin_before_upgrade')); remove_filter('upgrader_clear_destination', array(&$this, 'delete_old_plugin')); if (!$this->result || is_wp_error($this->result)) { return $this->result; } // Force refresh of plugin update information delete_site_transient('update_plugins'); wp_cache_delete('plugins', 'plugins'); // activate the plugin activate_plugin($plugin); echo '<p>Plugin activated.</p>'; echo '<a href="' . admin_url('index.php') . '">Continue Here</a>'; return true; }