Skip to content

Commit

Permalink
Launchpad: Add Verify Domain Email task logic (#34893)
Browse files Browse the repository at this point in the history
* Add the verify domain email task

* changelog

* Skip the checks if the task is complete

* The WPCOM check should be filtered by is_pending_icann_verification property

* Fix the request

* Fix the request function

* Fix space

* Fix spacing

* Fix atomic test

---------

Co-authored-by: Valter Lorran <valter.lorran@automattic.com>

Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/7490392774
  • Loading branch information
valterlorran authored and matticbot committed Jan 11, 2024
1 parent 333a751 commit 8dc1a3c
Show file tree
Hide file tree
Showing 5 changed files with 116 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 the completion logic for the `front_page_updated` task
- Add the Verify Domain Email task

### Removed
- Removes the `Set up your Professional Email` task
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,16 @@ function wpcom_launchpad_get_task_definitions() {
return site_url( '/wp-admin/admin.php?page=sensei' );
},
),
'verify_domain_email' => array(
'get_title' => function () {
return __( 'Verify the email address for your domains', 'jetpack-mu-wpcom' );
},
'is_complete_callback' => 'wpcom_launchpad_is_task_option_completed',
'is_visible_callback' => 'wpcom_launchpad_is_verify_domain_email_visible',
'get_calypso_path' => function ( $task, $default, $data ) {
return '/domains/manage/' . $data['site_slug_encoded'];
},
),
);

$extended_task_definitions = apply_filters( 'wpcom_launchpad_extended_task_definitions', array() );
Expand Down Expand Up @@ -974,6 +984,101 @@ function wpcom_launchpad_is_sensei_setup_visible() {
return is_plugin_active( 'sensei-lms/sensei-lms.php' );
}

/**
* Determines whether or not the verify domain email task should be visible.
*
* @return bool True if the verify domain email task should be visible.
*/
function wpcom_launchpad_is_verify_domain_email_visible() {
// If the task is complete, we should show it and prevent the logic below
// to be executed.
if ( wpcom_is_checklist_task_complete( 'verify_domain_email' ) ) {
return true;
}

$domains_pending_icann_verification = array();

// For Atomic sites we need to get the domain list from
// the public API.
$is_atomic_site = ( new Automattic\Jetpack\Status\Host() )->is_woa_site();
if ( $is_atomic_site ) {
$domains = wpcom_request_domains_list();

if ( is_wp_error( $domains ) ) {
// logs the erro
return false;
}

$domains_pending_icann_verification = array_filter(
$domains,
function ( $domain ) {
return $domain->is_pending_icann_verification;
}
);

return ! empty( $domains_pending_icann_verification );
} else {
if ( ! class_exists( 'Domain_Management' ) ) {
return false;
}

$domains = \Domain_Management::get_paid_domains_with_icann_verification_status();

$domains_pending_icann_verification = array_filter(
$domains,
function ( $domain ) {
return isset( $domain['is_pending_icann_verification'] ) && $domain['is_pending_icann_verification'];
}
);
}

return ! empty( $domains_pending_icann_verification );
}

/**
* Make a request to the WordPress.com API to get the domain list for the current site.
*
* @return array|WP_Error Array of domains and their verification status or WP_Error if the request fails.
*/
function wpcom_request_domains_list() {
$site_id = \Jetpack_Options::get_option( 'id' );
$request_path = sprintf( '/sites/%d/domains', $site_id );
$wpcom_request = Automattic\Jetpack\Connection\Client::wpcom_json_api_request_as_blog(
$request_path,
'1.2',
array(
'method' => 'GET',
'headers' => array(
'content-type' => 'application/json',
'X-Forwarded-For' => ( new Automattic\Jetpack\Status\Visitor() )->get_ip( true ),
),
),
null,
'rest'
);

$response_code = wp_remote_retrieve_response_code( $wpcom_request );
if ( 200 !== $response_code ) {
return new \WP_Error(
'failed_to_fetch_data',
esc_html__( 'Unable to fetch the requested data.', 'jetpack-mu-wpcom' ),
array( 'status' => $response_code )
);
}

$body = wp_remote_retrieve_body( $wpcom_request );
$decoded_body = json_decode( $body );

if ( ! isset( $decoded_body->domains ) ) {
return new \WP_Error(
'failed_to_fetch_data',
esc_html__( 'Unable to fetch the requested data.', 'jetpack-mu-wpcom' )
);
}

return $decoded_body->domains;
}

/**
* Identify whether we can retrieve newsletter subscriber counts in
* the current environment.
Expand Down
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": "5.8.2-alpha.1704910968",
"version_normalized": "5.8.2.0-alpha1704910968",
"version": "5.8.2-alpha.1704984367",
"version_normalized": "5.8.2.0-alpha1704984367",
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-mu-wpcom",
"reference": "30d7bd04f783e912868d64258b18f89ad3ebb3d0"
"reference": "184e40f9ac18957e1481aeed2c20483b04c00227"
},
"require": {
"php": ">=7.0"
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' => '5.8.2-alpha.1704910968',
'version' => '5.8.2.0-alpha1704910968',
'reference' => '30d7bd04f783e912868d64258b18f89ad3ebb3d0',
'pretty_version' => '5.8.2-alpha.1704984367',
'version' => '5.8.2.0-alpha1704984367',
'reference' => '184e40f9ac18957e1481aeed2c20483b04c00227',
'type' => 'jetpack-library',
'install_path' => __DIR__ . '/../automattic/jetpack-mu-wpcom',
'aliases' => array(),
Expand Down

0 comments on commit 8dc1a3c

Please sign in to comment.