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


Generated: Wed Dec 11 01:01:37 2019 Cross-referenced by PHPXref 0.7.1