Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
77.64% covered (warning)
77.64%
184 / 237
69.23% covered (warning)
69.23%
9 / 13
CRAP
0.00% covered (danger)
0.00%
0 / 1
jetpack_current_user_data
0.00% covered (danger)
0.00%
0 / 44
0.00% covered (danger)
0.00%
0 / 1
72
Jetpack_Redux_State_Helper
95.34% covered (success)
95.34%
184 / 193
75.00% covered (warning)
75.00%
9 / 12
38
0.00% covered (danger)
0.00%
0 / 1
 get_minimal_state
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
 get_plugins_page_state
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
1
 get_initial_state
97.86% covered (success)
97.86%
137 / 140
0.00% covered (danger)
0.00%
0 / 1
16
 get_dismissed_jetpack_notices
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 get_flattened_settings
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 get_update_modal_data
n/a
0 / 0
n/a
0 / 0
1
 allow_post_embed_iframe
n/a
0 / 0
n/a
0 / 0
2
 get_release_post_data
n/a
0 / 0
n/a
0 / 0
1
 get_host_upgrade_urls
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
 get_host_upgrade_url
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
1 / 1
5
 get_external_services_connect_urls
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
 get_purchase_token
28.57% covered (danger)
28.57%
2 / 7
0.00% covered (danger)
0.00%
0 / 1
6.28
 generate_purchase_token
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 get_site_image
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 has_social_page
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2/**
3 * A utility class that generates the initial state for Redux in wp-admin.
4 * Modularized from `class.jetpack-react-page.php`.
5 *
6 * @package automattic/jetpack
7 */
8
9use Automattic\Jetpack\Blaze;
10use Automattic\Jetpack\Comments\Comments;
11use Automattic\Jetpack\Connection\Manager as Connection_Manager;
12use Automattic\Jetpack\Connection\Plugin_Storage as Connection_Plugin_Storage;
13use Automattic\Jetpack\Connection\REST_Connector;
14use Automattic\Jetpack\Constants;
15use Automattic\Jetpack\Current_Plan as Jetpack_Plan;
16use Automattic\Jetpack\Device_Detection\User_Agent_Info;
17use Automattic\Jetpack\Identity_Crisis;
18use Automattic\Jetpack\IP\Utils as IP_Utils;
19use Automattic\Jetpack\Licensing;
20use Automattic\Jetpack\Licensing\Endpoints as Licensing_Endpoints;
21use Automattic\Jetpack\My_Jetpack\Initializer as My_Jetpack_Initializer;
22use Automattic\Jetpack\Partner;
23use Automattic\Jetpack\Plugin\Jetpack_Script_Data;
24use Automattic\Jetpack\Publicize\Keyring_Helper;
25use Automattic\Jetpack\Stats\Options as Stats_Options;
26use Automattic\Jetpack\Status;
27use Automattic\Jetpack\Status\Host;
28
29/**
30 * Responsible for populating the initial Redux state.
31 */
32class Jetpack_Redux_State_Helper {
33    /**
34     * Generate minimal state for React to fetch its own data asynchronously after load
35     * This can improve user experience, reducing time spent on server requests before serving the page
36     * e.g. used by React Disconnect Dialog on plugins page where the full initial state is not needed
37     */
38    public static function get_minimal_state() {
39        return array(
40            'WP_API_root'  => esc_url_raw( rest_url() ),
41            'WP_API_nonce' => wp_create_nonce( 'wp_rest' ),
42        );
43    }
44
45    /**
46     * Generate the state for the plugins page: the minimal state plus what the deactivation survey needs.
47     *
48     * @since 16.3
49     *
50     * @return array
51     */
52    public static function get_plugins_page_state() {
53        $state = self::get_minimal_state();
54
55        $connection = new Connection_Manager();
56
57        $state['pluginDeactivation'] = array(
58            'siteId'                 => (int) Jetpack_Options::get_option( 'id' ),
59            'hasConnectedUser'       => $connection->has_connected_user(),
60            'isCurrentUserConnected' => $connection->is_user_connected(),
61        );
62
63        return $state;
64    }
65
66    /**
67     * Generate the initial state array to be used by the Redux store.
68     */
69    public static function get_initial_state() {
70        global $is_safari;
71
72        // Load API endpoint base classes and endpoints for getting the module list fed into the JS Admin Page.
73        require_once JETPACK__PLUGIN_DIR . '_inc/lib/core-api/class.jetpack-core-api-xmlrpc-consumer-endpoint.php';
74        require_once JETPACK__PLUGIN_DIR . '_inc/lib/core-api/class.jetpack-core-api-module-endpoints.php';
75        require_once JETPACK__PLUGIN_DIR . '_inc/lib/core-api/class.jetpack-core-api-site-endpoints.php';
76        require_once __DIR__ . '/class-jetpack-settings-react-page.php';
77
78        $module_list_endpoint = new Jetpack_Core_API_Module_List_Endpoint();
79        $modules              = $module_list_endpoint->get_modules();
80
81        // Preparing translated fields for JSON encoding by transforming all HTML entities to
82        // respective characters.
83        foreach ( $modules as $slug => $data ) {
84            $modules[ $slug ]['name']              = html_entity_decode( $data['name'], ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401 );
85            $modules[ $slug ]['description']       = html_entity_decode( $data['description'], ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401 );
86            $modules[ $slug ]['short_description'] = html_entity_decode( $data['short_description'], ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401 );
87            $modules[ $slug ]['long_description']  = html_entity_decode( $data['long_description'], ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401 );
88        }
89
90        // "mock" a block module in order to get it searchable in the settings.
91        $modules['blocks']['module']                    = 'blocks';
92        $modules['blocks']['additional_search_queries'] = esc_html_x( 'blocks, block, gutenberg', 'Search terms', 'jetpack' );
93
94        // "mock" an Earn module in order to get it searchable in the settings.
95        $modules['earn']['module']                    = 'earn';
96        $modules['earn']['additional_search_queries'] = esc_html_x( 'earn, paypal, stripe, payments, pay', 'Search terms', 'jetpack' );
97
98        // Collecting roles that can view site stats.
99        $stats_roles   = array();
100        $enabled_roles = Stats_Options::get_option( 'roles' );
101
102        if ( ! function_exists( 'get_editable_roles' ) ) {
103            require_once ABSPATH . 'wp-admin/includes/user.php';
104        }
105        foreach ( get_editable_roles() as $slug => $role ) {
106            $stats_roles[ $slug ] = array(
107                'name'    => translate_user_role( $role['name'] ),
108                'canView' => is_array( $enabled_roles ) ? in_array( $slug, $enabled_roles, true ) : false,
109            );
110        }
111
112        // Get information about current theme.
113        $current_theme = wp_get_theme();
114
115        // Get last post, to build the link to Customizer in the Related Posts module.
116        $last_post = get_posts( array( 'posts_per_page' => 1 ) );
117        $last_post = isset( $last_post[0] ) && $last_post[0] instanceof WP_Post
118            ? get_permalink( $last_post[0]->ID )
119            : get_home_url();
120
121        $current_user_data = jetpack_current_user_data();
122
123        /**
124         * Adds information to the `connectionStatus` API field that is unique to the Jetpack React dashboard.
125         */
126        $connection_status = array(
127            'isInIdentityCrisis' => Identity_Crisis::validate_sync_error_idc_option(),
128            'sandboxDomain'      => JETPACK__SANDBOX_DOMAIN,
129
130            /**
131             * Filter to add connection errors
132             * Format: array( array( 'code' => '...', 'message' => '...', 'action' => '...' ), ... )
133             *
134             * @since 8.7.0
135             *
136             * @param array $errors Connection errors.
137             */
138            'errors'             => apply_filters( 'react_connection_errors_initial_state', array() ),
139        );
140
141        $connection_status = array_merge( REST_Connector::connection_status( false ), $connection_status );
142
143        $block_availability = Jetpack_Gutenberg::get_cached_availability();
144
145        return array(
146            'WP_API_root'                          => esc_url_raw( rest_url() ),
147            'WP_API_nonce'                         => wp_create_nonce( 'wp_rest' ),
148            'registrationNonce'                    => '', // Not used, keeping it for compatibility reasons, see https://github.com/Automattic/jetpack/pull/42076
149            'purchaseToken'                        => self::get_purchase_token(),
150            'pluginBaseUrl'                        => plugins_url( '', JETPACK__PLUGIN_FILE ),
151            'connectionStatus'                     => $connection_status,
152            'connectedPlugins'                     => Connection_Plugin_Storage::get_all(),
153            'connectUrl'                           => false == $current_user_data['isConnected'] // phpcs:ignore Universal.Operators.StrictComparisons.LooseEqual
154                ? Jetpack::init()->build_connect_url( true, false, false )
155                : '',
156            'dismissedNotices'                     => self::get_dismissed_jetpack_notices(),
157            'isDevVersion'                         => Jetpack::is_development_version(),
158            'currentVersion'                       => JETPACK__VERSION,
159            'is_gutenberg_available'               => true,
160            'getModules'                           => $modules,
161            'rawUrl'                               => ( new Status() )->get_site_suffix(),
162            'adminUrl'                             => esc_url( admin_url() ),
163            'siteTitle'                            => htmlspecialchars_decode( get_option( 'blogname' ), ENT_QUOTES ),
164            'stats'                                => array(
165                // data is populated asynchronously on page load.
166                'data'  => array(
167                    'general' => false,
168                    'day'     => false,
169                    'week'    => false,
170                    'month'   => false,
171                ),
172                'roles' => $stats_roles,
173            ),
174            'aff'                                  => Partner::init()->get_partner_code( Partner::AFFILIATE_CODE ),
175            'partnerSubsidiaryId'                  => Partner::init()->get_partner_code( Partner::SUBSIDIARY_CODE ),
176            'settings'                             => self::get_flattened_settings(),
177            'userData'                             => array(
178                'currentUser' => $current_user_data,
179            ),
180            'siteData'                             => array(
181                'blog_id'                    => Jetpack_Options::get_option( 'id', 0 ),
182                'icon'                       => has_site_icon()
183                    ? apply_filters( 'jetpack_photon_url', get_site_icon_url(), array( 'w' => 64 ) )
184                    : '',
185                'representativeImage'        => self::get_site_image(),
186                'siteVisibleToSearchEngines' => '1' == get_option( 'blog_public' ), // phpcs:ignore Universal.Operators.StrictComparisons.LooseEqual
187                /**
188                 * Whether promotions are visible or not.
189                 *
190                 * @since 4.8.0
191                 *
192                 * @param bool $are_promotions_active Status of promotions visibility. True by default.
193                 */
194                'showPromotions'             => apply_filters( 'jetpack_show_promotions', true ),
195                'plan'                       => Jetpack_Plan::get(),
196                'showBackups'                => Jetpack::show_backups_ui(),
197                'showScan'                   => Jetpack::show_scan_ui(),
198                /** This filter is documented in my-jetpack/src/class-initializer.php */
199                'showMyJetpack'              => My_Jetpack_Initializer::should_initialize(),
200                'isMultisite'                => is_multisite(),
201                // Set when Jetpack or the standalone plugin registered the Backup page on this request.
202                'hasBackupPage'              => (bool) did_action( 'jetpack_backup_initialized' ),
203                // Set when Jetpack or the Protect plugin registered the Protect page on this request.
204                'hasProtectPage'             => (bool) did_action( 'jetpack_protect_dashboard_initialized' ),
205                'hasSocialPage'              => self::has_social_page(),
206                'hostUpgradeUrls'            => self::get_host_upgrade_urls(),
207                'settingsTabs'               => Jetpack_Settings_React_Page::get_remaining_tabs(),
208                'dateFormat'                 => get_option( 'date_format' ),
209                'isSharingBlockAvailable'    => isset( $block_availability['sharing-buttons'] )
210                    && $block_availability['sharing-buttons']['available'],
211                'isLikeBlockAvailable'       => isset( $block_availability['like'] )
212                    && $block_availability['like']['available'],
213                'isCommentBlocksAvailable'   => Comments::is_enabled(),
214            ),
215            'themeData'                            => array(
216                'name'         => $current_theme->get( 'Name' ),
217                'stylesheet'   => $current_theme->get_stylesheet(),
218                'hasUpdate'    => (bool) get_theme_update_available( $current_theme ),
219                'isBlockTheme' => (bool) $current_theme->is_block_theme(),
220                'support'      => array(
221                    'infinite-scroll' => Jetpack_Script_Data::theme_supports_infinite_scroll(),
222                    'widgets'         => current_theme_supports( 'widgets' ),
223                    'webfonts'        => wp_theme_has_theme_json()
224                        && ( function_exists( 'wp_register_webfont_provider' ) || function_exists( 'wp_register_webfonts' ) ),
225                ),
226            ),
227            'jetpackStateNotices'                  => array(
228                'messageCode'      => Jetpack::state( 'message' ),
229                'errorCode'        => Jetpack::state( 'error' ),
230                'errorDescription' => Jetpack::state( 'error_description' ),
231            ),
232            'tracksUserData'                       => Jetpack_Tracks_Client::get_connected_user_tracks_identity(),
233            // Don't suggest the fallback address when the configured trusted header can't be resolved.
234            'currentIp'                            => method_exists( IP_Utils::class, 'is_trusted_header_unresolved' ) && IP_Utils::is_trusted_header_unresolved() ? false : IP_Utils::get_ip(),
235            'lastPostUrl'                          => esc_url( $last_post ),
236            'externalServicesConnectUrls'          => self::get_external_services_connect_urls(),
237            'calypsoEnv'                           => ( new Host() )->get_calypso_env(),
238            'isSafari'                             => $is_safari || User_Agent_Info::is_opera_desktop(), // @todo Rename isSafari everywhere.
239            'doNotUseConnectionIframe'             => Constants::is_true( 'JETPACK_SHOULD_NOT_USE_CONNECTION_IFRAME' ),
240            'licensing'                            => array(
241                'error'                   => Licensing::instance()->last_error(),
242                'showLicensingUi'         => Licensing::instance()->is_licensing_input_enabled(),
243                'userCounts'              => Licensing_Endpoints::get_user_license_counts(),
244                'activationNoticeDismiss' => Licensing::instance()->get_license_activation_notice_dismiss(),
245            ),
246            'useMyJetpackLicensingUI'              => My_Jetpack_Initializer::is_licensing_ui_enabled(),
247            'isOdysseyStatsEnabled'                => Stats_Options::get_option( 'enable_odyssey_stats' ),
248            'shouldInitializeBlaze'                => Blaze::should_initialize(),
249            'isBlazeDashboardEnabled'              => Blaze::is_dashboard_enabled(),
250            // The composed AI gate chain (host, and the master where its rollout
251            // is active) â€” what the editor enforces, for settings UI that must
252            // not contradict it.
253            'isAiEnabled'                          => Jetpack_AI_Settings::is_ai_enabled(),
254            // The AI SEO feature, gates folded in: controls that drive only its
255            // automatic half must follow it too.
256            'isAiSeoEnabled'                       => Jetpack_AI_Settings::is_ai_seo_enabled(),
257            'isSubscriptionSiteEnabled'            => apply_filters( 'jetpack_subscription_site_enabled', false ),
258            'newsletterDateExample'                => gmdate( get_option( 'date_format' ), time() ),
259            'subscriptionSiteEditSupported'        => $current_theme->is_block_theme(),
260
261            /*
262             * This filter is already documented in jetpack/modules/subscriptions.php.
263             * Defaults on for every site; hosts can opt out with the filter.
264             */
265            'isWpAdminSubscriberManagementEnabled' => apply_filters(
266                'jetpack_wp_admin_subscriber_management_enabled',
267                true
268            ),
269        );
270    }
271
272    /**
273     * Gets array of any Jetpack notices that have been dismissed.
274     *
275     * @return mixed|void
276     */
277    public static function get_dismissed_jetpack_notices() {
278        $jetpack_dismissed_notices = get_option( 'jetpack_dismissed_notices', array() );
279        /**
280         * Array of notices that have been dismissed.
281         *
282         * @param array $jetpack_dismissed_notices If empty, will not show any Jetpack notices.
283         */
284        $dismissed_notices = apply_filters( 'jetpack_dismissed_notices', $jetpack_dismissed_notices );
285        return $dismissed_notices;
286    }
287
288    /**
289     * Returns an array of modules and settings both as first class members of the object.
290     *
291     * @return array flattened settings with modules.
292     */
293    public static function get_flattened_settings() {
294        $core_api_endpoint = new Jetpack_Core_API_Data();
295        $settings          = $core_api_endpoint->get_all_options();
296        return $settings->data;
297    }
298
299    /**
300     * Returns the release post content and image data as an associative array.
301     *
302     * The update modal that consumed this data has been removed, so there is nothing to return.
303     *
304     * @deprecated 16.2
305     *
306     * @return null
307     */
308    public static function get_update_modal_data() {
309        _deprecated_function( __METHOD__, 'jetpack-16.2' );
310        return null;
311    }
312
313    /**
314     * Temporarily allow post content to contain iframes, e.g. for videopress.
315     *
316     * Only ever used while sanitizing the release post for the removed update modal.
317     *
318     * @deprecated 16.2
319     *
320     * @param string $tags    The tags.
321     * @param string $context The context.
322     */
323    public static function allow_post_embed_iframe( $tags, $context ) {
324        _deprecated_function( __METHOD__, 'jetpack-16.2' );
325
326        if ( 'post' === $context ) {
327            $tags['iframe'] = array(
328                'src'             => true,
329                'height'          => true,
330                'width'           => true,
331                'frameborder'     => true,
332                'allowfullscreen' => true,
333            );
334        }
335
336        return $tags;
337    }
338
339    /**
340     * Obtains the release post from the Jetpack release post blog.
341     *
342     * The release post blog has had no post tagged for a current Jetpack version since 2023, and the
343     * update modal that consumed this has been removed, so this no longer makes a remote request.
344     *
345     * @deprecated 16.2
346     *
347     * @return null
348     */
349    public static function get_release_post_data() {
350        _deprecated_function( __METHOD__, 'jetpack-16.2' );
351        return null;
352    }
353
354    /**
355     * Where Settings' Ads and Google Analytics upgrades go when the host sends them to its own plans.
356     *
357     * Each is the host's URL, '' when the host sells nothing on this site, or null to keep Jetpack's checkout.
358     *
359     * @since $$next-version$$
360     *
361     * @return array{ads: ?string, googleAnalytics: ?string}
362     */
363    public static function get_host_upgrade_urls() {
364        return array(
365            // The Monetize page's slug: both sell Jetpack Creator's ads.
366            'ads'             => self::get_host_upgrade_url( 'monetize-dashboard', 'Jetpack Creator', 'earn' ),
367            'googleAnalytics' => self::get_host_upgrade_url( 'google-analytics', 'Jetpack Security', 'traffic' ),
368        );
369    }
370
371    /**
372     * Ask the host where one upgrade goes, as the Monetize page does.
373     *
374     * @param string $slug The feature slug passed to `jetpack_feature_upgrade`.
375     * @param string $name The Jetpack product the upgrade sells. Product name, do not translate.
376     * @param string $tab  The Settings tab the upgrade sits on, for the host flow to return to.
377     * @return string|null
378     */
379    private static function get_host_upgrade_url( $slug, $name, $tab ) {
380        /** This filter is documented in projects/packages/my-jetpack/src/class-main-features.php */
381        $upgrade = apply_filters(
382            'jetpack_feature_upgrade',
383            array(
384                'path'     => '',
385                'name'     => $name,
386                'back_url' => admin_url( 'admin.php?page=jetpack-settings#/' . $tab ),
387            ),
388            $slug,
389            false
390        );
391
392        if ( ! is_array( $upgrade ) || ! isset( $upgrade['url'] ) ) {
393            return null;
394        }
395
396        if ( '' === $upgrade['url'] ) {
397            return '';
398        }
399
400        $url = esc_url_raw( (string) $upgrade['url'] );
401        return '' === $url ? null : $url;
402    }
403
404    /**
405     * Get external services connect URLs.
406     */
407    public static function get_external_services_connect_urls() {
408        $connect_urls = array();
409        foreach ( Keyring_Helper::SERVICES as $service_name => $service_info ) {
410            $connect_urls[ $service_name ] = Keyring_Helper::connect_url( $service_name, $service_info['for'] );
411        }
412        return $connect_urls;
413    }
414
415    /**
416     * Gets a purchase token that is used for Jetpack logged out visitor checkout.
417     * The purchase token should be appended to all CTA url's that lead to checkout.
418     *
419     * @since 9.8.0
420     * @return string|boolean
421     */
422    public static function get_purchase_token() {
423        if ( ! Jetpack::current_user_can_purchase() ) {
424            return false;
425        }
426
427        $purchase_token = Jetpack_Options::get_option( 'purchase_token', false );
428
429        if ( $purchase_token ) {
430            return $purchase_token;
431        }
432        // If the purchase token is not saved in the options table yet, then add it.
433        Jetpack_Options::update_option( 'purchase_token', self::generate_purchase_token(), true );
434        return Jetpack_Options::get_option( 'purchase_token', false );
435    }
436
437    /**
438     * Generates a purchase token that is used for Jetpack logged out visitor checkout.
439     *
440     * @since 9.8.0
441     * @return string
442     */
443    public static function generate_purchase_token() {
444        return wp_generate_password( 12, false );
445    }
446
447    /**
448     * Get a representative image for the site.
449     *
450     * @since 15.0
451     *
452     * @return string
453     */
454    public static function get_site_image(): string {
455        // Get the dynamic image generated for the Open Graph Meta tags.
456        require_once JETPACK__PLUGIN_DIR . 'functions.opengraph.php';
457        return jetpack_og_get_fallback_social_image( 200, 200 )['src'];
458    }
459
460    /**
461     * Whether the Jetpack Social page is in the Jetpack menu for this user.
462     *
463     * Publicize skips it when `jetpack_publicize_should_load` is false, even on a connected site, so this reads the built menu.
464     *
465     * @since 16.5
466     *
467     * @return bool
468     */
469    private static function has_social_page() {
470        global $submenu;
471
472        return in_array( 'jetpack-social', array_column( $submenu['jetpack'] ?? array(), 2 ), true );
473    }
474}
475
476// phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed -- TODO: Move these functions to some other file.
477
478/**
479 * Gather data about the current user.
480 *
481 * @since 4.1.0
482 *
483 * @return array
484 */
485function jetpack_current_user_data() {
486    $jetpack_connection = new Connection_Manager( 'jetpack' );
487
488    $current_user      = wp_get_current_user();
489    $is_user_connected = $jetpack_connection->is_user_connected( $current_user->ID );
490    $is_master_user    = $is_user_connected && (int) $current_user->ID && (int) Jetpack_Options::get_option( 'master_user' ) === (int) $current_user->ID;
491    $dotcom_data       = $jetpack_connection->get_connected_user_data();
492
493    // Add connected user gravatar to the returned dotcom_data.
494    // Probably we shouldn't do this when $dotcom_data is false, but we have been since 2016 so
495    // clients probably expect that by now.
496    if ( false === $dotcom_data ) {
497        $dotcom_data = array();
498    }
499    $dotcom_data['avatar'] = ( ! empty( $dotcom_data['email'] ) ?
500        get_avatar_url(
501            $dotcom_data['email'],
502            array(
503                'size'    => 64,
504                'default' => 'mysteryman',
505            )
506        )
507        : false );
508
509    $current_user_data = array(
510        'isConnected' => $is_user_connected,
511        'isMaster'    => $is_master_user,
512        'username'    => $current_user->user_login,
513        'displayName' => $current_user->display_name,
514        'email'       => $current_user->user_email,
515        'id'          => $current_user->ID,
516        'wpcomUser'   => $dotcom_data,
517        'gravatar'    => get_avatar_url( $current_user->ID ),
518        'permissions' => array(
519            'admin_page'         => current_user_can( 'jetpack_admin_page' ),
520            'connect'            => current_user_can( 'jetpack_connect' ),
521            'connect_user'       => current_user_can( 'jetpack_connect_user' ),
522            'disconnect'         => current_user_can( 'jetpack_disconnect' ),
523            'manage_modules'     => current_user_can( 'jetpack_manage_modules' ),
524            'network_admin'      => current_user_can( 'jetpack_network_admin_page' ),
525            'network_sites_page' => current_user_can( 'jetpack_network_sites_page' ),
526            'edit_posts'         => current_user_can( 'edit_posts' ),
527            'publish_posts'      => current_user_can( 'publish_posts' ),
528            'manage_options'     => current_user_can( 'manage_options' ),
529            'view_stats'         => current_user_can( 'view_stats' ),
530            'manage_plugins'     => current_user_can( 'install_plugins' )
531                                    && current_user_can( 'activate_plugins' )
532                                    && current_user_can( 'update_plugins' )
533                                    && current_user_can( 'delete_plugins' ),
534        ),
535    );
536
537    return $current_user_data;
538}