/bp-messages/bp-messages-screens.php

  1. <?php 
  2. /** 
  3. * BuddyPress Messages Screens. 
  4. * 
  5. * Screen functions are the controllers of BuddyPress. They will execute when 
  6. * their specific URL is caught. They will first save or manipulate data using 
  7. * business functions, then pass on the user to a template file. 
  8. * 
  9. * @package BuddyPress 
  10. * @subpackage MessagesScreens 
  11. * @since 1.5.0 
  12. */ 
  13.  
  14. // Exit if accessed directly. 
  15. defined( 'ABSPATH' ) || exit; 
  16.  
  17. /** 
  18. * Load the Messages > Inbox screen. 
  19. * 
  20. * @since 1.0.0 
  21. */ 
  22. function messages_screen_inbox() { 
  23.  
  24. if ( bp_action_variables() ) { 
  25. bp_do_404(); 
  26. return; 
  27.  
  28. /** 
  29. * Fires right before the loading of the Messages inbox screen template file. 
  30. * 
  31. * @since 1.0.0 
  32. */ 
  33. do_action( 'messages_screen_inbox' ); 
  34.  
  35. /** 
  36. * Filters the template to load for the Messages inbox screen. 
  37. * 
  38. * @since 1.0.0 
  39. * 
  40. * @param string $template Path to the messages template to load. 
  41. */ 
  42. bp_core_load_template( apply_filters( 'messages_template_inbox', 'members/single/home' ) ); 
  43.  
  44. /** 
  45. * Load the Messages > Sent screen. 
  46. * 
  47. * @since 1.0.0 
  48. */ 
  49. function messages_screen_sentbox() { 
  50.  
  51. if ( bp_action_variables() ) { 
  52. bp_do_404(); 
  53. return; 
  54.  
  55. /** 
  56. * Fires right before the loading of the Messages sentbox screen template file. 
  57. * 
  58. * @since 1.0.0 
  59. */ 
  60. do_action( 'messages_screen_sentbox' ); 
  61.  
  62. /** 
  63. * Filters the template to load for the Messages sentbox screen. 
  64. * 
  65. * @since 1.0.0 
  66. * 
  67. * @param string $template Path to the messages template to load. 
  68. */ 
  69. bp_core_load_template( apply_filters( 'messages_template_sentbox', 'members/single/home' ) ); 
  70.  
  71. /** 
  72. * Load the Messages > Compose screen. 
  73. * 
  74. * @since 1.0.0 
  75. */ 
  76. function messages_screen_compose() { 
  77.  
  78. if ( bp_action_variables() ) { 
  79. bp_do_404(); 
  80. return; 
  81.  
  82. // Remove any saved message data from a previous session. 
  83. messages_remove_callback_values(); 
  84.  
  85. /** 
  86. * Fires right before the loading of the Messages compose screen template file. 
  87. * 
  88. * @since 1.0.0 
  89. */ 
  90. do_action( 'messages_screen_compose' ); 
  91.  
  92. /** 
  93. * Filters the template to load for the Messages compose screen. 
  94. * 
  95. * @since 1.0.0 
  96. * 
  97. * @param string $template Path to the messages template to load. 
  98. */ 
  99. bp_core_load_template( apply_filters( 'messages_template_compose', 'members/single/home' ) ); 
  100.  
  101. /** 
  102. * Load an individual conversation screen. 
  103. * 
  104. * @since 1.0.0 
  105. * 
  106. * @return bool|null False on failure. 
  107. */ 
  108. function messages_screen_conversation() { 
  109.  
  110. // Bail if not viewing a single message. 
  111. if ( ! bp_is_messages_component() || ! bp_is_current_action( 'view' ) ) { 
  112. return false; 
  113.  
  114. $thread_id = (int) bp_action_variable( 0 ); 
  115.  
  116. if ( empty( $thread_id ) || ! messages_is_valid_thread( $thread_id ) || ( ! messages_check_thread_access( $thread_id ) && ! bp_current_user_can( 'bp_moderate' ) ) ) { 
  117. bp_core_redirect( trailingslashit( bp_displayed_user_domain() . bp_get_messages_slug() ) ); 
  118.  
  119. // Load up BuddyPress one time. 
  120. $bp = buddypress(); 
  121.  
  122. // Decrease the unread count in the nav before it's rendered. 
  123. $count = bp_get_total_unread_messages_count(); 
  124. $class = ( 0 === $count ) ? 'no-count' : 'count'; 
  125. $nav_name = sprintf( __( 'Messages <span class="%s">%s</span>', 'buddypress' ), esc_attr( $class ), bp_core_number_format( $count ) ); 
  126.  
  127. // Edit the Navigation name. 
  128. $bp->members->nav->edit_nav( array( 
  129. 'name' => $nav_name,  
  130. ), $bp->messages->slug ); 
  131.  
  132. /** 
  133. * Fires right before the loading of the Messages view screen template file. 
  134. * 
  135. * @since 1.7.0 
  136. */ 
  137. do_action( 'messages_screen_conversation' ); 
  138.  
  139. /** 
  140. * Filters the template to load for the Messages view screen. 
  141. * 
  142. * @since 1.0.0 
  143. * 
  144. * @param string $template Path to the messages template to load. 
  145. */ 
  146. bp_core_load_template( apply_filters( 'messages_template_view_message', 'members/single/home' ) ); 
  147. add_action( 'bp_screens', 'messages_screen_conversation' ); 
  148.  
  149. /** 
  150. * Load the Messages > Notices screen. 
  151. * 
  152. * @since 1.0.0 
  153. * 
  154. * @return false|null False on failure. 
  155. */ 
  156. function messages_screen_notices() { 
  157.  
  158. if ( bp_action_variables() ) { 
  159. bp_do_404(); 
  160. return; 
  161.  
  162. /** 
  163. * Fires right before the loading of the Messages notices screen template file. 
  164. * 
  165. * @since 1.0.0 
  166. */ 
  167. do_action( 'messages_screen_notices' ); 
  168.  
  169. /** 
  170. * Filters the template to load for the Messages notices screen. 
  171. * 
  172. * @since 1.0.0 
  173. * 
  174. * @param string $template Path to the messages template to load. 
  175. */ 
  176. bp_core_load_template( apply_filters( 'messages_template_notices', 'members/single/home' ) ); 
  177.  
  178. /** 
  179. * Render the markup for the Messages section of Settings > Notifications. 
  180. * 
  181. * @since 1.0.0 
  182. */ 
  183. function messages_screen_notification_settings() { 
  184.  
  185. if ( bp_action_variables() ) { 
  186. bp_do_404(); 
  187. return; 
  188.  
  189. if ( !$new_messages = bp_get_user_meta( bp_displayed_user_id(), 'notification_messages_new_message', true ) ) { 
  190. $new_messages = 'yes'; 
  191. } ?> 
  192.  
  193. <table class="notification-settings" id="messages-notification-settings"> 
  194. <thead> 
  195. <tr> 
  196. <th class="icon"></th> 
  197. <th class="title"><?php _e( 'Messages', 'buddypress' ) ?></th> 
  198. <th class="yes"><?php _e( 'Yes', 'buddypress' ) ?></th> 
  199. <th class="no"><?php _e( 'No', 'buddypress' )?></th> 
  200. </tr> 
  201. </thead> 
  202.  
  203. <tbody> 
  204. <tr id="messages-notification-settings-new-message"> 
  205. <td></td> 
  206. <td><?php _e( 'A member sends you a new message', 'buddypress' ) ?></td> 
  207. <td class="yes"><input type="radio" name="notifications[notification_messages_new_message]" id="notification-messages-new-messages-yes" value="yes" <?php checked( $new_messages, 'yes', true ) ?>/><label for="notification-messages-new-messages-yes" class="bp-screen-reader-text"><?php 
  208. /** translators: accessibility text */ 
  209. _e( 'Yes, send email', 'buddypress' ); 
  210. ?></label></td> 
  211. <td class="no"><input type="radio" name="notifications[notification_messages_new_message]" id="notification-messages-new-messages-no" value="no" <?php checked( $new_messages, 'no', true ) ?>/><label for="notification-messages-new-messages-no" class="bp-screen-reader-text"><?php 
  212. /** translators: accessibility text */ 
  213. _e( 'No, do not send email', 'buddypress' ); 
  214. ?></label></td> 
  215. </tr> 
  216.  
  217. <?php 
  218.  
  219. /** 
  220. * Fires inside the closing </tbody> tag for messages screen notification settings. 
  221. * 
  222. * @since 1.0.0 
  223. */ 
  224. do_action( 'messages_screen_notification_settings' ); ?> 
  225. </tbody> 
  226. </table> 
  227.  
  228. <?php 
  229. add_action( 'bp_notification_settings', 'messages_screen_notification_settings', 2 ); 
.