is_user_connected() public static method

Is a given user (or the current user if none is specified) linked to a WordPress.com user?
public static is_user_connected ( $user_id = false )
 /**
  * Synchronize connected user role changes
  */
 static function user_role_change($user_id)
 {
     if (Jetpack::is_active() && Jetpack::is_user_connected($user_id)) {
         $current_user_id = get_current_user_id();
         wp_set_current_user($user_id);
         $role = Jetpack::translate_current_user_to_role();
         $signed_role = Jetpack::sign_role($role);
         wp_set_current_user($current_user_id);
         $master_token = Jetpack_Data::get_access_token(JETPACK_MASTER_USER);
         $master_user_id = absint($master_token->external_user_id);
         if (!$master_user_id) {
             return;
         }
         // this shouldn't happen
         Jetpack::xmlrpc_async_call('jetpack.updateRole', $user_id, $signed_role);
         //@todo retry on failure
         //try to choose a new master if we're demoting the current one
         if ($user_id == $master_user_id && 'administrator' != $role) {
             $query = new WP_User_Query(array('fields' => array('id'), 'role' => 'administrator', 'orderby' => 'id', 'exclude' => array($master_user_id)));
             $new_master = false;
             foreach ($query->results as $result) {
                 $uid = absint($result->id);
                 if ($uid && Jetpack::is_user_connected($uid)) {
                     $new_master = $uid;
                     break;
                 }
             }
             if ($new_master) {
                 Jetpack_Options::update_option('master_user', $new_master);
             }
             // else disconnect..?
         }
     }
 }
 function remote_authorize($request)
 {
     foreach (array('secret', 'state', 'redirect_uri', 'code') as $required) {
         if (!isset($request[$required]) || empty($request[$required])) {
             return $this->error(new Jetpack_Error('missing_parameter', 'One or more parameters is missing from the request.', 400));
         }
     }
     if (!get_user_by('id', $request['state'])) {
         return $this->error(new Jetpack_Error('user_unknown', 'User not found.', 404));
     }
     if (Jetpack::is_active() && Jetpack::is_user_connected($request['state'])) {
         return $this->error(new Jetpack_Error('already_connected', 'User already connected.', 400));
     }
     $verified = $this->verify_action(array('authorize', $request['secret'], $request['state']));
     if (is_a($verified, 'IXR_Error')) {
         return $verified;
     }
     wp_set_current_user($request['state']);
     $client_server = new Jetpack_Client_Server();
     $result = $client_server->authorize($request);
     if (is_wp_error($result)) {
         return $this->error($result);
     }
     // Creates a new secret, allowing someone to activate the manage module for up to 1 day after authorization.
     $secrets = Jetpack::init()->generate_secrets('activate_manage', DAY_IN_SECONDS);
     @(list($secret) = explode(':', $secrets));
     $response = array('result' => $result, 'activate_manage' => $secret);
     return $response;
 }
 function remote_authorize($request)
 {
     foreach (array('secret', 'state', 'redirect_uri', 'code') as $required) {
         if (!isset($request[$required]) || empty($request[$required])) {
             return $this->error(new Jetpack_Error('missing_parameter', 'One or more parameters is missing from the request.', 400));
         }
     }
     if (!get_user_by('id', $request['state'])) {
         return $this->error(new Jetpack_Error('user_unknown', 'User not found.', 404));
     }
     if (Jetpack::is_active() && Jetpack::is_user_connected($request['state'])) {
         return $this->error(new Jetpack_Error('already_connected', 'User already connected.', 400));
     }
     $verified = $this->verify_action(array('authorize', $request['secret'], $request['state']));
     if (is_a($verified, 'IXR_Error')) {
         return $verified;
     }
     wp_set_current_user($request['state']);
     $client_server = new Jetpack_Client_Server();
     $result = $client_server->authorize($request);
     if (is_wp_error($result)) {
         return $this->error($result);
     }
     return $result;
 }
Exemplo n.º 4
0
 static function maybe_demote_master_user($user_id)
 {
     $master_user_id = Jetpack_Options::get_option('master_user');
     $role = self::get_role($user_id);
     if ($user_id == $master_user_id && 'administrator' != $role) {
         $query = new WP_User_Query(array('fields' => array('id'), 'role' => 'administrator', 'orderby' => 'id', 'exclude' => array($master_user_id)));
         $new_master = false;
         foreach ($query->results as $result) {
             $found_user_id = absint($result->id);
             if ($found_user_id && Jetpack::is_user_connected($found_user_id)) {
                 $new_master = $found_user_id;
                 break;
             }
         }
         if ($new_master) {
             Jetpack_Options::update_option('master_user', $new_master);
         }
         // else disconnect..?
     }
 }
Exemplo n.º 5
0
    function print_js()
    {
        $link_accounts_url = is_user_logged_in() && !Jetpack::is_user_connected() ? $this->jetpack->admin_url() : false;
        ?>
<script type="text/javascript">
/* <![CDATA[ */
	var wpNotesIsJetpackClient = true;
<?php 
        if ($link_accounts_url) {
            ?>
	var wpNotesLinkAccountsURL = '<?php 
            print $link_accounts_url;
            ?>
';
<?php 
        }
        ?>
/* ]]> */
</script>
<?php 
    }
Exemplo n.º 6
0
function jetpack_tracks_get_identity($user_id)
{
    // Meta is set, and user is still connected.  Use WPCOM ID
    $wpcom_id = get_user_meta($user_id, 'jetpack_tracks_wpcom_id', true);
    if ($wpcom_id && Jetpack::is_user_connected($user_id)) {
        return array('_ut' => 'wpcom:user_id', '_ui' => $wpcom_id);
    }
    // User is connected, but no meta is set yet.  Use WPCOM ID and set meta.
    if (Jetpack::is_user_connected($user_id)) {
        $wpcom_user_data = Jetpack::get_connected_user_data($user_id);
        add_user_meta($user_id, 'jetpack_tracks_wpcom_id', $wpcom_user_data['ID'], true);
        return array('_ut' => 'wpcom:user_id', '_ui' => $wpcom_user_data['ID']);
    }
    // User isn't linked at all.  Fall back to anonymous ID.
    $anon_id = get_user_meta($user_id, 'jetpack_tracks_anon_id', true);
    if (!$anon_id) {
        $anon_id = Jetpack_Tracks_Client::get_anon_id();
        add_user_meta($user_id, 'jetpack_tracks_anon_id', $anon_id, false);
    }
    if (!isset($_COOKIE['tk_ai']) && !headers_sent()) {
        setcookie('tk_ai', $anon_id);
    }
    return array('_ut' => 'anon', '_ui' => $anon_id);
}
Exemplo n.º 7
0
<a title="<?php 
    esc_attr_e('Learn about what being the Primary User means.', 'jetpack');
    ?>
" class="dashicons dashicons-editor-help what-is-primary" href="https://jetpack.me/support/primary-user" target="_blank"></a></h4>
						<?php 
    // Only show dropdown if there are other admins
    $all_users = count_users();
    $primary_text = __('(primary)', 'jetpack');
    if (1 < $all_users['avail_roles']['administrator']) {
        ?>
							<form action="" method="post">
								<select name="jetpack-new-master" id="user-list">
									<?php 
        $all_users = get_users();
        foreach ($all_users as $user) {
            if (Jetpack::is_user_connected($user->ID) && $user->caps['administrator']) {
                if ($user->ID == Jetpack_Options::get_option('master_user')) {
                    $master_user_option = "<option selected value='{$user->ID}'>{$user->user_login} {$primary_text}</option>";
                } else {
                    $user_options .= "<option value='{$user->ID}'>{$user->user_login}</option>";
                }
            }
        }
        // Show master first
        echo $master_user_option;
        // Show the rest of the linked admins
        $user_options = !empty($user_options) ? $user_options : printf(__('%sConnect more admins%s', 'jetpack'), "<option disabled='disabled'>", "</option>");
        echo $user_options;
        ?>
								</select>
								<?php 
Exemplo n.º 8
0
 function jetpack_show_user_connected_icon($val, $col, $user_id)
 {
     if ('user_jetpack' == $col && Jetpack::is_user_connected($user_id)) {
         $emblem_html = sprintf('<a title="%1$s" class="jp-emblem-user-admin">%2$s</a>', esc_attr__('This user is linked and ready to fly with Jetpack.', 'jetpack'), Jetpack::get_jp_emblem());
         return $emblem_html;
     }
     return $val;
 }
/**
 * Gather data about the current user.
 *
 * @since 4.1.0
 *
 * @return array
 */
function jetpack_current_user_data()
{
    global $current_user;
    $is_master_user = $current_user->ID == Jetpack_Options::get_option('master_user');
    $dotcom_data = Jetpack::get_connected_user_data();
    // Add connected user gravatar to the returned dotcom_data
    $avatar_data = Jetpack::get_avatar_url($dotcom_data['email']);
    $dotcom_data['avatar'] = $avatar_data[0];
    $current_user_data = array('isConnected' => Jetpack::is_user_connected($current_user->ID), 'isMaster' => $is_master_user, 'username' => $current_user->user_login, 'wpcomUser' => $dotcom_data, 'gravatar' => get_avatar($current_user->ID, 40), 'permissions' => array('admin_page' => current_user_can('jetpack_admin_page'), 'connect' => current_user_can('jetpack_connect'), 'disconnect' => current_user_can('jetpack_disconnect'), 'manage_modules' => current_user_can('jetpack_manage_modules'), 'network_admin' => current_user_can('jetpack_network_admin_page'), 'network_sites_page' => current_user_can('jetpack_network_sites_page'), 'edit_posts' => current_user_can('edit_posts'), 'manage_options' => current_user_can('manage_options'), 'view_stats' => current_user_can('view_stats'), 'manage_plugins' => current_user_can('install_plugins') && current_user_can('activate_plugins') && current_user_can('update_plugins') && current_user_can('delete_plugins')));
    return $current_user_data;
}
function jetpack_current_user_data()
{
    global $current_user;
    $is_master_user = $current_user->ID == Jetpack_Options::get_option('master_user');
    $dotcom_data = Jetpack::get_connected_user_data();
    $current_user_data = array('isConnected' => Jetpack::is_user_connected($current_user->ID), 'isMaster' => $is_master_user, 'username' => $current_user->user_login, 'wpcomUser' => $dotcom_data, 'gravatar' => get_avatar($current_user->ID, 40), 'permissions' => array('admin_page' => current_user_can('jetpack_admin_page'), 'connect' => current_user_can('jetpack_connect'), 'disconnect' => current_user_can('jetpack_disconnect'), 'manage_modules' => current_user_can('jetpack_manage_modules'), 'network_admin' => current_user_can('jetpack_network_admin_page'), 'network_sites_page' => current_user_can('jetpack_network_sites_page'), 'edit_posts' => current_user_can('edit_posts'), 'manage_options' => current_user_can('manage_options')));
    return $current_user_data;
}
Exemplo n.º 11
0
    function edit_profile_fields($user)
    {
        ?>

		<h3 id="single-sign-on"><?php 
        _e('Single Sign On', 'jetpack');
        ?>
</h3>
		<p><?php 
        _e('Connecting with Single Sign On enables you to log in via your WordPress.com account.', 'jetpack');
        ?>
</p>

		<?php 
        if ($this->is_user_connected($user->ID)) {
            /* If the user is currently connected... */
            ?>
			<?php 
            $user_data = $this->get_user_data($user->ID);
            ?>
			<table class="form-table jetpack-sso-form-table">
				<tbody>
					<tr>
						<td>
							<div class="profile-card">
								<?php 
            echo get_avatar($user_data->email);
            ?>
								<p class="connected"><strong><?php 
            _e('Connected', 'jetpack');
            ?>
</strong></p>
								<p><?php 
            echo esc_html($user_data->login);
            ?>
</p>
								<span class="two_step">
									<?php 
            if ($user_data->two_step_enabled) {
                ?>
 <p class="enabled"><a href="https://wordpress.com/me/security/two-step" target="_blank"><?php 
                _e('Two-Step Authentication Enabled', 'jetpack');
                ?>
</a></p> <?php 
            } else {
                ?>
 <p class="disabled"><a href="https://wordpress.com/me/security/two-step" target="_blank"><?php 
                _e('Two-Step Authentication Disabled', 'jetpack');
                ?>
</a></p> <?php 
            }
            ?>
								</span>

							</div>
							<p><a class="button button-secondary" href="<?php 
            echo esc_url(wp_nonce_url(add_query_arg('jetpack_sso', 'purge'), 'jetpack_sso_purge'));
            ?>
"><?php 
            _e('Unlink This Account', 'jetpack');
            ?>
</a></p>
						</td>
					</tr>
				</tbody>
			</table>
		<?php 
        } elseif (get_current_user_id() == $user->ID && Jetpack::is_user_connected($user->ID)) {
            ?>

			<?php 
            echo $this->button('state=sso-link-user&_wpnonce=' . wp_create_nonce('sso-link-user'));
            // update
            ?>

		<?php 
        } else {
            ?>

			<p><?php 
            esc_html_e(wptexturize(__("If you don't have a WordPress.com account yet, you can sign up for free in just a few seconds.", 'jetpack')));
            ?>
</p>
			<a href="<?php 
            echo Jetpack::init()->build_connect_url(false, get_edit_profile_url(get_current_user_id()) . '#single-sign-on');
            ?>
" class="button button-connector" id="wpcom-connect"><?php 
            esc_html_e('Link account with WordPress.com', 'jetpack');
            ?>
</a>

		<?php 
        }
    }
 /**
  * Verify that a user can use the /connection/user endpoint. Has to be a registered user and be currently linked.
  *
  * @since 4.3.0
  *
  * @uses Jetpack::is_user_connected();
  *
  * @return bool|WP_Error True if user is able to unlink.
  */
 public static function unlink_user_permission_callback()
 {
     if (current_user_can('jetpack_connect_user') && Jetpack::is_user_connected(get_current_user_id())) {
         return true;
     }
     return new WP_Error('invalid_user_permission_unlink_user', self::$user_permissions_error_msg, array('status' => self::rest_authorization_required_code()));
 }
Exemplo n.º 13
0
 /**
  * Cache user's display name and Gravatar so it can be displayed on the login screen. These cookies are
  * stored when the user logs out, and then deleted when the user logs in.
  */
 function store_wpcom_profile_cookies_on_logout()
 {
     if (!Jetpack::is_user_connected(get_current_user_id())) {
         return;
     }
     $user_data = $this->get_user_data(get_current_user_id());
     if (!$user_data) {
         return;
     }
     setcookie('jetpack_sso_wpcom_name_' . COOKIEHASH, $user_data->display_name, time() + WEEK_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN);
     setcookie('jetpack_sso_wpcom_gravatar_' . COOKIEHASH, get_avatar_url($user_data->email, array('size' => 144, 'default' => 'mystery')), time() + WEEK_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN);
 }
Exemplo n.º 14
0
 /**
  * Handles the page load events for the Jetpack admin page
  */
 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 .= '&notes_iframe';
             }
             wp_redirect($connect_url);
             exit;
         } else {
             Jetpack::state('message', 'already_authorized');
             wp_safe_redirect(Jetpack::admin_url());
             exit;
         }
     }
     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_description', $error);
                     Jetpack::state('error_description', $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(' ', '&nbsp;', $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');
 }
 /**
  * Handles the page load events for the Jetpack admin page
  */
 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 .= '&notes_iframe';
             }
             wp_redirect($connect_url);
             exit;
         } else {
             Jetpack::state('message', 'already_authorized');
             wp_safe_redirect(Jetpack::admin_url());
             exit;
         }
     }
     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_description', $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);
     }
     switch ($error) {
         case 'cheatin':
             $this->error = __('Cheatin&#8217; uh?', 'jetpack');
             break;
         case 'access_denied':
             $this->error = sprintf(__('Would you mind telling us why you did not complete the Jetpack connection in this <a href="%s">1 question survey</a>?', 'jetpack'), 'http://jetpack.com/cancelled-connection/') . '<br /><small>' . __('A Jetpack connection is required for our free security and traffic features to work.', 'jetpack') . '</small>';
             break;
         case 'wrong_state':
             $this->error = __('You need to stay logged in to your WordPress blog while you authorize Jetpack.', 'jetpack');
             break;
         case 'invalid_client':
             // @todo re-register instead of deactivate/reactivate
             $this->error = __('We had an issue connecting Jetpack; deactivate then reactivate the Jetpack plugin, then connect again.', 'jetpack');
             break;
         case 'invalid_grant':
             $this->error = __('There was an issue connecting your Jetpack. Please click &#8220;Connect to WordPress.com&#8221; again.', 'jetpack');
             break;
         case 'site_inaccessible':
         case 'site_requires_authorization':
             $this->error = sprintf(__('Your website needs to be publicly accessible to use Jetpack: %s', 'jetpack'), "<code>{$error}</code>");
             break;
         case 'module_activation_failed':
             $module = Jetpack::state('module');
             if (!empty($module) && ($mod = Jetpack::get_module($module))) {
                 $this->error = sprintf(__('%s could not be activated because it triggered a <strong>fatal error</strong>. Perhaps there is a conflict with another plugin you have installed?', 'jetpack'), $mod['name']);
                 if (isset($this->plugins_to_deactivate[$module])) {
                     $this->error .= ' ' . sprintf(__('Do you still have the %s plugin installed?', 'jetpack'), $this->plugins_to_deactivate[$module][1]);
                 }
             } else {
                 $this->error = __('Module could not be activated because it triggered a <strong>fatal error</strong>. Perhaps there is a conflict with another plugin you have installed?', 'jetpack');
             }
             if ($php_errors = Jetpack::state('php_errors')) {
                 $this->error .= "<br />\n";
                 $this->error .= $php_errors;
             }
             break;
         case 'master_user_required':
             $module = Jetpack::state('module');
             $module_name = '';
             if (!empty($module) && ($mod = Jetpack::get_module($module))) {
                 $module_name = $mod['name'];
             }
             $master_user = Jetpack_Options::get_option('master_user');
             $master_userdata = get_userdata($master_user);
             if ($master_userdata) {
                 if (!in_array($module, Jetpack::get_active_modules())) {
                     $this->error = sprintf(__('%s was not activated.', 'jetpack'), $module_name);
                 } else {
                     $this->error = sprintf(__('%s was not deactivated.', 'jetpack'), $module_name);
                 }
                 $this->error .= '  ' . sprintf(__('This module can only be altered by %s, the user who initiated the Jetpack connection on this site.', 'jetpack'), esc_html($master_userdata->display_name));
             } else {
                 $this->error = sprintf(__('Only the user who initiated the Jetpack connection on this site can toggle %s, but that user no longer exists. This should not happen.', 'jetpack'), $module_name);
             }
             break;
         case 'not_public':
             $this->error = __('<strong>Your Jetpack has a glitch.</strong> Connecting this site with WordPress.com is not possible. This usually means your site is not publicly accessible (localhost).', 'jetpack');
             break;
         case 'wpcom_408':
         case 'wpcom_5??':
         case 'wpcom_bad_response':
         case 'wpcom_outage':
             $this->error = __('WordPress.com is currently having problems and is unable to fuel up your Jetpack.  Please try again later.', 'jetpack');
             break;
         case 'register_http_request_failed':
         case 'token_http_request_failed':
             $this->error = sprintf(__('Jetpack could not contact WordPress.com: %s.  This usually means something is incorrectly configured on your web host.', 'jetpack'), "<code>{$error}</code>");
             break;
         default:
             if (empty($error)) {
                 break;
             }
             $error = trim(substr(strip_tags($error), 0, 20));
             // no break: fall through
         // no break: fall through
         case 'no_role':
         case 'no_cap':
         case 'no_code':
         case 'no_state':
         case 'invalid_state':
         case 'invalid_request':
         case 'invalid_scope':
         case 'unsupported_response_type':
         case 'invalid_token':
         case 'no_token':
         case 'missing_secrets':
         case 'home_missing':
         case 'siteurl_missing':
         case 'gmt_offset_missing':
         case 'site_name_missing':
         case 'secret_1_missing':
         case 'secret_2_missing':
         case 'site_lang_missing':
         case 'home_malformed':
         case 'siteurl_malformed':
         case 'gmt_offset_malformed':
         case 'timezone_string_malformed':
         case 'site_name_malformed':
         case 'secret_1_malformed':
         case 'secret_2_malformed':
         case 'site_lang_malformed':
         case 'secrets_mismatch':
         case 'verify_secret_1_missing':
         case 'verify_secret_1_malformed':
         case 'verify_secrets_missing':
         case 'verify_secrets_mismatch':
             $error = esc_html($error);
             $this->error = sprintf(__('<strong>Your Jetpack has a glitch.</strong>  We&#8217;re sorry for the inconvenience. Please try again later, if the issue continues please contact support with this message: %s', 'jetpack'), "<code>{$error}</code>");
             if (!Jetpack::is_active()) {
                 $this->error .= '<br />';
                 $this->error .= sprintf(__('Try connecting again.', 'jetpack'));
             }
             break;
     }
     $message_code = Jetpack::state('message');
     $active_state = Jetpack::state('activated_modules');
     if (!empty($active_state)) {
         $available = Jetpack::get_available_modules();
         $active_state = explode(',', $active_state);
         $active_state = array_intersect($active_state, $available);
         if (count($active_state)) {
             foreach ($active_state as $mod) {
                 $this->stat('module-activated', $mod);
             }
         } else {
             $active_state = false;
         }
     }
     if (Jetpack::state('optin-manage')) {
         $activated_manage = $message_code;
         $message_code = 'jetpack-manage';
     }
     switch ($message_code) {
         case 'modules_activated':
             $this->message = sprintf(__('Welcome to <strong>Jetpack %s</strong>!', 'jetpack'), JETPACK__VERSION);
             if ($active_state) {
                 $titles = array();
                 foreach ($active_state as $mod) {
                     if ($mod_headers = Jetpack::get_module($mod)) {
                         $titles[] = '<strong>' . preg_replace('/\\s+(?![^<>]++>)/', '&nbsp;', $mod_headers['name']) . '</strong>';
                     }
                 }
                 if ($titles) {
                     $this->message .= '<br /><br />' . wp_sprintf(__('The following new modules have been activated: %l.', 'jetpack'), $titles);
                 }
             }
             if ($reactive_state = Jetpack::state('reactivated_modules')) {
                 $titles = array();
                 foreach (explode(',', $reactive_state) as $mod) {
                     if ($mod_headers = Jetpack::get_module($mod)) {
                         $titles[] = '<strong>' . preg_replace('/\\s+(?![^<>]++>)/', '&nbsp;', $mod_headers['name']) . '</strong>';
                     }
                 }
                 if ($titles) {
                     $this->message .= '<br /><br />' . wp_sprintf(__('The following modules have been updated: %l.', 'jetpack'), $titles);
                 }
             }
             $this->message .= Jetpack::jetpack_comment_notice();
             break;
         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;
         case 'module_activated':
             if ($module = Jetpack::get_module(Jetpack::state('module'))) {
                 $this->message = sprintf(__('<strong>%s Activated!</strong> You can deactivate at any time by clicking the Deactivate link next to each module.', 'jetpack'), $module['name']);
                 $this->stat('module-activated', Jetpack::state('module'));
             }
             break;
         case 'module_deactivated':
             $modules = Jetpack::state('module');
             if (!$modules) {
                 break;
             }
             $module_names = array();
             foreach (explode(',', $modules) as $module_slug) {
                 $module = Jetpack::get_module($module_slug);
                 if ($module) {
                     $module_names[] = $module['name'];
                 }
                 $this->stat('module-deactivated', $module_slug);
             }
             if (!$module_names) {
                 break;
             }
             $this->message = wp_sprintf(_nx('<strong>%l Deactivated!</strong> You can activate it again at any time using the activate link next to each module.', '<strong>%l Deactivated!</strong> You can activate them again at any time using the activate links next to each module.', count($module_names), '%l = list of Jetpack module/feature names', 'jetpack'), $module_names);
             break;
         case 'module_configured':
             $this->message = __('<strong>Module settings were saved.</strong> ', 'jetpack');
             break;
         case 'already_authorized':
             $this->message = __('<strong>Your Jetpack is already connected.</strong> ', 'jetpack');
             break;
         case 'authorized':
             $this->message = __('<strong>You&#8217;re fueled up and ready to go, Jetpack is now active.</strong> ', 'jetpack');
             $this->message .= Jetpack::jetpack_comment_notice();
             break;
         case 'linked':
             $this->message = __('<strong>You&#8217;re fueled up and ready to go.</strong> ', 'jetpack');
             $this->message .= Jetpack::jetpack_comment_notice();
             break;
         case 'unlinked':
             $user = wp_get_current_user();
             $this->message = sprintf(__('<strong>You have unlinked your account (%s) from WordPress.com.</strong>', 'jetpack'), $user->user_login);
             break;
         case 'switch_master':
             global $current_user;
             $is_master_user = $current_user->ID == Jetpack_Options::get_option('master_user');
             $master_userdata = get_userdata(Jetpack_Options::get_option('master_user'));
             if ($is_master_user) {
                 $this->message = __('You have successfully set yourself as Jetpack’s primary user.', 'jetpack');
             } else {
                 $this->message = sprintf(_x('You have successfully set %s as Jetpack’s primary user.', '%s is a username', 'jetpack'), $master_userdata->user_login);
             }
             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(' ', '&nbsp;', $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');
 }
Exemplo n.º 16
0
 /**
  * Handles the page load events for the Jetpack admin page
  */
 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);
             if (isset($_GET['notes_iframe'])) {
                 $connect_url .= '&notes_iframe';
             }
             wp_redirect($connect_url);
             exit;
         } else {
             Jetpack::state('message', 'already_authorized');
             wp_safe_redirect(Jetpack::admin_url());
             exit;
         }
     }
     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->authorize();
                 exit;
             case 'register':
                 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_description', $registered->get_error_message());
                     break;
                 }
                 wp_redirect($this->build_connect_url(true));
                 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());
                 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));
                 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':
                 check_admin_referer('jetpack-unlink');
                 Jetpack::log('unlink');
                 $this->unlink_user();
                 Jetpack::state('message', 'unlinked');
                 wp_safe_redirect(Jetpack::admin_url());
                 exit;
             default:
                 do_action('jetpack_unrecognized_action', sanitize_key($_GET['action']));
         }
     }
     if (!($error = $error ? $error : Jetpack::state('error'))) {
         $this->activate_new_modules();
     }
     switch ($error) {
         case 'cheatin':
             $this->error = __('Cheatin&#8217; uh?', 'jetpack');
             break;
         case 'access_denied':
             $this->error = __('You need to authorize the Jetpack connection between your site and WordPress.com to enable the awesome features.', 'jetpack');
             break;
         case 'wrong_state':
             $this->error = __('Don&#8217;t cross the streams!  You need to stay logged in to your WordPress blog while you authorize Jetpack.', 'jetpack');
             break;
         case 'invalid_client':
             // @todo re-register instead of deactivate/reactivate
             $this->error = __('Return to sender.  Whoops! It looks like you got the wrong Jetpack in the mail; deactivate then reactivate the Jetpack plugin to get a new one.', 'jetpack');
             break;
         case 'invalid_grant':
             $this->error = __('Wrong size.  Hm&#8230; it seems your Jetpack doesn&#8217;t quite fit.  Have you lost weight? Click &#8220;Connect to WordPress.com&#8221; again to get your Jetpack adjusted.', 'jetpack');
             break;
         case 'site_inaccessible':
         case 'site_requires_authorization':
             $this->error = sprintf(__('Your website needs to be publicly accessible to use Jetpack: %s', 'jetpack'), "<code>{$error}</code>");
             break;
         case 'module_activation_failed':
             $module = Jetpack::state('module');
             if (!empty($module) && ($mod = Jetpack::get_module($module))) {
                 $this->error = sprintf(__('%s could not be activated because it triggered a <strong>fatal error</strong>. Perhaps there is a conflict with another plugin you have installed?', 'jetpack'), $mod['name']);
                 if (isset($this->plugins_to_deactivate[$module])) {
                     $this->error .= ' ' . sprintf(__('Do you still have the %s plugin installed?', 'jetpack'), $this->plugins_to_deactivate[$module][1]);
                 }
             } else {
                 $this->error = __('Module could not be activated because it triggered a <strong>fatal error</strong>. Perhaps there is a conflict with another plugin you have installed?', 'jetpack');
             }
             if ($php_errors = Jetpack::state('php_errors')) {
                 $this->error .= "<br />\n";
                 $this->error .= $php_errors;
             }
             break;
         case 'master_user_required':
             $module = Jetpack::state('module');
             $module_name = '';
             if (!empty($module) && ($mod = Jetpack::get_module($module))) {
                 $module_name = $mod['name'];
             }
             $master_user = Jetpack_Options::get_option('master_user');
             $master_userdata = get_userdata($master_user);
             if ($master_userdata) {
                 if (!in_array($module, Jetpack::get_active_modules())) {
                     $this->error = sprintf(__('%s was not activated.', 'jetpack'), $module_name);
                 } else {
                     $this->error = sprintf(__('%s was not deactivated.', 'jetpack'), $module_name);
                 }
                 $this->error .= '  ' . sprintf(__('This module can only be altered by %s, the user who initiated the Jetpack connection on this site.', 'jetpack'), esc_html($master_userdata->display_name));
             } else {
                 $this->error = sprintf(__('Only the user who initiated the Jetpack connection on this site can toggle %s, but that user no longer exists. This should not happen.', 'jetpack'), $module_name);
             }
             break;
         case 'not_public':
             $this->error = __('<strong>Your Jetpack has a glitch.</strong> Connecting this site with WordPress.com is not possible. This usually means your site is not publicly accessible (localhost).', 'jetpack');
             break;
         case 'wpcom_408':
         case 'wpcom_5??':
         case 'wpcom_bad_response':
         case 'wpcom_outage':
             $this->error = __('WordPress.com is currently having problems and is unable to fuel up your Jetpack.  Please try again later.', 'jetpack');
             break;
         case 'register_http_request_failed':
         case 'token_http_request_failed':
             $this->error = sprintf(__('Jetpack could not contact WordPress.com: %s.  This usually means something is incorrectly configured on your web host.', 'jetpack'), "<code>{$error}</code>");
             break;
         default:
             if (empty($error)) {
                 break;
             }
             $error = trim(substr(strip_tags($error), 0, 20));
             // no break: fall through
         // no break: fall through
         case 'no_role':
         case 'no_cap':
         case 'no_code':
         case 'no_state':
         case 'invalid_state':
         case 'invalid_request':
         case 'invalid_scope':
         case 'unsupported_response_type':
         case 'invalid_token':
         case 'no_token':
         case 'missing_secrets':
         case 'home_missing':
         case 'siteurl_missing':
         case 'gmt_offset_missing':
         case 'site_name_missing':
         case 'secret_1_missing':
         case 'secret_2_missing':
         case 'site_lang_missing':
         case 'home_malformed':
         case 'siteurl_malformed':
         case 'gmt_offset_malformed':
         case 'timezone_string_malformed':
         case 'site_name_malformed':
         case 'secret_1_malformed':
         case 'secret_2_malformed':
         case 'site_lang_malformed':
         case 'secrets_mismatch':
         case 'verify_secret_1_missing':
         case 'verify_secret_1_malformed':
         case 'verify_secrets_missing':
         case 'verify_secrets_mismatch':
             $error = esc_html($error);
             $this->error = sprintf(__('<strong>Your Jetpack has a glitch.</strong>  Something went wrong that&#8217;s never supposed to happen.  Guess you&#8217;re just lucky: %s', 'jetpack'), "<code>{$error}</code>");
             if (!Jetpack::is_active()) {
                 $this->error .= '<br />';
                 $this->error .= sprintf(__('Try connecting again.', 'jetpack'));
             }
             break;
     }
     $message_code = Jetpack::state('message');
     $active_state = Jetpack::state('activated_modules');
     if (!empty($active_state)) {
         $available = Jetpack::get_available_modules();
         $active_state = explode(',', $active_state);
         $active_state = array_intersect($active_state, $available);
         if (count($active_state)) {
             foreach ($active_state as $mod) {
                 $this->stat('module-activated', $mod);
             }
         } else {
             $active_state = false;
         }
     }
     switch ($message_code) {
         case 'modules_activated':
             $this->message = sprintf(__('Welcome to <strong>Jetpack %s</strong>!', 'jetpack'), JETPACK__VERSION);
             if ($active_state) {
                 $titles = array();
                 foreach ($active_state as $mod) {
                     if ($mod_headers = Jetpack::get_module($mod)) {
                         $titles[] = '<strong>' . preg_replace('/\\s+(?![^<>]++>)/', '&nbsp;', $mod_headers['name']) . '</strong>';
                     }
                 }
                 if ($titles) {
                     $this->message .= '<br /><br />' . wp_sprintf(__('The following new modules have been activated: %l.', 'jetpack'), $titles);
                 }
             }
             if ($reactive_state = Jetpack::state('reactivated_modules')) {
                 $titles = array();
                 foreach (explode(',', $reactive_state) as $mod) {
                     if ($mod_headers = Jetpack::get_module($mod)) {
                         $titles[] = '<strong>' . preg_replace('/\\s+(?![^<>]++>)/', '&nbsp;', $mod_headers['name']) . '</strong>';
                     }
                 }
                 if ($titles) {
                     $this->message .= '<br /><br />' . wp_sprintf(__('The following modules have been updated: %l.', 'jetpack'), $titles);
                 }
             }
             $this->message .= Jetpack::jetpack_comment_notice();
             break;
         case 'module_activated':
             if ($module = Jetpack::get_module(Jetpack::state('module'))) {
                 $this->message = sprintf(__('<strong>%s Activated!</strong> You can deactivate at any time by clicking the Deactivate link next to each module.', 'jetpack'), $module['name']);
                 $this->stat('module-activated', Jetpack::state('module'));
             }
             break;
         case 'module_deactivated':
             $modules = Jetpack::state('module');
             if (!$modules) {
                 break;
             }
             $module_names = array();
             foreach (explode(',', $modules) as $module_slug) {
                 $module = Jetpack::get_module($module_slug);
                 if ($module) {
                     $module_names[] = $module['name'];
                 }
                 $this->stat('module-deactivated', $module_slug);
             }
             if (!$module_names) {
                 break;
             }
             $this->message = wp_sprintf(_nx('<strong>%l Deactivated!</strong> You can activate it again at any time using the activate link next to each module.', '<strong>%l Deactivated!</strong> You can activate them again at any time using the activate links next to each module.', count($module_names), '%l = list of Jetpack module/feature names', 'jetpack'), $module_names);
             break;
         case 'module_configured':
             $this->message = __('<strong>Module settings were saved.</strong> ', 'jetpack');
             break;
         case 'already_authorized':
             $this->message = __('<strong>Your Jetpack is already connected.</strong> ', 'jetpack');
             break;
         case 'authorized':
             $this->message = __('<strong>You&#8217;re fueled up and ready to go.</strong> ', 'jetpack');
             $this->message .= "<br />\n";
             $this->message .= sprintf(__('Jetpack is now active. Browse through each Jetpack feature below. Visit the <a href="%s">settings page</a> to activate/deactivate features.', 'jetpack'), admin_url('admin.php?page=jetpack_modules'));
             $this->message .= Jetpack::jetpack_comment_notice();
             break;
         case 'linked':
             $this->message = __('<strong>You&#8217;re fueled up and ready to go.</strong> ', 'jetpack');
             $this->message .= Jetpack::jetpack_comment_notice();
             break;
         case 'unlinked':
             $user = wp_get_current_user();
             $this->message = sprintf(__('<strong>You have unlinked your account (%s) from WordPress.com.</strong>', 'jetpack'), $user->user_login);
             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(' ', '&nbsp;', $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) {
         add_action('jetpack_notices', array($this, 'admin_notices'));
     }
     if (isset($_GET['configure']) && Jetpack::is_module($_GET['configure']) && current_user_can('manage_options')) {
         do_action('jetpack_module_configuration_load_' . $_GET['configure']);
     }
     add_filter('jetpack_short_module_description', 'wptexturize');
 }
Exemplo n.º 17
0
    public function jetpack_configuration_screen()
    {
        ?>
		<p><?php 
        esc_html_e('Nobody likes downtime, and that\'s why Jetpack Monitor is on the job, keeping tabs on your site by checking it every five minutes. As soon as any downtime is detected, you will receive an email notification alerting you to the issue. That way you can act quickly, to get your site back online again!', 'jetpack');
        ?>
		<p><?php 
        esc_html_e('We’ll also let you know as soon as your site is up and running, so you can keep an eye on total downtime.', 'jetpack');
        ?>
</p>
		<div class="narrow">
		<?php 
        if (Jetpack::is_user_connected() && current_user_can('manage_options')) {
            ?>
			<?php 
            $user_email = Jetpack::get_connected_user_email();
            ?>
			<form method="post" id="monitor-settings">
				<input type="hidden" name="action" value="monitor-save" />
				<?php 
            wp_nonce_field('monitor-settings');
            ?>

				<table id="menu" class="form-table">
						<tr>
						<th scope="row">
							<?php 
            _e('Notifications', 'jetpack');
            ?>
						</th>
						<td>
							<label for="receive_jetpack_monitor_notification">
									<input type="checkbox" name="receive_jetpack_monitor_notification" id="receive_jetpack_monitor_notification" value="receive_jetpack_monitor_notification"<?php 
            checked($this->user_receives_notifications());
            ?>
 />
								<span><?php 
            _e('Receive Monitor Email Notifications.', 'jetpack');
            ?>
</span>
							</label>
							<p class="description"><?php 
            printf(__('Emails will be sent to %s (<a href="%s">Edit</a>)', 'jetpack'), $user_email, 'https://wordpress.com/settings/account/');
            ?>
</p>
						</td>
					</tr>
				</table>
				<?php 
            submit_button();
            ?>
			</form>
		<?php 
        } else {
            ?>
			<p><?php 
            _e('This profile is not currently linked to a WordPress.com Profile.', 'jetpack');
            ?>
</p>
		<?php 
        }
        ?>
		</div>
		<?php 
    }
Exemplo n.º 18
0
    function edit_profile_fields($user)
    {
        wp_enqueue_style('genericons');
        ?>

		<h3 id="single-sign-on"><?php 
        _e('Single Sign On', 'jetpack');
        ?>
</h3>
		<p><?php 
        _e('Connecting with Single Sign On enables you to log in via your WordPress.com account.', 'jetpack');
        ?>
</p>

		<?php 
        if ($this->is_user_connected($user->ID)) {
            /* If the user is currently connected... */
            ?>
			<?php 
            $user_data = $this->get_user_data($user->ID);
            ?>
			<table class="form-table jetpack-sso-form-table">
				<tbody>
					<tr>
						<td>
							<div class="profile-card">
								<?php 
            echo get_avatar($user_data->email);
            ?>
								<p class="connected"><strong><?php 
            _e('Connected', 'jetpack');
            ?>
</strong></p>
								<p><?php 
            echo esc_html($user_data->login);
            ?>
</p>
								<span class="two_step">
									<?php 
            if ($user_data->two_step_enabled) {
                ?>
 <p class="enabled"><a href="https://wordpress.com/me/security/two-step"><?php 
                _e('Two-Step Authentication Enabled', 'jetpack');
                ?>
</a></p> <?php 
            } else {
                ?>
 <p class="disabled"><a href="https://wordpress.com/me/security/two-step"><?php 
                _e('Two-Step Authentication Disabled', 'jetpack');
                ?>
</a></p> <?php 
            }
            ?>
								</span>

							</div>
							<p><a class="button button-secondary" href="<?php 
            echo esc_url(wp_nonce_url(add_query_arg('jetpack_sso', 'purge'), 'jetpack_sso_purge'));
            ?>
"><?php 
            _e('Unlink This Account', 'jetpack');
            ?>
</a></p>
						</td>
					</tr>
				</tbody>
			</table>

			<style>
			.jetpack-sso-form-table td {
				padding-left: 0;
			}

			.jetpack-sso-form-table .profile-card {
				padding: 10px;
				background: #fff;
				overflow: hidden;
				max-width: 400px;
				box-shadow: 0 1px 2px rgba( 0, 0, 0, 0.1 );
				margin-bottom: 1em;
			}

			.jetpack-sso-form-table .profile-card img {
				float: left;
				margin-right: 1em;
				width: 48px;
				height: 48px;
			}

			.jetpack-sso-form-table .profile-card .connected {
				float: right;
				margin-right: 0.5em;
				color: #0a0;
			}

			.jetpack-sso-form-table .profile-card p {
				margin-top: 0.7em;
				font-size: 1.2em;
			}

			.jetpack-sso-form-table .profile-card .two_step .enabled a {
				float: right;
				color: #0a0;
			}

			.jetpack-sso-form-table .profile-card .two_step .disabled a {
				float: right;
				color: red;
			}
			</style>

		<?php 
        } elseif (get_current_user_id() == $user->ID && Jetpack::is_user_connected($user->ID)) {
            ?>

			<?php 
            echo $this->button('state=sso-link-user&_wpnonce=' . wp_create_nonce('sso-link-user'));
            // update
            ?>

		<?php 
        } else {
            ?>

			<p><?php 
            esc_html_e(wptexturize(__("If you don't have a WordPress.com account yet, you can sign up for free in just a few seconds.", 'jetpack')));
            ?>
</p>
			<a href="<?php 
            echo Jetpack::init()->build_connect_url(false, get_edit_profile_url(get_current_user_id()) . '#single-sign-on');
            ?>
" class="button button-connector" id="wpcom-connect"><?php 
            esc_html_e('Link account with WordPress.com', 'jetpack');
            ?>
</a>

		<?php 
        }
    }
 function jetpack_current_user_data()
 {
     global $current_user;
     $is_master_user = $current_user->ID == Jetpack_Options::get_option('master_user');
     $dotcom_data = Jetpack::get_connected_user_data();
     $current_user_data = array('isUserConnected' => Jetpack::is_user_connected($current_user->ID), 'isMasterUser' => $is_master_user, 'adminUsername' => $current_user->user_login, 'userComData' => $dotcom_data, 'gravatar' => sprintf('<a href="%s">%s</a>', get_edit_user_link($current_user->ID), get_avatar($current_user->ID, 40)));
     return $current_user_data;
 }