long answer I’m afraid and in two parts
part 1 – setting the user permission to allow delete topic and delete reply
delete is easy, making it only trash is in part 2 !
Basically you’ll need to change a couple of capabilities of the participant role
see
https://codex.bbpress.org/bbpress-user-roles-and-capabilities/
you see the abilities delete topics and delete replies (as distinct from delete others topics and delete others replies)
Whilst you could amend the participant role, I haven’t documented that, so easiest is just for you to create a new role and give it the participant capabilities plus the ‘delete topics’ and ‘delete replies’. This article explains how
Custom Capabilities
add this code to your functions file – see
Functions files and child themes – explained !
part 2 – changing the function, so that delete is only shown for keymasters
This code will only allow a keymaster to permanently delete a topic
add the following to your functions file
add_filter ('bbp_get_topic_trash_link', 'topic_dont_delete');
add_filter ('bbp_get_reply_trash_link', 'reply_dont_delete');
function topic_dont_delete( $args = '') {
// Parse arguments against default values
$r = bbp_parse_args( $args, array(
'id' => 0,
'link_before' => '',
'link_after' => '',
'sep' => ' | ',
'trash_text' => esc_html__( 'Trash', 'bbpress' ),
'restore_text' => esc_html__( 'Restore', 'bbpress' ),
'delete_text' => esc_html__( 'Delete', 'bbpress' )
), 'get_topic_trash_link' );
$actions = array();
$topic = bbp_get_topic( bbp_get_topic_id( (int) $r['id'] ) );
if ( empty( $topic ) || !current_user_can( 'delete_topic', $topic->ID ) ) {
return;
}
if ( bbp_is_topic_trash( $topic->ID ) ) {
$actions['untrash'] = '<a title="' . esc_attr__( 'Restore this item from the Trash', 'bbpress' ) . '" href="' . esc_url( wp_nonce_url( add_query_arg( array( 'action' => 'bbp_toggle_topic_trash', 'sub_action' => 'untrash', 'topic_id' => $topic->ID ) ), 'untrash-' . $topic->post_type . '_' . $topic->ID ) ) . '" class="bbp-topic-restore-link">' . $r['restore_text'] . '</a>';
} elseif ( EMPTY_TRASH_DAYS ) {
$actions['trash'] = '<a title="' . esc_attr__( 'Move this item to the Trash', 'bbpress' ) . '" href="' . esc_url( wp_nonce_url( add_query_arg( array( 'action' => 'bbp_toggle_topic_trash', 'sub_action' => 'trash', 'topic_id' => $topic->ID ) ), 'trash-' . $topic->post_type . '_' . $topic->ID ) ) . '" class="bbp-topic-trash-link">' . $r['trash_text'] . '</a>';
}
if ( bbp_is_topic_trash( $topic->ID ) || !EMPTY_TRASH_DAYS ) {
if ( bbp_is_user_keymaster()) {
$actions['delete'] = '<a title="' . esc_attr__( 'Delete this item permanently', 'bbpress' ) . '" href="' . esc_url( wp_nonce_url( add_query_arg( array( 'action' => 'bbp_toggle_topic_trash', 'sub_action' => 'delete', 'topic_id' => $topic->ID ) ), 'delete-' . $topic->post_type . '_' . $topic->ID ) ) . '" onclick="return confirm(\'' . esc_js( __( 'Are you sure you want to delete that permanently?', 'bbpress' ) ) . '\' );" class="bbp-topic-delete-link">' . $r['delete_text'] . '</a>';
}
}
// Process the admin links
$retval = $r['link_before'] . implode( $r['sep'], $actions ) . $r['link_after'];
return $retval ;
}
function reply_dont_delete( $args = '' ) {
// Parse arguments against default values
$r = bbp_parse_args( $args, array(
'id' => 0,
'link_before' => '',
'link_after' => '',
'sep' => ' | ',
'trash_text' => esc_html__( 'Trash', 'bbpress' ),
'restore_text' => esc_html__( 'Restore', 'bbpress' ),
'delete_text' => esc_html__( 'Delete', 'bbpress' )
), 'get_reply_trash_link' );
$actions = array();
$reply = bbp_get_reply( bbp_get_reply_id( (int) $r['id'] ) );
if ( empty( $reply ) || !current_user_can( 'delete_reply', $reply->ID ) ) {
return;
}
if ( bbp_is_reply_trash( $reply->ID ) ) {
$actions['untrash'] = '<a title="' . esc_attr__( 'Restore this item from the Trash', 'bbpress' ) . '" href="' . esc_url( wp_nonce_url( add_query_arg( array( 'action' => 'bbp_toggle_reply_trash', 'sub_action' => 'untrash', 'reply_id' => $reply->ID ) ), 'untrash-' . $reply->post_type . '_' . $reply->ID ) ) . '" class="bbp-reply-restore-link">' . $r['restore_text'] . '</a>';
} elseif ( EMPTY_TRASH_DAYS ) {
$actions['trash'] = '<a title="' . esc_attr__( 'Move this item to the Trash', 'bbpress' ) . '" href="' . esc_url( wp_nonce_url( add_query_arg( array( 'action' => 'bbp_toggle_reply_trash', 'sub_action' => 'trash', 'reply_id' => $reply->ID ) ), 'trash-' . $reply->post_type . '_' . $reply->ID ) ) . '" class="bbp-reply-trash-link">' . $r['trash_text'] . '</a>';
}
if ( bbp_is_reply_trash( $reply->ID ) || !EMPTY_TRASH_DAYS ) {
if ( bbp_is_user_keymaster()) {
$actions['delete'] = '<a title="' . esc_attr__( 'Delete this item permanently', 'bbpress' ) . '" href="' . esc_url( wp_nonce_url( add_query_arg( array( 'action' => 'bbp_toggle_reply_trash', 'sub_action' => 'delete', 'reply_id' => $reply->ID ) ), 'delete-' . $reply->post_type . '_' . $reply->ID ) ) . '" onclick="return confirm(\'' . esc_js( __( 'Are you sure you want to delete that permanently?', 'bbpress' ) ) . '\' );" class="bbp-reply-delete-link">' . $r['delete_text'] . '</a>';
}
}
// Process the admin links
$retval = $r['link_before'] . implode( $r['sep'], $actions ) . $r['link_after'];
return $retval ;
}
I haven’t fully tested this code as my test site is in some disarray whilst I test something else, so you’ll need to check that it works