自留地
切勿乱来!
     找回密码

基于Chrome的添加到桌面应用Web APP 扩展修改

周涛 发布于 2025-12-15 18:57 分类:讨论 阅读

1769150301-1753066748
https://www.ediok.cn/blog/2025/07/6193.html 基于这个教程的二次扩展,增加安装次数记录

在JS部分的最后一个});上面增加ajax回调函数:

  window.addEventListener('appinstalled', () => {
        $.post(TBUI.ajaxurl, {
            action: 'install_notification_popup',
            nonce: TBUI.nonce
        });
  });

主题的functions.php里找个合适的位置增加如下代码:

add_action('wp_ajax_install_notification_popup', 'install_notification_popup');
add_action('wp_ajax_nopriv_install_notification_popup', 'install_notification_popup');
//WebAPP安装统计
function install_notification_popup() {
    check_ajax_referer('install_notification_popup', 'nonce');
    $current_count = get_option('install_notification_popup', 0);
    $popup = $current_count + 1;
    update_option( 'install_notification_popup', $popup );
    wp_send_json_success();
}

这是在安装的时候回调函数执行的ajax,在option表里增加一个自增的install_notification_popup

然后继续增加如下代码

//WebAPP安装统计widget
add_action('wp_dashboard_setup', 'my_custom_install_notification_popup');
function my_custom_install_notification_popup() {
    wp_add_dashboard_widget(
        'custom_dashboard_widget',
        'WebAPP安装',
        'custom_install_notification_popup'
    );
}
function custom_install_notification_popup() {
    // 获取并显示参数
    $custom_param = get_option('install_notification_popup', '0');
    echo '<ul class="wp_baidu_list"><li class="wp_baidu_other"><p>安装数量:<b style="font-size:24px">' . esc_html($custom_param) . '</b></p></li></ul>';
}

在后台首页增加一个名为WebAPP安装的widget仪表盘,显示安装数量

0个回复

  • 暂无回复
1 赞收藏

回复前必须登录!

 

关注互联网发展前沿,关注PHPCMS技术演进,钻研PHPCMS技术开发

问答社区 联系我们

登录

登录即表示同意本站用户协议、隐私政策
©2026 周涛博客 All rights reserved

注册

注册即表示同意本站用户协议、隐私政策
©2026 周涛博客 All rights reserved

觉得文章有用就打赏一下文章作者

非常感谢你的打赏,我们将继续给力更多优质内容,让我们一起创建更加美好的网络世界!

微信扫一扫

微信扫一扫