[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-messages/screens/ -> view.php (source)

   1  <?php
   2  /**
   3   * Messages: Conversation thread screen handler.
   4   *
   5   * @package BuddyPress
   6   * @subpackage MessageScreens
   7   * @since 3.0.0
   8   */
   9  
  10  /**
  11   * Load an individual conversation screen.
  12   *
  13   * @since 1.0.0
  14   *
  15   * @global BuddyPress $bp The one true BuddyPress instance.
  16   *
  17   * @return bool False on failure.
  18   */
  19  function messages_screen_conversation() {
  20  
  21      // Bail if not viewing a single message.
  22      if ( ! bp_is_messages_component() || ! bp_is_current_action( 'view' ) ) {
  23          return false;
  24      }
  25  
  26      $thread_id = (int) bp_action_variable( 0 );
  27  
  28      if ( empty( $thread_id ) || ! messages_is_valid_thread( $thread_id ) ) {
  29          if ( is_user_logged_in() ) {
  30              bp_core_add_message( __( 'The conversation you tried to access is no longer available', 'buddypress' ), 'error' );
  31          }
  32  
  33          bp_core_redirect( trailingslashit( bp_displayed_user_domain() . bp_get_messages_slug() ) );
  34      }
  35  
  36      // No access.
  37      if ( ( ! messages_check_thread_access( $thread_id ) || ! bp_is_my_profile() ) && ! bp_current_user_can( 'bp_moderate' ) ) {
  38          // If not logged in, prompt for login.
  39          if ( ! is_user_logged_in() ) {
  40              bp_core_no_access();
  41              return;
  42  
  43          // Redirect away.
  44          } else {
  45              bp_core_add_message( __( 'You do not have access to that conversation.', 'buddypress' ), 'error' );
  46              bp_core_redirect( trailingslashit( bp_loggedin_user_domain() . bp_get_messages_slug() ) );
  47          }
  48      }
  49  
  50      // Load up BuddyPress one time.
  51      $bp = buddypress();
  52  
  53      // Decrease the unread count in the nav before it's rendered.
  54      $count = bp_get_total_unread_messages_count();
  55      $class = ( 0 === $count ) ? 'no-count' : 'count';
  56  
  57      /* translators: 1: class name. 2: number of messages */
  58      $nav_name = sprintf( __( 'Messages <span class="%1$s">%2$s</span>', 'buddypress' ), esc_attr( $class ), bp_core_number_format( $count ) );
  59  
  60      // Edit the Navigation name.
  61      $bp->members->nav->edit_nav( array(
  62          'name' => $nav_name,
  63      ), $bp->messages->slug );
  64  
  65      /**
  66       * Fires right before the loading of the Messages view screen template file.
  67       *
  68       * @since 1.7.0
  69       */
  70      do_action( 'messages_screen_conversation' );
  71  
  72      /**
  73       * Filters the template to load for the Messages view screen.
  74       *
  75       * @since 1.0.0
  76       *
  77       * @param string $template Path to the messages template to load.
  78       */
  79      bp_core_load_template( apply_filters( 'messages_template_view_message', 'members/single/home' ) );
  80  }
  81  add_action( 'bp_screens', 'messages_screen_conversation' );


Generated: Mon Nov 29 01:01:02 2021 Cross-referenced by PHPXref 0.7.1