Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to cut inside bp_current_action switch ?

  • Avatar of Shmoo
    Shmoo
    Participant

    @macpresss

    I’ve got this problem where I would like to alter the layout of the messages pages.

    My mission is to have the inbox and sendbox loop always active on each page inside the sidebar of the messages pages. This isn’t really a real WP sidebar but I just spilled the messages template into two parts and called the left side sidebar. So everything stays together inside one template but I’ve got a problem understanding the switch( bp_current_action() ) tag.

    How can I break this into pieces, because I would like to have compose, single + notices always show up on the right side of the content and the inbox + sendbox on the left side + always active.

    Picture of the layout

    Only problem is if I use the switch bp_current_action tag twice on the same template it will break the code for some reason.

    
    <?php
    switch ( bp_current_action() ) :
    
    	// Inbox/Sentbox
    	case 'inbox'   :
    	case 'sentbox' :
    		do_action( 'bp_before_member_messages_content' ); ?>
    
    		<div class="messages" role="main">
    			<?php bp_get_template_part( 'members/single/messages/messages-loop' ); ?>
    		</div><!-- .messages -->
    
    		<?php do_action( 'bp_after_member_messages_content' );
    		break;
    
    	// Single Message View
    	case 'view' :
    		bp_get_template_part( 'members/single/messages/single' );
    		break;
    
    	// Compose
    	case 'compose' :
    		bp_get_template_part( 'members/single/messages/compose' );
    		break;
    
    	// Sitewide Notices
    	case 'notices' :
    		do_action( 'bp_before_member_messages_content' ); ?>
    
    		<div class="messages" role="main">
    			<?php bp_get_template_part( 'members/single/messages/notices-loop' ); ?>
    		</div><!-- .messages -->
    
    		<?php do_action( 'bp_after_member_messages_content' );
    		break;
    
    	// Any other
    	default :
    		bp_get_template_part( 'members/single/plugins' );
    		break;
    endswitch;
    
Viewing 2 replies - 1 through 2 (of 2 total)
  • Avatar of Shmoo
    Shmoo
    Participant

    @macpresss

    I think I’ve got it..

    
    <div class="three columns">
    	<?php bp_get_template_part( 'members/single/messages/messages-loop' ); ?>
    </div>
    
    <div class="five columns">
    	<div class="msg-content-wrap">
    	<?php
    	switch ( bp_current_action() ) :
    	
    	// Single Message View
    	case 'view' :
    		bp_get_template_part( 'members/single/messages/single' );
    	break;
    		
    	// Compose
    	case 'compose' :
    		bp_get_template_part( 'members/single/messages/compose' );
    	break;
    		
    	// Sitewide Notices
    	case 'notices' :
    		do_action( 'bp_before_member_messages_content' ); ?>
    		<?php bp_get_template_part( 'members/single/messages/notices-loop' ); ?>
    		<?php do_action( 'bp_after_member_messages_content' );
    	break;	
    	// Any other
    	default :
    		bp_get_template_part( 'members/single/plugins' );
    	break;
    	endswitch; ?>
    </div>
    

    The only thing I still have to do is protect the column 3 – messages-loop.php from showing to the public or all logged_in users.

    !Please do not use this code on Live BuddyPress sites!

    Avatar of Boone Gorges
    Boone Gorges
    Keymaster

    @boonebgorges

    The best way to ensure that a part of a template is only visible to a logged-in user who is viewing his own page is like this:

    <?php if ( bp_is_my_profile() ) : ?>
        This is only visible to users viewing their own profiles
    <?php endif; ?>
    
    This is visible to anyone.
    
Viewing 2 replies - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.