| 1 |
<?php |
| 2 |
// Add Agree/Disagree buttons counters |
| 3 |
function bbpc_get_reply_count(){ |
| 4 |
ob_start(); |
| 5 |
bbp_topic_reply_count(get_the_ID()); |
| 6 |
return ob_get_clean(); |
| 7 |
} |
| 8 |
|
| 9 |
// add a menu inside bbpress profile |
| 10 |
add_action('bbp_template_after_user_details_menu_items', function() { |
| 11 |
?> |
| 12 |
<ul> |
| 13 |
<li class="bbp-user-votings-wrap"> |
| 14 |
<span> |
| 15 |
<a href="<?php bbp_user_profile_url(); ?>?bbpc-voting=true" title="<?php printf( esc_attr__( "%s's Votings", 'bbp-core-pro' ), bbp_get_displayed_user_field( 'display_name' ) ); ?>"> |
| 16 |
<?php esc_html_e( 'Reactions', 'bbp-core-pro' ); ?> |
| 17 |
</a> |
| 18 |
</span> |
| 19 |
</li> |
| 20 |
</ul> |
| 21 |
<?php |
| 22 |
}); |
| 23 |
|
| 24 |
// Display the voting content |
| 25 |
function bbpc_geo_voting_content(){ |
| 26 |
ob_start(); |
| 27 |
echo do_shortcode("[bbpc_geo_votings type='liked']") . do_shortcode("[bbpc_geo_votings type='disliked']"); |
| 28 |
return ob_get_clean(); |
| 29 |
} |
| 30 |
|
| 31 |
// Display the voting content in profile content section |
| 32 |
add_action( 'bbp_template_before_user_wrapper', function(){ |
| 33 |
$bbpc_voting = $_GET['bbpc-voting'] ?? ''; |
| 34 |
if ( $bbpc_voting == true ) { |
| 35 |
if ( get_current_user_id() != bbp_get_displayed_user_field( 'ID' ) ) { |
| 36 |
wp_enqueue_style( 'bbpc' ); |
| 37 |
?> |
| 38 |
<script> |
| 39 |
;(function($){ |
| 40 |
$(document).ready(function(){ |
| 41 |
$('#bbp-user-navigation ul li').removeClass('current'); |
| 42 |
$('.bbp-user-votings-wrap').addClass('current'); |
| 43 |
$('#bbp-user-body').html("<div class='bbpc-no-voting-wrap'> You must logged in to view your votes! </div>"); |
| 44 |
$('.bbpc-no-voting-wrap:not(:last-child)').remove(); |
| 45 |
}); |
| 46 |
})(jQuery); |
| 47 |
</script> |
| 48 |
<?php |
| 49 |
} else { |
| 50 |
$voting_content = bbpc_geo_voting_content(); |
| 51 |
$voting_content = wp_json_encode($voting_content); |
| 52 |
wp_enqueue_style( 'bbpc' ); |
| 53 |
?> |
| 54 |
<script> |
| 55 |
;(function($){ |
| 56 |
$(document).ready(function(){ |
| 57 |
$('#bbp-user-navigation ul li').removeClass('current'); |
| 58 |
$('.bbp-user-votings-wrap').addClass('current'); |
| 59 |
$('#bbp-user-body').html(<?php echo $voting_content; ?>); |
| 60 |
$('.bbpc-no-voting-wrap:not(:last-child)').remove(); |
| 61 |
}); |
| 62 |
})(jQuery); |
| 63 |
</script> |
| 64 |
<?php |
| 65 |
} |
| 66 |
} |
| 67 |
} ); |