You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用WordPress admin-notices钩子无法添加后台通知求助

WordPress后台管理员通知不显示问题求助

我在收到API的特定响应时,尝试为WordPress后台添加管理员通知。日志已正常记录API配额超限的信息,且通过代码验证确认钩子已正确挂载,但后台始终无法显示通知,求技术帮助。

触发通知的代码(位于某函数内部)

if ( isset( $response_body['error'] ) && $response_body['error']['message'] === 'You exceeded your current quota, please check your plan and billing details.' ) {
    add_action( 'admin_notices', 'display_admin_notice' );
    function display_admin_notice() {
        ?>
        <div class="notice notice-error">
            <p><?php _e( 'API LIMIT reached. Please re-check your API credit for the plugin to work properly.', 'my-plugin-textdomain' ); ?></p>
        </div>
        <?php
    }
    error_log('API LIMIT EXCEEDED');
}
}

钩子验证代码(更新内容)

我用以下代码验证钩子是否挂载成功,日志显示钩子已正确挂载,但通知仍未显示:

if ( !add_action( 'admin_notices', 'display_admin_notice', 10, 1 ) ) {
    error_log( 'Hooked the notification correctly.' );
}

内容的提问来源于stack exchange,提问作者TECH FREEKS

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.24 21:09:57