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

Site-Level User Profile: Show links back to WordPress.com on profile.php #38638

Merged
merged 11 commits into from
Aug 6, 2024
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: added

Show links back to WordPress.com for them to manage their WordPress.com profile
2 changes: 1 addition & 1 deletion projects/packages/jetpack-mu-wpcom/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
},
"autotagger": true,
"branch-alias": {
"dev-trunk": "5.53.x-dev"
"dev-trunk": "5.54.x-dev"
},
"textdomain": "jetpack-mu-wpcom",
"version-constants": {
Expand Down
2 changes: 1 addition & 1 deletion projects/packages/jetpack-mu-wpcom/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@automattic/jetpack-mu-wpcom",
"version": "5.53.1",
"version": "5.54.0-alpha",
"description": "Enhances your site with features powered by WordPress.com",
"homepage": "https://github.com/Automattic/jetpack/tree/HEAD/projects/packages/jetpack-mu-wpcom/#readme",
"bugs": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* Jetpack_Mu_Wpcom main class.
*/
class Jetpack_Mu_Wpcom {
const PACKAGE_VERSION = '5.53.1';
const PACKAGE_VERSION = '5.54.0-alpha';
const PKG_DIR = __DIR__ . '/../';
const BASE_DIR = __DIR__ . '/';
const BASE_FILE = __FILE__;
Expand Down Expand Up @@ -103,6 +103,7 @@ public static function load_features() {
require_once __DIR__ . '/features/wpcom-admin-dashboard/wpcom-admin-dashboard.php';
require_once __DIR__ . '/features/wpcom-block-editor/class-jetpack-wpcom-block-editor.php';
require_once __DIR__ . '/features/wpcom-block-editor/functions.editor-type.php';
require_once __DIR__ . '/features/wpcom-profile-settings/profile-settings-link-to-wpcom.php';
require_once __DIR__ . '/features/wpcom-profile-settings/profile-settings-notices.php';
require_once __DIR__ . '/features/wpcom-themes/wpcom-theme-fixes.php';

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php
/**
* Show links back to WordPress.com for them to manage their WordPress.com profile.
*
* @package automattic/jetpack-mu-wpcom
*/

use Automattic\Jetpack\Jetpack_Mu_Wpcom;

/**
* Check if the site is a WordPress.com Simple site.
*
* @return bool
*/
function is_wpcom_simple() {
if ( ! class_exists( 'Automattic\Jetpack\Status\Host' ) ) {
return false;
}
$host = new Automattic\Jetpack\Status\Host();
return $host->is_wpcom_simple();
}

/**
* Adds a link to the WordPress.com profile settings page.
*/
function wpcom_profile_settings_add_links_to_wpcom() {
$asset_file = include Jetpack_Mu_Wpcom::BASE_DIR . 'build/wpcom-profile-settings-link-to-wpcom/wpcom-profile-settings-link-to-wpcom.asset.php';
wp_enqueue_script(
'wpcom-profile-settings-link-to-wpcom',
plugins_url( 'build/wpcom-profile-settings-link-to-wpcom/wpcom-profile-settings-link-to-wpcom.js', Jetpack_Mu_Wpcom::BASE_FILE ),
$asset_file['dependencies'] ?? array(),
$asset_file['version'] ?? filemtime( Jetpack_Mu_Wpcom::BASE_DIR . 'build/wpcom-profile-settings-link-to-wpcom/wpcom-profile-settings-link-to-wpcom.js' ),
true
);

$is_wpcom_simple = is_wpcom_simple();

wp_localize_script(
'wpcom-profile-settings-link-to-wpcom',
'wpcomProfileSettingsLinkToWpcom',
array(
'email' => array(
'link' => esc_url( 'https://wordpress.com/me/account' ),
'text' => __( 'Your WordPress.com email is managed on WordPress.com Account settings', 'jetpack-mu-wpcom' ),
),
'password' => array(
'link' => esc_url( 'https://wordpress.com/me/security' ),
'text' => __( 'Your WordPress.com password is managed on WordPress.com Security settings', 'jetpack-mu-wpcom' ),
),
'isWpcomSimple' => $is_wpcom_simple,
)
);
}
add_action( 'load-profile.php', 'wpcom_profile_settings_add_links_to_wpcom' );
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* Disable the email field on Simple sites.
*/
const wpcom_profile_settings_disable_email_field = () => {
if ( ! window.wpcomProfileSettingsLinkToWpcom?.isWpcomSimple ) {
return;
}
const emailField = document.getElementById( 'email' ) as HTMLInputElement;
if ( emailField ) {
emailField.disabled = true;
}

const emailDescription = document.getElementById( 'email-description' ) as HTMLInputElement;
emailDescription?.remove();
};

/**
* Add a link to the WordPress.com profile settings page.
*/
const wpcom_profile_settings_add_links_to_wpcom = () => {
const emailSection = document.querySelector( '.user-email-wrap' )?.querySelector( 'td' );
const newPasswordSection = document.getElementById( 'password' )?.querySelector( 'td' );
const userSessionSection = document.querySelector( '.user-sessions-wrap' );

userSessionSection?.remove();

// Simple sites cannot set a password in wp-admin.
if ( window.wpcomProfileSettingsLinkToWpcom?.isWpcomSimple && newPasswordSection ) {
newPasswordSection.innerHTML = '';
}

const emailSettingsLink = window.wpcomProfileSettingsLinkToWpcom?.email?.link;
const emailSettingsLinkText = window.wpcomProfileSettingsLinkToWpcom?.email?.text;
if ( emailSection && emailSettingsLink && emailSettingsLinkText ) {
const notice = document.createElement( 'p' );
notice.className = 'description';
notice.innerHTML = `<a href="${ emailSettingsLink }">${ emailSettingsLinkText }</a>.`;
emailSection.appendChild( notice );
}

const passwordSettingsLink = window.wpcomProfileSettingsLinkToWpcom?.password?.link;
const passwordSettingsLinkText = window.wpcomProfileSettingsLinkToWpcom?.password?.text;
if ( newPasswordSection && passwordSettingsLink && passwordSettingsLinkText ) {
const notice = document.createElement( 'p' );
notice.className = 'description';
notice.innerHTML = `<a href="${ passwordSettingsLink }">${ passwordSettingsLinkText }</a>.`;
newPasswordSection.appendChild( notice );
}
};

document.addEventListener( 'DOMContentLoaded', () => {
wpcom_profile_settings_add_links_to_wpcom();
wpcom_profile_settings_disable_email_field();
} );
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,18 @@ function maybe_show_wpcom_toolbar_proxy_notice() {

if ( $is_proxied && $is_atomic ) {
?>
<style>
.toolbar-autoproxxy-notice {
color: #666;
font-style: italic;
margin-top: 5px;
}
</style>
<script type="text/javascript">
document.addEventListener('DOMContentLoaded', function () {
// Find the Toolbar checkbox label container using the unique ID.
var toolbarCheckboxLabel = document.querySelector('#admin_bar_front').parentNode;
if (toolbarCheckboxLabel) {
// Create a new div for the notice.
var newDiv = document.createElement('div');
newDiv.className = 'toolbar-autoproxxy-notice';
newDiv.textContent = '<?php echo esc_js( __( 'The Toolbar is always visible on Atomic sites while connected to the Automattic proxy.', 'jetpack-mu-wpcom' ) ); ?>'
var toolbarCell = document.querySelector('.user-admin-bar-front-wrap')?.querySelector('td');
if (toolbarCell) {
// Create a new paragraph for the notice.
var notice = document.createElement('p');
notice.className = 'description';
notice.textContent = '<?php echo esc_js( __( 'The Toolbar is always visible on Atomic sites while connected to the Automattic proxy.', 'jetpack-mu-wpcom' ) ); ?>'

// Insert the new div after the checkbox and label.
toolbarCheckboxLabel.appendChild(newDiv);

// Find and remove the <br> tag following the label to improve spacing.
var brElement = toolbarCheckboxLabel.nextSibling;
if (brElement && brElement.tagName === 'BR') {
brElement.parentNode.removeChild(brElement);
}
toolbarCell.appendChild(notice);
}
});
</script>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
declare global {
interface Window {
wpcomProfileSettingsLinkToWpcom: {
email: {
link: string;
text: string;
};
password: {
link: string;
text: string;
};
isWpcomSimple: boolean;
};
}
}

export {};
2 changes: 2 additions & 0 deletions projects/packages/jetpack-mu-wpcom/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ module.exports = [
'./src/features/wpcom-documentation-links/wpcom-documentation-links.ts',
'wpcom-plugins-banner': './src/features/wpcom-plugins/js/banner.js',
'wpcom-plugins-banner-style': './src/features/wpcom-plugins/css/banner.css',
'wpcom-profile-settings-link-to-wpcom':
'./src/features/wpcom-profile-settings/profile-settings-link-to-wpcom.ts',
'wpcom-sidebar-notice': './src/features/wpcom-sidebar-notice/wpcom-sidebar-notice.js',
'starter-page-templates': './src/features/starter-page-templates/index.tsx',
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Updated composer.lock.


2 changes: 1 addition & 1 deletion projects/plugins/mu-wpcom-plugin/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@
]
},
"config": {
"autoloader-suffix": "d9d132a783958a00a2c7cccff60ca42d_jetpack_mu_wpcom_pluginⓥ2_5_4"
"autoloader-suffix": "d9d132a783958a00a2c7cccff60ca42d_jetpack_mu_wpcom_pluginⓥ2_5_5_alpha"
}
}
4 changes: 2 additions & 2 deletions projects/plugins/mu-wpcom-plugin/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion projects/plugins/mu-wpcom-plugin/mu-wpcom-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* Plugin Name: WordPress.com Features
* Description: Test plugin for the jetpack-mu-wpcom package
* Version: 2.5.4
* Version: 2.5.5-alpha
* Author: Automattic
* License: GPLv2 or later
* Text Domain: jetpack-mu-wpcom-plugin
Expand Down
2 changes: 1 addition & 1 deletion projects/plugins/mu-wpcom-plugin/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@automattic/jetpack-mu-wpcom-plugin",
"version": "2.5.4",
"version": "2.5.5-alpha",
"description": "Test plugin for the jetpack-mu-wpcom package",
"homepage": "https://jetpack.com",
"bugs": {
Expand Down
5 changes: 5 additions & 0 deletions projects/plugins/wpcomsh/changelog/add-profile-link-towpcom
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Updated composer.lock.


2 changes: 1 addition & 1 deletion projects/plugins/wpcomsh/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
"composer/installers": true,
"roots/wordpress-core-installer": true
},
"autoloader-suffix": "26841ac2064774301cbe06d174833bfc_wpcomshⓥ5_2_1"
"autoloader-suffix": "26841ac2064774301cbe06d174833bfc_wpcomshⓥ5_2_2_alpha"
},
"extra": {
"mirror-repo": "Automattic/wpcom-site-helper",
Expand Down
4 changes: 2 additions & 2 deletions projects/plugins/wpcomsh/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion projects/plugins/wpcomsh/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "@automattic/jetpack-wpcomsh",
"description": "A helper for connecting WordPress.com sites to external host infrastructure.",
"homepage": "https://jetpack.com",
"version": "5.2.1",
"version": "5.2.2-alpha",
"bugs": {
"url": "https://github.com/Automattic/jetpack/labels/[Plugin] Wpcomsh"
},
Expand Down
4 changes: 2 additions & 2 deletions projects/plugins/wpcomsh/wpcomsh.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
/**
* Plugin Name: WordPress.com Site Helper
* Description: A helper for connecting WordPress.com sites to external host infrastructure.
* Version: 5.2.1
* Version: 5.2.2-alpha
* Author: Automattic
* Author URI: http://automattic.com/
*
* @package wpcomsh
*/

define( 'WPCOMSH_VERSION', '5.2.1' );
define( 'WPCOMSH_VERSION', '5.2.2-alpha' );

// If true, Typekit fonts will be available in addition to Google fonts
add_filter( 'jetpack_fonts_enable_typekit', '__return_true' );
Expand Down