• Resolved Halil ESEN

    (@halilesen)


    Hello,
    I want to show forum notifications in WordPress. However, it is not possible to do as in phpBB. So I thought of doing it like this: https://i.hizliresim.com/bd3ax3f.jpg

    I will do the same for mobile. I will add it to the dropdown menu icon and the forum link when the menu opens.

    For a private use when I’m in the forum I can display it like this:
    <!-- IF NOTIFICATIONS_COUNT > 0 --><span class="blablax <!-- IF NOTIFICATIONS_COUNT > 9 -->blablaxxl<!-- ENDIF --> <!-- IF NOTIFICATIONS_COUNT > 99 -->blablaxxxl<!-- ENDIF -->">{NOTIFICATIONS_COUNT}</span><!-- ENDIF -->

    In short the following code is required:
    <!-- IF NOTIFICATIONS_COUNT > 0 -->{NOTIFICATIONS_COUNT}<!-- ENDIF -->

    So how can I show these notification numbers in WordPress?

    Thanks.

Viewing 15 replies - 16 through 30 (of 57 total)
  • Plugin Author axew3

    (@axewww)

    mhhh strange, are you sure that the user effectively have unread notifications into phpBB?

    Plugin Author axew3

    (@axewww)

    Look, i have test the code on fly, because it is ever a bad idea to write without testing.
    I see that you have to change into the query you added, that in one line is like this:
    WHERE ". $w3all_config["table_prefix"] ."notifications.user_id = ".$phpbb_user_session[0]->user_id."
    `
    CHANGE $phpbb_user_session[0]->user_id WITH $phpbb_u
    so to have this instead:
    WHERE ". $w3all_config["table_prefix"] ."notifications.user_id = ".$phpbb_u."

    because it depend by the type of login and cookies, the fact that at this point, the var $phpbb_user_session[0]->user_id is empty or NOT!

    • This reply was modified 2 years, 5 months ago by axew3.
    • This reply was modified 2 years, 5 months ago by axew3.
    Thread Starter Halil ESEN

    (@halilesen)

    Yes.

    Thread Starter Halil ESEN

    (@halilesen)

    No. The problem continues. I made the change you mentioned. Ultimately, it went like this:

        if(!empty($phpbb_user_session[0]->notification_data)){ // there is almost an unread notification for this user
     		// so we go to retrieve all unreads for this user session
     		$w3all_phpbb_unotifications = $w3all_phpbb_connection->get_results("SELECT *
         FROM ". $w3all_config["table_prefix"] ."notifications
         WHERE ". $w3all_config["table_prefix"] ."notifications.user_id = ".$phpbb_u."
         AND ". $w3all_config["table_prefix"] ."notifications.notification_read = 0",ARRAY_A);
     	}

    It still always shows the number 1.

    Plugin Author axew3

    (@axewww)

    It seem to be very hard to understand why it return always 1 to you!
    Substantially is impossible if there are new notifications.
    So since the query cannot fail about this, you can be sure, may follow on check your subsequent code, because an error should reside there.

    Thread Starter Halil ESEN

    (@halilesen)

    I can not understand. does this code work for you?

    Thread Starter Halil ESEN

    (@halilesen)

    After spending so much time, I don’t want to let go of the work. Please help me with working codes. I tried many compositions but failed.

    Plugin Author axew3

    (@axewww)

    Yes of course it is working, the code for 2.6.6 into files

    wp_w3all.php and class.wp.w3all-phpbb.php

    about notifications will be like this:

    https://github.com/axew3/common-test-files/archive/refs/heads/main.zip

    download the two zipped files and replace into folder:
    /wp-content/plugins/wp-w3all-phpbb-integration/

    then as explained on previous posts, anywhere and all over wordpress, you’ll have just to do this to get notifications count:

    global $w3all_phpbb_unotifications;
    $nnum = empty($w3all_phpbb_unotifications) ? 0 : count($w3all_phpbb_unotifications);

    note that the example var $nnum contain the number you want.
    So you have to execute this php code exactly where it need to display, template file or template functions file.

    Hope that this will help you

    • This reply was modified 2 years, 5 months ago by axew3.
    Thread Starter Halil ESEN

    (@halilesen)

    Very annoying but it didn’t work. I just added the code you gave. It didn’t work with the php code you provided either.

    I’m adding this to the theme files. It’s in the theme but it doesn’t work.
    I want it to show notification only if it is greater than 0, that is, at least one. So I can shape it with css. But so far I have not been successful. Because either it never showed, or it always showed one. I’m trying this with multiple notifications. Moreover, it was always showing one, regardless of whether he was logged in or not. Nothing appears with your last code.

    ?? Let’s not give up. What could be the problem?

    Plugin Author axew3

    (@axewww)

    Ok, it is a problem of the init that run after the setup of the theme’s template files.
    So that to explain to you the problem, let say i test it into a default twentysixteen theme.

    i go to open the file
    /wp-content/themes/twentysixteen/functions.php

    then i go to add the snippet to get the global var $w3all_phpbb_unotifications;

    
    global $w3all_phpbb_unotifications;
    print_r($w3all_phpbb_unotifications);exit;

    INSIDE THE FUNCTION

    function twentysixteen_setup() {

    will NOT WORK. This function fire before the plugin code.
    it is hooked into the after_setup_theme hook
    add_action( 'after_setup_theme', 'twentysixteen_setup' );

    but let instead add the code to get the result you want, inside another function that hook into wp_head:
    add_action( 'wp_head', 'twentysixteen_javascript_detection', 0 );

    so search for
    function twentysixteen_javascript_detection() {
    and inside this function put the code:

    function twentysixteen_javascript_detection() {
    global $w3all_phpbb_unotifications;
    if(empty($w3all_phpbb_unotifications)){
     $nnum = 0; } else { $nnum = count($w3all_phpbb_unotifications); 
     // echo $nnum; exit;
    }

    now you get the result.

    So, TO RESUME you can get the result you want also doing/ADDING this into your (ANY THEME) functions.php template file:

    function phpbb_notifications() {
    	global $w3all_phpbb_unotifications;
    
     if(!empty($w3all_phpbb_unotifications)){
     	//print_r(count($w3all_phpbb_unotifications));exit;
      echo'<script>var w3notificationsCount = '.count($w3all_phpbb_unotifications).';</script>';
     } else {
        echo'<script>var w3notificationsCount = 0;</script>'; // or remmove and check in javascript after, if the var exist, to detect that the user have or do not have new notifications
       }
    }
    add_action( 'wp_head', 'phpbb_notifications', 0 );

    use these two ready plugins files, the code will not change on 2.6.6 about this. You’ll have just to enable the new added and related option, into the plugin admin preferences on next 2.6.6 (will be Retrieve user’s phpBB notifications)
    https://github.com/axew3/common-test-files/archive/refs/heads/main.zip

    download the two zipped files and replace into folder
    /wp-content/plugins/wp-w3all-phpbb-integration/

    – we’ll never give up!

    • This reply was modified 2 years, 5 months ago by axew3.
    • This reply was modified 2 years, 5 months ago by axew3.
    • This reply was modified 2 years, 5 months ago by axew3.
    Thread Starter Halil ESEN

    (@halilesen)

    I added the following code to the functions.php file.

    function phpbb_notifications() {
    	global $w3all_phpbb_unotifications;
    
     if(!empty($w3all_phpbb_unotifications)){
     	//print_r(count($w3all_phpbb_unotifications));exit;
      echo'<script>var w3notificationsCount = '.count($w3all_phpbb_unotifications).';</script>';
     } else {
        echo'<script>var w3notificationsCount = 0;</script>'; // or remmove and check in javascript after, if the var exist, to detect that the user have or do not have new notifications
       }
    }
    add_action( 'wp_head', 'phpbb_notifications', 0 );

    I used the following php code:

    <?php global $w3all_phpbb_unotifications;
    print_r($w3all_phpbb_unotifications); ?>

    result:
    https://i.hizliresim.com/mftt4o3.jpg

    Since I only want numbers for now, I use it with echo:

    <?php global $w3all_phpbb_unotifications;
    echo($w3all_phpbb_unotifications); ?>

    result:
    https://i.hizliresim.com/giu6qvj.jpg

    When there is no notification, nothing appears, but when it is, these are the results.

    Plugin Author axew3

    (@axewww)

    use
    echo count($w3all_phpbb_unotifications);
    to get the number of notifications!

    you are printing out the entire array, that can be used to display more complex results

    Thread Starter Halil ESEN

    (@halilesen)

    <?php global $w3all_phpbb_unotifications; echo count($w3all_phpbb_unotifications); ?>

    Now it’s like this: It shows the number 1, whether there is a notification or not. However, if there are more notifications, it can show the number of notifications.

    No notification or there is one notification: 1
    There is one notification: 1
    There are 2 notifications: 2.
    There are 3 notifications: 3…

    Thread Starter Halil ESEN

    (@halilesen)

    I think the problem is in the global $w3all_phpbb_unotifications part. Correct me if I’m wrong, it checks for this notification and reports it, right?

    Plugin Author axew3

    (@axewww)

    You have to improve your php!
    You have all to display correctly any result, is up to you to write the right code that return the right result.
    My advice is to take a look to the entire topic where you’ll find out any possible code hint about this.
    Cheers!

Viewing 15 replies - 16 through 30 (of 57 total)
  • The topic ‘Show Number of Notifications’ is closed to new replies.