• 1.
    <?php
  • 2.
    if ( function_exists('dwqa_plugin_init') && function_exists('bp_is_active')) {
  • 3.
      /*-----------------------------------------------------------------------------------*/
  • 4.
      /*  Setup Questions in BuddyPress User Profile
  • 5.
      /*-----------------------------------------------------------------------------------*/
  • 6.
      add_action( 'bp_setup_nav', 'dw_simplex_bp_nav_adder' );
  • 7.
      function dw_simplex_bp_nav_adder() {
  • 8.
         bp_core_new_nav_item(
  • 9.
          array(
  • 10.
            'name' => __('Questions', 'dw-simplex'),
  • 11.
            'slug' => 'questions',
  • 12.
            'position' => 21,
  • 13.
            'show_for_displayed_user' => true,
  • 14.
            'screen_function' => 'questions_list',
  • 15.
            'item_css_id' => 'questions',
  • 16.
            'default_subnav_slug' => 'public'
  • 17.
          ));
  • 18.
      }
  • 19.
     
  • 20.
      function questions_list() {
  • 21.
        add_action( 'bp_template_content', 'profile_questions_loop' );
  • 22.
        bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
  • 23.
      }
  • 24.
     
  • 25.
      function profile_questions_loop() {
  • 26.
        global $dwqa_options;
  • 27.
        $submit_question_link = get_permalink( $dwqa_options['pages']['submit-question'] );
  • 28.
        $questions = get_posts(  array(
  • 29.
          'posts_per_page' => -1,
  • 30.
          'author'         => bp_displayed_user_id(),
  • 31.
          'post_type'      => 'dwqa-question'
  • 32.
        ));
  • 33.
        if( ! empty($questions) ) { ?>
  • 34.
          <div class="dwqa-container">
  • 35.
            <div class="dwqa-list-question">
  • 36.
              <div class="dw-question" id="archive-question">
  • 37.
                <?php foreach ($questions as $q) { ?>
  • 38.
                <article id="question-18267" class="dwqa-question">
  • 39.
                    <header class="dwqa-header">
  • 40.
                        <a class="dwqa-title" href="<?php echo get_post_permalink($q->ID); ?>" title="Permalink to <?php echo $q->post_title ?>" rel="bookmark"><?php echo $q->post_title ?></a>
  • 41.
                        <div class="dwqa-meta">
  • 42.
                            <?php dwqa_question_print_status($q->ID); ?>
  • 43.
                            <span><?php echo get_the_time( 'M d, Y, g:i a', $q->ID ); ?></span>
  • 44.
                            &nbsp;&nbsp;&bull;&nbsp;&nbsp;
  • 45.
                            <?php echo get_the_term_list( $q->ID, 'dwqa-question_category', '<span>Category: ', ', ', '</span>' ); ?> 
  • 46.
                        </div>
  • 47.
                    </header>
  • 48.
                </article>
  • 49.
                <?php } ?>
  • 50.
              </div>
  • 51.
            </div>
  • 52.
          </div>
  • 53.
        <?php } else { ?>
  • 54.
        <div class="info" id="message">
  • 55.
          <?php if( get_current_user_id() == bp_displayed_user_id() ) : ?>
  • 56.
            Why don't you have question for us. <a href="<?php echo $submit_question_link ?>">Start asking</a>!
  • 57.
          <?php else : ?>
  • 58.
            <p><strong><?php bp_displayed_user_fullname(); ?></strong> has not asked any question.</p>
  • 59.
          <?php endif; ?>
  • 60.
        </div>
  • 61.
        <?php }
  • 62.
      }
  • 63.
     
  • 64.
      /*-----------------------------------------------------------------------------------*/
  • 65.
      /*  Record Activities
  • 66.
      /*-----------------------------------------------------------------------------------*/
  • 67.
      // Question
  • 68.
      function dw_simplex_record_question_activity( $post_id ) {
  • 69.
        $post = get_post($post_id);
  • 70.
        if(($post->post_status != 'publish') && ($post->post_status != 'private'))
  • 71.
          return;
  • 72.
     
  • 73.
        $user_id = get_current_user_id();
  • 74.
        $post_permalink = get_permalink( $post_id );
  • 75.
        $post_title = get_the_title( $post_id );
  • 76.
        $activity_action = sprintf( __( '%s asked a new question: %s', 'dw-simplex' ), bp_core_get_userlink( $user_id ), '<a href="' . $post_permalink . '">' . $post->post_title . '</a>' );
  • 77.
        $content = $post->post_content;
  • 78.
        $hide_sitewide = ($post->post_status == 'private') ? true : false;
  • 79.
     
  • 80.
        bp_blogs_record_activity( array(
  • 81.
          'user_id' => $user_id,
  • 82.
          'action' => $activity_action,
  • 83.
          'content' => $content,
  • 84.
          'primary_link' => $post_permalink,
  • 85.
          'type' => 'new_blog_post',
  • 86.
          'item_id' => 0,
  • 87.
          'secondary_item_id' => $post_id,
  • 88.
          'recorded_time' => $post->post_date_gmt,
  • 89.
          'hide_sitewide' => $hide_sitewide,
  • 90.
        ));
  • 91.
      }
  • 92.
      add_action( 'dwqa_add_question', 'dw_simplex_record_question_activity');
  • 93.
     
  • 94.
      //Answer
  • 95.
      function dw_simplex_record_answer_activity( $post_id ) {
  • 96.
        $post = get_post($post_id);
  • 97.
     
  • 98.
        if($post->post_status != 'publish')
  • 99.
          return;
  • 100.
     
  • 101.
        $user_id = $post->post_author;
  • 102.
     
  • 103.
        $question_id = get_post_meta( $post_id, '_question', true );
  • 104.
        $question = get_post( $question_id );
  • 105.
     
  • 106.
        $post_permalink = get_permalink($question_id);
  • 107.
        $activity_action = sprintf( __( '%s answered the question: %s', 'dw-simplex' ), bp_core_get_userlink( $user_id ), '<a href="' . $post_permalink . '">' . $question->post_title . '</a>' );
  • 108.
        $content = $post->post_content;
  • 109.
     
  • 110.
        $hide_sitewide = ($question->post_status == 'private') ? true : false;
  • 111.
     
  • 112.
        bp_blogs_record_activity( array(
  • 113.
          'user_id' => $user_id,
  • 114.
          'action' => $activity_action,
  • 115.
          'content' => $content,
  • 116.
          'primary_link' => $post_permalink,
  • 117.
          'type' => 'new_blog_post',
  • 118.
          'item_id' => 0,
  • 119.
          'secondary_item_id' => $post_id,
  • 120.
          'recorded_time' => $post->post_date_gmt,
  • 121.
          'hide_sitewide' => $hide_sitewide,
  • 122.
        ));
  • 123.
      }
  • 124.
      add_action( 'dwqa_add_answer', 'dw_simplex_record_answer_activity');
  • 125.
      add_action( 'dwqa_update_answer', 'dw_simplex_record_answer_activity');
  • 126.
     
  • 127.
      //Comment
  • 128.
      function dw_simplex_record_comment_activity( $comment_id ) {
  • 129.
        $comment = get_comment($comment_id);
  • 130.
        $user_id = get_current_user_id();
  • 131.
        $post_id = $comment->comment_post_ID;
  • 132.
        $content = $comment->comment_content;
  • 133.
     
  • 134.
        if(get_post_type($post_id) == 'dwqa-question') {
  • 135.
          $post = get_post( $post_id );
  • 136.
          $post_permalink = get_permalink( $post_id );
  • 137.
          $activity_action = sprintf( __( '%s commented on the question: %s', 'dw-simplex' ), bp_core_get_userlink( $user_id ), '<a href="' . $post_permalink . '">' . $post->post_title . '</a>' );
  • 138.
          $hide_sitewide = ($post->post_status == 'private') ? true : false;
  • 139.
        } else {
  • 140.
          $post = get_post( $post_id );
  • 141.
          $question_id = get_post_meta( $post_id, '_question', true );
  • 142.
          $question = get_post( $question_id );
  • 143.
          $post_permalink = get_permalink( $question_id );
  • 144.
          $activity_action = sprintf( __( '%s commented on the answer at: %s', 'dw-simplex' ), bp_core_get_userlink( $user_id ), '<a href="' . $post_permalink . '">' . $question->post_title . '</a>' );
  • 145.
          $hide_sitewide = ($question->post_status == 'private') ? true : false;
  • 146.
        }
  • 147.
     
  • 148.
        bp_blogs_record_activity( array(
  • 149.
          'user_id' => $user_id,
  • 150.
          'action' => $activity_action,
  • 151.
          'content' => $content,
  • 152.
          'primary_link' => $post_permalink,
  • 153.
          'type' => 'new_blog_comment',
  • 154.
          'item_id' => 0,
  • 155.
          'secondary_item_id' => $comment_id,
  • 156.
          'recorded_time' => $comment->comment_date_gmt,
  • 157.
          'hide_sitewide' => $hide_sitewide,
  • 158.
        ));
  • 159.
      }
  • 160.
      add_action( 'dwqa_add_comment', 'dw_simplex_record_comment_activity');
  • 161.
    }
<?php if ( function_exists('dwqa_plugin_init') && function_exists('bp_is_active')) { /*-----------------------------------------------------------------------------------*/ /* Setup Questions in BuddyPress User Profile /*-----------------------------------------------------------------------------------*/ add_action( 'bp_setup_nav', 'dw_simplex_bp_nav_adder' ); function dw_simplex_bp_nav_adder() { bp_core_new_nav_item( array( 'name' => __('Questions', 'dw-simplex'), 'slug' => 'questions', 'position' => 21, 'show_for_displayed_user' => true, 'screen_function' => 'questions_list', 'item_css_id' => 'questions', 'default_subnav_slug' => 'public' )); } function questions_list() { add_action( 'bp_template_content', 'profile_questions_loop' ); bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) ); } function profile_questions_loop() { global $dwqa_options; $submit_question_link = get_permalink( $dwqa_options['pages']['submit-question'] ); $questions = get_posts( array( 'posts_per_page' => -1, 'author' => bp_displayed_user_id(), 'post_type' => 'dwqa-question' )); if( ! empty($questions) ) { ?> <div class="dwqa-container"> <div class="dwqa-list-question"> <div class="dw-question" id="archive-question"> <?php foreach ($questions as $q) { ?> <article id="question-18267" class="dwqa-question"> <header class="dwqa-header"> <a class="dwqa-title" href="<?php echo get_post_permalink($q->ID); ?>" title="Permalink to <?php echo $q->post_title ?>" rel="bookmark"><?php echo $q->post_title ?></a> <div class="dwqa-meta"> <?php dwqa_question_print_status($q->ID); ?> <span><?php echo get_the_time( 'M d, Y, g:i a', $q->ID ); ?></span> &nbsp;&nbsp;&bull;&nbsp;&nbsp; <?php echo get_the_term_list( $q->ID, 'dwqa-question_category', '<span>Category: ', ', ', '</span>' ); ?> </div> </header> </article> <?php } ?> </div> </div> </div> <?php } else { ?> <div class="info" id="message"> <?php if( get_current_user_id() == bp_displayed_user_id() ) : ?> Why don't you have question for us. <a href="<?php echo $submit_question_link ?>">Start asking</a>! <?php else : ?> <p><strong><?php bp_displayed_user_fullname(); ?></strong> has not asked any question.</p> <?php endif; ?> </div> <?php } } /*-----------------------------------------------------------------------------------*/ /* Record Activities /*-----------------------------------------------------------------------------------*/ // Question function dw_simplex_record_question_activity( $post_id ) { $post = get_post($post_id); if(($post->post_status != 'publish') && ($post->post_status != 'private')) return; $user_id = get_current_user_id(); $post_permalink = get_permalink( $post_id ); $post_title = get_the_title( $post_id ); $activity_action = sprintf( __( '%s asked a new question: %s', 'dw-simplex' ), bp_core_get_userlink( $user_id ), '<a href="' . $post_permalink . '">' . $post->post_title . '</a>' ); $content = $post->post_content; $hide_sitewide = ($post->post_status == 'private') ? true : false; bp_blogs_record_activity( array( 'user_id' => $user_id, 'action' => $activity_action, 'content' => $content, 'primary_link' => $post_permalink, 'type' => 'new_blog_post', 'item_id' => 0, 'secondary_item_id' => $post_id, 'recorded_time' => $post->post_date_gmt, 'hide_sitewide' => $hide_sitewide, )); } add_action( 'dwqa_add_question', 'dw_simplex_record_question_activity'); //Answer function dw_simplex_record_answer_activity( $post_id ) { $post = get_post($post_id); if($post->post_status != 'publish') return; $user_id = $post->post_author; $question_id = get_post_meta( $post_id, '_question', true ); $question = get_post( $question_id ); $post_permalink = get_permalink($question_id); $activity_action = sprintf( __( '%s answered the question: %s', 'dw-simplex' ), bp_core_get_userlink( $user_id ), '<a href="' . $post_permalink . '">' . $question->post_title . '</a>' ); $content = $post->post_content; $hide_sitewide = ($question->post_status == 'private') ? true : false; bp_blogs_record_activity( array( 'user_id' => $user_id, 'action' => $activity_action, 'content' => $content, 'primary_link' => $post_permalink, 'type' => 'new_blog_post', 'item_id' => 0, 'secondary_item_id' => $post_id, 'recorded_time' => $post->post_date_gmt, 'hide_sitewide' => $hide_sitewide, )); } add_action( 'dwqa_add_answer', 'dw_simplex_record_answer_activity'); add_action( 'dwqa_update_answer', 'dw_simplex_record_answer_activity'); //Comment function dw_simplex_record_comment_activity( $comment_id ) { $comment = get_comment($comment_id); $user_id = get_current_user_id(); $post_id = $comment->comment_post_ID; $content = $comment->comment_content; if(get_post_type($post_id) == 'dwqa-question') { $post = get_post( $post_id ); $post_permalink = get_permalink( $post_id ); $activity_action = sprintf( __( '%s commented on the question: %s', 'dw-simplex' ), bp_core_get_userlink( $user_id ), '<a href="' . $post_permalink . '">' . $post->post_title . '</a>' ); $hide_sitewide = ($post->post_status == 'private') ? true : false; } else { $post = get_post( $post_id ); $question_id = get_post_meta( $post_id, '_question', true ); $question = get_post( $question_id ); $post_permalink = get_permalink( $question_id ); $activity_action = sprintf( __( '%s commented on the answer at: %s', 'dw-simplex' ), bp_core_get_userlink( $user_id ), '<a href="' . $post_permalink . '">' . $question->post_title . '</a>' ); $hide_sitewide = ($question->post_status == 'private') ? true : false; } bp_blogs_record_activity( array( 'user_id' => $user_id, 'action' => $activity_action, 'content' => $content, 'primary_link' => $post_permalink, 'type' => 'new_blog_comment', 'item_id' => 0, 'secondary_item_id' => $comment_id, 'recorded_time' => $comment->comment_date_gmt, 'hide_sitewide' => $hide_sitewide, )); } add_action( 'dwqa_add_comment', 'dw_simplex_record_comment_activity'); }

Copy Code to Clipboard Raw

Sign-in or Create a Free Account.

Snippi uses Twitter or Facebook to register and create accounts. Registration will enable you to keep track of your snippets. We never spam your timeline or wall. Ever.

Sign-in with Facebook Sign-in with Twitter