【问题标题】:Frontend Buddypress Notifications - Show for Current User Only前端 Buddypress 通知 - 仅显示给当前用户
【发布时间】:2021-03-31 19:14:02
【问题描述】:

我添加了一个自定义滑出框以在任何页面上显示用户的 Buddypress 通知。

https://imgur.com/ellepqp

我基本上是在呼应 Buddypress 插件 Youzify(以前称为 Youzer)的模板部分。 Youzify 只是重新设计 Buddypress 的扩展,所以我认为这个问题不一定与此有关,而是与原生 Buddypress 有关。

当我在任何标准的 Wordpress 页面上时,我都能获得当前用户的通知。但是,如果我在用户的个人资料中,它会显示他们的通知!我知道默认情况下,如果管理员只是将 /notifications 添加到任何配置文件中,管理员实际上可以看到所有通知,但标准用户也会发生这种情况。

这是当前代码:

<?php global $bp; 

if( bp_has_notifications($bp->loggedin_user->id) ) : ?>

    <?php bp_get_template_part( 'members/single/notifications/notifications-loop' ); ?>

<div class="read-all-notifs"><a href="<?php bp_notifications_unread_permalink($bp->loggedin_user->id); ?>"> View All Notifications</a></div>

<?php else : ?>

    <?php bp_get_template_part( 'members/single/notifications/feedback-no-notifications' ); ?>


<?php endif; ?>

我认为这与模板部分和某些在 Buddypress 页面上强制使用 bp_displayed_user ID 的函数有关,所以我如何覆盖它以确保弹出窗口中的通知始终适用于任何页面上的当前用户?有人有想法么?谢谢。

【问题讨论】:

    标签: wordpress notifications buddypress


    【解决方案1】:

    我在开发人员的帮助下解决了这个问题。这是初始部分的正确格式:

    <?php if ( is_user_logged_in() && bp_has_notifications( array('user_id' => bp_loggedin_user_id(), 'per_page' => 10, 'search_terms' => false ) ) ) : ?>
    

    添加了搜索词部分,因为在任何搜索结果页面上,它都会为所有人显示“无通知”循环。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-17
      • 1970-01-01
      • 2013-12-06
      • 1970-01-01
      • 2021-08-04
      相关资源
      最近更新 更多