Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Untangle: Enable user data fields & color scheme selector #35271

Closed
wants to merge 14 commits into from
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: other

Untangle Calypso: Users > My Profile to default wp-admin users profile.
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class WPCOM_JSON_API_GET_Site_Endpoint extends WPCOM_JSON_API_Endpoint {
'was_migration_trial' => '(bool) If the site ever used a migration trial.',
'was_hosting_trial' => '(bool) If the site ever used a hosting trial.',
'wpcom_site_setup' => '(string) The WP.com site setup identifier.',
'admin_color' => '(string) Admin color schema.',
);

/**
Expand Down Expand Up @@ -116,6 +117,7 @@ class WPCOM_JSON_API_GET_Site_Endpoint extends WPCOM_JSON_API_Endpoint {
'is_core_site_editor_enabled',
'is_wpcom_atomic',
'is_wpcom_staging_site',
'admin_color',
);

/**
Expand Down Expand Up @@ -611,6 +613,9 @@ protected function render_response_key( $key, &$response, $is_user_logged_in ) {
case 'was_upgraded_from_trial':
$response[ $key ] = $this->site->was_upgraded_from_trial();
break;
case 'admin_color':
$response[ $key ] = get_user_meta( get_current_user_id(), 'admin_color', true );
break;
}

do_action( 'post_render_site_response_key', $key );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class WPCOM_JSON_API_GET_Site_V1_2_Endpoint extends WPCOM_JSON_API_GET_Site_Endp
'was_upgraded_from_trial' => '(bool) If the site ever upgraded to a paid plan from a trial.',
'was_migration_trial' => '(bool) If the site ever used a migration trial.',
'was_hosting_trial' => '(bool) If the site ever used a hosting trial.',
'admin_color' => '(string) Admin color schema.',
);

/**
Expand Down
4 changes: 3 additions & 1 deletion projects/plugins/jetpack/modules/masterbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
if ( ( new Host() )->is_woa_site() ) {
new Inline_Help();
require_once __DIR__ . '/masterbar/wp-posts-list/bootstrap.php';
require_once __DIR__ . '/masterbar/profile-edit/bootstrap.php';
if ( get_option( 'wpcom_admin_interface' ) !== 'wp-admin' ) {
require_once __DIR__ . '/masterbar/profile-edit/bootstrap.php';
}
require_once __DIR__ . '/masterbar/nudges/bootstrap.php';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,16 @@ public function get_preferred_view( $screen, $fallback_global_preference = true
return parent::get_preferred_view( $screen, $fallback_global_preference );
}

/**
* Whether the current user has is using the wp-admin interface.
*
* @param string $screen Dummy to match parent method signature.
* @return bool
*/
public function use_wp_admin_interface( $screen = '' ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
return 'wp-admin' === get_option( 'wpcom_admin_interface' );
}

/**
* Adds Users menu.
*/
Expand All @@ -131,8 +141,11 @@ public function add_users_menu() {

add_submenu_page( 'users.php', esc_attr__( 'Subscribers', 'jetpack' ), __( 'Subscribers', 'jetpack' ), 'list_users', 'https://wordpress.com/subscribers/' . $this->domain, null );

remove_submenu_page( 'users.php', 'profile.php' );
add_submenu_page( 'users.php', esc_attr__( 'My Profile', 'jetpack' ), __( 'My Profile', 'jetpack' ), 'read', 'https://wordpress.com/me/', null );
// When the interface is not set to wp-admin, we replace the Profile submenu.
if ( ! $this->use_wp_admin_interface() ) {
remove_submenu_page( 'users.php', 'profile.php' );
add_submenu_page( 'users.php', esc_attr__( 'My Profile', 'jetpack' ), __( 'My Profile', 'jetpack' ), 'read', 'https://wordpress.com/me/', null );
}

// Users who can't 'list_users' will see "Profile" menu & "Profile > Account Settings" as submenu.
add_submenu_page( $slug, esc_attr__( 'Account Settings', 'jetpack' ), __( 'Account Settings', 'jetpack' ), 'read', 'https://wordpress.com/me/account' );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,12 @@ public function __construct() {
update_user_option( $this->user_id, 'jetpack_admin_menu_link_destination', $this->user_data['use_wp_admin_links'] ? '1' : '0' );
}
// If Atomic, store and install user locale.
if ( $this->site_woa ) {
if ( $this->site_woa && 'wp-admin' !== get_option( 'wpcom_admin_interface' ) ) {
$this->user_locale = $this->get_jetpack_locale( $this->user_locale );
$this->install_locale( $this->user_locale );
update_user_option( $this->user_id, 'locale', $this->user_locale, true );
update_user_option( $this->user_id, 'admin_color', $this->user_data['color_scheme'] );
lupus2k marked this conversation as resolved.
Show resolved Hide resolved
}

add_action( 'admin_bar_init', array( $this, 'init' ) );

if ( ! empty( $this->user_data['ID'] ) ) {
Expand Down Expand Up @@ -214,6 +214,7 @@ class_exists( 'Jetpack_AMP_Support' )

// Hides and replaces the language dropdown for the current user, on WoA.
if ( $this->site_woa &&
'wp-admin' !== get_option( 'wpcom_admin_interface' ) &&
defined( 'IS_PROFILE_PAGE' ) && IS_PROFILE_PAGE ) {
add_action( 'user_edit_form_tag', array( $this, 'hide_language_dropdown' ) );
add_action( 'personal_options', array( $this, 'replace_language_dropdown' ), 9 );
Expand Down
Loading