I thought that I got it here, on a page that had various code to add to your WP site. If I could find it again I’d likely be able to resolve it…
.bbp-topics ul.sticky,
.bbp-forum-content ul.sticky
{
background-color: blue !important;
}
Can’t remember where I found this code, tried a search, but it use to show 4 topics underneath the Forum headers but no longer shows anymore. Was this affected on an update or perhaps if someone can direct me to the page that had these codes? Thanks.
/*
* Show 4 topics for Forum Groups
*/
ul.bbp-forums-list li:nth-child(n+5) {
display: none !important;
}
Hi Robin,
thank you for your reply.
For your reference, wp-cli commands often (if not all) have default outputs and they do not need to be explicitly declared unless particular outputs are expected.
Here is a list of all post types available on my WordPress installation:
https://markuphero.com/share/5dn5FOkMzGNpG9R6Unbx
As you can see, I have a custom post type named ‘sfwd-lessons’ so if I run the command wp post list --post_type=sfwd-lessons I have all these custom posts which are listed with the default outputs:
https://markuphero.com/share/8Mbqbgujeaou2QH60l1k
But when i’m trying wp post list --post_type=topic the output is empty:
https://markuphero.com/share/3APucSjLM0IHRgLHIuVb
https://markuphero.com/share/V3pihOOXPNQWUx3Knzqd
Have you really tried it on your end?
Warm regards,
Ludovic
Hi there,
if I run a command like wp post-type list I have ‘forum’, ‘topic’ and ‘reply’ which are listed but when I run wp post list --post_type=topic the table remains empty , is this normal?
Thanks for your help!
Ludovic
spectators should not be able to create topics.
Participants by default can.
you will either need to
change participant permissions -see this
Custom Capabilities
or add
Private groups
and set up topic permissions which will then let you set up a group with permission to reply only
you can make a topic ‘super sticky’ which will make it appear at the top of all forums.
I know of nothing that will do a couple of forums, and indeed the code to do so would need to catch lots of areas, such as subscriptions, freshness etc. which at the moment rely on the ‘post parent’ table element of WordPress, so lots of code might be needed to get it to work.
add_filter( 'bbp_get_forum_freshness_link', 'rew_show_forum_freshness' , 10 , 6) ;
function rew_show_forum_freshness ($anchor, $forum_id, $time_since, $link_url, $title, $active_id ){
return $time_since ;
}
add_filter( 'bbp_get_topic_freshness_link', 'rew_show_topic_freshness' , 10 , 6) ;
function rew_show_topic_freshness ($anchor, $topic_id, $time_since, $link_url, $title){
return $time_since ;
}
Put this in your child theme’s function file –
ie wp-content/themes/%your-theme-name%/functions.php
where %your-theme-name% is the name of your theme
or use
Code Snippets
Hello bbpress Support
I have two separate problems but for convenience sake, I’ll just open one topic.
I am currently in the process of building a Forum for an already existing website.
The Owner of this website wants threaded replies to be active for this forum so that users can reply to comments more directly. The problem is that as soon as the threaded replies are active the Page pagination just disappears and everything is displayed on one page. I’ve read online that those two features don’t work together on purpose, but why would that be? Nothing in the plugin mentions or even hints to it that these two features wouldn’t work together. Is there any kind of workaround for this or a custom script maybe? I have knowledge of PHP and JS so any kind of help would be appreciated.
The Next issue is that there seems to be no way to collapse/expand threaded replies. Since the pagination didn’t seem to work I thought collapsing threaded replies would help or else the topic pages would just get crazy long. Is there any code out there that would help me achieve this?
Any kind of help on even one of these issues would be appreciated.
I Would like to avoid working in the plugin itself if possible for obvious reasons.
Thanks in advance
Gerry Zeller
I’m using WP Astra as my theme and the plugin Sidebar Manager (also from Brainstorm Force), which just replaces the theme’s main sidebar with a different one based on the post type being displayed. Inside of the sidebar is a widget and inside of the widget, there are the shortcodes that aren’t being rendered. Let me know what other specific details I might be able to offer that would help. Thanks.
Hi,
Thank you for your reply. I have done first 2 steps. For the third step, you mentioned about this code
` return apply_filters( ‘bbp_get_forum_freshness_link’, $anchor, $forum_id, $time_since, $link_url, $title, $active_id );
}
Please let me know how to change this.
Thank you,
Joel.
untested, but this should take out newlines and change the excerpt length to 150 – just change the 150 in the code to whatever length you want.
so firstly you need to alter the default in wordpress which is 55 so
add_filter( 'excerpt_length', 'rew_change_default_length' ) ;
function rew_change_default_length () {
return 150;
}
then alter it in the bbpress function, and change to take out line breaks
add_filter ('bbp_get_topic_excerpt' , 'rew_remove_line_breaks', 10 , 3) ;
function rew_remove_line_breaks ($excerpt, $topic_id, $length){
$topic_id = bbp_get_topic_id( $topic_id );
//change length here
$length = 150 ;
$excerpt = get_post_field( 'post_excerpt', $topic_id );
if ( empty( $excerpt ) ) {
$excerpt = bbp_get_topic_content( $topic_id );
}
$excerpt = trim( strip_tags( $excerpt ) );
//take out line breaks
$excerpt = preg_replace("/\r|\n/", "", $excerpt);
// Multibyte support
if ( function_exists( 'mb_strlen' ) ) {
$excerpt_length = mb_strlen( $excerpt );
} else {
$excerpt_length = strlen( $excerpt );
}
if ( ! empty( $length ) && ( $excerpt_length > $length ) ) {
$excerpt = mb_substr( $excerpt, 0, $length - 1 );
$excerpt .= '…';
}
// Filter & return
return apply_filters( 'rew_get_topic_excerpt', $excerpt, $topic_id, $length );
}
Put this in your child theme’s function file –
ie wp-content/themes/%your-theme-name%/functions.php
where %your-theme-name% is the name of your theme
or use
Code Snippets
I’ve noticed that any shortcodes in my sidebar are not rendering on bbPress pages. Is there a way to make it so shortcodes are rendering properly? I’ve been searching the forums and can’t seem to find an answer to this. Thanks for any help.
– Aaron
Ah OK – I’ve just found out that RankMath simply extracts the bbpress topic excerpt and uses that for the meta description, i.e. bbp_topic_excerpt()
Is there a way to make bbp_topic_excerpt() ignore line breaks and increase character limit?
@joel-mohanraj
find
wp-content/plugins/bbpress/templates/default/bbpress/loop-single-forum.php
transfer this to your pc and edit
so you will want to take the link out of line 34
<a class="bbp-forum-title" href="<?php bbp_forum_permalink(); ?>"><?php bbp_forum_title(); ?></a>
and save
create a directory on your theme called ‘bbpress’
ie wp-content/themes/%your-theme-name%/bbpress
where %your-theme-name% is the name of your theme
Then transfer the file you saved above and put in in the directory called bbpress that you created above, so you end up with
wp-content/themes/%your-theme-name%/bbpress/loop-single-forum.php
bbPress will now use this template instead of the original
amending the freshness will require you to amend the bbp_get_forum_freshness_link function. if you are familiar with filters you can use the filter on line 585 of \includes\forums and a str_replace to take out the link
Robin W,
Thank you very much for volunteering some thoughts. Especially that you indicating that changes this year haven’t affected the bbp_add_user_forum_subscription function. And it appears that groups_join_group is a BuddyPress function. Your reminder to turn on the debug was priceless. There was only one, unrelated notice.
I rechecked the Developer’s (Harsha Vetkatesh’s) code online and realized that he had added an updated version! At https://gist.github.com/greathmaster/e67f1ae0feb28c9ab3521b404c8e0544. I added it into a staging copy and it threw a specific error. I’m going to see if I can contact him.
Thanks again for the Forum. Our trail club uses it very frequently.
Best Regards,
~April
Hello everyone!
I’m a new user of bbpress and I’m looking for a way for logged in users to subscribe/unsubscribe to all forums by clicking a button.
I’ve managed to do it by myself, but I’d like to know if there is an easier way to do it.
Here is the code in my loop-forums.php file:
<?php
/**
* Forums Loop
*
* @package bbPress
* @subpackage Theme
*/
// Exit if accessed directly
defined('ABSPATH') || exit;
do_action('bbp_template_before_forums_loop'); ?>
<?php
$current_user = get_userdata(get_current_user_id());
if (isset($current_user) && $current_user->ID > 0) :
$user_subscribed_forum_ids = bbp_get_user_subscribed_forum_ids($current_user->ID);
$forum_ids_list = array();
while (bbp_forums()) : bbp_the_forum();
if (bbp_get_forum_type() === 'category') :
foreach (bbp_forum_get_subforums() as $subforum) :
$forum_ids_list[] = $subforum->ID;
endforeach;
else :
$forum_ids_list[] = bbp_get_forum_id();
endif;
endwhile;
$check = sizeof($forum_ids_list) === sizeof($user_subscribed_forum_ids);
$bbp_action = $check ? "bbp_unsubscribe" : 'bbp_subscribe';
$label = $check ? "Unsubscribe of all forums" : "Subscribe of all forums";
$label .= bbp_get_forum_type() === 'category' ? " of this category" : "";
if (isset($_POST) && $_POST['action']) :
foreach ($forum_ids_list as $forum_id) :
$q_args = array(
'action' => $bbp_action,
'object_id' => $forum_id,
'object_type' => 'post'
);
$permalink = bbp_get_forum_permalink($forum_id);
$wp_nonce_url = esc_url(wp_nonce_url(add_query_arg($q_args), 'toggle-subscription_' . $forum_id));
$wp_nonce_url = substr($wp_nonce_url, strlen('/'));
$url = html_entity_decode($permalink . $wp_nonce_url);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_COOKIE, LOGGED_IN_COOKIE . '=' . $_COOKIE[LOGGED_IN_COOKIE]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$response = curl_exec($ch);
curl_close($ch);
endforeach;
$user_subscribed_forum_ids = bbp_get_user_subscribed_forum_ids($current_user->ID);
$check = sizeof($forum_ids_list) === sizeof($user_subscribed_forum_ids);
$bbp_action = $check ? "bbp_unsubscribe" : 'bbp_subscribe';
$label = $check ? "Unsubscribe of all forums" : "Subscribe of all forums";
$label .= bbp_get_forum_type() === 'category' ? " of this category" : "";
endif; // isset($_POST) && $_POST['action']
endif; // isset($current_user) && $current_user->ID > 0
?>
<?php if (isset($_POST) && $_POST['action']) : ?>
<script id="prevent-form-resubmission-when-page-is-refreshed" type="text/javascript">
// source: https://stackoverflow.com/questions/6320113/how-to-prevent-form-resubmission-when-page-is-refreshed-f5-ctrlr
if (window.history.replaceState) {
window.history.replaceState(null, null, window.location.href);
document.getElementById('prevent-form-resubmission-when-page-is-refreshed').remove();
}
</script>
<?php endif; ?>
<?php if (isset($current_user) && $current_user->ID > 0 && !bbp_is_single_user()) : ?>
<form action="" method="POST">
<input type="hidden" name="action" value="<?= $bbp_action ?>">
<button type="submit" style="color: black;"><?= __($label, 'ls') ?></button>
</form>
<?php endif; ?>
<table id="forums-list-<?php bbp_forum_id(); ?>" class="table table-bordered forums-list">
<thead>
<tr>
<th class="forum-title-column">
<?php esc_html_e('Forum', 'ls'); ?>
</th>
<th class="posts-count-column">
<?php bbp_show_lead_topic() ? esc_html_e('Replies', 'ls') : esc_html_e('Posts', 'ls'); ?>
</th>
<th class="last-post-column">
<?php esc_html_e('Last Post', 'ls'); ?>
</th>
</tr>
</thead>
<tbody>
<?php while (bbp_forums()) : bbp_the_forum(); ?>
<?php bbp_get_template_part('loop', 'single-forum'); ?>
<?php endwhile; ?>
</tbody>
</table>
<?php do_action('bbp_template_after_forums_loop');
ps – I presume you have a function
groups_join_group but have not shown it for simplicity ?
just looked at this – sorry, as you say I don’t get to every item, and this is bespoke code which means something to someone, but without a heavy investment of time, it is hard to debug why it is not working 🙂
the function bbp_add_user_forum_subscription is still valid, and should work fine, so the actual change to the way bbpress works should not affect it.
I have little knowledge of buddypress, so I cannot say whether that code is still valid.
Have you turned debugging on ? and is it showing anything ?
I can use the same theme for topics as well, as in this case:
https://www.aqazero.com/forums/forum/acquario-acquariofilia-%f0%9f%8c%8a%f0%9f%90%a0-aqa0-%f0%9f%90%9f%f0%9f%8c%bf/
Unfortunately, however, if I open the question (post) the theme is not inherited
https://www.aqazero.com/forums/topic/prova-topic/ friday night funkin
Is there a shortcodes to display the question (post) and the area to reply (reply form)?
Thanks in advance for your answers..
I have the same issue here. Did you find a fix for it, by any chance?
I am desperately searching for a forum that has the ability to rate threads. The forum will be for promo codes and I want users to have the abilty to ad a yes working or no working comment by way of thumbs. so if one had 10 down thumbs and no up thumbs dont bother!
Is there such an abilty by way of a plugin? I cant aford the hundreds to have code written to do the job (sorry coders)
Just had a thought and dug in the code further, the duplicate check doesn’t apply to those roles/users that can ‘throttle’
// No duplicate checks for those who can throttle
if ( user_can( (int) $r['post_author'], 'throttle' ) ) {
return true;
}
bbPress User Roles and Capabilities
so default Keymaster and Moderator can post duplicates
I am not a bbpress author, just someone who helps out here.
Every website is unique, and this doesn’t happen on my test site – I have not seen this reported elsewhere as an issue, and the code has a duplicate function check in it.
line 307 of includes/replies/functions
/** Reply Duplicate *******************************************************/
if ( ! bbp_check_for_duplicate( array( 'post_type' => bbp_get_reply_post_type(), 'post_author' => $reply_author, 'post_content' => $reply_content, 'post_parent' => $topic_id, 'anonymous_data' => $anonymous_data ) ) ) {
bbp_add_error( 'bbp_reply_duplicate', __( '<strong>Error</strong>: Duplicate reply detected; it looks as though you’ve already said that.', 'bbpress' ) );
}
I am not able to say why you are getting this.
ok, without knowing what is determining the order, it is hard to give you code to correct.
I’d suggest you play with publish dates of the stickies and ant replies to them to see if you can work out the issue, then come back and I’ll see if I can help further
line 322 of \includes\topics\template.php has the function I think
you’d use a filter to add an ‘order by’ probably using the parse args on line 330
so
add_filter ('bbp_before_add_sticky_topics_parse_args' , 'your_function') ;
function your_function ($r) {
//add the order you want to sort
$r['order_by'] = etc......
}
Sorry don’t have time to look at this evening, but come back if you need further help