BuddyDev

Search

Replies

  • Keymaster
    (BuddyDev Team)
    Posts: 25057
    Brajesh Singh on in reply to: [Resolved] BBpress – restrict topic creation #2311

    You are most welcome. Glad, I was able to help 🙂

  • Keymaster
    (BuddyDev Team)
    Posts: 25057
    Brajesh Singh on in reply to: [Resolved] BBpress Thread Prefix Plugin Idea #2310

    Thank you Joshua.
    I looked at it. Looks perfect to me 🙂

  • Keymaster
    (BuddyDev Team)
    Posts: 25057
    Brajesh Singh on in reply to: [Resolved] How to modify wp-admin-bar-my-account? #2307

    Thank Christopher for taking time to reply. Appreciate it 🙂

    PS: I wrote a blog post yesterday to make t available for everyone. Thank you Hans for bringing it 🙂
    https://buddydev.com/buddypress/enhancing-my-account-menu-with-buddypress-in-the-adminbar/

  • Keymaster
    (BuddyDev Team)
    Posts: 25057
    Brajesh Singh on in reply to: [Resolved] BBpress – restrict topic creation #2306

    Hi Joshua,
    I have updated the code.
    There was a logical issue where I used bpp_is_forum() that does not check for current forum just the post type. Have updated the code now.

  • Keymaster
    (BuddyDev Team)
    Posts: 25057
    Brajesh Singh on in reply to: [Resolved] BBpress – restrict topic creation #2300

    Hi Joshua,
    Thank you.
    You can put the following code in your theme’s functions.php and it will work

    
    
    function buddydev_bbp_restrict_topic_creation( $can ) {
    		
    	$forum_id = 222;//change your forum id
    	
    	if ( ! bbp_is_user_keymaster() &&  bbp_is_single_forum() &&  $forum_id ==  bbp_get_forum_id() ) {
    		$can = false;
    		
    	}
    	
    	return $can;
    	
    
    }
    add_filter( 'bbp_current_user_can_publish_topics', 'buddydev_bbp_restrict_topic_creation' );
    
    function buddydev_restrict_from_posting_topic( $forum_id ) {
    	
    	$restricted_forum_id = 222;
    	
    	if ( ! bbp_is_user_keymaster() && $forum_id == $restricted_forum_id ) {
    		//set error on bbpress and it will not allow creating topic
    		//not the best idea but I personaly don't like the way bbpress does not provide any forum info at other places to hook
    		bbp_add_error( 403, __( 'Not allowed' ) );
    		
    	}
    }
    add_action( 'bbp_new_topic_pre_extras', 'buddydev_restrict_from_posting_topic' );//
    
    

    The first filter prevents showing the topic creation form on single forum screen. The second action hook checks at the time of publish and restricts. Most of the time, the first one will suffice but that just hides the form, so I used the other hook to make sure the user is never able to post new topic.

    Please let me know how it goes.

    • This reply was modified 9 years, 6 months ago by Brajesh Singh. Reason: Fixing the bug in code
  • Keymaster
    (BuddyDev Team)
    Posts: 25057
    Brajesh Singh on in reply to: Buddyblog, images/media support. #2297

    Hi Peter,
    After looking at our admin panel, It does not seem a good idea to allow checking the terms and there can be multiple taxonomies allowed and that can lead to a lot of confusion.

    So, I am posting code snippet to make it work like you want here. You can put these snippets in your bp-custom.php or your theme’s functions.php

    Step 1: decide the taxonomy and terms you want to limit users

    
    
    function buddyblog_custom_get_allowed_taxonomy() {
    	
    	return 'category';//your taxonomy
    }
    
    function buddyblog_custom_get_allowed_term_ids() {
    	
    	return array( 1,2,23 );//your own set of ids for category
    }
    
    

    Change the values in these two functions as appropriate. We will use it in our next step.

    Step 2: Limiting Users to post to certain terms only

    
    /**
     * Limit User posts to selected category only
     * 
     * @param int $settings
     * @return int
     */
    function buddyblog_selected_cats_only( $settings ) {
    	
    	$taxonomy = buddyblog_custom_get_allowed_taxonomy();//which tax we are limiting too , you must have selected it in the admin settings
    	
    	
    	if ( $settings['tax'][ $taxonomy ] ) {
    		$settings['tax'][ $taxonomy ]['include'] = buddyblog_custom_get_allowed_term_ids() ;//array of term ids in that taxonomy
    	}
    	
    	
    	return $settings;
    }
    add_filter( 'buddyblog_post_form_settings', 'buddyblog_selected_cats_only' );
    
    

    That’s all, you don’t need to make any change in the second block as it uses the values from first block.

    Step 3: Do it only if you want to limit certain posts to be linked on profile and not others

    
    
    function buddyblog_filter_posts_permalink_preference( $pref, $post ) {
    	
    	$terms = get_the_terms( $post, buddyblog_custom_get_allowed_taxonomy() );
    	
    	
    	if ( empty( $terms ) ) {
    		//what to do when there are no cats attached
    		//you decide
    		return $pref;
    	}
    	
    	$selected_term_ids = buddyblog_custom_get_allowed_term_ids();
    	
    	$term_ids = wp_list_pluck( $terms, 'term_id' );
    	
    	$has_selected_terms = array_diff( $term_ids, $selected_term_ids );
    	
    	//all or atleast one term found
    	
    	if ( empty( $has_selected_terms ) || count( $has_selected_terms ) != count( $term_ids ) ) {
    		$pref = true; //yes show it on profile 
    	} else {
    		
    		$pref = false; //dont show it on profile
    	}
    	
    	return $pref;
    	
    	//return false if you don't want post to be linked to profile
    }
    
    add_filter( 'buddyblog_show_posts_on_profile', 'buddyblog_filter_posts_permalink_preference', 10, 2 );
    
    

    In the above example, we are doing it based on the selected category. I don’t think it is a good strategy as we we are looking for the post terms before deciding permalink. There is a better solution using custom meta. We store a meta field( “_is_buddyblog_post”) whenever a post is posted/edited from front end(It was added in 1.1 and due to back compatibility I can not use in the plugin itself).

    The simple way to filter permalink should to be to check if this meta exists and if yes, link to profile else link to normal like below

    
    
    function buddyblog_filter_posts_permalink_preference2( $pref, $post ) {
    	
    	if( get_post_meta( $post->ID, '_is_buddyblog_post', true ) ) {
    		//this was posted via buddyblog
    		$pref = true;
    	} else {
    		$pref = false;
    	}
    	
    	return $pref;
    	
    	//return false if you don't want post to be linked to profile
    }
    
    add_filter( 'buddyblog_show_posts_on_profile', 'buddyblog_filter_posts_permalink_preference2', 10, 2 );
    
    

    You can play with the filter ‘buddyblog_show_posts_on_profile’ and decide which posts should be linked on the profile and which should not be.

    Hope that helps.

  • Keymaster
    (BuddyDev Team)
    Posts: 25057
    Brajesh Singh on in reply to: [Resolved] BBpress – restrict topic creation #2296

    Hi Joshua,
    Do you want to restrict the users from creating in all forums and just reply(It is easy) or on specific forum only?

    My own solution was a bit mixed with template, so not very useful here but there are filters, if it is the first case, It will be super easy to do.

  • Keymaster
    (BuddyDev Team)
    Posts: 25057

    Thank you. I will have an update. Will be testing on my other system and will get back to you.

    Thank you
    Brajesh

  • Keymaster
    (BuddyDev Team)
    Posts: 25057
    Brajesh Singh on in reply to: Buddyblog, images/media support. #2294

    Hi Peter,
    I will have a definite solution today.

    Sorry to keep you waiting for long.

  • Keymaster
    (BuddyDev Team)
    Posts: 25057
    Brajesh Singh on in reply to: [Resolved] Excerpt on BuddyBlog #2293

    Hi Rodolfo,
    At the moment, BP Simple Front end post editor does not support post excerpts. It is possible to add extra content section using custom fields though.

    Would you like to add extra content section using custom field for now? I will add the excerpt support in simple front end post plugin in future.

    Thank you
    Brajesh