WordPress.org

Ready to get started?Download WordPress

Forums

Buddy-bbPress Support Topic
[resolved] Request: Always-on for selected forums (3 posts)

  1. Erlend Sogge Heggen
    Member
    Posted 1 year ago #

    It would be really great if we could set this plugin to be always-on for certain forums. We have a main category called "Troubleshooting" with a bunch of child-forums underneath it, all dedicated to support. It would be a much better user experience if we could make the "Support topic" option already checked i.e. opt-out (or even better, locked to opt-in) for all of these forums.

    http://wordpress.org/extend/plugins/buddy-bbpress-support-topic/

  2. imath
    Member
    Plugin Author

    Posted 1 year ago #

    Well, i can give you a way to explore how to achieve your goal. This is what i've tested with bbPress 2.2.3 (without BuddyPress), i imagine that forum 17 will always contain support topic..

    add_action('wp_footer', 'erlend_forces_support');
    
    function erlend_forces_support() {
    	// your forum id
    	$forum_id = 17;
    
    	if( bbp_get_forum_id() == $forum_id ) {
    		?>
    		<script type="text/javascript">
    			jQuery(document).ready(function($){
    				if( $('#bp_bbp_st_is_support').length ) {
    					$('#bp_bbp_st_is_support').attr('checked', 'checked' );
    					$("#bp_bbp_st_is_support").attr('disabled', 'disabled' );
    					$("#bp_bbp_st_is_support").attr('readonly', 'readonly' );
    				}
    
    				$('#bbp_topic_submit').on('click', function(){
    					$("#bp_bbp_st_is_support").attr('disabled', false );
    					return true;
    				});
    			});
    		</script>
    		<?php
    	}
    }
  3. Erlend Sogge Heggen
    Member
    Posted 1 year ago #

    That does the trick alright! Thanks a bunch.

    For our purposes we needed to apply it to more than one forum. Just applying it to a parent category (didn't try a parent forum though) won't recursively apply it to the forums underneath it, so we applied every forum id manually with this slightly modified snippet:

    add_action('wp_footer', 'erlend_forces_support');
    
    function erlend_forces_support(){
    	$forumIDs = array(17, 42, 999);
    	if(in_array(bbp_get_forum_id(), $forumIDs)){
    		?>
    		<script type="text/javascript">
    			jQuery(document).ready(function($){
    				if($('#bp_bbp_st_is_support').length){
    					$('#bp_bbp_st_is_support').attr('checked', 'checked');
    					$("#bp_bbp_st_is_support").attr('disabled', 'disabled');
    					$("#bp_bbp_st_is_support").attr('readonly', 'readonly');
    				}
    				$('#bbp_topic_submit').on('click', function(){
    					$("#bp_bbp_st_is_support").attr('disabled', false);
    					return true;
    				});
    			});
    		</script>
    		<?php
    	}
    }

    Oh, and for other tech-illiterates like myself, you're gonna want to put this code in your child-theme's functions.php file (do share if there are better alternatives, but this worked for me) and you'll find a forum's ID by going to /wp-admin/edit.php?post_type=forum and mousing over or opening a forum to reveal it's "post" number, i.e. it's id, for example post=197975. And yes, we had a number that large, almost definitely as a result of our conversion from the BuddyPress legacy forum.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic