PhotoSmash Extend use and need help on deleting pictures and post. Photos in the gallery are nuzzled, but I want to delete and post to the photo.
How do I setup for it and if it's possible.
Thanks in advance.
resolvedPhotoSmash Extend use and need help on deleting pictures and post. Photos in the gallery are nuzzled, but I want to delete and post to the photo.
How do I setup for it and if it's possible.
Thanks in advance.
Hi DDart,
Using the new [delete_button] tag in your custom layout will give the user a delete button for their images. If the image is associated with a Post and the User is the Author of that Post and the Post is in Pending status, it will delete the post as well. There isn't a way to let them delete the post if it is not Pending at this time. You would have to modify the ajax.php file to allow for that.
Doing that might be ok now that posts can go to Trash instead of Delete into oblivion. I haven't tested to see if the posts go to Trash or Delete.
Hope that helps,
Byron
As a followup, it does look like it goes to Trash as of WP 3.0.
Cheers,
Byron
To use the new feature [delete_button]. But when I use the delete button deletes the photo is only the image but not the post :( Publication remains a picture is not in the gallery that I have done something right! First Attempt to delete and post but now something does not work.
I am using WP 3.0.1
Cheers,
Dobrin
I think I hear you.
To do that, you will need to customize the ajax.php function: function userDeleteImage($deletePost)
But be aware that when you upgrade, you will lose any customized code. So be sure to back it up.
Cheers,
Byron
Unfortunately I'm not a programmer and do not know what to add in code ajax.php
function userDeleteImage($deletePost){
global $wpdb, $user_ID;
if(current_user_can('level_0')){
$imgid = (int)$_POST['image_id'];
$json['image_id'] = $imgid;
if($imgid){
$row = $wpdb->get_row($wpdb->prepare("SELECT file_name, post_id FROM "
.PSIMAGESTABLE. " WHERE image_id = %d AND user_id = %d AND status < 0 ", $imgid, $user_ID));
Can you help me with what must change in ajax.php
Thanks Byron
In the ajax.php file, you can change this line:
$postAuthor = $wpdb->get_var($wpdb->prepare("SELECT post_author FROM "
. $wpdb->posts . " WHERE ID = %d AND post_author = %d AND post_status = 'pending' ", $row->post_id, $user_ID));
To:
$postAuthor = $wpdb->get_var($wpdb->prepare("SELECT post_author FROM "
. $wpdb->posts . " WHERE ID = %d AND post_author = %d ", $row->post_id, $user_ID));
Again, I don't recommend doing this since I think you would only want to let users delete 'pending' posts, but it should do what you're looking for.
Cheers,
Byron
Hi, Byron!
Thank you for your help.
I changed the script that gave me, but he only erased from the picture gallery but not the post. Position still remains. This I need because every picture that gets created post. If the user removes the picture and post it remains not very efficient.
In addition script that needs to change if there are any setting that I missed to do?
I hope very much to help me!
Thank you for the compartment time.
Hi ddart,
I told you the wrong file before. Sorry.
I've tested this code, so it should work. Replace <b>the following function</b> in the file <b>ajax_useractions.php</b> with the code below:
function userDeleteImage($deletePost){
global $wpdb, $user_ID;
$imgid = (int)$_POST['image_id'];
if(current_user_can('level_0')){
$imgid = (int)$_POST['image_id'];
$json['image_id'] = $imgid;
if($imgid){
// Modified for DDART
$status = 2;
$row = $wpdb->get_row($wpdb->prepare("SELECT * FROM "
.PSIMAGESTABLE. " WHERE image_id = %d AND user_id = %d AND status < $status ", $imgid, $user_ID));
if(!$row){
//Bomb out if no row returned
$json['status'] = 0;
echo json_encode($json);
return;
}
if($row->file_name || $row->thumb_url){
// Legacy code - PhotoSmash originally used its own folders for uploads
if( is_file(PSIMAGESPATH.$row->file_name) ){
unlink(PSIMAGESPATH.$row->file_name);
}
if( is_file(PSTHUMBSPATH.$row->file_name) ){
unlink(PSTHUMBSPATH.$row->file_name);
}
if(!$row->wp_attach_id){
// PhotoSmash now uses the WordPress upload folder structure
$uploads = wp_upload_dir();
if( is_file($uploads['basedir'] . '/' . $row->thumb_url) ){
unlink($uploads['basedir'] . '/' . $row->thumb_url);
}
if( is_file($uploads['basedir'] . '/' . $row->medium_url) ){
unlink($uploads['basedir'] . '/' . $row->medium_url);
}
if( is_file($uploads['basedir'] . '/' . $row->image_url) ){
unlink($uploads['basedir'] . '/' . $row->image_url);
}
}
}
$json['status'] = $wpdb->query($wpdb->prepare('DELETE FROM '.
PSIMAGESTABLE.' WHERE image_id = %d AND user_ID = %d AND status < '
. $status, $imgid, $user_ID ));
if($json['status']){
$wpdb->query($wpdb->prepare('DELETE FROM '. PSCUSTOMDATATABLE
.' WHERE image_id = %d', $imgid));
$wpdb->query($wpdb->prepare('DELETE FROM '. PSRATINGSTABLE
.' WHERE image_id = %d', $imgid));
$wpdb->query($wpdb->prepare('DELETE FROM '. PSRATINGSSUMMARYTABLE
.' WHERE image_id = %d', $imgid));
$wpdb->query($wpdb->prepare('DELETE FROM '. PSCATEGORIESTABLE
.' WHERE image_id = %d', $imgid));
//Delete the related post if directed to
if( $deletePost && $row->post_id ){
//Check to make sure this person is deleting only his/her own post
//Also check to make sure that this post is "Pending"
//Modified for DDART
$postAuthor = $wpdb->get_var($wpdb->prepare("SELECT post_author FROM "
. $wpdb->posts . " WHERE ID = %d AND post_author = %d", $row->post_id, $user_ID));
if($postAuthor){
wp_delete_post((int)$row->post_id);
}
}
}
if( !$filename ){ $filename = ""; } else { $filename = " - ".$filename; }
$json['action'] = 'deleted'.$filename;
$json['deleted'] = 'deleted';
$json['message'] = "Image deleted.";
} else {
$json['status'] = 0;
$json['message'] = "Unable to delete image at this time.";
}
} else {
$json['status'] = 0;
$json['message'] = "Must be logged in.";
}
echo json_encode($json);
return;
}
<b>Important note to anyone else reading this:</b> This will let your users delete their images and posts no matter what status they have.
Cheers,
Byron
Thank you! :)
Works perfectly. Just as I want.
This plugin is the only one who meets me. Plugin is a great work. :)
And I will not forget you can donate money again to continue to create. :)
Cheers,
Dobrin Draganov DD ART
You're welcome!
BB