Skip to:
Content
Pages
Categories
Search
Top
Bottom

Prevent participant from creating topic but allow replies


  • norcom41
    Participant

    @norcom41

    In a bbPress forum I want to prevent participants from creating topics but allow replies. In searching the Internet I found code examples from which I selected some to build a plugin. I know a little PHP but WordPress is like a “black box.”

    add_action(‘wp_loaded’,’modify_participant’);

    function ‘modify_participant'()
    {
    add_filter(‘mod_participant’, ‘upd_participant’);
    }

    function upd_participant($role,$caps)
    {
    $role = bbp_get_participant_role();
    $caps = modify_capabilities($role);
    }

    function modify_capabilities($role)
    {
    return array(

    // Topic caps
    ‘publish_topics’ => false,
    ‘edit_topics’ => false,
    ‘edit_others_topics’ => false,
    ‘delete_topics’ => false,
    ‘delete_others_topics’ => false,
    ‘read_private_topics’ => false,

    // Topic tag caps
    ‘manage_topic_tags’ => false,
    ‘edit_topic_tags’ => false,
    ‘delete_topic_tags’ => false,
    ‘assign_topic_tags’ => false
    )
    }

    For instance the WP loaded hook causes it to run once at the start which should call those functions to initialize things. Is an add_filter also executed at that time to complete initialization? Then the black box proceeds with the bbp_get_parcipant_role routine so that the capabilities array elements can be updated. I read that WP filters always expect an object to be returned. It seems that these wouldn’t be permanent but just temporary in memory for executing that page. However my suspicion is that more coding would be necessary because that would be too much to depend on the black box for.

Viewing 4 replies - 1 through 4 (of 4 total)

  • Robin W
    Moderator

    @robin-w

    I am not a bbpress author

    A possible reason is detailed on my site

    bbpress role adder

    you could use this to amend the role

    come back if you need to


    norcom41
    Participant

    @norcom41

    I suppose add_filter(‘mod_’,’upd_($role,$caps)’) should have this for arguments even though they’re for the return values. bbp_get_participant_role probably provides the elements for all the capabilities, but if only some are modified in the array, the others could be lost during the return if not also repeated. In my test the init statements are displayed on the screen as if they are errors. Then when the user choses a subforum it prompts for a login to add a topic. This opens up another area to suppress that request itself. That’s why programmers get plugins because you have to be an expert to know how to do all this. If you want to know the basics you have to go back to school.


    norcom41
    Participant

    @norcom41

    Some research (paraphrased) is: “Roles are stored in the database so modifying capabilities shouldn’t be done on every page load. They are stored as a serialized array in wp-config.php under the wp_user_roles option. Because adding capabilities to a role is a permanent change, you should only do this when a plugin is activated. I tried to change a T/F value but it failed perhaps because WP doesn’t permit updates that way. However if I delete a role and then later change a capability it succeeds (end paraphrase).”
    So using a plugin to update participant capabilities each time temporarily appears to be discouraged as opposed to the admin making permanent updates using the file manager from the dashboard. However, you’d think with the current level of sophistication and a logical need for it a simple plugin for just that one purpose would exist somewhere.


    Robin W
    Moderator

    @robin-w

    not really sure if you’re asking for help or just complaining 🙁

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.
Skip to toolbar