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
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = tab
indent_size = 4

[*.{json,yml,yaml}]
indent_style = space
indent_size = 2
2 changes: 1 addition & 1 deletion inc/admin-pages/class-setup-wizard-admin-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ public function alert_incomplete_installation(): void {

if (! defined('SUNRISE') || ! SUNRISE) {
// translators: %s code snippet.
$message = sprintf(__('The SUNRISE constant is missing. Domain mapping and plugin/theme limits will not function until `%s` is added to wp-config.php. Please complete the setup to attempt to do this automatically.', 'multisite-ultimate'), 'define( \'SUNRISE\', \'1\' );');
$message = sprintf(__('The SUNRISE constant is missing. Domain mapping and plugin/theme limits will not function until `%s` is added to wp-config.php. Please complete the setup to attempt to do this automatically.', 'ultimate-multisite'), 'define( \'SUNRISE\', \'1\' );');
} else {
$message = __('Ultimate Multisite installation is incomplete. The sunrise.php file is missing. Please complete the setup to ensure proper functionality.', 'ultimate-multisite');
}
Expand Down
14 changes: 7 additions & 7 deletions inc/apis/trait-mcp-abilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ public function register_ability_category(): void {
return;
}

if (wp_has_ability_category('multisite-ultimate')) {
if (wp_has_ability_category('ultimate-multisite')) {
return;
}
wp_register_ability_category(
'multisite-ultimate',
'ultimate-multisite',
[
'label' => __('Multisite Ultimate', 'ultimate-multisite'),
'description' => __('CRUD operations for Multisite Ultimate entities including customers, sites, products, memberships, and more.', 'ultimate-multisite'),
Expand Down Expand Up @@ -180,7 +180,7 @@ protected function register_get_item_ability(string $ability_prefix, string $dis
'label' => sprintf(__('Get %s by ID', 'ultimate-multisite'), $display_name),
// translators: %s: entity name (e.g., customer, site, product)
'description' => sprintf(__('Retrieve a single %s by its ID', 'ultimate-multisite'), strtolower($display_name)),
'category' => 'multisite-ultimate',
'category' => 'ultimate-multisite',
'execute_callback' => [$this, 'mcp_get_item'],
'permission_callback' => [$this, 'mcp_permission_callback'],
'input_schema' => [
Expand Down Expand Up @@ -231,7 +231,7 @@ protected function register_get_items_ability(string $ability_prefix, string $di
'label' => sprintf(__('List %s', 'ultimate-multisite'), $display_name),
// translators: %s: entity name (e.g., customer, site, product)
'description' => sprintf(__('Retrieve a list of %s with optional filters', 'ultimate-multisite'), strtolower($display_name)),
'category' => 'multisite-ultimate',
'category' => 'ultimate-multisite',
'execute_callback' => [$this, 'mcp_get_items'],
'permission_callback' => [$this, 'mcp_permission_callback'],
'input_schema' => [
Expand Down Expand Up @@ -289,7 +289,7 @@ protected function register_create_item_ability(string $ability_prefix, string $
'label' => sprintf(__('Create %s', 'ultimate-multisite'), $display_name),
// translators: %s: entity name (e.g., customer, site, product)
'description' => sprintf(__('Create a new %s', 'ultimate-multisite'), strtolower($display_name)),
'category' => 'multisite-ultimate',
'category' => 'ultimate-multisite',
'execute_callback' => [$this, 'mcp_create_item'],
'permission_callback' => [$this, 'mcp_permission_callback'],
'input_schema' => $input_schema,
Expand Down Expand Up @@ -339,7 +339,7 @@ protected function register_update_item_ability(string $ability_prefix, string $
'label' => sprintf(__('Update %s', 'ultimate-multisite'), $display_name),
// translators: %s: entity name (e.g., customer, site, product)
'description' => sprintf(__('Update an existing %s', 'ultimate-multisite'), strtolower($display_name)),
'category' => 'multisite-ultimate',
'category' => 'ultimate-multisite',
'execute_callback' => [$this, 'mcp_update_item'],
'permission_callback' => [$this, 'mcp_permission_callback'],
'input_schema' => $input_schema,
Expand Down Expand Up @@ -374,7 +374,7 @@ protected function register_delete_item_ability(string $ability_prefix, string $
'label' => sprintf(__('Delete %s', 'ultimate-multisite'), $display_name),
// translators: %s: entity name (e.g., customer, site, product)
'description' => sprintf(__('Delete a %s by its ID', 'ultimate-multisite'), strtolower($display_name)),
'category' => 'multisite-ultimate',
'category' => 'ultimate-multisite',
'execute_callback' => [$this, 'mcp_delete_item'],
'permission_callback' => [$this, 'mcp_permission_callback'],
'input_schema' => [
Expand Down
30 changes: 15 additions & 15 deletions inc/class-domain-mapping.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
namespace WP_Ultimo;

use WP_Ultimo\Models\Domain;
use WP_Ultimo\Models\Site;

// Exit if accessed directly
defined('ABSPATH') || exit;
Expand All @@ -28,7 +27,7 @@ class Domain_Mapping {
* Keeps a copy of the current mapping.
*
* @since 2.0.0
* @var \WP_Ultimo\Models\Domain
* @var Domain
*/
public $current_mapping = null;

Expand All @@ -53,6 +52,13 @@ public function init(): void {
} else {
$this->maybe_startup();
}

/*
* Allow redirects to any host that belongs to this network
* (either a mapped domain or a site's original domain).
* Always run this to allow wp_safe_redirect in any context.
*/
add_filter('allowed_redirect_hosts', [$this, 'allow_network_redirect_hosts'], 20, 2);
}

/**
Expand Down Expand Up @@ -135,12 +141,6 @@ public function startup(): void {
*/
add_action('ms_loaded', [$this, 'register_mapped_filters'], 11);

/*
* Allow redirects to any host that belongs to this network
* (either a mapped domain or a site's original domain).
*/
add_filter('allowed_redirect_hosts', [$this, 'allow_network_redirect_hosts'], 20, 2);

/**
* On WP Ultimo 1.X builds we used Mercator. The Mercator actions and filters are now deprecated.
*/
Expand All @@ -156,7 +156,7 @@ function ($domain_list, $site_id): array {
[
'active' => true,
'blog_id' => $site_id,
'stage__not_in' => \WP_Ultimo\Models\Domain::INACTIVE_STAGES,
'stage__not_in' => Domain::INACTIVE_STAGES,
'fields' => 'domain',
]
);
Expand Down Expand Up @@ -235,7 +235,7 @@ public function allow_network_redirect_hosts($allowed_hosts, $host) {

// 1) Check mapped domains (including www/no-www variants)
$domains_to_check = $this->get_www_and_nowww_versions($host);
$mapping = \WP_Ultimo\Models\Domain::get_by_domain($domains_to_check);
$mapping = Domain::get_by_domain($domains_to_check);

if ($mapping && ! is_wp_error($mapping)) {
$allowed_hosts[] = $host;
Expand Down Expand Up @@ -281,7 +281,7 @@ public function allow_network_redirect_hosts($allowed_hosts, $host) {
public function fix_sso_target_site($target_site, $domain) {

if ( ! $target_site || ! $target_site->blog_id) {
$mapping = \WP_Ultimo\Models\Domain::get_by_domain($domain);
$mapping = Domain::get_by_domain($domain);

if ($mapping) {
$target_site = get_site($mapping->get_site_id());
Expand Down Expand Up @@ -385,7 +385,7 @@ public function check_domain_mapping($site, $domain) {
* be mapped too, simply filter here.
*
* @param boolean $is_active Should the mapping be treated as active?
* @param \WP_Ultimo\Models\Domain $mapping Mapping that we're inspecting
* @param Domain $mapping Mapping that we're inspecting
* @param string $domain
*/
$is_active = apply_filters('wu_use_domain_mapping', $mapping->is_active(), $mapping, $domain);
Expand Down Expand Up @@ -556,11 +556,11 @@ function ($callback) use ($hooks) {
/**
* Replaces the URL.
*
* @since 2.0.0
* @param string $url URL to replace.
* @param null|Domain $current_mapping The current mapping.
*
* @param string $url URL to replace.
* @param null|\WP_Ultimo\Models\Domain $current_mapping The current mapping.
* @return string
* @since 2.0.0
*/
public function replace_url($url, $current_mapping = null) {

Expand Down
23 changes: 0 additions & 23 deletions inc/database/engine/class-base.php

This file was deleted.

5 changes: 5 additions & 0 deletions inc/sso/class-admin-bar-magic-links.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ public function show_access_denied_with_magic_links(): void {
);
}

if ( 1 === count($blogs) ) {
wp_safe_redirect(get_admin_url(current($blogs)->userblog_id));
exit;
}

$output = '<p>' . sprintf(
/* translators: 1: Site title. */
__('You attempted to access the "%1$s" dashboard, but you do not currently have privileges on this site. If you believe you should be able to access the "%1$s" dashboard, please contact your network administrator.'),
Expand Down
26 changes: 5 additions & 21 deletions inc/sso/class-magic-link.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Magic_Link {
* @since 2.0.0
* @var string
*/
const TOKEN_QUERY_VAR = 'wu_magic_token';
const TOKEN_QUERY_ARG = 'wu_magic_token';

/**
* Transient prefix for storing tokens.
Expand Down Expand Up @@ -58,28 +58,12 @@ public function init(): void {

add_action('init', array($this, 'handle_magic_link'), 5);

add_filter('query_vars', array($this, 'add_query_vars'));

add_filter('removable_query_args', array($this, 'add_removable_query_args'));

// Hook into frontend admin my site URLs to add magic links.
add_filter('wp_frontend_admin/my_site_url', array($this, 'maybe_convert_to_magic_link'), 15);
}

/**
* Add custom query vars.
*
* @since 2.0.0
* @param array $vars Existing query vars.
* @return array Modified query vars.
*/
public function add_query_vars($vars) {

$vars[] = self::TOKEN_QUERY_VAR;

return $vars;
}

/**
* Add magic link query args to removable list.
*
Expand All @@ -89,7 +73,7 @@ public function add_query_vars($vars) {
*/
public function add_removable_query_args($args) {

$args[] = self::TOKEN_QUERY_VAR;
$args[] = self::TOKEN_QUERY_ARG;

return $args;
}
Expand Down Expand Up @@ -146,7 +130,7 @@ public function generate_magic_link($user_id, $site_id, $redirect_to = '') {

$magic_link = add_query_arg(
array(
self::TOKEN_QUERY_VAR => $token,
self::TOKEN_QUERY_ARG => $token,
),
$site_url
);
Expand Down Expand Up @@ -204,7 +188,7 @@ protected function verify_user_site_access($user_id, $site_id) {
*/
public function handle_magic_link(): void {

$token = wu_request(self::TOKEN_QUERY_VAR);
$token = wu_request(self::TOKEN_QUERY_ARG);

if ( empty($token) ) {
return;
Expand Down Expand Up @@ -254,7 +238,7 @@ public function handle_magic_link(): void {
}

// Remove the token from the URL and redirect.
$redirect_to = remove_query_arg(self::TOKEN_QUERY_VAR, $redirect_to);
$redirect_to = remove_query_arg(self::TOKEN_QUERY_ARG, $redirect_to);

nocache_headers();

Expand Down
Loading
Loading