Skip to:
Content
Pages
Categories
Search
Top
Bottom

delete notifications


  • mohamedalikortli
    Participant

    @mohamedalikortli

    if buddypress clear notifications plugin does not working for u , this is a solution how to do it ,we will add a button”clear all notifications” in the notifications nav menu , first we will edit a php script called test.php wich contain this code

    <?php
    
    	 function clear_all_notifications() {
    		 require_once( 'wp-load.php' ); //put correct absolute path for this file
    
    $id = get_current_user_id();
    		 
    		 
    		// on se connecte Ă  MySQL 
    $db = mysql_connect('localhost', 'user', 'password'); //replace user and password
    mysql_select_db('name of database',$db); 
    $requete = 'SELECT * FROM prefix_bp_notifications WHERE user_id='. $id ; // verify the name of table here prefix_bp_notifications can be wp_bp_notifications
    $sql = 'DELETE FROM prefix_bp_notifications WHERE user_id ='. $id ; // verify the name of table here prefix_bp_notifications can be wp_bp_notifications
    $reponse = mysql_query($requete);
    $resultat = mysql_num_rows($reponse);
    if($resultat > 0){ 
    $req = mysql_query($sql) or die('Erreur SQL !<br>'.$sql.'<br>'.mysql_error()); 		
    		
         
    	 
    mysql_close(); 	 
    		
    		echo "Notifications supprimees";
    }
    else {
    	echo $resultat ;
    
    		echo "pas de notifications";
    mysql_close();
    }  
        }
    	
    	clear_all_notifications();
    	?>
    
    copy this script into ur document root where u have installed ur wordpress
    
    then add this code to wp-content/plugins/buddypress/bp-templates/bp-legacy/buddypress/members/single/notifications.php  under <?php bp_get_options_nav(); ?> line 13
    
    <li id="notifications-my-notifications-personal-li" class="current selected"> 
    		<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
        <script type = "text/javascript">
    function myAjax () {
    $.ajax( { type : 'POST',
              data : { },
              url  : 'ur website adresse/test.php',              // <=== CALL THE PHP FUNCTION HERE.
              success: function ( data ) {
                return 1;               // <=== VALUE RETURNED FROM FUNCTION.
              },
              error: function (  ) {
                return 1;
              }
            });
    }
    
    //function execute_del(){
    	//myAjax();
    	//window.location.reload();
    	
    //}
        </script>
    	<button onclick="myAjax();window.location.reload();">delete all notifications</button> <!-- BUTTON CALL PHP FUNCTION -->
    	
    	</li>

    that’s all 🙂

Viewing 1 replies (of 1 total)

  • danbp
    Moderator

    @danbp

    Hi @mohamedalikortli,

    thank you for the sharing, but I am afraid that your proposal is not acceptable in regard of coding best practice. I let your snippet in place, but i also warn all readers to use it, unless they know what they do.

    This forum is public and most users coming here for help are querying at first for BuddyPress related issues solution, not third party plugin tricks like the one you share here. The majority is also not very comfortable with php or even site development.
    This aspect is one of the main reason to provide usefull and safe code.
    IT IS NOT THE CASE HERE – and i wouldn’t recommand it.

    Not because it doesn’t or wouldn’t work ( and i haven’t tested it), but because it is not correctly written. Allowing such a snippet is like encouraging (and by the way perpetuating) bad practices. Hopefully you understand and agree that we don’t want this on the BuddyPress support forum.


    @sbrajesh
    ‘s BuddyPress Clear Notification plugin was last updated in march 2016, which is pretty recent. I doubt that the bug is in his plugin and i expect more a menu related issue… but this is only an expectation of mine.

    If you estimate that your workaround is helpfull for that plugin, get in touch with Brajesh or publish it on the plugin support.

    By the way, next time you publish code on this form, use the code button available on the editor toolbar to insert it properly.

    FYI about what you did wrong or not properly:
    – hacking a core file. Notification template should be used, but from inside a child-theme, not directly from bp-legacy).
    – comments should be in english (some in your example are in french)
    – your recommendation is against all WP usage:

    copy this script into ur document root where u have installed ur wordpress

    – you can add custom code via bp-custom.php. There is also no need to go to wp root, when you can do the same thing from within your child-theme.
    – why do you recall jquery ? It is already loaded when you run BP…
    – i’m not a developer, but i’m pretty sure there are other things to mention about coding.

    In regard of the script itself, BP provide much simplier way to delete notification or show a delete button: reference.
    You’re also using french in that script.

    Calling a file “test” is ok, but in that case you should provide some explanation on how to finally use your snippet. As already said, not everybody here is able to understand – and use raw code – when you provide a workaround. Providing code is fine, providing code+tutorial is always better.

    DĂ©solĂ© d’ĂȘtre sĂ©vĂšre et rien de personnel, mais juste une mise au point nĂ©cessaire.

    [modlook] @jjj, @DJPaul, @boonebgorges, @mercime, @hnla, @shanebp, @henrywright

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.
Skip to toolbar