function admin_page_load()
{
$error = false;
// Make sure we have the right body class to hook stylings for subpages off of.
add_filter('admin_body_class', array(__CLASS__, 'add_jetpack_pagestyles'));
if (!empty($_GET['jetpack_restate'])) {
// Should only be used in intermediate redirects to preserve state across redirects
Jetpack::restate();
}
if (isset($_GET['connect_url_redirect'])) {
// User clicked in the iframe to link their accounts
if (!Jetpack::is_user_connected()) {
$connect_url = $this->build_connect_url(true, false, 'iframe');
if (isset($_GET['notes_iframe'])) {
$connect_url .= '¬es_iframe';
}
wp_redirect($connect_url);
exit;
} else {
if (!isset($_GET['calypso_env'])) {
Jetpack::state('message', 'already_authorized');
wp_safe_redirect(Jetpack::admin_url());
} else {
$connect_url = $this->build_connect_url(true, false, 'iframe');
$connect_url .= '&already_authorized=true';
wp_redirect($connect_url);
}
}
}
if (isset($_GET['action'])) {
switch ($_GET['action']) {
case 'authorize':
if (Jetpack::is_active() && Jetpack::is_user_connected()) {
Jetpack::state('message', 'already_authorized');
wp_safe_redirect(Jetpack::admin_url());
exit;
}
Jetpack::log('authorize');
$client_server = new Jetpack_Client_Server();
$client_server->client_authorize();
exit;
case 'register':
if (!current_user_can('jetpack_connect')) {
$error = 'cheatin';
break;
}
check_admin_referer('jetpack-register');
Jetpack::log('register');
Jetpack::maybe_set_version_option();
$registered = Jetpack::try_registration();
if (is_wp_error($registered)) {
$error = $registered->get_error_code();
Jetpack::state('error', $error);
Jetpack::state('error', $registered->get_error_message());
break;
}
$from = isset($_GET['from']) ? $_GET['from'] : false;
wp_redirect($this->build_connect_url(true, false, $from));
exit;
case 'activate':
if (!current_user_can('jetpack_activate_modules')) {
$error = 'cheatin';
break;
}
$module = stripslashes($_GET['module']);
check_admin_referer("jetpack_activate-{$module}");
Jetpack::log('activate', $module);
Jetpack::activate_module($module);
// The following two lines will rarely happen, as Jetpack::activate_module normally exits at the end.
wp_safe_redirect(Jetpack::admin_url('page=jetpack'));
exit;
case 'activate_default_modules':
check_admin_referer('activate_default_modules');
Jetpack::log('activate_default_modules');
Jetpack::restate();
$min_version = isset($_GET['min_version']) ? $_GET['min_version'] : false;
$max_version = isset($_GET['max_version']) ? $_GET['max_version'] : false;
$other_modules = isset($_GET['other_modules']) && is_array($_GET['other_modules']) ? $_GET['other_modules'] : array();
Jetpack::activate_default_modules($min_version, $max_version, $other_modules);
wp_safe_redirect(Jetpack::admin_url('page=jetpack'));
exit;
case 'disconnect':
if (!current_user_can('jetpack_disconnect')) {
$error = 'cheatin';
break;
}
check_admin_referer('jetpack-disconnect');
Jetpack::log('disconnect');
Jetpack::disconnect();
wp_safe_redirect(Jetpack::admin_url('disconnected=true'));
exit;
case 'reconnect':
if (!current_user_can('jetpack_reconnect')) {
$error = 'cheatin';
break;
}
check_admin_referer('jetpack-reconnect');
Jetpack::log('reconnect');
$this->disconnect();
wp_redirect($this->build_connect_url(true, false, 'reconnect'));
exit;
case 'deactivate':
if (!current_user_can('jetpack_deactivate_modules')) {
$error = 'cheatin';
break;
}
$modules = stripslashes($_GET['module']);
check_admin_referer("jetpack_deactivate-{$modules}");
foreach (explode(',', $modules) as $module) {
Jetpack::log('deactivate', $module);
Jetpack::deactivate_module($module);
Jetpack::state('message', 'module_deactivated');
}
Jetpack::state('module', $modules);
wp_safe_redirect(Jetpack::admin_url('page=jetpack'));
exit;
case 'unlink':
$redirect = isset($_GET['redirect']) ? $_GET['redirect'] : '';
check_admin_referer('jetpack-unlink');
Jetpack::log('unlink');
$this->unlink_user();
Jetpack::state('message', 'unlinked');
if ('sub-unlink' == $redirect) {
wp_safe_redirect(admin_url());
} else {
wp_safe_redirect(Jetpack::admin_url(array('page' => $redirect)));
}
exit;
default:
/**
* Fires when a Jetpack admin page is loaded with an unrecognized parameter.
*
* @since 2.6.0
*
* @param string sanitize_key( $_GET['action'] ) Unrecognized URL parameter.
*/
do_action('jetpack_unrecognized_action', sanitize_key($_GET['action']));
}
}
if (!($error = $error ? $error : Jetpack::state('error'))) {
self::activate_new_modules(true);
}
$message_code = Jetpack::state('message');
if (Jetpack::state('optin-manage')) {
$activated_manage = $message_code;
$message_code = 'jetpack-manage';
}
switch ($message_code) {
case 'jetpack-manage':
$this->message = '<strong>' . sprintf(__('You are all set! Your site can now be managed from <a href="%s" target="_blank">wordpress.com/sites</a>.', 'jetpack'), 'https://wordpress.com/sites') . '</strong>';
if ($activated_manage) {
$this->message .= '<br /><strong>' . __('Manage has been activated for you!', 'jetpack') . '</strong>';
}
break;
}
$deactivated_plugins = Jetpack::state('deactivated_plugins');
if (!empty($deactivated_plugins)) {
$deactivated_plugins = explode(',', $deactivated_plugins);
$deactivated_titles = array();
foreach ($deactivated_plugins as $deactivated_plugin) {
if (!isset($this->plugins_to_deactivate[$deactivated_plugin])) {
continue;
}
$deactivated_titles[] = '<strong>' . str_replace(' ', ' ', $this->plugins_to_deactivate[$deactivated_plugin][1]) . '</strong>';
}
if ($deactivated_titles) {
if ($this->message) {
$this->message .= "<br /><br />\n";
}
$this->message .= wp_sprintf(_n('Jetpack contains the most recent version of the old %l plugin.', 'Jetpack contains the most recent versions of the old %l plugins.', count($deactivated_titles), 'jetpack'), $deactivated_titles);
$this->message .= "<br />\n";
$this->message .= _n('The old version has been deactivated and can be removed from your site.', 'The old versions have been deactivated and can be removed from your site.', count($deactivated_titles), 'jetpack');
}
}
$this->privacy_checks = Jetpack::state('privacy_checks');
if ($this->message || $this->error || $this->privacy_checks || $this->can_display_jetpack_manage_notice()) {
add_action('jetpack_notices', array($this, 'admin_notices'));
}
if (isset($_GET['configure']) && Jetpack::is_module($_GET['configure']) && current_user_can('manage_options')) {
/**
* Fires when a module configuration page is loaded.
* The dynamic part of the hook is the configure parameter from the URL.
*
* @since 1.1.0
*/
do_action('jetpack_module_configuration_load_' . $_GET['configure']);
}
add_filter('jetpack_short_module_description', 'wptexturize');
}