bbpress participant가 자신의 토픽과 댓글을 지울 수 있도록 하는 방법

bbpress participant 토픽과 댓글 지울 수 있도록 권한을 부여하는 방법

 /*Customize the BBPress roles to allow Participants to trash topics*/
add_filter( 'bbp_get_caps_for_role', 'ST_add_role_caps_filter', 10, 2 );

function ST_add_role_caps_filter( $caps, $role ){
    // Only filter for roles we are interested in!
    if( $role == bbp_get_participant_role() ) {
			
			$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,
			);

	}
	
    return $caps;
}
/*then only allow participants to trash their own topics*/

add_filter( 'bbp_map_reply_meta_caps', 'ST_tweak_trash_meta_caps', 11, 4 );
add_filter( 'bbp_map_topic_meta_caps', 'ST_tweak_trash_meta_caps', 11, 4 );

function ST_tweak_trash_meta_caps( $caps, $cap, $user_id, $args ){

	// apply only to delete_reply and delete_topic
	if ( $cap == "delete_reply" || $cap == "delete_topic" ){
		// Get the post
		$_post = get_post( $args[0] );
		if ( !empty( $_post ) ) {

			// Get caps for post type object
			$post_type = get_post_type_object( $_post->post_type );
			//$caps      = array();

			// Add 'do_not_allow' cap if user is spam or deleted
			if ( bbp_is_user_inactive( $user_id ) ) {
				$caps[] = 'do_not_allow';

			// Moderators can always edit forum content
			} elseif ( user_can( $user_id, 'moderate' ) ) {
				$caps[] = 'moderate';

			// User is author so allow edit if not in admin
            } elseif ( user_can( $user_id, 'participate' ) && ( (int) $user_id === (int) $_post->post_author ) ) {
                $caps      = array();
				//$caps[] = $post_type->cap->delete_posts;

			// Unknown so do not allow
			} else {
				$caps[] = 'do_not_allow';
			}
		}
	}	
	// return the capabilities
	return $caps;
	}

댓글 남기기

이메일은 공개되지 않습니다. 필수 입력창은 * 로 표시되어 있습니다