Search Results for 'notification user id'
-
Search Results
-
Hello,
I have a follow up question to this old thread:
https://buddypress.org/support/topic/how-to-get-notification-count-code/chatty24 asked “Could that also happen in real time (without refreshing the page)?”.
I am having the same question. How can I ajaxify “bp_notifications_get_unread_notification_count( $user_id)”?
Thanks for any help!
BuddyPress site-wide notifications work well for me on all platforms except Android.
On Android the notification is transparent – superimposed over the page and the dismiss button does not work. There is no way to dismiss it.
Confirmed using
Wordpress 6.6.2
Buddypress 14.1.0
No other plugins except StopEmails and UserSwitching
Theme: Twenty Tweny-FourTopic: Unable to register users
I’m trying to troubleshoot my BuddyPress registration form, which seems to be having some serious problems. I should start by noting that I have added some customizations to my form to add additional data fields, but the registration fails regardless of whether the customizations and overrides are enabled or disabled, and fails in exactly the same manner based on the error log, so the customizations are unlikely to be having an impact.
Here are the hooks that I am using to track where the problem is originating from:
// Hook into various stages of the BuddyPress registration process
add_action( ‘bp_before_registration_submit_buttons’, ‘log_before_registration_submit_buttons’ );
add_action( ‘bp_core_screen_signup’, ‘log_core_screen_signup’ );
add_action( ‘bp_signup_pre_validate’, ‘log_signup_pre_validate’ );
add_action( ‘bp_signup_validate’, ‘ex_custom_bp_signup_validate’ );
add_action( ‘bp_core_signup_user’, ‘log_core_signup_user’, 10, 2 );
add_action( ‘bp_core_activate_user’, ‘log_core_activate_user’, 10, 3 );
add_filter( ‘bp_core_validate_user_signup’, ‘log_core_validate_user_signup’ );
add_filter( ‘bp_core_signup_user_notification’, ‘log_core_signup_user_notification’, 10, 2 );function log_before_registration_submit_buttons() {
error_log( ‘Hook: bp_before_registration_submit_buttons fired.’ );
}function log_core_screen_signup() {
error_log( ‘Hook: bp_core_screen_signup fired.’ );
error_log( ‘Form submission data: ‘ . print_r( $_POST, true ) );
}function log_signup_pre_validate() {
error_log( ‘Hook: bp_signup_pre_validate fired.’ );
}function ex_custom_bp_signup_validate() {
global $bp;
error_log( ‘bp_signup_validate hook fired. Validation errors: ‘ . print_r( $bp->signup->errors, true ) );
}function log_core_signup_user( $user_id, $user_data ) {
error_log( ‘Hook: bp_core_signup_user fired.’ );
error_log( ‘User ID: ‘ . $user_id );
error_log( ‘User Data: ‘ . print_r( $user_data, true ) );
}function log_core_activate_user( $user_id, $key, $user ) {
error_log( ‘Hook: bp_core_activate_user fired.’ );
error_log( ‘User ID: ‘ . $user_id );
error_log( ‘Activation Key: ‘ . $key );
error_log( ‘User Data: ‘ . print_r( $user, true ) );
}function log_core_validate_user_signup( $result ) {
error_log( ‘Hook: bp_core_validate_user_signup fired.’ );
error_log( ‘Validation Result: ‘ . print_r( $result, true ) );
return $result;
}function log_core_signup_user_notification( $user_id, $user_data ) {
error_log( ‘Hook: bp_core_signup_user_notification fired.’ );
error_log( ‘User ID: ‘ . $user_id );
error_log( ‘User Data: ‘ . print_r( $user_data, true ) );
return $user_data;
}Here is a sample of the outputs from testing, with and without the Extended Profiles setting turned on:
[19-Jul-2024 00:01:28 UTC] Hook: bp_core_screen_signup fired.
[19-Jul-2024 00:01:28 UTC] Form submission data: Array
(
[signup_username] => TestUserAlpha
[signup_email] => AlphaEmail@EmailAlpha.com
[signup_password] => xEO^ONJS1ZkY
[signup_password_confirm] => xEO^ONJS1ZkY
[field_1] => Imma User
[signup_profile_field_ids] => 1
[signup-privacy-policy-check] => 1
[signup-privacy-policy-accept] => on
[signup_submit] => Complete Sign Up
[_wpnonce] => 3184f10172
[_wp_http_referer] => /register
)[19-Jul-2024 00:01:28 UTC] Hook: bp_before_registration_submit_buttons fired.
[19-Jul-2024 00:01:32 UTC] Hook: bp_core_screen_signup fired.
[19-Jul-2024 00:01:32 UTC] Form submission data: Array
(
[signup_username] => TestUserBeta
[signup_email] => AlphaEmail@EmailAlpha.com
[signup_password] => oeHAfbtPlIRG
[signup_password_confirm] => oeHAfbtPlIRG
[signup-privacy-policy-check] => 1
[signup-privacy-policy-accept] => on
[signup_submit] => Complete Sign Up
[_wpnonce] => 9240fe3ccc
[_wp_http_referer] => /register
)After poking around in various threads and ChatGPT, the suggestion is that the error is happening in the form validation, and I was told to look at bp-core-signup.php in the bp-core folder. Problem: this file does not exist in my BuddyPress installation. I deleted everything, did a fresh installation, and the file still does not exist. I added the hooks back in, made another test, and got exactly the same result. So am I just straight up missing a file in my installation? Or is there a deeper problem that’s outside the scope of my current awareness?
I just tested it and it worked here is my site to view it , view it on your desktop i haven’t added the bell to my mobile header yet
Let me how it goes for you
function register_bp_notification_bell_block() { // Inline JavaScript for the block $block_js = " (function (wp) { var registerBlockType = wp.blocks.registerBlockType; var el = wp.element.createElement; var withSelect = wp.data.withSelect; var __ = wp.i18n.__; registerBlockType('buddypress/notification-bell', { title: __('BuddyPress Notification Bell', 'buddypress'), icon: 'bell', category: 'widgets', edit: withSelect(function (select) { return { userId: select('core').getCurrentUser().id }; })(function (props) { var userId = props.userId; var unreadCount = 0; // Dummy content for editor preview if (!userId) { return el( 'div', { className: 'notification-bell' }, el('span', { className: 'bell-icon' }, '🔔'), el('span', { className: 'unread-count' }, '0') ); } // Fetch notifications count wp.apiFetch({ path: '/wp-json/bp/v1/notifications/unread_count/' + userId }).then(function(count) { unreadCount = count; props.setAttributes({ unreadCount: unreadCount }); }); return el( 'a', { className: 'notification-bell', href: '/members/' + userId + '/notifications/' }, el('span', { className: 'bell-icon' }, '🔔'), unreadCount > 0 && el('span', { className: 'unread-count' }, unreadCount) ); }), save: function () { return null; } }); })(window.wp); "; // Enqueue inline script wp_add_inline_script('wp-blocks', $block_js); // Register the block type register_block_type('buddypress/notification-bell', array( 'render_callback' => 'bp_notification_bell_block_render', )); } add_action('init', 'register_bp_notification_bell_block'); function bp_notification_bell_block_render($attributes) { if (!is_user_logged_in()) { return ''; } $user_id = get_current_user_id(); $unread_count = bp_notifications_get_unread_notification_count($user_id); $notifications_url = bp_loggedin_user_domain() . bp_get_notifications_slug() . '/'; ob_start(); ?> <a class="notification-bell" href="<?php echo esc_url($notifications_url); ?>"> <span class="bell-icon">🔔</span> <?php if ($unread_count > 0) : ?> <span class="unread-count"><?php echo esc_html($unread_count); ?></span> <?php endif; ?> </a> <style> .notification-bell { position: relative; display: inline-block; width: 30px; height: 30px; text-decoration: none; } .bell-icon { font-size: 24px; /* Adjust the font size as needed */ line-height: 30px; /* Match the container height */ display: block; text-align: center; } .unread-count { position: absolute; top: -5px; right: -5px; background: red; color: white; border-radius: 50%; padding: 2px 6px; font-size: 12px; } </style> <?php return ob_get_clean(); } add_action('rest_api_init', function() { register_rest_route('bp/v1', '/notifications/unread_count/(?P<user_id>\d+)', array( 'methods' => 'GET', 'callback' => 'get_bp_unread_notifications_count', )); }); function get_bp_unread_notifications_count($request) { $user_id = $request['user_id']; if (!$user_id) { return new WP_Error('no_user', 'Invalid user ID', array('status' => 404)); } return bp_notifications_get_unread_notification_count($user_id); }
Hello BuddyPress Support Team / Community,
I hope this message finds you well. I am writing to request a feature enhancement for our BuddyPress community. We would love to see an option to automatically display when a user uploads or updates their avatar in the activity feed. This feature would significantly enhance user engagement by keeping the community informed of profile updates and encouraging interactions.
Benefits:Increased Visibility: Members can immediately see when someone updates their avatar, promoting profile visits and interactions.
Enhanced Engagement: Users are more likely to comment or react to avatar changes, fostering a sense of community.
Streamlined User Experience: Automated updates in the activity feed ensure that members do not miss out on important profile changes.
Suggested Implementation:Avatar Update Trigger: When a user uploads or updates their avatar, a trigger should generate a new activity entry.
Activity Message: The activity entry could display a message like “User [Username] has updated their avatar.”
Integration with Existing Feed: The new activity entry should seamlessly integrate with the existing activity feed, appearing in chronological order.
Customization Options:Privacy Settings: Allow users to opt-out of broadcasting their avatar changes if they prefer privacy.
Activity Message Customization: Option for users to add a custom message along with their avatar update notification.We believe this feature would greatly benefit our community and enhance user experience. Thank you for considering our request. We look forward to your response and any potential updates on this feature. We did find a way to block certain activity types from showing up in the activity feed – however we’re looking for a way to add this particular type in our feeds.
Best regards,
I created a small plugin where users can subscribe to authors, but for some reason users are not notified when the author publishes a new post. Please help to solve this problem. I checked the logs, it shows that the notification was sent, but the notification itself is not there!
<?php /* Plugin Name: Author Subscription and Notification Description: Allows users to subscribe to authors and receive notifications when authors publish new posts. Version: 1.3 Author: test */ // Hook to create the database table upon plugin activation register_activation_hook(__FILE__, 'create_subscriptions_table'); function create_subscriptions_table() { global $wpdb; $table_name = $wpdb->prefix . 'author_subscriptions'; $charset_collate = $wpdb->get_charset_collate(); $sql = "CREATE TABLE $table_name ( id bigint(20) NOT NULL AUTO_INCREMENT, user_id bigint(20) NOT NULL, author_id bigint(20) NOT NULL, PRIMARY KEY (id), UNIQUE KEY user_author (user_id, author_id) ) $charset_collate;"; require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); dbDelta($sql); } // Hook to add subscription button in the post content add_filter('the_content', 'add_author_subscription_button_to_post'); function add_author_subscription_button_to_post($content) { if (is_single() && is_user_logged_in()) { $author_id = get_the_author_meta('ID'); $current_user_id = get_current_user_id(); global $wpdb; $table_name = $wpdb->prefix . 'author_subscriptions'; // Check if user is already subscribed $is_subscribed = $wpdb->get_var($wpdb->prepare( "SELECT COUNT(*) FROM $table_name WHERE user_id = %d AND author_id = %d", $current_user_id, $author_id )); $button_text = $is_subscribed ? 'Unsubscribe' : 'Subscribe'; $button_html = '<button id="subscribe-author" class="subscribe-button" data-author-id="' . esc_attr($author_id) . '">' . esc_html($button_text) . '</button>'; $button_html .= '<div id="subscription-message"></div>'; $content .= $button_html; } return $content; } // Enqueue the JavaScript file and localize script add_action('wp_enqueue_scripts', 'enqueue_subscription_script'); function enqueue_subscription_script() { if (is_single() && is_user_logged_in()) { wp_enqueue_script('subscription-script', plugin_dir_url(__FILE__) . 'subscription.js', array('jquery'), '1.0', true); wp_localize_script('subscription-script', 'subscriptionData', array( 'ajax_url' => admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('subscription_nonce') )); } } // Handle the AJAX request for subscription add_action('wp_ajax_handle_author_subscription', 'handle_author_subscription'); function handle_author_subscription() { check_ajax_referer('subscription_nonce', 'nonce'); if (is_user_logged_in()) { global $wpdb; $table_name = $wpdb->prefix . 'author_subscriptions'; $current_user_id = get_current_user_id(); $author_id = intval($_POST['author_id']); $operation = sanitize_text_field($_POST['operation']); if ($operation === 'subscribe') { $wpdb->insert($table_name, array( 'user_id' => $current_user_id, 'author_id' => $author_id )); wp_send_json_success('Subscribed successfully.'); error_log("User ID $current_user_id subscribed to author ID $author_id"); } else if ($operation === 'unsubscribe') { $wpdb->delete($table_name, array( 'user_id' => $current_user_id, 'author_id' => $author_id )); wp_send_json_success('Unsubscribed successfully.'); error_log("User ID $current_user_id unsubscribed from author ID $author_id"); } } wp_send_json_error('Failed to update subscription.'); } // Hook to send notifications when an author publishes a new post add_action('publish_post', 'notify_subscribers_on_new_post'); function notify_subscribers_on_new_post($post_id) { global $wpdb; $table_name = $wpdb->prefix . 'author_subscriptions'; $post = get_post($post_id); $author_id = $post->post_author; error_log("New post published by author ID: " . $author_id); // Get subscribers $subscribers = $wpdb->get_results($wpdb->prepare( "SELECT user_id FROM $table_name WHERE author_id = %d", $author_id )); error_log("Subscribers found: " . count($subscribers)); foreach ($subscribers as $subscriber) { // Send BuddyPress notification bp_notifications_add_notification(array( 'user_id' => $subscriber->user_id, 'item_id' => $post_id, 'secondary_item_id' => $author_id, 'component_name' => 'buddypress', 'component_action' => 'new_post_by_subscribed_author', 'date_notified' => bp_core_current_time(), 'is_new' => true, )); error_log("Notification sent to user ID: " . $subscriber->user_id); } } // Custom notification format add_filter('bp_notifications_get_notifications_for_user', 'custom_bp_notification_format', 10, 5); function custom_bp_notification_format($content, $item_id, $secondary_item_id, $action, $component_name) { if ($component_name === 'buddypress' && $action === 'new_post_by_subscribed_author') { $author_name = get_the_author_meta('display_name', $secondary_item_id); $post_title = get_the_title($item_id); $post_url = get_permalink($item_id); $content = sprintf(__('New post by %s: <a href="%s">%s</a>', 'text-domain'), $author_name, $post_url, $post_title); } return $content; } ?>
[23-May-2024 09:42:15 UTC] a:0:{} [23-May-2024 09:42:40 UTC] New post published by author ID: 1 [23-May-2024 09:42:40 UTC] Subscribers found: 2 [23-May-2024 09:42:40 UTC] Notification sent to user ID: 1 [23-May-2024 09:42:40 UTC] Notification sent to user ID: 27 [23-May-2024 09:42:43 UTC] a:0:{}
I’m trying to create a block with notifications that should be displayed using a shortcode, but for some reason I get one message (Error: Unable to retrieve notification data.) in the place of the notifications themselves. Tell me where did I mess up?
The code itself:<?php /* Plugin Name: BuddyPress Real-Time Notifications Description: Version: 1.0 Author: */ // JavaScript function bprtn_enqueue_scripts() { wp_enqueue_script('bprtn-scripts', plugin_dir_url(__FILE__) . 'scripts.js', array('jquery'), null, true); } add_action('wp_enqueue_scripts', 'bprtn_enqueue_scripts'); // CSS function bprtn_enqueue_styles() { wp_enqueue_style('bprtn-styles', plugin_dir_url(__FILE__) . 'styles.css'); } add_action('wp_enqueue_scripts', 'bprtn_enqueue_styles'); // function function bprtn_display_notification($notification) { if (isset($notification->component_name) && isset($notification->component_action) && isset($notification->item_id)) { echo '<div class="bprtn-notification">'; echo '<p class="bprtn-description">' . bp_the_notification_description($notification->component_action, $notification->item_id) . '</p>'; echo '<p class="bprtn-date">' . bp_the_notification_time_since($notification->date_notified) . '</p>'; echo '<div class="bprtn-actions">'; // buttons bp_the_notification_action_links(array('before' => '<div class="bprtn-action">', 'after' => '</div>', 'notification' => $notification)); echo '</div>'; echo '</div>'; } else { echo '<p class="bprtn-notification-error">Error: Unable to retrieve notification data.</p>'; } } // function load notifications function bprtn_load_notifications() { $user_id = bp_loggedin_user_id(); $notifications = bp_notifications_get_notifications_for_user($user_id); if (!empty($notifications)) { foreach ($notifications as $notification) { bprtn_display_notification($notification); } } else { echo '<p class="bprtn-no-notifications">No new notifications.</p>'; } } // shortcode function bprtn_notifications_shortcode() { ob_start(); bprtn_load_notifications(); return ob_get_clean(); } add_shortcode('bprtn_notifications', 'bprtn_notifications_shortcode'); // AJAX function bprtn_mark_as_read() { if (isset($_POST['notification_id'])) { $notification_id = $_POST['notification_id']; bp_notifications_mark_notifications_by_id(array($notification_id), 'read'); } wp_die(); } add_action('wp_ajax_bprtn_mark_as_read', 'bprtn_mark_as_read'); ?>
When I create a group and set it to hidden, it is not visible to me as admin (or any other user whether they’re members of the group or not.
To test, I created a fresh WordPress install, installed the BuddyX (free) theme, then BuddyPress, bbPress, and finally BP Classic plugin. I’m logged in as admin. I created a user called sub1 who is a subscriber.
I created a group called Normal which is set up as a public group. Then I created a second group called Private which is set up as private. Then I set up a group called Hidden which is set to hidden. When creating each group, I sent an invite to user Sub1.
When I go to the Groups page (/groups), I see the group count as 3. I see the group Normal which I can click into and view group info, and the group Private which I can click into and see group info (since I’m logged in as admin who created the group). I do not see the group Hidden. But on the bottom it says “Viewing 1 – 3 of 3 groups” even though I can only see 2.
If I log out, I can see the group Normal and click into it and see group info. I can see the group Private and click into it, but see a message saying that this is a private group. No group Hidden when logged out (as expected) and on the bottom it says “Viewing 1 – 2 of 2 groups”.
If I log in as user Sub1, I only see 2 groups but “Viewing 1 – 3 of 3 groups”. The group Private says I have to be a member of the group to see anything. Then I accept the invite to group Private. Then I can see everything in the group. I don’t see the group Hidden. In my notifications, I click on the invitation to group Hidden and nothing happens.
I tried and succeeded to reproduce this in a vanilla environment. Any help would be appreciated.
Thanks.
Topic: Notifications page
I have a problem with the notifications page, because when you are in the user’s profile, and you want to see your notifications, the page is not shown, a page error appears, because it does not exist.
https://tudominio.com/miembros/horacios/notifications/
BuddyPress Versión 12.2.0I don’t have any idea how fix it.