Info
- 18 posts
- 9 voices
- Started 3 years ago by dresah
- Latest reply from danielkj
- This topic is not resolved
Delete Post by It's Owner
-
- Posted 3 years ago #
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?
-
- Posted 3 years ago #
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.
-
- Posted 3 years ago #
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.
-
- Posted 3 years ago #
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???
-
- Posted 3 years ago #
You tried the second method and it does that?
It works for me, just tested it on 0.9function 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). -
- Posted 3 years ago #
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.
-
- Posted 3 years ago #
It's a mini-plugin, just make a plugin out of it.
I keep a single plugin composed of all my mini-plugins calledtweaks.phpbut 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); ?> -
- Posted 3 years ago #
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?
-
- Posted 3 years ago #
In the admin under Settings > General, there is a post timeout setting ("Lock post editing after"):
/bb-admin/options-general.phpThe 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.
-
- Posted 3 years ago #
Sweet thanks for that.
-
- Posted 2 years ago #
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); -
- Posted 2 years ago #
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)? -
- Posted 2 years ago #
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!). :-)
-
- Posted 2 years ago #
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!
-
- Posted 2 years ago #
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?
-
- Posted 5 months ago #
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); -
- Posted 5 months ago #
Great ! Helpful !Thank you
-
- Posted 5 months ago #
niceactor
QTTg
iftomkinsBeen there and it does not work - Old threads, old codes.
Found a solution and IT WORKS :)
http://bbpress.org/forums/topic/user-close-topic-trash-etc-resolved
-
You must log in to post.