Fix hot reload infinite loop and graceful degradation for Duolingo badge API block

This commit is contained in:
User
2026-03-12 16:05:56 +08:00
parent 3eaef5b06a
commit 0387c7d9e5
3 changed files with 11 additions and 10 deletions

View File

@@ -522,7 +522,7 @@ function argon_frontend_hot_reload_notice() {
<div style="display:flex;align-items:center;margin-bottom:8px;"> <div style="display:flex;align-items:center;margin-bottom:8px;">
<span style="background:var(--themecolor,#5e72e4);color:#fff;padding:2px 8px;border-radius:4px;font-size:12px;margin-right:8px;"><?php _e('热更新', 'argon'); ?></span> <span style="background:var(--themecolor,#5e72e4);color:#fff;padding:2px 8px;border-radius:4px;font-size:12px;margin-right:8px;"><?php _e('热更新', 'argon'); ?></span>
<strong><?php _e('主题已更新', 'argon'); ?></strong> <strong><?php _e('主题已更新', 'argon'); ?></strong>
<span onclick="document.getElementById('argon-hot-reload-frontend-notice').remove();jQuery.post(ajaxurl,{action:'argon_dismiss_update_notice',nonce:'<?php echo wp_create_nonce('argon_dismiss_update_notice'); ?>',index:-1});" style="margin-left:auto;cursor:pointer;opacity:0.5;font-size:18px;">&times;</span> <span onclick="document.getElementById('argon-hot-reload-frontend-notice').remove();jQuery.post('<?php echo admin_url('admin-ajax.php'); ?>',{action:'argon_dismiss_update_notice',nonce:'<?php echo wp_create_nonce('argon_dismiss_update_notice'); ?>',index:-1});" style="margin-left:auto;cursor:pointer;opacity:0.5;font-size:18px;">&times;</span>
</div> </div>
<p style="margin:0;color:#666;font-size:14px;"> <p style="margin:0;color:#666;font-size:14px;">
<?php echo sprintf( <?php echo sprintf(
@@ -5285,14 +5285,10 @@ function argon_get_duolingo_data() {
'headers' => $headers 'headers' => $headers
)); ));
// 如果返回了诸如 401/403 错误JWT 过期或无效),尝试移除 JWT 重新获取,确保基础连胜可见 // 如果返回了诸如 401/403 错误,说明可能遭到了 Cloudflare 拦截或者是 JWT 无效
if (!is_wp_error($response) && wp_remote_retrieve_response_code($response) !== 200 && !empty($jwt)) { // 我们直接返回缓存,而不是剥离 JWT 去重试,因为当前服务器 IP 很可能就是被封的
unset($headers['Authorization']); if (!is_wp_error($response) && wp_remote_retrieve_response_code($response) !== 200) {
$response = wp_remote_get($url, array( return $cached !== false ? $cached : false;
'timeout' => 15,
'headers' => $headers
));
$jwt = ''; // 标记为无效,后续不请求私有好友连胜数据
} }
if (is_wp_error($response)) { if (is_wp_error($response)) {

View File

@@ -670,6 +670,11 @@ $author_desc = get_option('argon_sidebar_author_description');
<span class="duolingo-streak<?php echo $is_today_done ? '' : ' not-done'; ?>"<?php echo $tooltip_attr; ?>> <span class="duolingo-streak<?php echo $is_today_done ? '' : ' not-done'; ?>"<?php echo $tooltip_attr; ?>>
<img src="<?php echo get_template_directory_uri(); ?>/assets/icons/duolingo-streak<?php echo $is_today_done ? '' : '-empty'; ?>.svg" class="duolingo-flame" alt="streak"> <img src="<?php echo get_template_directory_uri(); ?>/assets/icons/duolingo-streak<?php echo $is_today_done ? '' : '-empty'; ?>.svg" class="duolingo-flame" alt="streak">
<?php echo $duo_data['streak']; ?> <?php echo $duo_data['streak']; ?>
</span>
<?php else: ?>
<span class="duolingo-streak not-done" data-toggle="tooltip" data-placement="bottom" title="<?php _e('API 获取失败 / 用户名错误 / 或被频控拦截', 'argon'); ?>">
<img src="<?php echo get_template_directory_uri(); ?>/assets/icons/duolingo-streak-empty.svg" class="duolingo-flame" alt="streak">
?
</span> </span>
<?php endif; endif; ?> <?php endif; endif; ?>
</h6> </h6>

View File

@@ -8,7 +8,7 @@ Author URI: https://solstice23.top/
Description: 轻盈、简洁、美观的 Wordpress 主题 Description: 轻盈、简洁、美观的 Wordpress 主题
Version: 1.5.1 Version: 1.5.3
License: GNU General Public License v3.0 License: GNU General Public License v3.0