Skip to:
Content
Pages
Categories
Search
Top
Bottom

Curious if this is correct php for showing X to Z people.

  • Avatar of Shmoo
    Shmoo
    Participant

    @macpresss

    I’ve made a custom Notification Loop inside the header of my site that should of course only be visible for logged-in users + only the notifications-list of the current loggedin_user_id.

    This is what I made, first I check if user_is_logged in -> if TRUE start the has_notifications Loop of the user_id => loggedin_user_id.

    Everything seems to work fine but I’m not very convinced I did this the correct way.

    
    <?php if ( is_user_logged_in() ): ?>
    <?php if ( bp_has_notifications( array( 'user_id' => bp_loggedin_user_id() ) ) ): ?>
    
    ... here I've got the loop stuff ...
    
    <?php endif; ?>
    <?php endif; ?>
    
Viewing 2 replies - 1 through 2 (of 2 total)
  • Avatar of Henry
    Henry
    Participant

    @henrywright-1

    @macpresss

    Looks solid to me. If you wanted to condense the code into two lines you could use the logical operator &&

    e.g.

    if ( bp_has_notifications( 'user_id=' . bp_loggedin_user_id() ) && is_user_logged_in() ) {
        // ... here I've got the loop stuff ...
    }

    You could also append this bit which will let you output something to logged in users having no notifications:

    else {
        // ... no notifications ...
    }
    Avatar of Shmoo
    Shmoo
    Participant

    @macpresss

    Thanks..

    We’ll keep learning each day.

    I just found out that you can easily overwrite exciting functions or actions with just two little steps.

    
    function shmoo_messages_screen_notification_settings() {
    	if ( bp_action_variables() ) {
    		bp_do_404();
    		return;
    	}
    .... wall of code ....
    
    }
    remove_action( 'bp_notification_settings', 'messages_screen_notification_settings', 2 );
    add_action( 'bp_notification_settings', 'shmoo_messages_screen_notification_settings', 10 );
    

    I just copied the original code to my functions.php renamed the function name by simply adding shmoo in front of it and last add the remove_action() tag just above the add_action with the original function that you wanna hide.

    So cool. Now I can change more dynamic content into my own content.

Viewing 2 replies - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.