Skip to:
Content
Pages
Categories
Search
Top
Bottom

Allow participants to trash their own topic and replies?


  • Leonyipa
    Participant

    @leonyipa

    How to Allow participants to “trash” their own topic and replies?
    like keymaster did?

    I only want them to be able to trash, but not delete it.

    Thanks!

Viewing 14 replies - 1 through 14 (of 14 total)

  • Robin W
    Moderator

    @robin-w

    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

    http://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

    http://codex.bbpress.org/custom-capabilities/

    add this code to your functions file – see

    http://codex.bbpress.org/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


    Leonyipa
    Participant

    @leonyipa

    hi, sorry for the late reply.

    I tried both ways:

    1) changing the Participant role directly

    // Participant/Default
    case bbp_get_participant_role() :
    default :
    $caps = array(

    // Primary caps
    ‘spectate’ => true,
    ‘participate’ => true,

    // Forum caps
    ‘read_private_forums’ => true,

    // Topic caps
    ‘publish_topics’ => true,
    ‘edit_topics’ => true,
    ‘delete_topics’ => true,

    // Reply caps
    ‘publish_replies’ => true,
    ‘edit_replies’ => true,
    ‘delete_replies’ => true,

    // Topic tag caps
    ‘assign_topic_tags’ => true,
    );

    break;
    }

    after I changed it, nothing happened :/

    and
    2) making custom role, but it says:

    Parse error: syntax error, unexpected ‘roles’ (T_STRING), expecting ‘(‘ in /home/gleam/public_html/wp-content/plugins/bbpress/includes/core/capabilities.php on line 216

    
    216: function add_new roles( $bbp_roles )
    217: {

    Robin W
    Moderator

    @robin-w

    you shouldn’t be changing directly !

    can you come back and post your code for 2, you’ve just missed a “‘” somewhere I expect.


    Leonyipa
    Participant

    @leonyipa

    yes, sorry for the late reply,
    where did I miss?


    Robin W
    Moderator

    @robin-w

    can you come back and post your code for 2

    that’s why I need your to post your code, so that I can work out where it’s wrong :-)


    Leonyipa
    Participant

    @leonyipa

    Sorry for the late reply,

    why changing directly doesn’t work? I am a bit confused sorry

    yes, I will paste the code


    Leonyipa
    Participant

    @leonyipa

    My Full Code in /public_html/wp-content/plugins/bbpress/includes/core/capabilitiese.php

    http://pastebin.com/bdisb0Bb


    Robin W
    Moderator

    @robin-w

    why changing directly doesn’t work?

    because on every software update you will lose your changes!

    My Full Code

    sorry but pastebin adds millions of blank lines, so without re-editing the file I can’t see what you are doing.

    If you go back to my original instructions and follow these and get an error, then come back and I’ll try and help you further

    or if you go back to your

    2) making custom role, but it says:

    “ Parse error: syntax error, unexpected ‘roles’ (T_STRING), expecting ‘(‘ in /home/gleam/public_html/wp-content/plugins/bbpress/includes/core/capabilities.php on line 216

    216: function add_new roles( $bbp_roles )
    217: {

    and let me have lines 210 to 220 I’ll try and sort the error


    Leonyipa
    Participant

    @leonyipa

    yes, I followed your instructions, and when I saw:

    http://codex.bbpress.org/custom-capabilities/

    I followed it and copy-and-pasted the code into my capabilities.php

    however, it still show me the error message.

    sorry but pastebin adds millions of blank lines, so without re-editing the file I can’t see what you are doing.

    Does it work if using RAW Paste Data?


    Robin W
    Moderator

    @robin-w

    Apologies was trying to answer many threads with guests due for dinner, so prevouis answer was a bit short !

    I followed it and copy-and-pasted the code into my capabilities.php

    ahhh, now I understand, as per original thread you need to add that code to your functions.php, not to capabilities.php, and that would explain the error.

    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

    http://codex.bbpress.org/custom-capabilities/

    add this code to your functions file – see

    http://codex.bbpress.org/functions-files-and-child-themes-explained/


    Leonyipa
    Participant

    @leonyipa

    Thanks very much for the quick response, I will try it right away!


    Leonyipa
    Participant

    @leonyipa

    now I added the code in functions.php
    but the error message still appear:

    Parse error: syntax error, unexpected T_STRING, expecting ‘(‘ in /home/u639474582/public_html/wp-content/plugins/bbpress/includes/core/functions.php on line 168

    My Full Code:

    http://pastebin.com/75iu9ijH


    Robin W
    Moderator

    @robin-w

    [ignore this post]


    Robin W
    Moderator

    @robin-w

    ok, I’ve worked out that error

    You have two issues

    1. the code is slightly wrong, I’ve corrected it in the documentation, but you need to change your line 168 from

    function add_new roles( $bbp_roles )
    

    to

    function add_new_roles( $bbp_roles )

    ie an underline between ‘new’ and ‘roles’

    BUT MORE IMPORTANTLY

    2. you have now put the code in a core functions file of bbpress, and it cannot run there as it calls code that has not yet been loaded.

    The code needs to go into your THEME’s functions.php file, not any functions file with the PLUGIN bbpress.

    Please read again

    http://codex.bbpress.org/functions-files-and-child-themes-explained/

Viewing 14 replies - 1 through 14 (of 14 total)

You must be logged in to reply to this topic.