Skip to content

Commit 7d21877

Browse files
authored
Fix templates (#175)
* Fix grammar * Fix rendering logo * Fix saving objects with html * Fix warnings * Fix logo without a custom logo * Fix warning * Fix saving content * Add feature to allow admins to edit user accounts * Update readme
1 parent 99e0caa commit 7d21877

File tree

9 files changed

+156
-14
lines changed

9 files changed

+156
-14
lines changed

inc/class-wp-ultimo.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,7 @@ function () {
603603
* Now it is native, but needs to be activated on Multisite Ultimate settings.
604604
*/
605605
\WP_Ultimo\Compat\Multiple_Accounts_Compat::get_instance();
606+
\WP_Ultimo\Compat\Edit_Users_Compat::get_instance();
606607

607608
/*
608609
* Network Admin Widgets
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
<?php
2+
/**
3+
* Adds support to for site owners to edit user accounts for users on their site.
4+
*
5+
* WordPress, even in multisite mode, has only one User database table.
6+
* This can cause problems in a WaaS environment.
7+
*
8+
* A site owner with administrator role wants to edit the display name of a subscriber.
9+
* In the default Multisite only super admins can edit user accounts.
10+
* This makes it possible for Admins to edit users in their own sites.
11+
*
12+
* @package WP_Ultimo
13+
* @subpackage Compat/Edit_Users_Compat
14+
* @since 2.4.4
15+
*/
16+
17+
namespace WP_Ultimo\Compat;
18+
19+
class Edit_Users_Compat {
20+
21+
use \WP_Ultimo\Traits\Singleton;
22+
23+
public function init(): void {
24+
// Add the settings to enable or disable this feature.
25+
add_action('wu_settings_login', [$this, 'add_settings'], 10);
26+
27+
if ($this->should_load()) {
28+
// Apply the update_users_caps function to the 'map_meta_cap' filter.
29+
add_filter('map_meta_cap', [$this, 'update_users_caps'], 1, 4);
30+
31+
// Add a filter to enable editing any user configuration.
32+
add_filter('enable_edit_any_user_configuration', '__return_true', 15);
33+
}
34+
}
35+
36+
/**
37+
* Allows subsite administrators to edit users in a WordPress Multisite network.
38+
*
39+
* In a WordPress 3.x Network, the Super Admin role is the only role allowed to edit users.
40+
*
41+
* @param array $caps The user's capabilities.
42+
* @param string $cap The capability being checked.
43+
* @param int $user_id The user ID.
44+
* @param mixed $args Additional arguments.
45+
*
46+
* @return array Modified user capabilities.
47+
*/
48+
function update_users_caps($caps, $cap, $user_id, $args) {
49+
foreach ($caps as $key => $capability) {
50+
if ('do_not_allow' !== $capability) {
51+
continue;
52+
}
53+
54+
switch ( $cap ) {
55+
case 'edit_user':
56+
// Editing a user profile.
57+
if (empty($args[0]) || is_super_admin($args[0])) {
58+
// Trying to edit a super admin while not being a super admin.
59+
$caps[] = 'do_not_allow';
60+
} elseif ( ! is_user_member_of_blog($args[0], get_current_blog_id()) || ! is_user_member_of_blog($user_id, get_current_blog_id())) {
61+
// Editing user and edited user aren't members of the same blog.
62+
$caps[] = 'do_not_allow';
63+
} else {
64+
$caps[ $key ] = 'edit_users';
65+
}
66+
67+
break;
68+
case 'edit_users':
69+
$caps[ $key ] = 'edit_users';
70+
break;
71+
case 'delete_user':
72+
case 'delete_users':
73+
$caps[ $key ] = 'delete_users';
74+
break;
75+
case 'create_users':
76+
$caps[ $key ] = $cap;
77+
break;
78+
}
79+
}
80+
81+
return $caps;
82+
}
83+
84+
/**
85+
* Allow plugin developers to disable this functionality to prevent compatibility issues.
86+
*
87+
* @since 2.0.0
88+
*
89+
* @return boolean
90+
*/
91+
public function should_load() {
92+
93+
return apply_filters('wu_should_load_edit_user_support', wu_get_setting('enable_edit_users', false));
94+
}
95+
96+
/**
97+
* Add edit user setting to enable or disable this feature.
98+
*
99+
* @since 2.0.0
100+
*
101+
* @return void.
102+
*/
103+
public function add_settings(): void {
104+
105+
wu_register_settings_field(
106+
'login-and-registration',
107+
'enable_edit_users',
108+
[
109+
'title' => __('Enable Edit User Capability', 'multisite-ultimate'),
110+
'desc' => __('Allow site owners to edit the user accounts of users on their own site.', 'multisite-ultimate'),
111+
'type' => 'toggle',
112+
'default' => 0,
113+
]
114+
);
115+
}
116+
}

inc/helpers/class-validator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function __construct() {
7373
'required_without' => $field_required_message,
7474
'required_with' => $field_required_message,
7575
// translators: %s is the email field identifier
76-
'email' => sprintf(__('The %s is not valid email', 'multisite-ultimate'), ':attribute'),
76+
'email' => sprintf(__('The %s is not a valid email', 'multisite-ultimate'), ':attribute'),
7777
// translators: 1st %s is the field name; 2nd is the allowed value
7878
'min' => sprintf(__('The %1$s minimum is %2$s', 'multisite-ultimate'), ':attribute', ':min'),
7979
// translators: 1st %s is the field name; 2nd is the allowed value

inc/invoices/class-invoice.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ private function pdf_setup(): void {
9797
'tempDir' => get_temp_dir(),
9898
]
9999
);
100+
$this->printer->curlFollowLocation = true;
100101

101102
$this->printer->setDefaultFont($this->font);
102103

inc/models/class-post-base-model.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,20 @@ class Post_Base_Model extends Base_Model {
9696
*/
9797
protected $query_class = \WP_Ultimo\Database\Posts\Post_Query::class;
9898

99+
100+
/**
101+
* @return $this
102+
*/
103+
public function load_attributes_from_post() {
104+
parent::load_attributes_from_post();
105+
106+
if (isset($_POST['content'])) { // phpcs:ignore WordPress.Security.NonceVerification
107+
$this->set_content(sanitize_post_field('content', wp_unslash($_POST['content']), $this->get_id(), 'db')); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification
108+
}
109+
110+
return $this;
111+
}
112+
99113
/**
100114
* Get author ID.
101115
*

inc/ui/class-checkout-element.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ public function output_thank_you($atts, $content = null) {
290290

291291
$checkout_form = wu_get_checkout_form_by_slug($slug);
292292

293-
$atts = $checkout_form->get_meta('wu_thank_you_settings');
293+
$atts = $checkout_form->get_meta('wu_thank_you_settings', []);
294294

295295
$atts['checkout_form'] = $checkout_form;
296296

readme.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,11 @@ We recommend running this in a staging environment before updating your producti
229229

230230
== Changelog ==
231231

232+
Version [2.4.4] - Released on 2025-08-XX
233+
- Fixed: Saving email templates without stripping html
234+
- New: Option to allow site owners to edit users on their site
235+
- Fixed: Invoices not loading when logo is not set
236+
232237
Version [2.4.3] - Released on 2025-08-15
233238
- Fixed: Bug in Slim SEO plugin
234239
- New: Addon Marketplace

views/email/widget-placeholders.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
<td class="wu-align-left wu-text-xs">
4242

43-
<span :id="'payload_event_name_' + placeholder.placeholder" class="wu-rounded-sm wu-text-xs"><?php echo esc_html(str_replace(['Id', 'Url'], ['ID', 'URL'], $placeholder['name'])); ?></span>
43+
<span :id="'payload_event_name_' + placeholder.placeholder" class="wu-rounded-sm wu-text-xs"><?php echo esc_html(str_replace(['Id', 'Url'], ['ID', 'URL'], $placeholder['name'] ?? '')); ?></span>
4444

4545
</td>
4646

views/invoice/template.php

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
* @since 2.0.0
66
*/
7-
defined( 'ABSPATH' ) || exit;
7+
defined('ABSPATH') || exit;
88

99
$has_tax_included = false;
1010
// Inline styles for invoice template - required for PDF generation and email formatting.
@@ -139,16 +139,21 @@
139139
<table>
140140
<tr>
141141
<td class="title">
142-
<?php if ($use_custom_logo && $custom_logo) :
143-
$logo_path = get_attached_file($custom_logo);
144-
$logo_data = base64_encode(file_get_contents($logo_path));
145-
$logo_mime = mime_content_type($logo_path); ?>
146-
<img style="max-width:280px; width:auto; max-height:70px;" src="data:<?php echo esc_attr($logo_mime); ?>;base64,<?php echo $logo_data; ?>" alt="<?php echo esc_attr($site_name); ?>">
147-
<?php else :
148-
$logo_url = get_network_option(null, 'site_logo');
149-
$logo_data = base64_encode(file_get_contents($logo_url));
150-
$logo_mime = mime_content_type($logo_url); ?>
151-
<img style="max-width:280px; width:auto; max-height:70px;" src="data:<?php echo esc_attr($logo_mime); ?>;base64,<?php echo $logo_data; ?>" alt="<?php echo esc_attr($site_name); ?>">
142+
<?php if ($use_custom_logo && $custom_logo) : ?>
143+
<?php
144+
echo (wp_get_attachment_image(
145+
$custom_logo,
146+
'full',
147+
false,
148+
array(
149+
'loading' => false,
150+
'decoding' => false,
151+
'style' => 'width: 100px; height: auto;',
152+
)
153+
));
154+
?>
155+
<?php else : ?>
156+
<img width="100" src="<?php echo esc_attr($logo_url); ?>" alt="<?php echo esc_attr(get_network_option(null, 'site_name')); ?>">
152157
<?php endif; ?>
153158
</td>
154159

0 commit comments

Comments
 (0)