Skip to:
Content
Pages
Categories
Search
Top
Bottom

User Role Modification

  • @scare31125

    Participant

    Hello,
    I have a bbPress site. I want to change some role permission.
    1. Participant Role will be able to delete their post and topic.
    2. Annonymous user can delete their post and reply.
    For number 1. I tried to follow this post but i am very confused. I added this code to theme child function.php

    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 ;
    	}

    But as I understood that, it was trashing post not deleting them. What I have missed? This code didnot worked for me. May be I have missed some steps.

    And for 2, I don’t know if its possible or not. Searched a lot but haven’t found any solution yet. My understanding is annonymous is not a role, nore a user. So how we can achieve that?

    Thank You

  • You must be logged in to reply to this topic.
Skip to toolbar