BuddyDev

Search

Edit Blog Post layout

Tagged: 

  • Participant
    Level: Initiated
    Posts: 14
    Brendan Cotterell on #3645

    I am wondering I have another plugin for user roles and what category they can post too but it is not showing up for my posting area it is showing all categories how do we limit them per a user role?

  • Keymaster
    (BuddyDev Team)
    Posts: 24645
    Brajesh Singh on #3648

    Hi Brendan,
    Thank you for posting. Can you please point me to the plugin you are using to restrict categories. I will need to add compatibility for the specific plugin to make it work together.

    Thank you
    Brajesh

  • Participant
    Level: Initiated
    Posts: 14
    Brendan Cotterell on #3664

    What would you recommend? 🙂

  • Keymaster
    (BuddyDev Team)
    Posts: 24645
    Brajesh Singh on #3665

    Hi Brendan,
    There are many I have seen in the past. I don’t have any particular choice. It will be nice to know your preference and provide a way to have it.

    Thank you
    Brajesh

  • Participant
    Level: Initiated
    Posts: 14
    Brendan Cotterell on #3668
  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #3681

    Hi Brendan,

    Brajesh Sir is away so I am posting here. Please use the following code in your bp-custom.php file
    and let me know if it works or not.

    
    function buddydev_filter_buddyblog_settings( $settings ) {
    
        if ( ! is_user_logged_in() ) {
            return $settings;
        }
    
        // Get the current user in the admin
        $user = new WP_User( get_current_user_id() );
    
        // Get the user role
        $user_cap = $user->roles;
    
        // Get the user login name/ID
        if ( function_exists( 'get_users' ) )
            $user_login = $user->user_nicename;
        elseif ( function_exists( 'get_users_of_blog' ) )
            $user_login = $user->ID;
    
        $defaults = array( 'RestrictCategoriesDefault' );
        // Get selected categories for Roles
        $settings = get_option( 'RestrictCats_options' );
    
        // Get selected categories for Users
        $settings_user = get_option( 'RestrictCats_user_options' );
    
        $user_key = $user_login . '_user_cats';
    
        $term_ids = [];
    
        if ( is_array( $settings_user ) && array_key_exists( $user_key, $settings_user ) && count( $settings_user[ $user_key ] ) > 1 ) {
    
            $settings_user[ $user_key ] = array_values( array_diff( $settings_user[ $user_key ], $defaults ) );
            $user_terms = $settings_user[ $user_key ];
    
            foreach ( $user_terms as $term ) {
                $term_ids[] = get_term_by( 'slug', $term, 'category')->term_id;
            }
    
        } else{
    
            foreach ( $user_cap as $key ) {
    
                if ( is_array( $settings ) && !empty( $settings[ $key . '_cats' ] ) ) {
    
                    $settings[ $key . '_cats' ] = array_values( array_diff( $settings[ $key . '_cats' ], $defaults ) );
                    
                    foreach ( $settings[ $key . '_cats' ] as $category ) {
    
                        $term_ids[] = get_term_by( 'slug', $category, 'category' )->term_id;
    
                    }
    
                }
    
            }
    
        }
    
        $settings['tax'] =  array(
            'category' => array(
                'include' => array_unique( $term_ids ),
                'view_type' => 'checkbox'
            )
        );
    
        return $settings;
    }
    add_filter( 'buddyblog_post_form_settings', 'buddydev_filter_buddyblog_settings' );
    
    

    Thank You
    Ravi

  • Participant
    Level: Initiated
    Posts: 14
    Brendan Cotterell on #3691

    Do I have to create the bp-custom.php? Cant find it anywhere.

    Ok had to create it and it worked! Thanks a lot!

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #3693

    Hello Brendan,

    It should be in “wp-content/plugins/” directory. If it is not present create one. You can refer following url

    https://buddydev.com/docs/guides/guides/buddypress-guides/what-is-bp-custom-php/

    Thank You
    Ravi

You must be logged in to reply to this topic.

This topic is: not resolved