Skip to:
Content
Pages
Categories
Search
Top
Bottom

Delete Post by It’s Owner

  • Is it possible to Delete a Post by It’s Owner?

    I added this to member capabilities, but it shows me it’s a bad idea :D ;

    ‘delete_posts => true,//+’

    How can I do?

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

  • _ck_
    Participant

    @_ck_

    Technically this could be done by wrapping the delete_posts capability in a function to check the current post id # and if the member owns it.


    _ck_
    Participant

    @_ck_

    Here try this – completely untested – let me know!

    update: forget this one, use the 2nd one below it

    function delete_own_post($retvalue, $capability, $args) {
    global $bb_current_user, $bb_post;
    if ($capability=="delete_post" && $bb_current_user->ID && $bb_post && $bb_post->post_id && $bb_post->post_id ==intval($args[1]) && $bb_post->poster_id && $bb_post->poster_id==$bb_current_user->ID && bb_current_user_can( 'edit_post', $bb_post->post_id) {return true;} // lots and lots of double checks
    return $retvalue;
    }
    add_filter('bb_current_user_can', 'delete_own_post',10,3);

    .

    This checks if the user can still edit the post, and if so, allows them to delete their own post too.

    This plugin could be enhanced by checking if the user has been marked as blocked or inactive and prevent them from deleting it at all.

    Update: I may have “over engineered the above function, this may be a much more simplified approach:

    function delete_own_post($retvalue, $capability, $args) {
    if ($capability=="delete_post") {return bb_current_user_can( 'edit_post', $args[1]);}
    return $retvalue;
    }
    add_filter('bb_current_user_can', 'delete_own_post',10,3);

    This second method simply allows delete if the user can still edit a post. Once the edit times out, so does the delete.


    brad_langdon
    Member

    @brad_langdon

    I also have the problem of members not being able to delete their posts.

    I tried the above code, the delete button appears now but when clicked it says you do not have permission to delete.

    I am not even sure if I put it in the right place though.

    Does anyone have a tested method of making this work???


    _ck_
    Participant

    @_ck_

    You tried the second method and it does that?

    It works for me, just tested it on 0.9

    function delete_own_post($retvalue, $capability, $args) {
    if ($capability=="delete_post") {return bb_current_user_can( 'edit_post', $args[1]);}
    return $retvalue;
    }
    add_filter('bb_current_user_can', 'delete_own_post',10,3);

    .

    Note that the delete ability times out with the edit ability (1 hour in default install).


    brad_langdon
    Member

    @brad_langdon

    I may have put the code in the wrong place…where exactly did you put it and in which file.

    Did you replace old code or just add this to it?

    Sorry I am not exactly an expert with this kind of stuff.


    _ck_
    Participant

    @_ck_

    It’s a mini-plugin, just make a plugin out of it.

    I keep a single plugin composed of all my mini-plugins called tweaks.php but you can call it anything.

    <?php
    /*
    Plugin Name: Tweaks (mini-plugins)
    */

    function delete_own_post($retvalue, $capability, $args) {
    if ($capability=="delete_post") {return bb_current_user_can( 'edit_post', $args[1]);}
    return $retvalue;
    }
    add_filter('bb_current_user_can', 'delete_own_post',10,3);

    ?>


    brad_langdon
    Member

    @brad_langdon

    Great Cheers for that!

    One more thing…(sorry)

    How do you change the timeout length for editing and deleting posts?

    Can you take the timeout off all togehter?


    chrishajer
    Participant

    @chrishajer

    In the admin under Settings > General, there is a post timeout setting (“Lock post editing after”):

    /bb-admin/options-general.php

    The default is 60. Try setting it to -1 and see if a normal user can edit an old post. If the -1 does not work, try some insanely large number of minutes so it appears that there is no limit to editing the posts. 525600 is a year’s worth of minutes.


    brad_langdon
    Member

    @brad_langdon

    Sweet thanks for that.


    _ck_
    Participant

    @_ck_

    In theory it should be also possible to allow users to move their own topics if placed in the wrong category:

    (untested, should allow a user to move only their own topics within the same time period they can typically edit a topic, ie. 1 hour default)

    function move_own_topic($retvalue, $capability, $args) {
    if ($capability=="move_topic") {return bb_current_user_can( 'edit_topic', $args[1]);}
    return $retvalue;
    }
    add_filter('bb_current_user_can', 'move_own_topic',10,3);

    sorry to raise an old topic from the dead, but I think I have found a significant problem with the current version…

    If you try to post an empty reply in a topic, you are met with a message saying ‘You need to actually submit some content!’ and bbpress won’t let you reply.

    However, if you edit a post, and delete all the information from inside, you can resubmit the post as a completely empty reply, because the filter for new replies does not work for edits.

    And because there is no delete post function for normal users, some of my users have been doing this to remove their posts.

    This means there are blank replies in some topics, which have to be manually found and removed by moderators!

    I suggest there are two possible solutions

    1) Allow users to delete their own posts, but within a certain time limit, I don’t want users deleting posts they made 2 months ago!

    and/or

    2) Have the empty-post filter work for post-edits as well as for brand new posts.

    How can I make the edit-post function call the same minimum-character filter as the new post function??

    Is it possible to mod the above post-delete plugin to include a time-limit on deleting posts (as found in phpbb)?

    I believe that the code above should honor the “user can edit a post for this many minutes after submitting” setting? What’s it set to on your install (just as a way of checking if that might be an issue here!). :-)

    yes, john, you are right. The option to delete your own posts times-out after one hour – I was just a bit impatient!!

    Being able to submit an empty post via edit is still an issue though, which would be nice to solve!

    That “empty post via edit” issue is a tough one – because even if you prevented people from submitting empty posts through edits, they could still just submit some junk characters and overwrite their old post?

    If it’s a growing problem for you, you could maybe cut down that “edit a post after submitting” time from one hour… to maybe just 10 or 15 minutes?


    iftomkins
    Participant

    @iftomkins

    Hi! I’m a little late on this one. Using bbpress 2.0 but the above code still kinda works. When I add it, I get the edit button, but no delete button. Any tips? I want all users to be able to edit and delete their own posts. Also, I’m confused whether assigning someone the role Forum Participant vs. Subcriber has anything to do with it, but I’ve tried both. Here’s the code I was using from above:

    function delete_own_post($retvalue, $capability, $args) {
    if ($capability=="delete_post") {return bb_current_user_can( 'edit_post', $args[1]);}
    return $retvalue;
    }
    add_filter('bb_current_user_can', 'delete_own_post',10,3);

    Great ! Helpful !Thank you

    niceactor

    QTTg

    iftomkins

    Been there and it does not work – Old threads, old codes.

    Found a solution and IT WORKS :)

    https://bbpress.org/forums/topic/user-close-topic-trash-etc-resolved


    ochiba77
    Participant

    @ochiba77

    I tried this with the latest version 2.1.3 and get erros. Anyone success with the latest version?


    vanaila
    Participant

    @vanaila

    Sorry to put this up again.

    I add delete_topics in capabilities for participant and it doesn’t work.

    I don’t know how to allow them to trash their own topics.

    I tried everything in this topics but nothing seems to work.

    Please Help


    inderpreet2018
    Participant

    @inderpreet2018

    Hi,

    I used above code/plugin to add delete_topics in capabilities for participant and it doesn’t work.

    Can you help me, how I allow users trash their own topics?

    Thanks


    Robin W
    Moderator

    @robin-w

    I’ve just added functionality to bbp-style pack for participants to close their own topics – to set see item 17 in Topic/Reply Display tab to set this

    bbp style pack

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