feat(frontend): replace lazy loading with zibll lazysizes

This commit is contained in:
2026-08-18 01:33:38 +08:00
parent 02571eecd6
commit 435ee1daa7
78 changed files with 1515 additions and 909 deletions
+4 -2
View File
@@ -115,9 +115,11 @@ if (!function_exists('aksrt_get_avatar_html')) {
'alt' => '',
'width' => (string) $size,
'height' => (string) $size,
'loading' => 'lazy',
];
$attrs = array_merge($defaults, $attrs);
unset($attrs['loading']);
$class = (string) ($attrs['class'] ?? $defaults['class']);
unset($attrs['class']);
$html_attrs = '';
foreach ($attrs as $name => $value) {
$name = sanitize_key((string) $name);
@@ -126,7 +128,7 @@ if (!function_exists('aksrt_get_avatar_html')) {
}
$html_attrs .= ' ' . $name . '="' . esc_attr((string) $value) . '"';
}
return '<img src="' . esc_url($url) . '"' . $html_attrs . ' />';
return '<img' . aksrt_get_lazy_attr('lazy_avatar', $url, $class, aksrt_get_default_avatar_url()) . $html_attrs . '>';
}
}
+1 -1
View File
@@ -453,7 +453,7 @@ if (!function_exists('aksrt_render_mini_post_item')) :
?>
<article class="<?php echo esc_attr(implode(' ', array_unique($classes))); ?>">
<a href="<?php echo esc_url($permalink); ?>" class="item-thumbnail" aria-label="<?php echo esc_attr($title); ?>">
<img class="fit-cover" src="<?php echo esc_url($thumb_url !== '' ? $thumb_url : $placeholder_url); ?>" alt="<?php echo esc_attr($title); ?>" loading="lazy">
<img<?php echo aksrt_get_lazy_attr('lazy_posts_thumb', (string) ($thumb_url !== '' ? $thumb_url : $placeholder_url), 'fit-cover'); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> alt="<?php echo esc_attr($title); ?>">
</a>
<div class="posts-mini-con">
<h4 class="item-heading">
+9 -9
View File
@@ -24,7 +24,7 @@ if (!function_exists('aksrt_graphic_card')) :
* @type string $text2 Secondary text.
* @type string $text3 Tertiary / badge text (HTML allowed for icon+count).
* @type string $more Extra absolute HTML (badge etc).
* @type bool $lazy Use aksrt-lazy data-src.
* @type bool $lazy Use the Zibll lazySizes contract.
* @type int|float $height_scale Padding-bottom % (0 = default CSS).
* @type int|float $mask_opacity 0–100 overlay opacity.
* @type string $hide pc|m|'' hide on device.
@@ -89,21 +89,21 @@ if (!function_exists('aksrt_graphic_card')) :
$link_target = sanitize_text_field((string) ($link['target'] ?? ''));
$lazy = !empty($args['lazy']);
$placeholder = get_template_directory_uri() . '/assets/img/placeholder.svg';
$media = '';
if ($video_url !== '' && !(function_exists('wp_is_mobile') && wp_is_mobile())) {
$poster = $img_url !== '' ? ' poster="' . esc_url($img_url) . '"' : '';
if ($lazy) {
$media = '<video autoplay loop muted playsinline class="fit-cover aksrt-lazy lazyload" data-src="' . esc_url($video_url) . '" src=""' . $poster . '></video>';
if ($lazy && aksrt_is_lazy('lazy_other')) {
$poster = $img_url !== '' ? ' data-poster="' . esc_url($img_url) . '"' : '';
$media = '<video autoplay loop muted playsinline class="fit-cover lazyload" data-src="' . esc_url($video_url) . '" src=""' . $poster . '></video>';
} else {
$poster = $img_url !== '' ? ' poster="' . esc_url($img_url) . '"' : '';
$media = '<video autoplay loop muted playsinline class="fit-cover" src="' . esc_url($video_url) . '"' . $poster . '></video>';
}
} elseif ($img_url !== '') {
$alt = (string) ($args['alt'] !== '' ? $args['alt'] : __('图片', 'aksrt'));
if ($lazy) {
$media = '<img class="fit-cover aksrt-lazy lazyload" data-src="' . esc_url($img_url) . '" src="' . esc_url($placeholder) . '" alt="' . esc_attr($alt) . '" loading="lazy" />';
$media = '<img' . aksrt_get_lazy_attr('lazy_other', $img_url, 'fit-cover') . ' alt="' . esc_attr($alt) . '">';
} else {
$media = '<img class="fit-cover" src="' . esc_url($img_url) . '" alt="' . esc_attr($alt) . '" loading="lazy" />';
$media = '<img class="fit-cover" src="' . esc_url($img_url) . '" alt="' . esc_attr($alt) . '">';
}
}
if ($media === '') {
@@ -228,7 +228,7 @@ if (!function_exists('aksrt_author_minicard')) :
? aksrt_get_user_home_url($user_id)
: get_author_posts_url($user_id);
$avatar_box = '<div class="avatar-img"><a href="' . esc_url($home) . '"><img class="avatar" src="' . esc_url($avatar_url) . '" alt="" loading="lazy" width="42" height="42" /></a></div>';
$avatar_box = '<div class="avatar-img"><a href="' . esc_url($home) . '"><img' . aksrt_get_lazy_attr('lazy_avatar', $avatar_url, 'avatar', aksrt_get_lazy_thumb('sm')) . ' alt="" width="42" height="42"></a></div>';
$name = function_exists('aksrt_get_user_name')
? aksrt_get_user_name([
@@ -260,7 +260,7 @@ if (!function_exists('aksrt_author_minicard')) :
$blur = '';
if ($blur_bg) {
$blur = '<div class="abs-blur-bg blur"><img src="' . esc_url($avatar_url) . '" alt="" loading="lazy" /></div>';
$blur = '<div class="abs-blur-bg blur"><img' . aksrt_get_lazy_attr('lazy_avatar', $avatar_url, '', aksrt_get_lazy_thumb('sm')) . ' alt=""></div>';
}
return '<div class="author-minicard radius8 relative-h ' . esc_attr($class) . '">'
+4 -4
View File
@@ -42,7 +42,7 @@ if (!function_exists('aksrt_icon_card')) :
if ($icon_img === '' && is_string($args['customize_icon']) && str_contains((string) $args['customize_icon'], '<')) {
$custom_html = wp_kses((string) $args['customize_icon'], [
'i' => ['class' => true, 'aria-hidden' => true],
'img' => ['src' => true, 'alt' => true, 'class' => true, 'width' => true, 'height' => true, 'loading' => true],
'img' => ['src' => true, 'data-src' => true, 'alt' => true, 'class' => true, 'width' => true, 'height' => true],
'span'=> ['class' => true],
]);
}
@@ -80,7 +80,7 @@ if (!function_exists('aksrt_icon_card')) :
if ($custom_html !== '') {
$icon_inner = $custom_html;
} elseif ($icon_img !== '') {
$icon_inner = '<img src="' . esc_url($icon_img) . '" alt="" loading="lazy" />';
$icon_inner = '<img' . aksrt_get_lazy_attr('lazy_other', $icon_img, 'img-icon') . ' alt="">';
} else {
if ($icon_fa !== '' && !str_contains($icon_fa, 'fa-') && !str_contains($icon_fa, ' ')) {
$icon_fa = 'fa fa-' . $icon_fa;
@@ -181,7 +181,7 @@ if (!function_exists('aksrt_icon_cover_card')) :
if ($icon_img === '' && $custom_src !== '' && str_contains($custom_src, '<')) {
$custom_html = wp_kses($custom_src, [
'i' => ['class' => true, 'aria-hidden' => true],
'img' => ['src' => true, 'alt' => true, 'class' => true, 'loading' => true, 'width' => true, 'height' => true],
'img' => ['src' => true, 'data-src' => true, 'alt' => true, 'class' => true, 'width' => true, 'height' => true],
'span' => ['class' => true],
'svg' => ['class' => true, 'viewbox' => true, 'viewBox' => true, 'width' => true, 'height' => true, 'fill' => true, 'xmlns' => true, 'aria-hidden' => true],
'path' => ['d' => true, 'fill' => true, 'stroke' => true, 'stroke-width' => true],
@@ -235,7 +235,7 @@ if (!function_exists('aksrt_icon_cover_card')) :
if ($custom_html !== '') {
$icon_inner = $custom_html;
} elseif ($icon_img !== '') {
$icon_inner = '<img src="' . esc_url($icon_img) . '" alt="" loading="lazy" />';
$icon_inner = '<img' . aksrt_get_lazy_attr('lazy_other', $icon_img, 'img-icon') . ' alt="">';
} else {
// zibll: zib_get_cfs_icon($args['icon'], 'em09') — keep FA class + em09.
if ($icon_fa !== '' && !str_contains($icon_fa, 'fa-') && !str_contains($icon_fa, ' ') && !str_starts_with($icon_fa, 'zibsvg-')) {
+7 -7
View File
@@ -99,7 +99,7 @@ if (!function_exists('aksrt_render_user_identity_chips')) {
if ($type !== '') {
$classes .= ' aksrt-identity-medal--' . $type;
}
$html .= '<img class="' . esc_attr($classes) . '" src="' . $icon_url . '" alt="' . esc_attr($label) . '" title="' . esc_attr($title) . '" loading="lazy" decoding="async" />';
$html .= '<img' . aksrt_get_lazy_attr('lazy_other', $icon_url, $classes) . ' alt="' . esc_attr($label) . '" title="' . esc_attr($title) . '" decoding="async">';
$n++;
continue;
}
@@ -180,20 +180,20 @@ if (!function_exists('aksrt_get_user_name')) {
$auth_html = $icon_url !== ''
? '<img class="aksrt-identity-certification-icon img-icon ml3" src="' . $icon_url . '" alt="' . esc_attr($label) . '" title="' . esc_attr($title) . '" loading="lazy" decoding="async" />'
? '<img' . aksrt_get_lazy_attr('lazy_other', $icon_url, 'aksrt-identity-certification-icon img-icon ml3') . ' alt="' . esc_attr($label) . '" title="' . esc_attr($title) . '" decoding="async">'
: '<span class="badg badg-sm ml3 aksrt-identity-chip aksrt-identity-chip--success" title="' . esc_attr($title) . '"><i class="fa fa-check-circle" aria-hidden="true"></i> ' . esc_html($label) . '</span>';
} elseif ($type === 'level' && !empty($args['level']) && $level_html === '') {
if ($icon_url !== '') {
$level_html = '<img class="aksrt-user-level-icon img-icon ml3" src="' . $icon_url . '" alt="' . esc_attr($label) . '" title="' . esc_attr($title) . '" loading="lazy" decoding="async" />';
$level_html = '<img' . aksrt_get_lazy_attr('lazy_other', $icon_url, 'aksrt-user-level-icon img-icon ml3') . ' alt="' . esc_attr($label) . '" title="' . esc_attr($title) . '" decoding="async">';
} else {
// Text fallback mirrors zibll LV badge: small pill, never oversized.
$level_html = '<span class="badg badg-sm ml3 aksrt-user-level-badge" title="' . esc_attr($title) . '">' . esc_html($label) . '</span>';
}
} elseif ($type === 'badge' && !empty($args['medal']) && $medal_html === '' && !empty($signal['wear'])) {
if ($icon_url !== '') {
$medal_html = '<img class="medal-icon img-icon ml3 aksrt-identity-medal is-wear" src="' . $icon_url . '" alt="' . esc_attr($label) . '" title="' . esc_attr($title) . '" loading="lazy" decoding="async" />';
$medal_html = '<img' . aksrt_get_lazy_attr('lazy_other', $icon_url, 'medal-icon img-icon ml3 aksrt-identity-medal is-wear') . ' alt="' . esc_attr($label) . '" title="' . esc_attr($title) . '" decoding="async">';
} else {
$medal_html = '<span class="badg badg-sm ml3 aksrt-identity-chip is-wear" title="' . esc_attr($title) . '"><i class="fa fa-award" aria-hidden="true"></i> ' . esc_html($label) . '</span>';
}
@@ -212,7 +212,7 @@ if (!function_exists('aksrt_get_user_name')) {
continue;
}
if ($icon_url !== '') {
$medal_html = '<img class="medal-icon img-icon ml3 aksrt-identity-medal" src="' . $icon_url . '" alt="' . esc_attr($label) . '" title="' . esc_attr($title) . '" loading="lazy" decoding="async" />';
$medal_html = '<img' . aksrt_get_lazy_attr('lazy_other', $icon_url, 'medal-icon img-icon ml3 aksrt-identity-medal') . ' alt="' . esc_attr($label) . '" title="' . esc_attr($title) . '" decoding="async">';
} else {
$medal_html = '<span class="badg badg-sm ml3 aksrt-identity-chip" title="' . esc_attr($title) . '"><i class="fa fa-award" aria-hidden="true"></i> ' . esc_html($label) . '</span>';
}
@@ -282,7 +282,7 @@ if (!function_exists('aksrt_render_user_medal_entry')) {
continue;
}
$label = sanitize_text_field((string) ($item['label'] ?? __('徽章', 'aksrt')));
$icons[] = '<img class="img-icon medal-icon aksrt-medal-entry__icon" src="' . $icon_url . '" alt="' . esc_attr($label) . '" title="' . esc_attr($label) . '" loading="lazy" decoding="async" />';
$icons[] = '<img' . aksrt_get_lazy_attr('lazy_other', $icon_url, 'img-icon medal-icon aksrt-medal-entry__icon') . ' alt="' . esc_attr($label) . '" title="' . esc_attr($label) . '" decoding="async">';
if (count($icons) >= $limit) {
break 2;
}
@@ -409,7 +409,7 @@ if (!function_exists('aksrt_get_worn_medal_icon')) {
if ($icon !== '') {
$extra = $class !== '' ? ' ' . esc_attr($class) : '';
return '<img class="medal-icon img-icon ml3 aksrt-identity-medal is-wear' . $extra . '" src="' . $icon . '" alt="' . esc_attr($label) . '" title="' . esc_attr($label) . '" loading="lazy" decoding="async" />';
return '<img' . aksrt_get_lazy_attr('lazy_other', $icon, 'medal-icon img-icon ml3 aksrt-identity-medal is-wear' . $extra) . ' alt="' . esc_attr($label) . '" title="' . esc_attr($label) . '" decoding="async">';
}
// Text fallback (rare): small pill labelled with badge text.
+2 -2
View File
@@ -152,7 +152,7 @@ if (!function_exists('aksrt_links_box')) :
$dec = !empty($link['desc']) ? (string) $link['desc'] : '';
$rel = $nofollow ? ' rel="nofollow noopener noreferrer"' : ' rel="noopener noreferrer"';
$img_src = $src !== '' ? $src : $placeholder;
$img = '<img class="lazyload aksrt-lazy avatar" src="' . esc_url($placeholder) . '" data-src="' . esc_url($img_src) . '" alt="" loading="lazy">';
$img = '<img' . aksrt_get_lazy_attr('lazy_other', $img_src, 'avatar') . ' alt="">';
$data_dec = $dec !== ''
? ' title="' . esc_attr($title) . '" data-content="' . esc_attr($dec) . '"'
: ' data-content="' . esc_attr($title) . '"';
@@ -385,7 +385,7 @@ if (!function_exists('aksrt_link_get_search_cover')) :
. '<div class="tab-content">' . $type_con . '</div></div></div>';
return '<div class="page-cover theme-box radius8 main-shadow link-page-search-cover">'
. '<img class="fit-cover no-scale lazyload" src="' . esc_url($src) . '" data-src="' . esc_url($img) . '" alt="">'
. '<img' . aksrt_get_lazy_attr('lazy_cover', (string) $img, 'fit-cover no-scale', (string) $src) . ' alt="">'
. $search . '</div>';
}
endif;
+1 -1
View File
@@ -59,7 +59,7 @@ if (!function_exists('aksrt_get_null')) {
$style .= 'opacity:.7;';
$src = aksrt_null_image_url($img);
return '<div class="text-center aksrt-null ' . esc_attr($class) . '" style="padding:' . esc_attr($margin) . 'px 0;">'
. '<img class="no-imgbox aksrt-null__img" style="' . esc_attr($style) . '" src="' . esc_url($src) . '" alt="" loading="lazy" decoding="async">'
. '<img class="no-imgbox aksrt-null__img" style="' . esc_attr($style) . '" src="' . esc_url($src) . '" alt="" decoding="async">'
. $caption
. '</div>';
}
+11 -12
View File
@@ -1243,7 +1243,7 @@ if (!function_exists('aksrt_render_paid_gallery')) {
<div class="swiper-wrapper">
<?php foreach ($images as $img_url) : ?>
<div class="swiper-slide">
<img src="<?php echo esc_url($img_url); ?>" alt="" loading="lazy">
<img<?php echo aksrt_get_lazy_attr('lazy_other', (string) $img_url, '', aksrt_get_lazy_thumb('lg')); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> alt="">
</div>
<?php endforeach; ?>
</div>
@@ -1255,7 +1255,7 @@ if (!function_exists('aksrt_render_paid_gallery')) {
<!-- 未付费:仅首图模糊预览,不输出完整图库 URL 列表 -->
<div class="aksrt-paid-gallery__locked">
<div class="aksrt-paid-gallery__preview">
<img src="<?php echo esc_url((string) $images[0]); ?>" alt="" class="aksrt-gallery-locked" loading="lazy">
<img<?php echo aksrt_get_lazy_attr('lazy_other', (string) $images[0], 'aksrt-gallery-locked', aksrt_get_lazy_thumb('lg')); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> alt="">
</div>
<div class="aksrt-paid-gallery__overlay">
<i class="fas fa-images" aria-hidden="true"></i>
@@ -1316,16 +1316,15 @@ if (!function_exists('aksrt_render_paid_video')) {
<div class="aksrt-paid-video" data-post-id="<?php echo esc_attr((string) $post->ID); ?>">
<?php if ($has_access) : ?>
<!-- 已付费:视频播放器 -->
<div class="aksrt-paid-video__player">
<?php if (preg_match('/\.(mp4|webm|ogg)$/i', $video_url)) : ?>
<video controls preload="metadata" style="width:100%;border-radius:var(--radius-lg);">
<source src="<?php echo esc_url($video_url); ?>">
<?php esc_html_e('您的浏览器不支持视频播放。', 'aksrt'); ?>
</video>
<?php else : ?>
<div class="aksrt-paid-video__embed">
<iframe src="<?php echo esc_url($video_url); ?>" frameborder="0" allowfullscreen></iframe>
</div>
<div class="aksrt-paid-video__player">
<?php if (preg_match('/\.(mp4|webm|ogg)$/i', $video_url)) : ?>
<video controls preload="metadata"<?php echo aksrt_is_lazy('lazy_posts_content') ? ' class="lazyload" src="" data-src="' . esc_url($video_url) . '"' : ' src="' . esc_url($video_url) . '"'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> style="width:100%;border-radius:var(--radius-lg);">
<?php esc_html_e('您的浏览器不支持视频播放。', 'aksrt'); ?>
</video>
<?php else : ?>
<div class="aksrt-paid-video__embed">
<iframe<?php echo aksrt_is_lazy('lazy_posts_content') ? ' class="lazyload" src="" data-src="' . esc_url($video_url) . '"' : ' src="' . esc_url($video_url) . '"'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> frameborder="0" allowfullscreen></iframe>
</div>
<?php endif; ?>
</div>
<?php else : ?>
+2 -4
View File
@@ -494,15 +494,13 @@ if (!function_exists('aksrt_render_related_graphic_card')) :
$views = function_exists('aksrt_get_post_views') ? (int) aksrt_get_post_views($post->ID) : 0;
$views_label = function_exists('aksrt_format_number') ? aksrt_format_number($views) : number_format_i18n($views);
$img_attrs = function_exists('aksrt_lazy_img_attrs')
? aksrt_lazy_img_attrs($thumb, 'cover', 'fit-cover')
: 'class="fit-cover" src="' . esc_url($thumb) . '" loading="lazy"';
$img_attrs = aksrt_get_lazy_attr('lazy_cover', (string) $thumb, 'fit-cover', aksrt_get_lazy_thumb('lg'));
$html = '<div class="swiper-slide mr10">';
$html .= '<div class="graphic style-3 mb10">';
$html .= '<a href="' . esc_url((string) $url) . '" class="radius8" title="' . esc_attr($title) . '">';
$html .= '<div class="graphic-img" style="padding-bottom:70%">';
$html .= '<img ' . $img_attrs . ' alt="' . esc_attr($title) . '">';
$html .= '<img' . $img_attrs . ' alt="' . esc_attr($title) . '">';
$html .= '<div class="abs-center left-bottom graphic-text">';
$html .= '<div class="text1 text-ellipsis">' . esc_html($title) . '</div>';
$html .= '<div class="text3 muted-2-color em09"><span class="item">' . esc_html($time) . '</span>';
+4 -6
View File
@@ -119,7 +119,7 @@ if (!function_exists('aksrt_single_render_cover')) :
<?php else : ?>
<div class="graphic mb20 single-cover single-cover--slide imgbox-container" style="padding-bottom:calc(<?php echo esc_attr((string) $img_scale); ?>% + 50px);">
<?php foreach ($slides as $idx => $slide_url) : ?>
<img src="<?php echo esc_url($slide_url); ?>" alt="" class="fit-cover" style="<?php echo $idx === 0 ? '' : 'display:none;'; ?>" loading="<?php echo $idx === 0 ? 'eager' : 'lazy'; ?>">
<img<?php echo aksrt_get_lazy_attr('lazy_sider', (string) $slide_url, 'fit-cover', aksrt_get_lazy_thumb('lg')); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> alt="" style="<?php echo $idx === 0 ? '' : 'display:none;'; ?>">
<?php endforeach; ?>
<?php echo $overlay; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
</div>
@@ -130,13 +130,11 @@ if (!function_exists('aksrt_single_render_cover')) :
endif;
// Image cover (default).
$img_attrs = function_exists('aksrt_lazy_img_attrs')
? aksrt_lazy_img_attrs((string) $ctx['cover_url'], 'cover', 'fit-cover')
: 'class="fit-cover" src="' . esc_url((string) $ctx['cover_url']) . '" loading="eager"';
$img_attrs = aksrt_get_lazy_attr('lazy_cover', (string) $ctx['cover_url'], 'fit-cover', aksrt_get_lazy_thumb('lg'));
?>
<div class="single-head-cover">
<div class="graphic mb20 single-cover imgbox-container" style="padding-bottom:calc(<?php echo esc_attr((string) $img_scale); ?>% + 50px);">
<img <?php echo $img_attrs; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> alt="<?php echo esc_attr(wp_strip_all_tags(get_the_title())); ?>">
<img<?php echo $img_attrs; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> alt="<?php echo esc_attr(wp_strip_all_tags(get_the_title())); ?>">
<div class="abs-center left-bottom single-cover-con">
<h1 class="article-title title-h-left"><?php echo $title_html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></h1>
<?php if ($crumbs !== '') : ?>
@@ -480,7 +478,7 @@ if (!function_exists('aksrt_single_render_author_card')) :
?>
<a class="item mr10 mb10" href="<?php echo esc_url(get_permalink($rp)); ?>" style="display:block;width:46%;">
<?php if ($thumb) : ?>
<img class="fit-cover radius8" src="<?php echo esc_url($thumb); ?>" alt="" loading="lazy" decoding="async" style="width:100%;aspect-ratio:16/10;object-fit:cover;" />
<img<?php echo aksrt_get_lazy_attr('lazy_posts_thumb', (string) $thumb, 'fit-cover radius8'); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> alt="" decoding="async" style="width:100%;aspect-ratio:16/10;object-fit:cover;">
<?php endif; ?>
<div class="em09 mt6 text-ellipsis"><?php echo esc_html(get_the_title($rp)); ?></div>
</a>
+1 -2
View File
@@ -137,8 +137,7 @@ function aksrt_render_slider(array $args = []): string {
}
if ($image) {
$html .= '<img class="swiper-lazy fit-cover" data-src="' . esc_url($image) . '" src="' . esc_url($image) . '" alt="' . esc_attr($alt) . '" loading="lazy">';
$html .= '<div class="swiper-lazy-preloader"></div>';
$html .= '<img' . aksrt_get_lazy_attr('lazy_sider', (string) $image, 'fit-cover', aksrt_get_lazy_thumb('lg')) . ' alt="' . esc_attr($alt) . '">';
}
if ($link) {
+1 -1
View File
@@ -125,7 +125,7 @@ if (!function_exists('aksrt_render_user_card_posts')) :
echo '<div class="swiper-slide mr10">';
echo '<a class="aksrt-more-post-card" href="' . esc_url(get_permalink($rp)) . '">';
if ($thumb) {
echo '<span class="aksrt-more-post-card__thumb"><img class="fit-cover" src="' . esc_url($thumb) . '" alt="" loading="lazy" decoding="async" /></span>';
echo '<span class="aksrt-more-post-card__thumb"><img' . aksrt_get_lazy_attr('lazy_posts_thumb', (string) $thumb, 'fit-cover') . ' alt="" decoding="async"></span>';
}
echo '<span class="aksrt-more-post-card__body">';
echo '<span class="aksrt-more-post-card__title text-ellipsis">' . esc_html($title) . '</span>';
+1 -1
View File
@@ -364,7 +364,7 @@ function aksrt_render_vip_badge(int $user_id = 0, string $size = 'sm'): string {
$icon_url = esc_url((string) ($vip_settings['levels'][$level]['img_icon'] ?? ''));
}
$icon = $icon_url !== ''
? '<img class="aksrt-vip-badge__icon" src="' . $icon_url . '" alt="" loading="lazy" decoding="async" />'
? '<img' . aksrt_get_lazy_attr('lazy_other', $icon_url, 'aksrt-vip-badge__icon') . ' alt="" decoding="async">'
: '<i class="fas fa-crown" aria-hidden="true"></i>';
return '<span class="aksrt-vip-badge aksrt-vip-badge--gold ' . esc_attr($size_class . ' ' . $level_class) . '" title="' . esc_attr($badge_text) . '">' . $icon . '</span>';
+9 -9
View File
@@ -88,12 +88,9 @@ if (!function_exists('aksrt_render_comment_smilie')) :
if (!isset($map[$lookup])) {
return '[g=' . esc_html($raw) . ']';
}
return sprintf(
'<img class="smilie-icon" src="%1$s" alt="%2$s" title="%2$s" width="30" height="30" loading="lazy" decoding="async" data-smilie="%3$s" />',
esc_url($map[$lookup]),
esc_attr('[' . $lookup . ']'),
esc_attr($lookup)
);
$label = esc_attr('[' . $lookup . ']');
return '<img' . aksrt_get_lazy_attr('lazy_comment', (string) $map[$lookup], 'smilie-icon', aksrt_get_lazy_thumb('sm'))
. ' alt="' . $label . '" title="' . $label . '" width="30" height="30" decoding="async" data-smilie="' . esc_attr($lookup) . '">';
}
endif;
@@ -103,9 +100,12 @@ if (!function_exists('aksrt_render_comment_content')) :
*/
function aksrt_render_comment_content(string $content): string {
// [img=url]
$rendered = preg_replace(
$rendered = preg_replace_callback(
'/\[img=(https?:\/\/[^\s\[\]]+)\]/i',
'<img class="box-img comment-inline-img" src="$1" alt="' . esc_attr__('评论图片', 'aksrt') . '" loading="lazy" decoding="async" />',
static function (array $matches): string {
return '<img' . aksrt_get_lazy_attr('lazy_comment', (string) $matches[1], 'box-img comment-inline-img', aksrt_get_lazy_thumb('lg'))
. ' alt="' . esc_attr__('评论图片', 'aksrt') . '" decoding="async">';
},
$content
);
// [code]...[/code]
@@ -134,7 +134,7 @@ if (!function_exists('aksrt_render_comment_content')) :
'title' => true,
'width' => true,
'height' => true,
'loading' => true,
'data-src' => true,
'decoding' => true,
'data-smilie' => true,
'data-src' => true,
+1 -1
View File
@@ -45,7 +45,7 @@ if (!function_exists('aksrt_get_input_expand_but')) :
$map = function_exists('aksrt_comment_smilie_map') ? aksrt_comment_smilie_map() : [];
$icons = '';
foreach ($map as $key => $url) {
$icons .= '<a class="smilie-icon" href="javascript:;" data-smilie="' . esc_attr((string) $key) . '"><img src="' . esc_url($url) . '" alt="[' . esc_attr((string) $key) . ']" width="28" height="28" loading="lazy" /></a>';
$icons .= '<a class="smilie-icon" href="javascript:;" data-smilie="' . esc_attr((string) $key) . '"><img' . aksrt_get_lazy_attr('lazy_comment', (string) $url, '', aksrt_get_lazy_thumb('sm')) . ' alt="[' . esc_attr((string) $key) . ']" width="28" height="28"></a>';
}
$but = '<a class="but btn-input-expand input-smilie mr6" href="javascript:;" data-toggle-class="open" data-target=".dropdown-smilie-wrap" title="' . esc_attr__('表情', 'aksrt') . '"><i class="fa fa-fw fa-smile-o" aria-hidden="true"></i><span class="hide-sm">' . esc_html__('表情', 'aksrt') . '</span></a>';
$drop = '<div class="dropdown-smilie-wrap relative dropup"><div class="dropdown-smilie scroll-y mini-scrollbar dropdown-menu">' . $icons . '</div></div>';
+4 -4
View File
@@ -148,7 +148,7 @@ if (!function_exists('aksrt_header_user_box_html')) :
if ($user_id > 0) {
$user = $ctx['current_user'] instanceof WP_User ? $ctx['current_user'] : wp_get_current_user();
$display_name = $user->display_name ?: $user->user_login;
$avatar = get_avatar($user_id, 44, '', esc_attr($display_name), ['loading' => 'lazy']);
$avatar = aksrt_get_avatar_html($user_id, 44, ['alt' => $display_name]);
$desc = (string) ($ctx['user_desc'] ?? '');
$vip_badge = function_exists('aksrt_render_vip_badge') ? aksrt_render_vip_badge($user_id, 'sm') : '';
// Level and certification icons ride inline to the right of the display name.
@@ -167,7 +167,7 @@ if (!function_exists('aksrt_header_user_box_html')) :
$icon_url = esc_url((string) ($signal['icon_url'] ?? ''));
$title = (string) ($signal['title'] ?? $signal['label'] ?? '');
if ($icon_url !== '' && $title !== '') {
$certification_badge = '<img class="aksrt-identity-certification-icon img-icon ml3" src="' . $icon_url . '" alt="" title="' . esc_attr($title) . '" loading="lazy" decoding="async" />';
$certification_badge = '<img' . aksrt_get_lazy_attr('lazy_other', $icon_url, 'aksrt-identity-certification-icon img-icon ml3') . ' alt="" title="' . esc_attr($title) . '" decoding="async">';
}
break;
}
@@ -329,7 +329,7 @@ if (!function_exists('aksrt_menu_button')) :
$user_sub = '<div class="padding-10">' . aksrt_header_user_box_html($ctx) . '</div>';
if ('2' === $layout) {
if ($user_id > 0) {
$avatar = get_avatar($user_id, 36, '', '', ['loading' => 'lazy', 'class' => 'avatar']);
$avatar = aksrt_get_avatar_html($user_id, 36, ['class' => 'avatar']);
$sign_but = '<li><a href="javascript:;" class="navbar-avatar">' . $avatar . '</a><ul class="sub-menu">'
. $user_sub . '</ul></li>';
} else {
@@ -340,7 +340,7 @@ if (!function_exists('aksrt_menu_button')) :
}
} else {
$trigger = $user_id > 0
? get_avatar($user_id, 36, '', '', ['loading' => 'lazy'])
? aksrt_get_avatar_html($user_id, 36)
: '<i class="fas fa-user" aria-hidden="true"></i>';
$cls = $user_id > 0 ? 'navbar-avatar' : 'btn signin-loader';
$dot = ($user_id > 0 && (int) ($ctx['unread_count'] ?? 0) > 0)
-24
View File
@@ -342,30 +342,6 @@ if (!function_exists('aksrt_renderer_resolve_images')) {
}
}
if (!function_exists('aksrt_renderer_lazyload_config')) {
/**
* Small lazyload config subset for post cards.
*
* @return array<string,mixed>
*/
function aksrt_renderer_lazyload_config(): array {
if (class_exists('\AKSRT\Settings\Settings')) {
$lazy = \AKSRT\Settings\Settings::get_lazyload_config();
return [
'enabled' => !empty($lazy['enabled']) && !empty($lazy['posts_thumb_enabled']),
'placeholder_url' => (string) ($lazy['placeholder_url'] ?? ''),
'blur' => !empty($lazy['blur']),
];
}
return [
'enabled' => false,
'placeholder_url' => '',
'blur' => false,
];
}
}
if (!function_exists('aksrt_renderer_thumb_ratio_value')) {
/**
* Convert ratio tokens like 4:3 to CSS aspect ratio values.
+5 -4
View File
@@ -169,10 +169,11 @@ if (!function_exists('aksrt_renderer_mini')) {
$thumb_html = '';
$target_attr = !empty($cfg['target_blank']) ? ' target="_blank"' : '';
if ($cfg['show_thumb'] && !empty($data['has_img'])) {
$lazy = $data['lazy'];
$thumb_img = !empty($lazy['enabled']) && !empty($data['has_real_img'])
? '<span class="aksrt-skeleton"></span><img class="' . (!empty($cfg['thumb_fit']) && $cfg['thumb_fit'] === 'contain' ? 'fit-contain' : 'fit-cover') . ' aksrt-lazy lazyload" data-src="' . esc_url($data['img_url']) . '" src="' . esc_url($lazy['placeholder_url']) . '" alt="' . esc_attr($data['title']) . '">'
: '<img class="fit-cover" src="' . esc_url($data['img_url']) . '" alt="' . esc_attr($data['title']) . '"' . (!empty($data['has_real_img']) ? ' loading="lazy"' : '') . '>';
$fit_class = !empty($cfg['thumb_fit']) && $cfg['thumb_fit'] === 'contain' ? 'fit-contain' : 'fit-cover';
$thumb_attr = !empty($cfg['thumb_lazy'])
? aksrt_get_lazy_attr('lazy_posts_thumb', (string) $data['img_url'], $fit_class)
: ' class="' . esc_attr($fit_class) . '" src="' . esc_url($data['img_url']) . '"';
$thumb_img = '<img' . $thumb_attr . ' alt="' . esc_attr($data['title']) . '">';
$thumb_html = '<a href="' . esc_url($data['permalink']) . '" class="item-thumbnail" aria-label="' . esc_attr($data['title']) . '"' . $target_attr . '>' . $thumb_img . '</a>';
}
+7 -19
View File
@@ -20,9 +20,6 @@ if (!function_exists('aksrt_renderer_collect_post_data')) {
return [];
}
$lazy = aksrt_renderer_lazyload_config();
$lazy['enabled'] = !empty($lazy['enabled']) && !empty($cfg['thumb_lazy']);
$images = aksrt_renderer_resolve_images($post_id, $cfg);
$gallery_images = array_slice($images['gallery'], 0, $cfg['multi_thumb_limit']);
$is_mult_thumb = !empty($cfg['multi_thumb_enabled'])
@@ -71,7 +68,6 @@ if (!function_exists('aksrt_renderer_collect_post_data')) {
'resource_strip' => $resource_strip,
'is_resource' => function_exists('aksrt_is_resource_post') ? aksrt_is_resource_post($post_id) : false,
'is_sticky' => is_sticky($post_id),
'lazy' => $lazy,
'thumb_ratio_css' => aksrt_renderer_thumb_ratio_value((string) $cfg['thumb_ratio']),
'thumb_ratio_key' => (string) $cfg['thumb_ratio'],
];
@@ -110,19 +106,17 @@ if (!function_exists('aksrt_renderer_thumb')) {
return '';
}
$lazy = $data['lazy'];
$img = (string) $data['img_url'];
$title = (string) $data['title'];
$href = (string) $data['permalink'];
$is_sticky = !empty($data['is_sticky']);
$has_real_img = !empty($data['has_real_img']);
if ($has_real_img && !empty($lazy['enabled'])) {
$img_html = '<span class="aksrt-skeleton"></span>'
. '<img class="' . (!empty($cfg['thumb_fit']) && $cfg['thumb_fit'] === 'contain' ? 'fit-contain' : 'fit-cover') . ' aksrt-lazy lazyload" data-src="' . esc_url($img) . '" src="' . esc_url($lazy['placeholder_url']) . '" alt="' . esc_attr($title) . '">';
} else {
$img_html = '<img class="' . (!empty($cfg['thumb_fit']) && $cfg['thumb_fit'] === 'contain' ? 'fit-contain' : 'fit-cover') . '" src="' . esc_url($img) . '" alt="' . esc_attr($title) . '"' . ($has_real_img ? ' loading="lazy"' : '') . '>';
}
$fit_class = !empty($cfg['thumb_fit']) && $cfg['thumb_fit'] === 'contain' ? 'fit-contain' : 'fit-cover';
$img_attr = !empty($cfg['thumb_lazy'])
? aksrt_get_lazy_attr('lazy_posts_thumb', $img, $fit_class)
: ' class="' . esc_attr($fit_class) . '" src="' . esc_url($img) . '"';
$img_html = '<img' . $img_attr . ' alt="' . esc_attr($title) . '">';
$sticky_html = ($is_sticky && !empty($cfg['badge_show']))
? '<badge class="img-badge left jb-red">' . esc_html__('置顶', 'aksrt') . '</badge>'
@@ -164,17 +158,11 @@ if (!function_exists('aksrt_renderer_mult_thumb')) {
return '';
}
$lazy = $data['lazy'];
$html = '<a class="thumb-items contain" href="' . esc_url($data['permalink']) . '" aria-label="' . esc_attr($data['title']) . '">';
foreach (array_slice($data['gallery_images'], 0, 4) as $image) {
$html .= '<span>';
if (!empty($lazy['enabled'])) {
$html .= '<span class="aksrt-skeleton"></span>'
. '<img class="fit-cover aksrt-lazy lazyload" data-src="' . esc_url($image) . '" src="' . esc_url($lazy['placeholder_url']) . '" alt="">';
} else {
$html .= '<img class="fit-cover" src="' . esc_url($image) . '" alt="" loading="lazy">';
}
$html .= '<img' . aksrt_get_lazy_attr('lazy_posts_thumb', (string) $image, 'fit-cover') . ' alt="">';
$html .= '</span>';
}
@@ -277,7 +265,7 @@ if (!function_exists('aksrt_renderer_meta')) {
$left = [];
if (!empty($cfg['show_author'])) {
$left[] = '<item class="meta-author flex ac"><img src="' . esc_url($data['avatar_url']) . '" alt="" class="avatar-mini" width="20" height="20" loading="lazy"><name class="meta-name">' . esc_html($data['author_name']) . '</name></item>';
$left[] = '<item class="meta-author flex ac"><img' . aksrt_get_lazy_attr('lazy_avatar', (string) $data['avatar_url'], 'avatar-mini', aksrt_get_lazy_thumb('sm')) . ' alt="" width="20" height="20"><name class="meta-name">' . esc_html($data['author_name']) . '</name></item>';
}
if (!empty($cfg['show_date'])) {
$left[] = '<item class="meta-time">' . esc_html($data['time_ago']) . '</item>';
+2 -4
View File
@@ -187,10 +187,8 @@ function aksrt_render_slider_markup(array $slides, array $args = array()) {
<div class="swiper-slide"<?php if (! empty($slide['link'])) : ?> data-link="<?php echo esc_url($slide['link']); ?>"<?php endif; ?>>
<div class="hero__slide-bg">
<?php if (! empty($slide['image'])) : ?>
<img
src="<?php echo esc_url($slide['image']); ?>"
<img<?php echo aksrt_get_lazy_attr('lazy_sider', (string) $slide['image'], 'fit-cover', aksrt_get_lazy_thumb('lg')); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
alt="<?php echo esc_attr($slide['title'] ?: get_bloginfo('name')); ?>"
loading="<?php echo 0 === $index ? 'eager' : 'lazy'; ?>"
decoding="async"
>
<?php else : ?>
@@ -451,6 +449,6 @@ function aksrt_get_adaptive_theme_img(string $white_src = '', string $dark_src =
}
$this_src = $is_dark ? $dark_src : $white_src;
return '<img src="' . esc_url($this_src) . '" white-src="' . esc_url($white_src) . '" dark-src="' . esc_url($dark_src) . '" alt="' . esc_attr($alt) . '"' . ($more !== '' ? ' ' . $more : '') . ' loading="lazy">';
return '<img' . aksrt_get_lazy_attr('lazy_other', (string) $this_src) . ' white-src="' . esc_url($white_src) . '" dark-src="' . esc_url($dark_src) . '" alt="' . esc_attr($alt) . '"' . ($more !== '' ? ' ' . $more : '') . '>';
}
endif;
@@ -109,9 +109,8 @@ if (!function_exists('aksrt_render_pagination')) {
data-max-pages="<?php echo esc_attr((string) $max_pages); ?>"
data-query-context="<?php echo esc_attr($query_context); ?>"
data-query-vars="<?php echo esc_attr(wp_json_encode($query_vars)); ?>"
data-render-config="<?php echo esc_attr(wp_json_encode($render_config)); ?>"
data-lazyload-action="ias">
<div class="next-page ajax-next aksrt-load-more-btn" lazyload-action="ias" role="button" tabindex="0">
data-render-config="<?php echo esc_attr(wp_json_encode($render_config)); ?>">
<div class="next-page ajax-next aksrt-load-more-btn<?php echo $pagination_mode === 'infinite' ? ' lazyload' : ''; ?>"<?php echo $pagination_mode === 'infinite' ? ' lazyload-action="ias"' : ''; ?> role="button" tabindex="0">
<?php echo esc_html($trigger_text); ?>
</div>
<div class="aksrt-loading-indicator" style="display:none;" aria-hidden="true">
@@ -175,66 +174,176 @@ function aksrt_auto_image_alt(string $content): string {
add_filter('the_content', 'aksrt_auto_image_alt', 999);
/**
* 懒加载 per-scope 开关判断
* Detect search-engine crawlers that must receive real image URLs.
*
* 检查总开关 + 指定 scope 开关。
*
* @param string $scope avatar|content|comment|private|slider|cover|other|widget
* @return bool
* @return string|false Matched crawler name, or false.
*/
function aksrt_is_lazyload_enabled(string $scope = 'other'): bool {
if (!class_exists('\AKSRT\Settings\Settings')) return true; // 默认开
$cfg = \AKSRT\Settings\Settings::get_lazyload_config();
if (!$cfg['enabled']) return false;
return !empty($cfg[$scope] ?? true);
function aksrt_is_crawler() {
static $crawler = null;
if ($crawler !== null) {
return $crawler;
}
$bots = [
'Baidu' => 'baiduspider', 'Google Bot' => 'google', '360spider' => '360spider',
'Sogou' => 'spider', 'soso.com' => 'sosospider', 'MSN' => 'msnbot',
'Alex' => 'ia_archiver', 'Lycos' => 'lycos', 'Ask Jeeves' => 'jeeves',
'Altavista' => 'scooter', 'AllTheWeb' => 'fast-webcrawler', 'Inktomi' => 'slurp@inktomi',
'Turnitin.com' => 'turnitinbot', 'Technorati' => 'technorati', 'Yahoo' => 'yahoo',
'Findexa' => 'findexa', 'NextLinks' => 'findlinks', 'Gais' => 'gaisbo',
'WiseNut' => 'zyborg', 'WhoisSource' => 'surveybot', 'Bloglines' => 'bloglines',
'BlogSearch' => 'blogsearch', 'PubSub' => 'pubsub', 'Syndic8' => 'syndic8',
'RadioUserland' => 'userland', 'Gigabot' => 'gigabot', 'Become.com' => 'become.com',
'Yandex' => 'yandex',
];
$user_agent = strtolower((string) ($_SERVER['HTTP_USER_AGENT'] ?? ''));
$crawler = false;
foreach ($bots as $name => $needle) {
if ($user_agent !== '' && stripos($user_agent, $needle) !== false) {
$crawler = $name;
break;
}
}
return $crawler;
}
/**
* 返回 img 标签的 lazy-loading 属性字符串
*
* 当 scope 启用懒加载时:class="aksrt-lazy" + data-src(需配合 skeleton 使用)
* 当 scope 禁用时:loading="lazy"(浏览器原生)
*
* @param string $url 图片 URL
* @param string $scope 场景名
* @param string $extra_class 额外 CSS 类
* @return string HTML 属性字符串
* Determine whether one Zibll-style lazy-loading scope is enabled.
*/
function aksrt_lazy_img_attrs(string $url, string $scope = 'other', string $extra_class = ''): string {
if (empty($url)) return '';
if (aksrt_is_lazyload_enabled($scope)) {
$cfg = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::get_lazyload_config() : [];
$placeholder = $cfg['placeholder_url'] ?? '';
$animation = $cfg['animation'] ?? 'blur';
$cls = trim('fit-cover aksrt-lazy ' . $extra_class);
$attrs = sprintf('class="%s" data-src="%s" data-lazy-animation="%s"', esc_attr($cls), esc_url($url), esc_attr($animation));
if ($placeholder) {
$attrs .= sprintf(' src="%s"', esc_url($placeholder));
}
return $attrs;
}
// 原生 lazy
$cls = trim('fit-cover ' . $extra_class);
return sprintf('class="%s" src="%s" loading="lazy"', esc_attr($cls), esc_url($url));
function aksrt_is_lazy(string $key, bool $default = false): bool {
if (aksrt_is_crawler()) {
return false;
}
$defaults = [
'lazy_posts_thumb' => true,
'lazy_avatar' => true,
'lazy_posts_content' => false,
'lazy_comment' => true,
'lazy_private' => true,
'lazy_sider' => true,
'lazy_cover' => true,
'lazy_other' => true,
];
$default = array_key_exists($key, $defaults) ? $defaults[$key] : $default;
if (!class_exists('\AKSRT\Settings\Settings')) {
return $default;
}
return (bool) \AKSRT\Settings\Settings::get_value($key, $default);
}
/**
* 返回条件懒加载 loading 属性字符串
*
* 当指定 scope 启用懒加载时返回 loading="lazy",否则返回空字符串。
*
* @param string $scope 场景名 (cover|other 等)
* @return string HTML 属性字符串
* Return the configured lazy placeholder or a bundled size variant.
*/
function aksrt_lazy_loading(string $scope = 'other'): string {
if (function_exists('aksrt_is_lazyload_enabled') && aksrt_is_lazyload_enabled($scope)) {
return ' loading="lazy"';
}
return '';
function aksrt_get_lazy_thumb(string $size = ''): string {
$configured = $size === '' && class_exists('\AKSRT\Settings\Settings')
? (string) \AKSRT\Settings\Settings::get_value('thumbnail', '')
: '';
if ($configured !== '') {
return $configured;
}
$suffix = $size !== '' ? '-' . sanitize_key($size) : '';
return get_template_directory_uri() . '/assets/img/thumbnail' . $suffix . '.svg';
}
/**
* Build the only supported lazy-media attribute set.
*/
function aksrt_get_lazy_attr(string $key, string $src, string $class = '', string $lazy_src = ''): string {
$class = trim($class);
if ($src === '') {
return ' class="' . esc_attr($class) . '" src=""';
}
if (!aksrt_is_lazy($key)) {
return ' class="' . esc_attr($class) . '" src="' . esc_url($src) . '"';
}
$lazy_src = $lazy_src !== '' ? $lazy_src : aksrt_get_lazy_thumb();
return ' class="lazyload ' . esc_attr($class) . '" src="' . esc_url($lazy_src) . '" data-src="' . esc_url($src) . '"';
}
/**
* Remove Zibll-style lazy attributes from a rendered image string.
*/
function aksrt_str_remove_lazy(string $html = ''): string {
$pattern = "/<img(.*?)src=('|\")(.*?)('|\") data-src=('|\")(.*?)('|\")(.*?)>/i";
$replacement = '<img$1src=$5$6$7$8>';
return (string) preg_replace($pattern, $replacement, str_replace('lazyload', '', $html));
}
/**
* Convert post-content images to the same lazySizes contract as Zibll.
*/
function aksrt_lazy_content_images(string $content): string {
if ((is_admin() && !wp_doing_ajax()) || !aksrt_is_lazy('lazy_posts_content')) {
return $content;
}
$placeholder = esc_url(aksrt_get_lazy_thumb('lg'));
$content = (string) preg_replace(
"/<img(.*?)src=('|\")([^>]*).(bmp|gif|jpeg|jpg|png|ico|tiff|svg|webp)('|\")(.*?)>/i",
'<img$1src="' . $placeholder . '" data-src=$2$3.$4$5 $6>',
$content
);
return (string) preg_replace(
"/<img(.*?)srcset=('|\")([^>]*)('|\")(.*?)>/i",
'<img$1data-srcset=$2$3$4 $5>',
$content
);
}
add_filter('the_content', 'aksrt_lazy_content_images', 10);
/**
* Route WordPress-generated attachment images through the same lazySizes path.
*
* @param array<string,string> $attr Image attributes.
* @param WP_Post $attachment Attachment post.
* @return array<string,string>
*/
function aksrt_lazy_attachment_attributes(array $attr, $attachment): array {
unset($attr['loading'], $attr['fetchpriority']);
if ((is_admin() && !wp_doing_ajax()) || empty($attr['src']) || !empty($attr['data-src'])) {
return $attr;
}
$key = 'lazy_other';
$placeholder_size = '';
$attachment_id = is_object($attachment) ? (int) $attachment->ID : 0;
if ($attachment_id > 0 && $attachment_id === (int) get_post_thumbnail_id()) {
$key = is_singular() ? 'lazy_cover' : 'lazy_posts_thumb';
$placeholder_size = is_singular() ? 'lg' : '';
}
if (!aksrt_is_lazy($key)) {
return $attr;
}
$attr['data-src'] = (string) $attr['src'];
$attr['src'] = aksrt_get_lazy_thumb($placeholder_size);
if (!empty($attr['srcset'])) {
$attr['data-srcset'] = (string) $attr['srcset'];
unset($attr['srcset']);
}
$attr['class'] = trim('lazyload ' . (string) ($attr['class'] ?? ''));
return $attr;
}
add_filter('wp_get_attachment_image_attributes', 'aksrt_lazy_attachment_attributes', 10, 2);
/**
* Convert avatars produced directly by WordPress into the avatar lazy scope.
*/
function aksrt_lazy_avatar_html(string $avatar): string {
$avatar = (string) preg_replace('/\sloading=("|\')[^"\']*("|\')/i', '', $avatar);
if ((is_admin() && !wp_doing_ajax()) || !aksrt_is_lazy('lazy_avatar') || str_contains($avatar, 'data-src=')) {
return $avatar;
}
$avatar = preg_replace('/\ssrc=("|\')([^"\']+)("|\')/i', ' src="' . esc_url(aksrt_get_default_avatar_url()) . '" data-src="$2"', $avatar, 1);
if (str_contains($avatar, 'class="')) {
return str_replace('class="', 'class="lazyload ', (string) $avatar);
}
return str_replace('<img ', '<img class="lazyload" ', (string) $avatar);
}
add_filter('get_avatar', 'aksrt_lazy_avatar_html', 20);
// The theme uses lazySizes exclusively; WordPress must not add a native lazy path.
add_filter('wp_lazy_loading_enabled', '__return_false');
// ================================================================
// §8.1 Global capability check helper
// ================================================================
@@ -406,4 +515,3 @@ if (!function_exists('aksrt_render_footer_tabbar_single_extend')) :
endif;
}
endif;
@@ -52,7 +52,7 @@ if ($vip_level >= 1 && !empty($vip_settings['levels'][$vip_level]['name'])) {
$level_icon_url = esc_url((string) ($vip_settings['levels'][$vip_level]['img_icon'] ?? ''));
$level_icon = $level_icon_url !== ''
? '<img class="aksrt-vip-level-icon" src="' . $level_icon_url . '" alt="" loading="lazy" decoding="async">'
? '<img' . aksrt_get_lazy_attr('lazy_other', $level_icon_url, 'aksrt-vip-level-icon') . ' alt="" decoding="async">'
: '<i class="fas fa-crown" aria-hidden="true"></i>';
if (class_exists('\AKSRT\Settings\Settings')) {
$paid_display = \AKSRT\Settings\Settings::get_paid_content_settings();
@@ -63,7 +63,7 @@ $day_max = \AKSRT\User\Level::day_max();
<div class="uc-level-road__item<?php echo esc_attr($state); ?>">
<div class="uc-level-road__icon">
<?php $icon = \AKSRT\User\Level::get_level_icon_url($level); ?>
<?php if ($icon !== '') : ?><img src="<?php echo esc_url($icon); ?>" alt="" loading="lazy"><?php else : ?><span>LV<?php echo esc_html((string) $level); ?></span><?php endif; ?>
<?php if ($icon !== '') : ?><img<?php echo aksrt_get_lazy_attr('lazy_other', (string) $icon); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> alt=""><?php else : ?><span>LV<?php echo esc_html((string) $level); ?></span><?php endif; ?>
</div>
<strong><?php echo esc_html($name); ?></strong>
<small><?php echo esc_html((string) $need); ?> EXP</small>
@@ -48,7 +48,7 @@ if ($vip_level > 0) {
$sidebar_level = $vip_level > 0 ? $vip_level : $expired_level;
$sidebar_icon_url = esc_url((string) ($vip_levels[$sidebar_level]['img_icon'] ?? ''));
$sidebar_icon = $sidebar_icon_url !== ''
? '<img class="aksrt-vip-level-icon" src="' . $sidebar_icon_url . '" alt="" loading="lazy" decoding="async">'
? '<img' . aksrt_get_lazy_attr('lazy_other', $sidebar_icon_url, 'aksrt-vip-level-icon') . ' alt="" decoding="async">'
: '<i class="fas fa-crown" aria-hidden="true"></i>';
?>
<a class="uc-sidebar-vip" href="<?php echo esc_url($vip_url); ?>" data-tab="vip">
@@ -92,7 +92,7 @@ if ($level > 0) {
$status_icon_url = esc_url((string) ($levels[$vip_level_number]['img_icon'] ?? ''));
$status_icon = $status_icon_url !== ''
? '<img class="aksrt-vip-level-icon" src="' . $status_icon_url . '" alt="" loading="lazy" decoding="async">'
? '<img' . aksrt_get_lazy_attr('lazy_other', $status_icon_url, 'aksrt-vip-level-icon') . ' alt="" decoding="async">'
: '<i class="fas fa-crown"></i>';
$status_html = '<div class="uc-vip-status" role="status">'
. '<div class="uc-vip-status__heading">'
@@ -124,7 +124,7 @@ foreach ([1, 2] as $lv) {
$vip_attr = $lv;
$lv_icon_url = esc_url((string) ($levels[$lv]['img_icon'] ?? ''));
$lv_icon = $lv_icon_url !== ''
? '<img class="aksrt-vip-level-icon" src="' . $lv_icon_url . '" alt="" loading="lazy" decoding="async">'
? '<img' . aksrt_get_lazy_attr('lazy_other', $lv_icon_url, 'aksrt-vip-level-icon') . ' alt="" decoding="async">'
: '<i class="fas fa-crown" aria-hidden="true"></i>';
if (str_starts_with($btn_type, 'renew_')) {
$renew_lv = (int) substr($btn_type, 6);