public static deactivate_plugin ( $probable_file, $probable_title ) |
public static function activate_module($module, $exit = true, $redirect = true) { do_action('jetpack_pre_activate_module', $module, $exit); $jetpack = Jetpack::init(); if (!strlen($module)) { return false; } if (!Jetpack::is_module($module)) { return false; } // If it's already active, then don't do it again $active = Jetpack::get_active_modules(); foreach ($active as $act) { if ($act == $module) { return true; } } $module_data = Jetpack::get_module($module); if (!Jetpack::is_active()) { if (!Jetpack::is_development_mode()) { return false; } // If we're not connected but in development mode, make sure the module doesn't require a connection if (Jetpack::is_development_mode() && $module_data['requires_connection']) { return false; } } // Check and see if the old plugin is active if (isset($jetpack->plugins_to_deactivate[$module])) { // Deactivate the old plugin if (Jetpack_Client_Server::deactivate_plugin($jetpack->plugins_to_deactivate[$module][0], $jetpack->plugins_to_deactivate[$module][1])) { // If we deactivated the old plugin, remembere that with ::state() and redirect back to this page to activate the module // We can't activate the module on this page load since the newly deactivated old plugin is still loaded on this page load. Jetpack::state('deactivated_plugins', $module); wp_safe_redirect(add_query_arg('jetpack_restate', 1)); exit; } } // Check the file for fatal errors, a la wp-admin/plugins.php::activate Jetpack::state('module', $module); Jetpack::state('error', 'module_activation_failed'); // we'll override this later if the plugin can be included without fatal error Jetpack::catch_errors(true); ob_start(); require Jetpack::get_module_path($module); do_action('jetpack_activate_module', $module); $active[] = $module; Jetpack_Options::update_option('active_modules', array_unique($active)); Jetpack::state('error', false); // the override Jetpack::state('message', 'module_activated'); Jetpack::state('module', $module); ob_end_clean(); Jetpack::catch_errors(false); if ($redirect) { wp_safe_redirect(Jetpack::admin_url('page=jetpack')); } if ($exit) { exit; } }
/** * Request an api key from wordpress.com * * @return bool | string */ public function get_protect_key() { $protect_blog_id = Jetpack_Protect_Module::get_main_blog_jetpack_id(); // If we can't find the the blog id, that means we are on multisite, and the main site never connected // the protect api key is linked to the main blog id - instruct the user to connect their main blog if (!$protect_blog_id) { $this->api_key_error = __('Your main blog is not connected to WordPress.com. Please connect to get an API key.', 'jetpack'); return false; } $request = array('jetpack_blog_id' => $protect_blog_id, 'bruteprotect_api_key' => get_site_option('bruteprotect_api_key'), 'multisite' => '0'); // Send the number of blogs on the network if we are on multisite if (is_multisite()) { $request['multisite'] = get_blog_count(); if (!$request['multisite']) { global $wpdb; $request['multisite'] = $wpdb->get_var("SELECT COUNT(blog_id) as c FROM {$wpdb->blogs} WHERE spam = '0' AND deleted = '0' and archived = '0'"); } } // Request the key Jetpack::load_xml_rpc_client(); $xml = new Jetpack_IXR_Client(array('user_id' => get_current_user_id())); $xml->query('jetpack.protect.requestKey', $request); // Hmm, can't talk to wordpress.com if ($xml->isError()) { $code = $xml->getErrorCode(); $message = $xml->getErrorMessage(); $this->api_key_error = sprintf(__('Error connecting to WordPress.com. Code: %1$s, %2$s', 'jetpack'), $code, $message); return false; } $response = $xml->getResponse(); // Hmm. Can't talk to the protect servers ( api.bruteprotect.com ) if (!isset($response['data'])) { $this->api_key_error = __('No reply from Jetpack servers', 'jetpack'); return false; } // There was an issue generating the key if (empty($response['success'])) { $this->api_key_error = $response['data']; return false; } // Key generation successful! $active_plugins = Jetpack::get_active_plugins(); // We only want to deactivate BruteProtect if we successfully get a key if (in_array('bruteprotect/bruteprotect.php', $active_plugins)) { Jetpack_Client_Server::deactivate_plugin('bruteprotect/bruteprotect.php', 'BruteProtect'); } $key = $response['data']; update_site_option('jetpack_protect_key', $key); return $key; }
function activate_module($module) { $jetpack = Jetpack::init(); if (!Jetpack::is_active()) { return false; } if (!strlen($module)) { return false; } if (!Jetpack::is_module($module)) { return false; } // If it's already active, then don't do it again $active = Jetpack::get_active_modules(); foreach ($active as $act) { if ($act == $module) { return true; } } // Check and see if the old plugin is active if (isset($jetpack->plugins_to_deactivate[$module])) { // Deactivate the old plugin if (Jetpack_Client_Server::deactivate_plugin($jetpack->plugins_to_deactivate[$module][0], $jetpack->plugins_to_deactivate[$module][1])) { // If we deactivated the old plugin, remembere that with ::state() and redirect back to this page to activate the module // We can't activate the module on this page load since the newly deactivated old plugin is still loaded on this page load. Jetpack::state('deactivated_plugins', $module); wp_safe_redirect(add_query_arg('jetpack_restate', 1)); exit; } } // Check the file for fatal errors, a la wp-admin/plugins.php::activate Jetpack::state('module', $module); Jetpack::state('error', 'module_activation_failed'); // we'll override this later if the plugin can be included without fatal error wp_safe_redirect(Jetpack::admin_url()); if ('sharedaddy' == $module && version_compare(PHP_VERSION, '5', '<')) { exit; } Jetpack::catch_errors(true); ob_start(); require Jetpack::get_module_path($module); do_action("jetpack_activate_module_{$module}"); $active[] = $module; Jetpack::update_option('active_modules', array_unique($active)); Jetpack::state('error', false); // the override Jetpack::state('message', 'module_activated'); Jetpack::state('module', $module); ob_end_clean(); Jetpack::catch_errors(false); exit; }
public static function activate_module($module, $exit = true, $redirect = true) { /** * Fires before a module is activated. * * @since 2.6.0 * * @param string $module Module slug. * @param bool $exit Should we exit after the module has been activated. Default to true. * @param bool $redirect Should the user be redirected after module activation? Default to true. */ do_action('jetpack_pre_activate_module', $module, $exit, $redirect); $jetpack = Jetpack::init(); if (!strlen($module)) { return false; } if (!Jetpack::is_module($module)) { return false; } // If it's already active, then don't do it again $active = Jetpack::get_active_modules(); foreach ($active as $act) { if ($act == $module) { return true; } } $module_data = Jetpack::get_module($module); if (!Jetpack::is_active()) { if (!Jetpack::is_development_mode()) { return false; } // If we're not connected but in development mode, make sure the module doesn't require a connection if (Jetpack::is_development_mode() && $module_data['requires_connection']) { return false; } } // Check and see if the old plugin is active if (isset($jetpack->plugins_to_deactivate[$module])) { // Deactivate the old plugin if (Jetpack_Client_Server::deactivate_plugin($jetpack->plugins_to_deactivate[$module][0], $jetpack->plugins_to_deactivate[$module][1])) { // If we deactivated the old plugin, remembere that with ::state() and redirect back to this page to activate the module // We can't activate the module on this page load since the newly deactivated old plugin is still loaded on this page load. Jetpack::state('deactivated_plugins', $module); wp_safe_redirect(add_query_arg('jetpack_restate', 1)); exit; } } // Check the file for fatal errors, a la wp-admin/plugins.php::activate Jetpack::state('module', $module); Jetpack::state('error', 'module_activation_failed'); // we'll override this later if the plugin can be included without fatal error Jetpack::catch_errors(true); ob_start(); require Jetpack::get_module_path($module); /** This action is documented in class.jetpack.php */ do_action('jetpack_activate_module', $module); $active[] = $module; Jetpack_Options::update_option('active_modules', array_unique($active)); Jetpack::state('error', false); // the override Jetpack::state('message', 'module_activated'); Jetpack::state('module', $module); ob_end_clean(); Jetpack::catch_errors(false); // A flag for Jump Start so it's not shown again. Only set if it hasn't been yet. if ('new_connection' === Jetpack_Options::get_option('jumpstart')) { Jetpack_Options::update_option('jumpstart', 'jetpack_action_taken'); //Jump start is being dismissed send data to MC Stats $jetpack->stat('jumpstart', 'manual,' . $module); $jetpack->do_stats('server_side'); } if ($redirect) { wp_safe_redirect(Jetpack::admin_url('page=jetpack')); } if ($exit) { exit; } return true; }
/** * @author scotchfield * @runInSeparateProcess * @covers Jetpack_Client_Server::deactivate_plugin * @since 3.2 */ public function test_jetpack_client_server_deactivate_plugin() { $client_server = new Jetpack_Client_Server(); $return_value = $client_server->deactivate_plugin('herp', 'derp'); $this->assertEquals($return_value, 0); }