Skip to content
Open
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
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@
"mpdf/psr-log-aware-trait": [
"patches/mpdf-psr-log-aware-trait-void-return.patch",
"patches/mpdf-mpdf-psr-log-aware-trait-void-return.patch"
],
"mpdf/psr-http-message-shim": [
"patches/mpdf-psr-http-message-shim-php8-compat.patch"
]
},
"installer-paths": {
Expand Down
6 changes: 3 additions & 3 deletions inc/admin-pages/class-email-list-admin-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,13 +242,13 @@ public function handle_send_new_test_modal() {
}

$from = [
'name' => wu_get_setting('from_name'),
'email' => wu_get_setting('from_email'),
'name' => wu_get_setting('from_name', ''),
'email' => wu_get_setting('from_email', ''),
];

$to = [
[
'name' => wu_get_setting('from_name'),
'name' => wu_get_setting('from_name', ''),
'email' => $send_to,
],
];
Expand Down
5 changes: 3 additions & 2 deletions inc/admin-pages/class-top-admin-nav-menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,11 @@ public function add_top_bar_menus($wp_admin_bar): void {
}

/*
* Add the settings sub-menus.
* Add the settings sub-menus using the lightweight section names
* to avoid triggering the full default_sections() field registration.
*/
if (current_user_can('wu_read_settings')) {
$settings_tabs = Settings::get_instance()->get_sections();
$settings_tabs = Settings::get_instance()->get_section_names();

$addon_tabs = [];

Expand Down
2 changes: 1 addition & 1 deletion inc/checkout/class-checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -942,7 +942,7 @@ public function process_order() {
$this->membership->set_date_trial_end(gmdate('Y-m-d 23:59:59', $this->order->get_billing_start_date()));
$this->membership->set_date_expiration(gmdate('Y-m-d 23:59:59', $this->order->get_billing_start_date()));

if (wu_get_setting('allow_trial_without_payment_method') && $this->customer->get_email_verification() !== 'pending') {
if (wu_get_setting('allow_trial_without_payment_method', false) && $this->customer->get_email_verification() !== 'pending') {
/*
* In this particular case, we need to set the status to trialing here as we will not update the membership after and then, publish the site.
*/
Expand Down
4 changes: 2 additions & 2 deletions inc/checkout/class-legacy-checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ public function check_geolocation(): void {

$this->session->set('geolocation', $location);

$allowed_countries = wu_get_setting('allowed_countries');
$allowed_countries = wu_get_setting('allowed_countries', []);

if (isset($location['country']) && $location['country'] && $allowed_countries) {
if ( ! in_array($location['country'], $allowed_countries, true)) {
Expand Down Expand Up @@ -754,7 +754,7 @@ public function sort_steps_and_fields($a, $b) {
public function form_fields($current_plan = false, $step = 'plan', $freq = false): void {

/** Select the default frequency */
$freq = $freq ?: wu_get_setting('default_pricing_option');
$freq = $freq ?: wu_get_setting('default_pricing_option', 1);

?>

Expand Down
2 changes: 1 addition & 1 deletion inc/checkout/signup-fields/class-signup-field-payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public function to_fields_array($attributes) {
* Checks if we need to add the
* auto renew field.
*/
if ( ! wu_get_setting('force_auto_renew', 1)) {
if ( ! wu_get_setting('force_auto_renew', true)) {
$auto_renewable_gateways = Gateway_Manager::get_instance()->get_auto_renewable_gateways();

$fields['auto_renew'] = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ public function to_fields_array($attributes) {

$customer_sites = [];

if (wu_get_setting('allow_own_site_as_template')) {
if (wu_get_setting('allow_own_site_as_template', false)) {
$customer = wu_get_current_customer();

if ($customer) {
Expand Down
4 changes: 2 additions & 2 deletions inc/class-dashboard-widgets.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,14 @@ public function register_widgets(): void {
/*
* Maintenance Mode Widget
*/
if (wu_get_setting('maintenance_mode')) {
if (wu_get_setting('maintenance_mode', false)) {
\WP_Ultimo\UI\Site_Maintenance_Element::get_instance()->as_metabox($screen->id, 'side');
}

/*
* Domain Mapping Widget
*/
if (wu_get_setting('enable_domain_mapping') && wu_get_setting('custom_domains')) {
if (wu_get_setting('enable_domain_mapping', false) && wu_get_setting('custom_domains', false)) {
\WP_Ultimo\UI\Domain_Mapping_Element::get_instance()->as_metabox($screen->id, 'side');
}
}
Expand Down
2 changes: 1 addition & 1 deletion inc/class-maintenance-mode.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function init(): void {

add_action('init', [$this, 'add_settings']);

if (wu_get_setting('maintenance_mode')) {
if (wu_get_setting('maintenance_mode', false)) {
$this->hooks();
}
}
Expand Down
212 changes: 202 additions & 10 deletions inc/class-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,14 @@ public function get_setting($setting, $default_value = false) {
_doing_it_wrong(esc_html($setting), esc_html__('Dashes are no longer supported when registering a setting. You should change it to underscores in later versions.', 'ultimate-multisite'), '2.0.0');
}

$setting_value = $settings[ $setting ] ?? $default_value;
if (isset($settings[ $setting ])) {
$setting_value = $settings[ $setting ];
} elseif (false !== $default_value) {
$setting_value = $default_value;
} else {
$defaults = static::get_setting_defaults();
$setting_value = $defaults[ $setting ] ?? false;
}

return apply_filters('wu_get_setting', $setting_value, $setting, $default_value, $settings);
}
Expand Down Expand Up @@ -518,15 +525,6 @@ function ($fields) use ($field_slug, $atts) {
},
$priority
);

$settings = $this->get_all();

/*
* Makes sure we install the default value if it is not set yet.
*/
if (isset($atts['default']) && null !== $atts['default'] && ! isset($settings[ $field_slug ])) {
$this->save_setting($field_slug, $atts['default']);
}
}

/**
Expand Down Expand Up @@ -1832,6 +1830,200 @@ public function default_sections(): void {
do_action('wu_settings_other');
}

/**
* Returns a flat map of setting keys to their default values.
*
* This is used as a lightweight fallback in get_setting() so that
* default_sections() (which is expensive) does not need to run on
* every page load.
*
* @since 2.5.0
* @return array<string, mixed>
*/
public static function get_setting_defaults(): array {

return [
// General
'company_name' => '',
'company_logo' => '',
'company_email' => '',
'company_address' => '',
'company_country' => 'US',
'currency_symbol' => 'USD',
'currency_position' => '%s %v',
'decimal_separator' => '.',
'thousand_separator' => ',',
'precision' => '2',
'enable_error_reporting' => 0,
'enable_beta_updates' => 0,

// Login & Registration
'enable_registration' => 1,
'enable_email_verification' => 'free_only',
'enable_custom_login_page' => 0,
'default_login_page' => 0,
'obfuscate_original_login_url' => 0,
'subsite_custom_login_logo' => 0,
'force_publish_sites_sync' => 0,
'minimum_password_strength' => 'medium',
'default_role' => 'administrator',
'add_users_to_main_site' => 0,
'main_site_default_role' => 'subscriber',

// Memberships
'block_frontend' => 0,
'block_frontend_grace_period' => 0,
'enable_multiple_memberships' => 0,
'enable_multiple_sites' => 0,
'block_sites_on_downgrade' => 'none',
'move_posts_on_downgrade' => 'none',
'emulated_post_types' => [],

// Sites
'enable_visits_limiting' => 1,
'enable_screenshot_generator' => 1,
'menu_items_plugin' => 1,
'add_new_users' => 1,
'allow_template_switching' => 1,
'allow_own_site_as_template' => 0,
'copy_media' => 1,
'stop_template_indexing' => 0,

// Payment Gateways
'force_auto_renew' => 1,
'allow_trial_without_payment_method' => 0,
'attach_invoice_pdf' => 1,
'invoice_numbering_scheme' => 'reference_code',
'next_invoice_number' => '1',
'invoice_prefix' => '',

// Emails (registered via hooks but commonly queried)
'from_name' => '',
'from_email' => '',

// Domain Mapping (registered via hooks but commonly queried)
'enable_domain_mapping' => false,
'custom_domains' => false,
'domain_mapping_instructions' => '',

// SSO (registered via hooks)
'enable_sso' => 1,

// Other
'hide_tours' => 0,
'disable_image_zoom' => 0,
'error_logging_level' => 'default',
'security_mode' => 0,
'uninstall_wipe_tables' => 0,

// Whitelabel (registered via hooks)
'rename_site_plural' => '',
'rename_site_singular' => '',
'rename_wordpress' => '',

// Maintenance mode (registered via hooks)
'maintenance_mode' => false,

// Notifications
'hide_notifications_subsites' => false,

// Taxes
'enable_taxes' => false,

// Checkout-related
'default_pricing_option' => 1,
'allowed_countries' => [],
'trial' => 0,

// Manual gateway
'manual_payment_instructions' => '',

// Event manager
'saving_type' => [],

// Jumper
'jumper_custom_links' => '',

// Limits
'limits_and_quotas' => [],

// Legacy pricing toggles
'enable_price_3' => true,
'enable_price_12' => true,
];
}

/**
* Returns a lightweight list of section slugs and titles for use
* in the admin bar and other places that don't need full field definitions.
*
* This avoids triggering default_sections() and all the expensive
* field registration that comes with it.
*
* @since 2.5.0
* @return array<string, array{title: string, icon: string}>
*/
public function get_section_names(): array {

$core_sections = [
'general' => [
'title' => __('General', 'ultimate-multisite'),
'icon' => 'dashicons-wu-cog',
],
'login-and-registration' => [
'title' => __('Login & Registration', 'ultimate-multisite'),
'icon' => 'dashicons-wu-key',
],
'memberships' => [
'title' => __('Memberships', 'ultimate-multisite'),
'icon' => 'dashicons-wu-infinity',
],
'sites' => [
'title' => __('Sites', 'ultimate-multisite'),
'icon' => 'dashicons-wu-browser',
],
'payment-gateways' => [
'title' => __('Payments', 'ultimate-multisite'),
'icon' => 'dashicons-wu-credit-card',
],
'emails' => [
'title' => __('Emails', 'ultimate-multisite'),
'icon' => 'dashicons-wu-email',
],
'domain-mapping' => [
'title' => __('Domain Mapping', 'ultimate-multisite'),
'icon' => 'dashicons-wu-link',
],
'sso' => [
'title' => __('Single Sign-On', 'ultimate-multisite'),
'icon' => 'dashicons-wu-add-user',
],
'integrations' => [
'title' => __('Integrations', 'ultimate-multisite'),
'icon' => 'dashicons-wu-power-plug',
],
'import-export' => [
'title' => __('Import/Export', 'ultimate-multisite'),
'icon' => 'dashicons-wu-download',
'order' => 995,
],
'other' => [
'title' => __('Other Options', 'ultimate-multisite'),
'icon' => 'dashicons-wu-switch',
'order' => 1000,
],
];

/**
* Allows addons to register their section names without triggering
* the full field registration in default_sections().
*
* @since 2.5.0
* @param array $sections Section slug => array with 'title', 'icon', and optionally 'addon' => true.
*/
return apply_filters('wu_settings_section_names', $core_sections);
}

/**
* Tries to determine the location of the company based on the admin IP.
*
Expand Down
12 changes: 6 additions & 6 deletions inc/class-whitelabel.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ public function hooks(): void {
add_action('network_admin_menu', [$this, 'remove_sites_admin_menu']);
}

if (wu_get_setting('rename_site_plural') ||
wu_get_setting('rename_site_singular') ||
wu_get_setting('rename_wordpress')
if (wu_get_setting('rename_site_plural', '') ||
wu_get_setting('rename_site_singular', '') ||
wu_get_setting('rename_wordpress', '')
) {
$this->allowed_domains = apply_filters(
'wu_replace_text_allowed_domains',
Expand All @@ -102,21 +102,21 @@ public function hooks(): void {
);

$search_and_replace = [];
$site_plural = wu_get_setting('rename_site_plural');
$site_plural = wu_get_setting('rename_site_plural', '');

if ($site_plural) {
$search_and_replace['sites'] = strtolower((string) $site_plural);
$search_and_replace['Sites'] = ucfirst((string) $site_plural);
}

$site_singular = wu_get_setting('rename_site_singular');
$site_singular = wu_get_setting('rename_site_singular', '');

if ($site_singular) {
$search_and_replace['site'] = strtolower((string) $site_singular);
$search_and_replace['Site'] = ucfirst((string) $site_singular);
}

$wordpress = wu_get_setting('rename_wordpress');
$wordpress = wu_get_setting('rename_wordpress', '');

if ($wordpress) {
$search_and_replace['wordpress'] = strtolower((string) $wordpress);
Expand Down
4 changes: 2 additions & 2 deletions inc/deprecated/deprecated.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php

Check failure on line 1 in inc/deprecated/deprecated.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Class file names should be based on the class name with "class-" prepended. Expected class-wu-settings.php, but found deprecated.php.
/**
* Contains deprecated functions.
*
Expand Down Expand Up @@ -29,7 +29,7 @@
* @param bool $filters Deprecated argument.
* @return array
*/
public static function get_sections($filters = true) {

Check warning on line 32 in inc/deprecated/deprecated.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

The method parameter $filters is never used

_deprecated_function(__METHOD__, '2.0.0', 'WP_Ultimo()->settings->get_sections()');

Expand Down Expand Up @@ -137,7 +137,7 @@
*
* @deprecated 2.0.0
*/
class WU_Page extends \WP_Ultimo\Admin_Pages\Base_Admin_Page {

Check failure on line 140 in inc/deprecated/deprecated.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Only one object structure is allowed in a file

/**
* Holds the attributes.
Expand Down Expand Up @@ -225,7 +225,7 @@
*
* @deprecated 2.0.0
*/
class WU_Site_Templates {

Check failure on line 228 in inc/deprecated/deprecated.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Only one object structure is allowed in a file

/**
* Returns the template preview URL.
Expand All @@ -248,7 +248,7 @@
*
* @deprecated 2.0.0
*/
class WU_Mail {

Check failure on line 251 in inc/deprecated/deprecated.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Only one object structure is allowed in a file

use \WP_Ultimo\Traits\Singleton;

Expand All @@ -271,8 +271,8 @@
_deprecated_function(__METHOD__, '2.0.0', 'wu_send_mail()');

$from = [
'name' => wu_get_setting('from_name'),
'email' => wu_get_setting('from_email'),
'name' => wu_get_setting('from_name', ''),
'email' => wu_get_setting('from_email', ''),
];

/*
Expand Down Expand Up @@ -340,7 +340,7 @@
/**
* Deprecated: WU_Plans class.
*/
class WU_Plans {

Check failure on line 343 in inc/deprecated/deprecated.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Only one object structure is allowed in a file

/**
* Deprecated.
Expand Down Expand Up @@ -400,7 +400,7 @@
*
* @deprecated 2.0.0
*/
class WU_Multi_Network {

Check failure on line 403 in inc/deprecated/deprecated.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Only one object structure is allowed in a file

/**
* Catch-all for all static methods to deprecate.
Expand Down
Loading
Loading