Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions inc/functions/sovereign.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
/**
* Sovereign Mode Helper Functions
*
* Functions for handling sovereign-mode tenant redirects.
*
* @package WP_Ultimo
* @subpackage Functions/Sovereign
* @since 2.2.0
*/

// Exit if accessed directly
defined('ABSPATH') || exit;

/**
* Get the main site account URL for sovereign-mode redirects.
*
* Returns the account page URL on the main site, with a return_to parameter
* pointing back to the current site's admin.
*
* @since 2.2.0
* @return string The main site account URL.
*/
function wu_mt_main_site_account_url() {
$main_site_blog_id = get_main_site_id();

return get_admin_url(
$main_site_blog_id,
'admin.php?page=account&return_to=' . rawurlencode(home_url('/wp-admin/'))
);
}
11 changes: 11 additions & 0 deletions inc/ui/class-account-summary-element.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,17 @@
*/
public function output($atts, $content = null) {

if (defined('WU_MT_SOVEREIGN_TENANT') && WU_MT_SOVEREIGN_TENANT) {
echo wu_get_template_contents(

Check warning on line 296 in inc/ui/class-account-summary-element.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found 'wu_get_template_contents'.
'elements/sovereign-redirect',
[
'main_site_account_url' => wu_mt_main_site_account_url(),
'element_label' => __('Your account', 'ultimate-multisite'),
]
);
return;
}

$this->ensure_setup();

// Return empty if no site available (e.g., during SEO processing)
Expand Down
11 changes: 11 additions & 0 deletions inc/ui/class-billing-info-element.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,17 @@
*/
public function output($atts, $content = null) {

if (defined('WU_MT_SOVEREIGN_TENANT') && WU_MT_SOVEREIGN_TENANT) {
echo wu_get_template_contents(

Check warning on line 274 in inc/ui/class-billing-info-element.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found 'wu_get_template_contents'.
'elements/sovereign-redirect',
[
'main_site_account_url' => wu_mt_main_site_account_url(),
'element_label' => __('Billing information', 'ultimate-multisite'),
]
);
return;
}

$this->ensure_setup();

// Return empty if no membership available (e.g., during SEO processing)
Expand Down
11 changes: 11 additions & 0 deletions inc/ui/class-current-membership-element.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,17 @@ public function setup_preview() {
*/
public function output($atts, $content = null) {

if (defined('WU_MT_SOVEREIGN_TENANT') && WU_MT_SOVEREIGN_TENANT) {
echo wu_get_template_contents(
'elements/sovereign-redirect',
[
'main_site_account_url' => wu_mt_main_site_account_url(),
'element_label' => __('Subscription', 'ultimate-multisite'),
]
);
return;
}

$atts['membership'] = $this->membership;
$atts['plan'] = $this->plan;
$atts['element'] = $this;
Expand Down
11 changes: 11 additions & 0 deletions inc/ui/class-current-site-element.php
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,17 @@
*/
public function output($atts, $content = null) {

if (defined('WU_MT_SOVEREIGN_TENANT') && WU_MT_SOVEREIGN_TENANT) {
echo wu_get_template_contents(

Check warning on line 356 in inc/ui/class-current-site-element.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found 'wu_get_template_contents'.
'elements/sovereign-redirect',
[
'main_site_account_url' => wu_mt_main_site_account_url(),
'element_label' => __('Site actions', 'ultimate-multisite'),
]
);
return;
}

$this->ensure_setup();

// Return empty if no site available (e.g., during SEO processing)
Expand Down
11 changes: 11 additions & 0 deletions inc/ui/class-domain-mapping-element.php
Original file line number Diff line number Diff line change
Expand Up @@ -1097,6 +1097,17 @@ public function setup_preview() {
*/
public function output($atts, $content = null) {

if (defined('WU_MT_SOVEREIGN_TENANT') && WU_MT_SOVEREIGN_TENANT) {
echo wu_get_template_contents(
'elements/sovereign-redirect',
[
'main_site_account_url' => wu_mt_main_site_account_url(),
'element_label' => __('Domain mapping', 'ultimate-multisite'),
]
);
return;
}

$current_site = $this->site;

$all_domains = wu_get_domains(
Expand Down
11 changes: 11 additions & 0 deletions inc/ui/class-invoices-element.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,17 @@
*/
public function output($atts, $content = null) {

if (defined('WU_MT_SOVEREIGN_TENANT') && WU_MT_SOVEREIGN_TENANT) {
echo wu_get_template_contents(

Check warning on line 276 in inc/ui/class-invoices-element.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found 'wu_get_template_contents'.
'elements/sovereign-redirect',
[
'main_site_account_url' => wu_mt_main_site_account_url(),
'element_label' => __('Invoices', 'ultimate-multisite'),
]
);
return;
}

$this->ensure_setup();

// Return empty if no membership available (e.g., during SEO processing)
Expand Down
11 changes: 11 additions & 0 deletions inc/ui/class-my-sites-element.php
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,17 @@
*/
public function output($atts, $content = null) {

if (defined('WU_MT_SOVEREIGN_TENANT') && WU_MT_SOVEREIGN_TENANT) {
echo wu_get_template_contents(

Check warning on line 327 in inc/ui/class-my-sites-element.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found 'wu_get_template_contents'.
'elements/sovereign-redirect',
[
'main_site_account_url' => wu_mt_main_site_account_url(),
'element_label' => __('My sites', 'ultimate-multisite'),
]
);
return;
}

$atts['customer'] = $this->customer;

$atts['sites'] = $this->get_sites(wu_get_isset($atts, 'site_show'));
Expand Down
11 changes: 11 additions & 0 deletions inc/ui/class-template-switching-element.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@
return;
}

$this->membership = $this->site->get_membership();

Check warning on line 268 in inc/ui/class-template-switching-element.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Equals sign not aligned with surrounding assignments; expected 7 spaces but found 1 space
$this->permission_state = $this->membership ? self::STATE_OK : self::STATE_NO_MEMBERSHIP;

$this->products = [];
Expand Down Expand Up @@ -406,8 +406,8 @@
[
'redirect_url' => add_query_arg(
[
'updated' => 1,

Check warning on line 409 in inc/ui/class-template-switching-element.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Array double arrow not aligned correctly; expected 12 space(s) between "'updated'" and double arrow, but found 14.
'wu_template_action' => $action_label,

Check warning on line 410 in inc/ui/class-template-switching-element.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Array double arrow not aligned correctly; expected 1 space(s) between "'wu_template_action'" and double arrow, but found 3.
],
$referer
),
Expand All @@ -430,6 +430,17 @@
*/
public function output($atts, $content = null) {

if (defined('WU_MT_SOVEREIGN_TENANT') && WU_MT_SOVEREIGN_TENANT) {
echo wu_get_template_contents(

Check warning on line 434 in inc/ui/class-template-switching-element.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found 'wu_get_template_contents'.
'elements/sovereign-redirect',
[
'main_site_account_url' => wu_mt_main_site_account_url(),
'element_label' => __('Template switching', 'ultimate-multisite'),
]
);
return;
}

if ( ! $this->site || self::STATE_NOT_ALLOWED === $this->permission_state) {
$this->render_not_allowed_notice();

Expand Down Expand Up @@ -703,7 +714,7 @@
* (1024px) lines up with the rest of the customer panel content
* areas; wu-mx-auto centres it.
*/
/*

Check warning on line 717 in inc/ui/class-template-switching-element.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Empty line required before block comment
* Scoped CSS adjustments for the switching page only. Each rule
* is scoped to .wu-template-switching-wrap so signup/checkout
* (which reuses views/checkout/templates/template-selection/
Expand Down
179 changes: 179 additions & 0 deletions tests/WP_Ultimo/UI/Sovereign_Mode_Elements_Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
<?php
/**
* Tests for sovereign-mode UI elements.
*
* @package WP_Ultimo\Tests
*/

namespace WP_Ultimo\UI;

use WP_UnitTestCase;

/**
* Test class for sovereign-mode element short-circuits.
*/
class Sovereign_Mode_Elements_Test extends WP_UnitTestCase {

/**
* Set up test fixtures.
*/
protected function setUp(): void {
parent::setUp();

// Define sovereign mode constant if not already defined
if ( ! defined('WU_MT_SOVEREIGN_TENANT') ) {
define('WU_MT_SOVEREIGN_TENANT', true);
}

// Load the sovereign helper function
require_once dirname(__DIR__, 3) . '/inc/functions/sovereign.php';
}

/**
* Test Account_Summary_Element outputs redirect in sovereign mode.
*/
public function test_account_summary_element_sovereign_mode(): void {
$element = Account_Summary_Element::get_instance();

ob_start();
$element->output([]);
$output = ob_get_clean();

$this->assertStringContainsString('wu-sovereign-redirect', $output);
$this->assertStringContainsString('manage on main site', $output);
$this->assertStringContainsString('Your account', $output);
}

/**
* Test Billing_Info_Element outputs redirect in sovereign mode.
*/
public function test_billing_info_element_sovereign_mode(): void {
$element = Billing_Info_Element::get_instance();

ob_start();
$element->output([]);
$output = ob_get_clean();

$this->assertStringContainsString('wu-sovereign-redirect', $output);
$this->assertStringContainsString('manage on main site', $output);
$this->assertStringContainsString('Billing information', $output);
}

/**
* Test Invoices_Element outputs redirect in sovereign mode.
*/
public function test_invoices_element_sovereign_mode(): void {
$element = Invoices_Element::get_instance();

ob_start();
$element->output([]);
$output = ob_get_clean();

$this->assertStringContainsString('wu-sovereign-redirect', $output);
$this->assertStringContainsString('manage on main site', $output);
$this->assertStringContainsString('Invoices', $output);
}

/**
* Test My_Sites_Element outputs redirect in sovereign mode.
*/
public function test_my_sites_element_sovereign_mode(): void {
$element = My_Sites_Element::get_instance();

ob_start();
$element->output([]);
$output = ob_get_clean();

$this->assertStringContainsString('wu-sovereign-redirect', $output);
$this->assertStringContainsString('manage on main site', $output);
$this->assertStringContainsString('My sites', $output);
}

/**
* Test Current_Membership_Element outputs redirect in sovereign mode.
*/
public function test_current_membership_element_sovereign_mode(): void {
$element = Current_Membership_Element::get_instance();

ob_start();
$element->output([]);
$output = ob_get_clean();

$this->assertStringContainsString('wu-sovereign-redirect', $output);
$this->assertStringContainsString('manage on main site', $output);
$this->assertStringContainsString('Subscription', $output);
}

/**
* Test Current_Site_Element outputs redirect in sovereign mode.
*/
public function test_current_site_element_sovereign_mode(): void {
$element = Current_Site_Element::get_instance();

ob_start();
$element->output([]);
$output = ob_get_clean();

$this->assertStringContainsString('wu-sovereign-redirect', $output);
$this->assertStringContainsString('manage on main site', $output);
$this->assertStringContainsString('Site actions', $output);
}

/**
* Test Template_Switching_Element outputs redirect in sovereign mode.
*/
public function test_template_switching_element_sovereign_mode(): void {
$element = Template_Switching_Element::get_instance();

ob_start();
$element->output([]);
$output = ob_get_clean();

$this->assertStringContainsString('wu-sovereign-redirect', $output);
$this->assertStringContainsString('manage on main site', $output);
$this->assertStringContainsString('Template switching', $output);
}

/**
* Test Domain_Mapping_Element outputs redirect in sovereign mode.
*/
public function test_domain_mapping_element_sovereign_mode(): void {
$element = Domain_Mapping_Element::get_instance();

ob_start();
$element->output([]);
$output = ob_get_clean();

$this->assertStringContainsString('wu-sovereign-redirect', $output);
$this->assertStringContainsString('manage on main site', $output);
$this->assertStringContainsString('Domain mapping', $output);
}

/**
* Test redirect output contains button element.
*/
public function test_redirect_output_contains_button(): void {
$element = Account_Summary_Element::get_instance();

ob_start();
$element->output([]);
$output = ob_get_clean();

$this->assertStringContainsString('<a class="button button-primary"', $output);
$this->assertStringContainsString('href=', $output);
}

/**
* Test redirect output contains main site URL.
*/
public function test_redirect_output_contains_main_site_url(): void {
$element = Account_Summary_Element::get_instance();

ob_start();
$element->output([]);
$output = ob_get_clean();

$this->assertStringContainsString('admin.php?page=account', $output);
$this->assertStringContainsString('return_to=', $output);
}
}
17 changes: 17 additions & 0 deletions views/elements/sovereign-redirect.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
/**
* Sovereign Mode Redirect Element
*
* Displays a redirect link to the main site for sovereign-mode tenants.
*
* @since 2.2.0
*/

defined('ABSPATH') || exit;

?>
<div class="wu-sovereign-redirect">
<a class="button button-primary" href="<?php echo esc_url($main_site_account_url); ?>">
<?php echo esc_html($element_label); ?> → <?php esc_html_e('manage on main site', 'ultimate-multisite'); ?>
</a>
</div>
Loading