BuddyDev

Search

Buddyblog – Only allow Authors or Contributors to post in one category they pick

Tagged: 

  • Participant
    Scott A on #31552

    I found both of these snipets on Buddydev

    (We have a long list of Categories and we only want members to be able to post to one category of their choice.)

    1:

    [sourcecode language=”php”]

    add_filter(‘buddyblog_post_form_settings’,’buddyblog_my_postform_settings’);
    /**
    * Filter on the Post form settings which is used by BP Simple Post Form settings
    * The settings array is structured like this
    *
    * array(
    * ‘post_type’=>buddyblog_get_posttype(),//do not change it, use the filter buddyblog_get_posttype to change it
    * ‘post_status’=>’draft’//allowed values are draft|publish|inherit(any valid post status value)
    * ‘tax’=>array(
    * ‘taxonomy_name’=>array(‘taxonomy’=>’taxonomy_name’,//taxonomy_name is the name of taxonomy e.g category, post_tag or your custom taxonomy
    * ‘view_type’=>’checkbox’,//valid values are checkbox|dd, it tell whether to list the taxonomy terms as checkbox or drop down
    * ‘selected’=>array(termid1,termid2),//optional, if you want some terms to be selected by default
    * ‘include’=>array(termid1, termid2,termid3)//if you want only these terms to be available to the user, user can select from these terms, if he does not select any terms, all of these terms will be associated to the post
    *
    * ),
    * ‘another_taxonomy_name’=>array(‘taxonomy’=>’another_taxonomy_name’,//another_taxonomy_name is the name of taxonomy e.g category, post_tag or your custom taxonomy
    * ‘view_type’=>’dd’//valid values are checkbox|dd
    * )//you can add as many taxonomies as you want. Just make sure, the post type is allowed to have these taxonomies
    *
    *
    * ),//end of taxonomies
    * //use custom fields to allow as many custom fields as you want
    * ‘custom_fields’=>array(
    * ‘custom_field_key_name’=>array(
    * ‘label’=>’What ever you want to display as the label for this custom field
    * ‘type’=>’type of the custom field’,//allowed values are hidden|select|radio|checkbox|textbox|textarea
    * ) ‘options’=>array();//array of value=>Label use only for checkbox/radio/select
    * ‘default’=>’some default value which is valid for current type’
    * //examples
    * ‘privacy’=>array(
    * ‘label’=>’Privacy’,
    * ‘required’=>true,
    * ‘type’=>’select’,
    * ‘options’=>array(
    * array(‘label’=>’Anyone’,’value’=>’public’),
    * array(‘label’=>’Friends Only’,’value’=>’friendsonly’),
    * array(‘label’=>’Logged In Users Only’,’value’=>’loggedin’),
    *
    *
    * )//end of options dat
    * )//end of privacy custom field
    * ),//end of custom fields
    * ‘upload_count’=>2;//how many attachments you want to allow with each post, It is a little bit misleading really
    * )//end of settings array
    *

    *
    * @param array $settings is a multidimensional array explained above
    *
    */
    function buddyblog_my_postform_settings($settings){

    $settings=array(
    ‘post_type’=> buddyblog_get_posttype(),
    ‘post_status’=>’draft’,//’publish’|’draft’ etc

    ‘tax’=>array( //all the associated taxonomies, the below is settings for post category and post tag
    ‘category’=>array(‘taxonomy’=>’category’,
    ‘view_type’=>’checkbox’
    ),
    ‘post_tag’=>array(‘taxonomy’=>’post_tag’,
    ‘view_type’=>’checkbox’
    )

    ),
    ‘upload_count’=>2//how may uploads
    );

    return $settings;

    }

    [/sourcecode]

    ——————–

    2:

    add_filter(‘buddyblog_post_form_settings’, ‘buddyblog_custom_form_settings’);
    function buddyblog_custom_form_settings( $settings ){
    unset( $settings[‘upload_count’] );
    unset( $settings[‘tax’][ ‘post_tag’] );//no need to show posts tag
    $category = get_category_by_slug( ‘blog’ );
    $settings[‘tax’][‘category’][‘include’] = array( 0 => $category->term_id );
    return $settings;
    }

    —————–

    I pasted both into my theme functions.php

    Number 1. Throws errors and I don’t know how to clean up the code.

    Number 2. Was sucessfully added but all posts that are chosen from the list of categories just automatically go to “Uncategorized” Category.

    Any help with where to paste the code and what code to paste would be so greatly appreciated.

  • Keymaster
    (BuddyDev Team)
    Posts: 24212
    Brajesh Singh on #31568

    Hi Scott,
    I am sorry for the messed code. We recently disable one of our code highlighters and that broke almost all old code posts. Have cleaned the blog now for code(still 13 posts remaining).

    If you visit that post again, you will have the correct code.

    Please do note that the above code does not restrict a user to 1 category. we will most probably need to do that at the time of validation.

    I will ask one of colleague to look into it and post the code(Or I will do it tomorrow).

    Regards
    Brajesh

You must be logged in to reply to this topic.

This topic is: not resolved