fix(widgets): align user card backgrounds
This commit is contained in:
@@ -122,7 +122,7 @@
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
}
|
||||
.aksrt-user-card__vip {
|
||||
.aksrt-user-card__avatar-wrap > .aksrt-vip-badge {
|
||||
position: absolute;
|
||||
right: -5px;
|
||||
bottom: -3px;
|
||||
@@ -130,20 +130,14 @@
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-width: 28px;
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
padding: 3px;
|
||||
border: 2px solid var(--surface-1, #fff);
|
||||
border-radius: 50%;
|
||||
background: var(--surface-1, #fff);
|
||||
box-shadow: 0 2px 6px rgba(0, 0, 0, .18);
|
||||
max-width: none;
|
||||
padding: 0;
|
||||
line-height: 1;
|
||||
}
|
||||
.aksrt-user-card__vip .aksrt-vip-badge {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
.aksrt-user-card__vip .aksrt-vip-badge__icon {
|
||||
.aksrt-user-card__avatar-wrap > .aksrt-vip-badge .aksrt-vip-badge__icon {
|
||||
display: block;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
max-width: 100%;
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 1.5 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 46 KiB |
@@ -10,6 +10,8 @@ namespace AKSRT\Widgets;
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
class WidgetUserCard extends \WP_Widget {
|
||||
private const DEFAULT_COVER_FILE = 'assets/img/person_background.png';
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct(
|
||||
'aksrt_user_card',
|
||||
@@ -61,7 +63,7 @@ class WidgetUserCard extends \WP_Widget {
|
||||
}
|
||||
|
||||
if ($user_id <= 0) {
|
||||
$this->render_guest($show_cover, $loged_title);
|
||||
$this->render_guest($show_cover, $loged_title, $this->get_guest_cover_url($instance));
|
||||
if ($affix['class'] !== '') {
|
||||
echo '</div>';
|
||||
}
|
||||
@@ -104,9 +106,9 @@ class WidgetUserCard extends \WP_Widget {
|
||||
if (!is_string($bio) || $bio === '') {
|
||||
$bio = (string) $user->description;
|
||||
}
|
||||
$cover = (string) get_user_meta($user_id, 'aksrt_cover', true);
|
||||
$cover = (string) get_user_meta($user_id, 'aksrt_background_image', true);
|
||||
if ($cover === '') {
|
||||
$cover = (string) get_user_meta($user_id, 'custom_avatar_cover', true);
|
||||
$cover = $this->get_default_cover_url();
|
||||
}
|
||||
|
||||
$post_count = count_user_posts($user_id, 'post', true);
|
||||
@@ -138,23 +140,7 @@ class WidgetUserCard extends \WP_Widget {
|
||||
|
||||
echo '<div class="aksrt-user-card user-card' . ($show_cover ? ' has-cover' : ' no-cover') . '">';
|
||||
if ($show_cover) {
|
||||
if ($cover !== '') {
|
||||
echo '<div class="aksrt-user-card__cover" style="background-image:url(' . esc_url($cover) . ')">' . $checkin_html . '</div>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
} else {
|
||||
// Prefer site default cover image when available.
|
||||
$default_cover = '';
|
||||
if (class_exists('\AKSRT\Settings\Settings') && method_exists('\AKSRT\Settings\Settings', 'get_user_cover_default')) {
|
||||
$default_cover = (string) \AKSRT\Settings\Settings::get_user_cover_default();
|
||||
}
|
||||
if ($default_cover === '' && function_exists('get_theme_mod')) {
|
||||
$default_cover = (string) get_theme_mod('aksrt_user_cover', '');
|
||||
}
|
||||
if ($default_cover !== '') {
|
||||
echo '<div class="aksrt-user-card__cover" style="background-image:url(' . esc_url($default_cover) . ')">' . $checkin_html . '</div>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
} else {
|
||||
echo '<div class="aksrt-user-card__cover is-empty">' . $checkin_html . '</div>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
}
|
||||
}
|
||||
} elseif ($checkin_btn !== '') {
|
||||
echo '<div class="aksrt-user-card__checkin aksrt-user-card__checkin--without-cover">' . $checkin_btn . '</div>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
}
|
||||
@@ -165,7 +151,7 @@ class WidgetUserCard extends \WP_Widget {
|
||||
echo '<a href="' . esc_url($profile_url) . '"><img class="aksrt-lazy lazyload" data-src="' . esc_url($avatar_url) . '" src="' . esc_url($ph) . '" alt="' . esc_attr($user->display_name) . '" loading="lazy" width="76" height="76" /></a>';
|
||||
echo '</div>';
|
||||
if ($vip_badge !== '') {
|
||||
echo '<span class="aksrt-user-card__vip">' . $vip_badge . '</span>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
echo $vip_badge; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
}
|
||||
echo '</div>';
|
||||
echo '<h4 class="aksrt-user-card__name user-name">' . $name_html . '</h4>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
@@ -207,7 +193,7 @@ class WidgetUserCard extends \WP_Widget {
|
||||
echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
}
|
||||
|
||||
private function render_guest(bool $show_cover, string $loged_title): void {
|
||||
private function render_guest(bool $show_cover, string $loged_title, string $cover): void {
|
||||
$login = function_exists('aksrt_get_login_url') ? aksrt_get_login_url() : wp_login_url();
|
||||
$register = function_exists('aksrt_get_register_url') ? aksrt_get_register_url() : wp_registration_url();
|
||||
$default_avatar = function_exists('get_avatar_url')
|
||||
@@ -226,15 +212,7 @@ class WidgetUserCard extends \WP_Widget {
|
||||
|
||||
echo '<div class="aksrt-user-card user-card is-guest' . ($show_cover ? ' has-cover' : ' no-cover') . '">';
|
||||
if ($show_cover) {
|
||||
$default_cover = '';
|
||||
if (class_exists('\AKSRT\Settings\Settings') && method_exists('\AKSRT\Settings\Settings', 'get_user_cover_default')) {
|
||||
$default_cover = (string) \AKSRT\Settings\Settings::get_user_cover_default();
|
||||
}
|
||||
if ($default_cover !== '') {
|
||||
echo '<div class="aksrt-user-card__cover" style="background-image:url(' . esc_url($default_cover) . ')"></div>';
|
||||
} else {
|
||||
echo '<div class="aksrt-user-card__cover is-empty"></div>';
|
||||
}
|
||||
echo '<div class="aksrt-user-card__cover" style="background-image:url(' . esc_url($cover) . ')"></div>';
|
||||
}
|
||||
echo '<div class="aksrt-user-card__body card-content">';
|
||||
echo '<div class="aksrt-user-card__avatar-wrap"><div class="aksrt-user-card__avatar user-avatar"><img src="' . esc_url($default_avatar) . '" alt="" width="76" height="76" loading="lazy" /></div></div>';
|
||||
@@ -272,6 +250,11 @@ class WidgetUserCard extends \WP_Widget {
|
||||
<input class="widefat" type="text" name="<?php echo esc_attr($this->get_field_name('loged_title')); ?>" value="<?php echo esc_attr((string) ($instance['loged_title'] ?? __('Hi!请登录', 'aksrt'))); ?>">
|
||||
</label>
|
||||
</p>
|
||||
<p>
|
||||
<label><?php esc_html_e('未登录封面图 URL(留空使用默认图片)', 'aksrt'); ?>
|
||||
<input class="widefat" type="url" name="<?php echo esc_attr($this->get_field_name('guest_cover')); ?>" value="<?php echo esc_attr((string) ($instance['guest_cover'] ?? '')); ?>" placeholder="<?php echo esc_attr($this->get_default_cover_url()); ?>">
|
||||
</label>
|
||||
</p>
|
||||
<p>
|
||||
<label><?php esc_html_e('按钮1文案', 'aksrt'); ?>
|
||||
<input class="widefat" type="text" name="<?php echo esc_attr($this->get_field_name('button_1_text')); ?>" value="<?php echo esc_attr((string) ($instance['button_1_text'] ?? __('发布文章', 'aksrt'))); ?>">
|
||||
@@ -348,6 +331,7 @@ class WidgetUserCard extends \WP_Widget {
|
||||
'title' => sanitize_text_field((string) ($new_instance['title'] ?? '')),
|
||||
'user_id' => max(0, (int) ($new_instance['user_id'] ?? 0)),
|
||||
'loged_title' => sanitize_text_field((string) ($new_instance['loged_title'] ?? '')),
|
||||
'guest_cover' => esc_url_raw(trim((string) ($new_instance['guest_cover'] ?? ''))),
|
||||
'button_1' => 'post',
|
||||
'button_1_text' => sanitize_text_field((string) ($new_instance['button_1_text'] ?? '')),
|
||||
'button_1_class'=> self::sanitize_palette((string) ($new_instance['button_1_class'] ?? 'jb-pink'), 'jb-pink'),
|
||||
@@ -365,6 +349,15 @@ class WidgetUserCard extends \WP_Widget {
|
||||
];
|
||||
}
|
||||
|
||||
private function get_default_cover_url(): string {
|
||||
return get_theme_file_uri(self::DEFAULT_COVER_FILE);
|
||||
}
|
||||
|
||||
private function get_guest_cover_url(array $instance): string {
|
||||
$cover = esc_url_raw(trim((string) ($instance['guest_cover'] ?? '')));
|
||||
return $cover !== '' ? $cover : $this->get_default_cover_url();
|
||||
}
|
||||
|
||||
/** Zibll CFS_Module::zib_palette() gradient/solid keys (c/b/jb families). */
|
||||
public static function palette_opts(): array {
|
||||
return [
|
||||
|
||||
Reference in New Issue
Block a user