Snippi
A super awesome snippet tool.
- 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.
•
- 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.
}