vapvarun

BuddyPress for Sensei: Contact lessaon teacher(Messaging rec

Jul 22nd, 2016
354
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.45 KB | None | 0 0
  1. /**
  2.  * BuddyPress for Sensei: Contact lessaon teacher(Messaging recipient fix)
  3.  */
  4. function bboss_custom_sensei_send_message_link() {
  5.     global $BUDDYPRESS_SENSEI;
  6.  
  7.     remove_action( 'sensei_single_lesson_content_inside_before', array( $BUDDYPRESS_SENSEI->bp_sensei_loader, 'bp_sensei_send_message_link' ), 110 );
  8.  
  9.     add_action( 'sensei_single_lesson_content_inside_before', 'bboss_sensei_send_message_link', 110 );
  10. }
  11.  
  12. add_action( 'init', 'bboss_custom_sensei_send_message_link', 99 );
  13.  
  14. /**
  15.  * Sensei send message link override
  16.  */
  17. function bboss_sensei_send_message_link() {
  18.     global $woothemes_sensei, $post;
  19.     $sensei_message_class_object = $woothemes_sensei->post_types->messages;
  20.  
  21.     if ( ! ( is_singular( 'course' ) || is_singular( 'lesson' ) ) ) return;
  22.  
  23.     $html = '';
  24.  
  25.     if( ! isset( $woothemes_sensei->settings->settings['messages_disable'] ) || ! $woothemes_sensei->settings->settings['messages_disable'] ) {
  26.  
  27.         if( ! is_user_logged_in() ) return;
  28.  
  29.         if( isset( $_GET['contact'] ) ) {
  30.             $html .= $sensei_message_class_object->teacher_contact_form( $post );
  31.         } else {
  32.             $href = esc_url(add_query_arg( array( 'contact' => $post->post_type ) ));
  33.             if( bp_is_active( 'messages' ) ){
  34.                 $user_domain   = bp_loggedin_user_domain();
  35.                 $messages_link = trailingslashit( $user_domain . BP_MESSAGES_SLUG );
  36.                 $compose_link = trailingslashit( $messages_link . 'compose' ) . '?r=' . bp_core_get_username( $post->post_author );
  37.                 $html .= '<p class="bp-sensei-msg-link"><a class="button send-message-button" href="' . $compose_link . '">' . sprintf( __( 'Contact %1$s Teacher', 'sensei-buddypress' ), ucfirst( $post->post_type ) ) . '</a></p>';
  38.             }else{
  39.                 $html .= '<p class="bp-sensei-msg-link"><a class="button send-message-button" href="' . $href . '#private_message">' . sprintf( __( 'Contact %1$s Teacher', 'sensei-buddypress' ), ucfirst( $post->post_type ) ) . '</a></p>';
  40.             }
  41.         }
  42.  
  43.         if( isset( $sensei_message_class_object->message_notice ) && isset( $sensei_message_class_object->message_notice['type'] ) && isset( $sensei_message_class_object->message_notice['notice'] ) ) {
  44.             $html .= '<div class="sensei-message ' . $sensei_message_class_object->message_notice['type'] . '">' . $sensei_message_class_object->message_notice['notice'] . '</div>';
  45.         }
  46.  
  47.     }
  48.  
  49.     echo $html;
  50. }
Add Comment
Please, Sign In to add comment