User's own avatar class


Home Forums Front End PM PRO User's own avatar class

This topic is: Resolved
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #7709
    Dominique Baril
    Participant

    Hi Shamim,

    Against all odds, I modified class-fep-message.php in order to give a new .fep-avatar-own class to current user’s avatar. I don’t know if it’s something you would like to add into a future release, however, here’s the code.
    It’s now possible to stylize differently a user’s own avatar or even make It disappear.

    Have a good day!

    		case 'avatar' :
    			$participants = fep_get_participants( get_the_ID() );
    			$current_user = get_current_user_id();
    			$count = 1;
    		?>
    		<div class="fep-avatar-p <?php echo ( count( $participants ) > 2 ) ? 'fep-avatar-p-120' : 'fep-avatar-p-90' ?>"><?php
    			foreach( $participants as $p ){
    				$participant_id = fep_get_userdata( $p, 'ID', 'ID' );
    				if( $count > 2 ){
    					echo '<div class="fep-avatar-more-60" title="' . __('More users', 'front-end-pm') . '"></div>';
    					break;
    				}
    
    				?><div class="fep-avatar-<?php echo $count; ?> <?php if ( $participant_id === $current_user) { echo "fep-avatar-own";} ?>"><?php echo get_avatar( $p, 60, '', '', array( 'extra_attr'=> 'title="'. fep_get_userdata( $p, 'display_name', 'ID' ) . '"') ); ?></div><?php
    
    				$count++;
    			}
    		echo '</div>';
    		break;
    #7712
    Dominique Baril
    Participant

    Here’s the css to remove current user’s avatar

    .fep-avatar-own {display: none;}
    .fep-avatar-p {width:55px; max-width:55px;}
    .fep-avatar-p .fep-avatar-2 {left:0px;}
    #7726
    Shamim Hasan
    Keymaster

    It is highly recommended NOT to modify any core plugin code. When you will update this plugin you will loss all your modification.

    Same result can be achieved using add_action( 'fep_message_table_column_content_avatar', 'your_function' );
    Also if you want to remove own avatar you can use

    
    if (($key = array_search(get_current_user_id(), $participants)) !== false) {
        unset($participants[$key]);
    }
    

    just after $participants = fep_get_participants( get_the_ID() ); line.

    I am planing to add a filter to remove own avatar in next release.

    #7766
    Dominique Baril
    Participant

    All right, so I added this to my function.php and it works fine. Thanks Shamim

    function fep_remove_own_avatar() {
      $participants = fep_get_participants( get_the_ID() );
      if (($key = array_search(get_current_user_id(), $participants)) !== false) {
        unset($participants[$key]);
    }
      $current_user = get_current_user_id();
      $count = 1;
      ?>
      <div class="fep-avatar-p <?php echo ( count( $participants ) > 2 ) ? 'fep-avatar-p-120' : 'fep-avatar-p-90' ?>"><?php
      foreach( $participants as $p ){
        $participant_id = fep_get_userdata( $p, 'ID', 'ID' );
        if( $count > 2 ){
          echo '<div class="fep-avatar-more-60" title="' . __('More users', 'front-end-pm') . '"></div>';
          break;
        }
    
        ?><div class="fep-avatar-<?php echo $count; ?> <?php if ( $participant_id === $current_user) { echo "fep-avatar-own";} ?>"><?php echo get_avatar( $p, 60, '', '', array( 'extra_attr'=> 'title="'. fep_get_userdata( $p, 'display_name', 'ID' ) . '"') ); ?></div><?php
    
        $count++;
      }
      echo '</div>';
    }
    add_action( 'fep_message_table_column_content_avatar', 'fep_remove_own_avatar' );
Viewing 4 posts - 1 through 4 (of 4 total)

You need to purchase ‘Front End PM PRO’ to create topic in this support forum.

If you already purchased ‘Front End PM PRO’ please LOGIN.