BuddyDev

Search

DISABLE HEARTBEAT API

  • Participant
    Level: Guru
    Posts: 900
    Tosin on #28301

    Hello,

    I would like to know if it is possible to remove or completely disable the Heartbeat API requirement from all components excluding Activity, which reduces total requests to server. I am not sure how this will affect the component for notifications and messages.

    Thanks

  • Participant
    Level: Guru
    Posts: 900
    Tosin on #28302

    How can I apply this code below but exclude the buddypress activity page

     add_action( 'init', 'stop_heartbeat', 1 );
    function stop_heartbeat() {
    wp_deregister_script('heartbeat');
    } 

    thanks

  • Keymaster
    (BuddyDev Team)
    Posts: 24706
    Brajesh Singh on #28307

    Hi Tosin,
    Please use the following

    
    add_action( 'init', 'stop_heartbeat', 1 );
    function stop_heartbeat() {
    	if ( bp_is_activity_component() || bp_is_group_activity() ) {
    		return;
    	}
    	wp_deregister_script( 'heartbeat' );
    }
    
    

    Regards
    Brajesh

  • Participant
    Level: Guru
    Posts: 900
    Tosin on #28315

    Thank you very much brajesh I would also like to ask if your plugin https://wordpress.org/plugins/bp-live-notification/ would still work with the above code if not is there a way to bypass it.

    Thanks

  • Keymaster
    (BuddyDev Team)
    Posts: 24706
    Brajesh Singh on #28322

    Hi Tosin,
    yes, It will affect that plugin.

    I am sorry, but there is no alternative. The live notification needs heartbat to work.

    Regards
    Brajesh

  • Participant
    Level: Guru
    Posts: 900
    Tosin on #28975

    Hello brajesh

    The sitewide activity directory is not being excluded with your code above and below. I need heartbeat to load only sitewide activity directory

     add_action( 'init', 'stop_heartbeat', 1 );
    function stop_heartbeat() {
    	if ( bp_is_activity_directory() && bp_is_user_activity() && bp_is_activity_component() && bp_is_group_activity() ) {
    		return;
    	}
    	wp_deregister_script( 'heartbeat' );
    } 

    Thanks

  • Keymaster
    (BuddyDev Team)
    Posts: 24706
    Brajesh Singh on #28987

    Hi Tosin,
    try changing the order

    
    add_action( 'template_redirect', 'stop_heartbeat', 1 );
    function stop_heartbeat() {
    	if ( bp_is_activity_component() || bp_is_group_activity() ) {
    		return;
    	}
    	wp_deregister_script( 'heartbeat' );
    }
    

    That should work.

    PS:- It makes heartbeat work on activity directory, user’s own activity page and group’s activity page.

    Regards
    Brajesh

You must be logged in to reply to this topic.

This topic is: not resolved