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?
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?
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.
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.
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???
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).
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.
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);
?>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?
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.
Sweet thanks for that.
You must log in to post.