Skip to content

Commit

Permalink
Frontend email nag for custom domain (#33390)
Browse files Browse the repository at this point in the history
* add plugin to show email nag on the frontend

* show frontend domain email nag

* add changelog

* fix doc

* Update domain-email-nag.php

Add slash to do class look-up in global namespace instead of relative to package (it was causing an error on the frontend for me)

* Rework logic to use Domain_Management class; change backround to red

* Use the correct URL

---------

Co-authored-by: Michael Kelly <mike.kelly@a8c.com>
Co-authored-by: mpkelly <kikemelly@gmail.com>

Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/6376528204
  • Loading branch information
mpkelly authored and matticbot committed Oct 2, 2023
1 parent eab66cc commit c1f2835
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 10 deletions.
8 changes: 4 additions & 4 deletions composer.lock

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

1 change: 1 addition & 0 deletions vendor/automattic/jetpack-mu-wpcom/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ This is an alpha version! The changes listed here are not final.

### Added
- Add new task for user to confirm email when purchasing a domain.
- Add plugin to show frontend email nag for domains with unverified email address

## [4.12.0] - 2023-09-28
### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public static function init() {
add_action( 'plugins_loaded', array( __CLASS__, 'load_marketplace_products_updater' ) );

add_action( 'plugins_loaded', array( __CLASS__, 'load_first_posts_stream_helpers' ) );
add_action( 'plugins_loaded', array( __CLASS__, 'load_domain_email_nag' ) );

// Unified navigation fix for changes in WordPress 6.2.
add_action( 'admin_enqueue_scripts', array( __CLASS__, 'unbind_focusout_on_wp_admin_bar_menu_toggle' ) );
Expand Down Expand Up @@ -95,6 +96,12 @@ public static function load_coming_soon() {
public static function load_launchpad() {
require_once __DIR__ . '/features/launchpad/launchpad.php';
}
/**
* Load the domain email nag feature.
*/
public static function load_domain_email_nag() {
require_once __DIR__ . '/features/domain-email-nag/domain-email-nag.php';
}

/**
* Load WP REST API plugins for wpcom.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php
/**
* Frontend Domain Email Nag
*
* @package A8C\Domain\Frontend_Email_Nag
*/

namespace A8C\Domain\Frontend_Email_Nag;

use Automattic\Jetpack\Jetpack_Mu_Wpcom;

/**
* Determines whether the email nag should be shown.
*
* @return boolean
*/
function should_show_domain_frontend_email_nag() {
if ( ! is_front_page() || ( is_front_page() && ! is_user_logged_in() ) ) {
return false;
}
return true;
}

/**
* Returns the domain url for site that has a domain with an
* univerified email address.
*
* @return string account url
*/
function get_account_url() {
return 'https://wordpress.com/domains/manage/' . wpcom_get_site_slug();
}

/**
* Find the domain, if any, that has an unverified email address.
*/
function get_domain_with_unverified_email() {
if ( ! class_exists( 'Domain_Management' ) ) {
return false;
}

$domains = \Domain_Management::get_paid_domains_with_icann_verification_status();

foreach ( $domains as $domain ) {
if ( $domain['is_pending_icann_verification'] === true ) {
return $domain['domain'];
}
}
return false;
}

/**
* Decides whether to render to the email nag.
*/
function domain_email_nag() {
if ( ! should_show_domain_frontend_email_nag() ) {
return;
}

$domain = get_domain_with_unverified_email();

if ( ! $domain ) {
return;
}

wp_enqueue_style( 'wpcom-domain-email-nag-style', plugins_url( 'domain-nag.style.css', __FILE__ ), array(), Jetpack_Mu_Wpcom::PACKAGE_VERSION );

$notice = sprintf(
/* translators: %1 User's email address, %2 current domain */
__( 'You need to confirm your domain email address to avoid having your domain <strong>%1$s</strong> suspended. Please check your inbox.', 'jetpack-mu-wpcom' ),
$domain
);

?>
<div class="wp-domain-nag-sticky-message">
<div class="wp-domain-nag-inner">
<p class="wp-domain-nag-text"><?php echo wp_kses( $notice, array( 'strong' => array() ) ); ?></p>
<a class="button" href="<?php echo esc_url( get_account_url() ); ?>"><?php esc_html_e( 'Fix', 'jetpack-mu-wpcom' ); ?></a>
</div>
</div>
<?php
}
add_action( 'wp_footer', __NAMESPACE__ . '\domain_email_nag' );

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
.wp-domain-nag-sticky-message {
position: sticky;
bottom: 10px;
width: 50%;
margin: auto;
background-color: #d9534f;
border-radius: 2px;
color: #fff;
padding: 10px;
}

.wp-domain-nag-inner {
display: inline-block;
}

.wp-domain-nag-text {
display: inline;
}

.wp-domain-nag-sticky-message .button {
background: #fff;
border-radius: 2px;
border: 1px solid #fff;
box-sizing: border-box;
display: inline-block;
line-height: 21px;
padding: 8px;
text-align: center;
text-overflow: ellipsis;
text-decoration: none;
transition: opacity .15s ease-out;
white-space: nowrap;
width: 120px;
margin-left: 16px;
}
6 changes: 3 additions & 3 deletions vendor/composer/installed.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
"packages": [
{
"name": "automattic/jetpack-mu-wpcom",
"version": "4.13.0-alpha.1696224944",
"version_normalized": "4.13.0.0-alpha1696224944",
"version": "4.13.0-alpha.1696226389",
"version_normalized": "4.13.0.0-alpha1696226389",
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-mu-wpcom",
"reference": "dcea782b53e7f3c95a2566ea37fa5a82b5272f38"
"reference": "88468d6961398295e57e3e4126c395e478d17c65"
},
"require-dev": {
"automattic/jetpack-changelogger": "^3.3.11",
Expand Down
6 changes: 3 additions & 3 deletions vendor/composer/installed.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
),
'versions' => array(
'automattic/jetpack-mu-wpcom' => array(
'pretty_version' => '4.13.0-alpha.1696224944',
'version' => '4.13.0.0-alpha1696224944',
'reference' => 'dcea782b53e7f3c95a2566ea37fa5a82b5272f38',
'pretty_version' => '4.13.0-alpha.1696226389',
'version' => '4.13.0.0-alpha1696226389',
'reference' => '88468d6961398295e57e3e4126c395e478d17c65',
'type' => 'jetpack-library',
'install_path' => __DIR__ . '/../automattic/jetpack-mu-wpcom',
'aliases' => array(),
Expand Down

0 comments on commit c1f2835

Please sign in to comment.