Use new code style

This commit is contained in:
David Stone
2025-02-07 19:02:33 -07:00
parent 0181024ae1
commit 8433379d90
672 changed files with 37107 additions and 45249 deletions

View File

@ -9,11 +9,11 @@
namespace WP_Ultimo\UI;
use \WP_Ultimo\UI\Base_Element;
use \WP_Ultimo\Models\Domain;
use \WP_Ultimo\Database\Domains\Domain_Stage;
use \WP_Ultimo\Models\Site;
use \WP_Ultimo\Models\Membership;
use WP_Ultimo\UI\Base_Element;
use WP_Ultimo\Models\Domain;
use WP_Ultimo\Database\Domains\Domain_Stage;
use WP_Ultimo\Models\Site;
use WP_Ultimo\Models\Membership;
// Exit if accessed directly
defined('ABSPATH') || exit;
@ -67,23 +67,20 @@ class Domain_Mapping_Element extends Base_Element {
protected $membership;
/**
* The icon of the UI element.
* e.g. return fa fa-search
*
* @since 2.0.0
* @param string $context One of the values: block, elementor or bb.
*/
* The icon of the UI element.
* e.g. return fa fa-search
*
* @since 2.0.0
* @param string $context One of the values: block, elementor or bb.
*/
public function get_icon($context = 'block'): string {
if ($context === 'elementor') {
return 'eicon-url';
} // end if;
}
return 'fa fa-search';
} // end get_icon;
}
/**
* The title of the UI element.
@ -98,8 +95,7 @@ class Domain_Mapping_Element extends Base_Element {
public function get_title() {
return __('Domains', 'wp-ultimo');
} // end get_title;
}
/**
* The description of the UI element.
@ -115,8 +111,7 @@ class Domain_Mapping_Element extends Base_Element {
public function get_description() {
return __('Adds the site\'s domains block.', 'wp-ultimo');
} // end get_description;
}
/**
* The list of fields to be added to Gutenberg.
@ -154,8 +149,7 @@ class Domain_Mapping_Element extends Base_Element {
);
return $fields;
} // end fields;
}
/**
* The list of keywords for this element.
@ -181,8 +175,7 @@ class Domain_Mapping_Element extends Base_Element {
'WP Multisite WaaS',
'Domain',
);
} // end keywords;
}
/**
* List of default parameters for the element.
@ -203,8 +196,7 @@ class Domain_Mapping_Element extends Base_Element {
return array(
'title' => __('Domains', 'wp-ultimo'),
);
} // end defaults;
}
/**
* Initializes the singleton.
@ -217,32 +209,25 @@ class Domain_Mapping_Element extends Base_Element {
parent::init();
if ($this->is_preview()) {
$this->site = wu_mock_site();
return;
} // end if;
}
$this->site = wu_get_current_site();
$maybe_limit_domain_mapping = true;
if ($this->site->has_limitations()) {
$maybe_limit_domain_mapping = $this->site->get_limitations()->domain_mapping->is_enabled();
}
} // end if;
if (!$this->site || !wu_get_setting('enable_domain_mapping') || !wu_get_setting('custom_domains') || !$maybe_limit_domain_mapping) {
if ( ! $this->site || ! wu_get_setting('enable_domain_mapping') || ! wu_get_setting('custom_domains') || ! $maybe_limit_domain_mapping) {
$this->set_display(false);
} // end if;
}
add_action('plugins_loaded', array($this, 'register_forms'));
} // end init;
}
/**
* Loads the required scripts.
@ -253,8 +238,7 @@ class Domain_Mapping_Element extends Base_Element {
public function register_scripts() {
add_wubox();
} // end register_scripts;
}
/**
* Register ajax forms used to add a new domain.
@ -266,25 +250,33 @@ class Domain_Mapping_Element extends Base_Element {
/*
* Add new Domain
*/
wu_register_form('user_add_new_domain', array(
'render' => array($this, 'render_user_add_new_domain_modal'),
'handler' => array($this, 'handle_user_add_new_domain_modal'),
'capability' => 'exist',
));
wu_register_form(
'user_add_new_domain',
array(
'render' => array($this, 'render_user_add_new_domain_modal'),
'handler' => array($this, 'handle_user_add_new_domain_modal'),
'capability' => 'exist',
)
);
wu_register_form('user_make_domain_primary', array(
'render' => array($this, 'render_user_make_domain_primary_modal'),
'handler' => array($this, 'handle_user_make_domain_primary_modal'),
'capability' => 'exist',
));
wu_register_form(
'user_make_domain_primary',
array(
'render' => array($this, 'render_user_make_domain_primary_modal'),
'handler' => array($this, 'handle_user_make_domain_primary_modal'),
'capability' => 'exist',
)
);
wu_register_form('user_delete_domain_modal', array(
'render' => array($this, 'render_user_delete_domain_modal'),
'handler' => array($this, 'handle_user_delete_domain_modal'),
'capability' => 'exist',
));
} // end register_forms;
wu_register_form(
'user_delete_domain_modal',
array(
'render' => array($this, 'render_user_delete_domain_modal'),
'handler' => array($this, 'handle_user_delete_domain_modal'),
'capability' => 'exist',
)
);
}
/**
* Renders the add new customer modal.
@ -313,7 +305,7 @@ class Domain_Mapping_Element extends Base_Element {
'display_value' => sprintf('<div class="wu--mt-2 wu--mb-2">%s</div>', wpautop($instructions)),
'wrapper_html_attr' => array(
'v-show' => '!ready',
'v-cloak' => 1
'v-cloak' => 1,
),
),
'ready' => array(
@ -327,7 +319,7 @@ class Domain_Mapping_Element extends Base_Element {
),
'wrapper_html_attr' => array(
'v-show' => '!ready',
'v-cloak' => 1
'v-cloak' => 1,
),
),
'current_site' => array(
@ -340,7 +332,7 @@ class Domain_Mapping_Element extends Base_Element {
'placeholder' => __('mydomain.com', 'wp-ultimo'),
'wrapper_html_attr' => array(
'v-show' => 'ready',
'v-cloak' => 1
'v-cloak' => 1,
),
),
'primary_domain' => array(
@ -371,27 +363,32 @@ class Domain_Mapping_Element extends Base_Element {
'wrapper_classes' => 'wu-items-end',
'wrapper_html_attr' => array(
'v-show' => 'ready',
'v-cloak' => 1
'v-cloak' => 1,
),
),
);
$form = new \WP_Ultimo\UI\Form('add_new_domain', $fields, array(
'views' => 'admin-pages/fields',
'classes' => 'wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0',
'field_wrapper_classes' => 'wu-w-full wu-box-border wu-items-center wu-flex wu-justify-between wu-p-4 wu-m-0 wu-border-t wu-border-l-0 wu-border-r-0 wu-border-b-0 wu-border-gray-300 wu-border-solid',
'html_attr' => array(
'data-wu-app' => 'add_new_domain',
'data-state' => json_encode(array(
'ready' => 0,
'primary_domain' => false,
)),
),
));
$form = new \WP_Ultimo\UI\Form(
'add_new_domain',
$fields,
array(
'views' => 'admin-pages/fields',
'classes' => 'wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0',
'field_wrapper_classes' => 'wu-w-full wu-box-border wu-items-center wu-flex wu-justify-between wu-p-4 wu-m-0 wu-border-t wu-border-l-0 wu-border-r-0 wu-border-b-0 wu-border-gray-300 wu-border-solid',
'html_attr' => array(
'data-wu-app' => 'add_new_domain',
'data-state' => json_encode(
array(
'ready' => 0,
'primary_domain' => false,
)
),
),
)
);
$form->render();
} // end render_user_add_new_domain_modal;
}
/**
* Handles creation of a new customer.
@ -407,46 +404,44 @@ class Domain_Mapping_Element extends Base_Element {
$current_site = wu_get_site($current_site_id);
if (!is_super_admin() && (!$current_site || $current_user_id !== $current_site->get_customer()->get_user_id())) {
if ( ! is_super_admin() && (! $current_site || $current_user_id !== $current_site->get_customer()->get_user_id())) {
wp_send_json_error(
new \WP_Error('no-permissions', __('You do not have permissions to perform this action.', 'wp-ultimo'))
);
exit;
} // end if;
}
/*
* Tries to create the domain
*/
$domain = wu_create_domain(array(
'domain' => wu_request('domain'),
'blog_id' => absint($current_site_id),
'primary_domain' => (bool) wu_request('primary_domain'),
));
$domain = wu_create_domain(
array(
'domain' => wu_request('domain'),
'blog_id' => absint($current_site_id),
'primary_domain' => (bool) wu_request('primary_domain'),
)
);
if (is_wp_error($domain)) {
wp_send_json_error($domain);
} // end if;
}
if (wu_request('primary_domain')) {
$old_primary_domains = wu_get_domains(array(
'primary_domain' => true,
'blog_id' => $current_site_id,
'id__not_in' => array($domain->get_id()),
'fields' => 'ids',
));
$old_primary_domains = wu_get_domains(
array(
'primary_domain' => true,
'blog_id' => $current_site_id,
'id__not_in' => array($domain->get_id()),
'fields' => 'ids',
)
);
/*
* Trigger async action to update the old primary domains.
*/
do_action_ref_array('wu_async_remove_old_primary_domains', array($old_primary_domains));
} // end if;
}
wu_enqueue_async_action('wu_async_process_domain_stage', array('domain_id' => $domain->get_id()), 'domain');
@ -455,13 +450,14 @@ class Domain_Mapping_Element extends Base_Element {
*/
do_action('wu_domain_created', $domain, $domain->get_site(), $domain->get_site()->get_membership());
wp_send_json_success(array(
'redirect_url' => wu_get_current_url(),
));
wp_send_json_success(
array(
'redirect_url' => wu_get_current_url(),
)
);
exit;
} // end handle_user_add_new_domain_modal;
}
/**
* Renders the domain delete action.
@ -497,21 +493,26 @@ class Domain_Mapping_Element extends Base_Element {
),
);
$form = new \WP_Ultimo\UI\Form('user_delete_domain_modal', $fields, array(
'views' => 'admin-pages/fields',
'classes' => 'wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0',
'field_wrapper_classes' => 'wu-w-full wu-box-border wu-items-center wu-flex wu-justify-between wu-p-4 wu-m-0 wu-border-t wu-border-l-0 wu-border-r-0 wu-border-b-0 wu-border-gray-300 wu-border-solid',
'html_attr' => array(
'data-wu-app' => 'user_delete_domain_modal',
'data-state' => json_encode(array(
'confirmed' => false,
)),
),
));
$form = new \WP_Ultimo\UI\Form(
'user_delete_domain_modal',
$fields,
array(
'views' => 'admin-pages/fields',
'classes' => 'wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0',
'field_wrapper_classes' => 'wu-w-full wu-box-border wu-items-center wu-flex wu-justify-between wu-p-4 wu-m-0 wu-border-t wu-border-l-0 wu-border-r-0 wu-border-b-0 wu-border-gray-300 wu-border-solid',
'html_attr' => array(
'data-wu-app' => 'user_delete_domain_modal',
'data-state' => json_encode(
array(
'confirmed' => false,
)
),
),
)
);
$form->render();
} // end render_user_delete_domain_modal;
}
/**
* Handles deletion of the selected domain
@ -522,10 +523,8 @@ class Domain_Mapping_Element extends Base_Element {
public function handle_user_delete_domain_modal() {
if (wu_request('user_id')) {
$customer = wu_get_customer_by_user_id(wu_request('user_id'));
} // end if;
}
$current_site = wu_request('current_site');
@ -534,16 +533,15 @@ class Domain_Mapping_Element extends Base_Element {
$domain = new Domain($get_domain);
if ($domain) {
$domain->delete();
}
} // end if;
wp_send_json_success(array(
'redirect_url' => wu_get_current_url(),
));
} // end handle_user_delete_domain_modal;
wp_send_json_success(
array(
'redirect_url' => wu_get_current_url(),
)
);
}
/**
* Renders the domain delete action.
@ -579,21 +577,26 @@ class Domain_Mapping_Element extends Base_Element {
),
);
$form = new \WP_Ultimo\UI\Form('user_delete_domain_modal', $fields, array(
'views' => 'admin-pages/fields',
'classes' => 'wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0',
'field_wrapper_classes' => 'wu-w-full wu-box-border wu-items-center wu-flex wu-justify-between wu-p-4 wu-m-0 wu-border-t wu-border-l-0 wu-border-r-0 wu-border-b-0 wu-border-gray-300 wu-border-solid',
'html_attr' => array(
'data-wu-app' => 'user_delete_domain_modal',
'data-state' => json_encode(array(
'confirmed' => false,
)),
),
));
$form = new \WP_Ultimo\UI\Form(
'user_delete_domain_modal',
$fields,
array(
'views' => 'admin-pages/fields',
'classes' => 'wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0',
'field_wrapper_classes' => 'wu-w-full wu-box-border wu-items-center wu-flex wu-justify-between wu-p-4 wu-m-0 wu-border-t wu-border-l-0 wu-border-r-0 wu-border-b-0 wu-border-gray-300 wu-border-solid',
'html_attr' => array(
'data-wu-app' => 'user_delete_domain_modal',
'data-state' => json_encode(
array(
'confirmed' => false,
)
),
),
)
);
$form->render();
} // end render_user_make_domain_primary_modal;
}
/**
* Handles conversion to primary domain.
@ -610,38 +613,37 @@ class Domain_Mapping_Element extends Base_Element {
$domain = wu_get_domain($domain_id);
if ($domain) {
$domain->set_primary_domain(true);
$status = $domain->save();
if (is_wp_error($status)) {
wp_send_json_error($status);
}
} // end if;
$old_primary_domains = wu_get_domains(array(
'primary_domain' => true,
'blog_id' => $domain->get_blog_id(),
'id__not_in' => array($domain->get_id()),
'fields' => 'ids',
));
$old_primary_domains = wu_get_domains(
array(
'primary_domain' => true,
'blog_id' => $domain->get_blog_id(),
'id__not_in' => array($domain->get_id()),
'fields' => 'ids',
)
);
/*
* Trigger async action to update the old primary domains.
*/
do_action_ref_array('wu_async_remove_old_primary_domains', array($old_primary_domains));
wp_send_json_success(array(
'redirect_url' => is_main_site() ? wu_get_current_url() : get_admin_url($current_site),
));
} // end if;
wp_send_json_success(
array(
'redirect_url' => is_main_site() ? wu_get_current_url() : get_admin_url($current_site),
)
);
}
wp_send_json_error(new \WP_Error('error', __('Something wrong happenned.', 'wp-ultimo')));
} // end handle_user_make_domain_primary_modal;
}
/**
* Runs early on the request lifecycle as soon as we detect the shortcode is present.
@ -653,20 +655,17 @@ class Domain_Mapping_Element extends Base_Element {
$this->site = WP_Ultimo()->currents->get_site();
if (!$this->site || !$this->site->is_customer_allowed()) {
if ( ! $this->site || ! $this->site->is_customer_allowed()) {
$this->set_display(false);
return;
} // end if;
}
// Ensure admin.php is loaded as we need wu_responsive_table_row function
require_once wu_path('inc/functions/admin.php');
$this->membership = $this->site->get_membership();
} // end setup;
}
/**
* Allows the setup in the context of previews.
@ -679,8 +678,7 @@ class Domain_Mapping_Element extends Base_Element {
$this->site = wu_mock_site();
$this->membership = wu_mock_membership();
} // end setup_preview;
}
/**
* The content to be output on the screen.
@ -699,16 +697,17 @@ class Domain_Mapping_Element extends Base_Element {
$current_site = $this->site;
$all_domains = wu_get_domains(array(
'blog_id' => $current_site->get_id(),
'orderby' => 'primary_domain',
'order' => 'DESC',
));
$all_domains = wu_get_domains(
array(
'blog_id' => $current_site->get_id(),
'orderby' => 'primary_domain',
'order' => 'DESC',
)
);
$domains = array();
foreach ($all_domains as $key => $domain) {
$stage = new Domain_Stage($domain->get_stage());
$secure = 'dashicons-wu-lock-open';
@ -716,12 +715,10 @@ class Domain_Mapping_Element extends Base_Element {
$secure_message = __('Domain not secured with HTTPS', 'wp-ultimo');
if ($domain->is_secure()) {
$secure = 'dashicons-wu-lock wu-text-green-500';
$secure_message = __('Domain secured with HTTPS', 'wp-ultimo');
} // end if;
}
$url_atts = array(
'current_site' => $current_site->get_id(),
@ -731,7 +728,7 @@ class Domain_Mapping_Element extends Base_Element {
$delete_url = wu_get_form_url('user_delete_domain_modal', $url_atts);
$primary_url = wu_get_form_url('user_make_domain_primary', $url_atts);
$domains[$key] = array(
$domains[ $key ] = array(
'id' => $domain->get_id(),
'domain_object' => $domain,
'domain' => $domain->get_domain(),
@ -742,9 +739,8 @@ class Domain_Mapping_Element extends Base_Element {
'secure_message' => $secure_message,
'delete_link' => $delete_url,
'primary_link' => $primary_url,
);
} // end foreach;
);
}
$url_atts = array(
'current_site' => $current_site->get_ID(),
@ -763,7 +759,5 @@ class Domain_Mapping_Element extends Base_Element {
$atts = array_merge($other_atts, $atts);
return wu_get_template_contents('dashboard-widgets/domain-mapping', $atts);
} // end output;
} // end class Domain_Mapping_Element;
}
}