Custom notification not working – table “prefix.n” doesn’t exists.
-
Hello,
I’m creating a gifting system for my website. When user sends gift to another user, receiver should receive a notification.
Here’s what I tried:
gift class:
<?php class tbtPoklon { public function init() { add_filter( 'bp_notifications_get_registered_components', array($this, 'add_component') ); add_filter( 'bp_notifications_get_notifications_for_user', array($this, 'display_notification'), 10, 5 ); } public function get_gifts() { global $wpdb; $gifts = json_decode(json_encode($wpdb->get_results("SELECT * FROM tbt_pokloni")), True); return $gifts; } public function get_gift($gift_id) { global $wpdb; $gift_data = json_decode(json_encode($wpdb->get_results("SELECT * FROM tbt_pokloni WHERE gift_id = {$gift_id}")), True); return $gift_data[0]; } public function add_component( $component_names = array() ) { if ( ! is_array( $component_names ) ) { $component_names = array(); } array_push( $component_names, 'tbtPoklon' ); return $component_names; } public function display_notification( $action, $item_id, $secondary_item_id, $total_items, $format = 'string' ) { if ( 'tbtPoklonPoslan' === $action ) { $senderName = bp_core_get_user_displayname( $item_id ); $custom_title = $senderName." ti je poslao/la poklon! otvori..."; $custom_link = "#"; $custom_text = $custom_title; if ( 'string' === $format ) { $return = apply_filters( 'tbtPoklon_filter', '<a href="' . esc_url( $custom_link ) . '" title="' . esc_attr( $custom_title ) . '">' . esc_html( $custom_text ) . '</a>', $custom_text, $custom_link ); } else { $return = apply_filters( 'tbtPoklon_filter', array( 'text' => $custom_text, 'link' => $custom_link ), $custom_link, (int) $total_items, $custom_text, $custom_title ); } return $return; } } public function send_notification( $sender, $reciever, $gift ) { bp_notifications_add_notification( array( 'user_id' => $reciever, // Gift reciever 'item_id' => $sender, // Gift sender 'secondary_item_id' => $gift, // Gift ID 'component_name' => 'tbtPoklon', 'component_action' => 'tbtPoklonPoslan', 'date_notified' => bp_core_current_time(), 'is_new' => 1, ) ); } }
calling send_notification method:
<?php function test_notification() { $class = new tbtPoklon(); $class->init(); $class->send_notification(17 /* sender */, 1 /* receiver */, 5 /* gift id */); } test_notification();
I get this error: [13-Feb-2018 21:59:06 UTC] Table ‘prefix.n’ doesn’t exist za upit SELECT * FROM n WHERE user_id IN (1) AND item_id IN (17) AND secondary_item_id IN (5) AND component_name IN (‘tbtPoklon’) AND component_action IN (‘tbtPoklonPoslan’) AND is_new = 1 koji je postavio/la require(‘wp-blog-header.php’), require_once(‘wp-load.php’), require_once(‘wp-config.php’), require_once(‘wp-settings.php’), include(‘/themes/kleo-child/functions.php’), sendtestnot, tbtPoklon->send_notification, bp_notifications_add_notification, BP_Notifications_Notification::get
I hope you could help me. Thanks, regards.
- You must be logged in to reply to this topic.