Skip to:
Content
Pages
Categories
Search
Top
Bottom

Dynamic Capabilities and Events Manager

  • Probably best directed at @johnjamesjacoby, any suggestions welcome!

    Already read your post here (love the concept, makes sense) and have a question : http://bbpress.org/forums/topic/roles-and-capabilities-in-bbpress-2-2/

    I’m the developer of Events Manager and in this plugin you can assign custom capabilities to existing roles. Unfortunately your recent update regarding caps is preventing our plugin from adding custom caps to your roles.

    I’ve figured out a way around this, but this requires at least 1 extra database query each instance since I can’t load wp_user_roles via get_option due to your hooks.


    function em_bbp_get_caps_for_role( $caps, $role ){
    global $em_capabilities_array, $wpdb;
    //get the non-dynamic role from the wp_options table
    $roles = maybe_unserialize($wpdb->get_var("SELECT option_value FROM {$wpdb->options} WHERE option_name='wp_user_roles'"));
    //loop through the original role if it exists and add our em caps to the bp role
    if( !empty($roles[$role]) ){
    foreach($roles[$role]['capabilities'] as $cap_name => $has_cap ){
    if( array_key_exists($cap_name, $em_capabilities_array) ){
    $caps[$cap_name] = $has_cap;
    }
    }
    }
    return $caps;
    }
    add_filter('bbp_get_caps_for_role', 'em_bbp_get_caps_for_role', 10, 2);

    What it does is load our caps into your caps by referencing the original wp_user_roles array

    So, my questions are:

    • Is there a better way to do this, preferably avoiding extra DB queries?
    • Since you seem to be assigning a second role to the user, would an alternative solution be to prevent EM from assigning caps to bbpress user roles and let the primary/secondary role inherit the relevant caps?

    thanks for reading!

  • You must be logged in to reply to this topic.
Skip to toolbar