How to prevent users from permanently deleting a post from trash, but allow them to restore it?
How to prevent users from permanently deleting a post from trash, but allow them to restore it?
How to prevent users from permanently deleting a post from trash, but allow them to restore it?
wp_trash_post not firing as expected (also applies to trashed_post)
wp_trash_post and trashed_post – from source: function wp_trash_post($post_id = 0) { if ( !EMPTY_TRASH_DAYS ) return wp_delete_post($post_id, true); if ( !$post = wp_get_single_post($post_id, ARRAY_A) ) return $post; if ( $post[‘post_status’] == ‘trash’ ) return false; do_action(‘wp_trash_post’, $post_id); add_post_meta($post_id,’_wp_trash_meta_status’, $post[‘post_status’]); add_post_meta($post_id,’_wp_trash_meta_time’, time()); $post[‘post_status’] = ‘trash’; wp_insert_post($post); wp_trash_post_comments($post_id); do_action(‘trashed_post’, $post_id); return $post; }
Technically, defining define(‘EMPTY_TRASH_DAYS’, 0 ); in wp-config.php file should delete whatever is in Trash after zero days. I just tried it, but didn’t work immediately. I may have to wait for a day to see the result.
Definitely time for an upgrade. 🙂 Try logging into your admin and following the link below. Just make sure to change ‘yoururl.com’ to whatever your website name is. If you have posts in the trash, that should take you to your trash to see them. http://yoururl.com/wp-admin/edit.php?post_status=trash&post_type=post
Why is that even happening aside, from quick look at core it does the following to achieve that in WP_Posts_List_Table class: $sticky_posts = implode( ‘, ‘, array_map( ‘absint’, (array) $sticky_posts ) ); $this->sticky_posts_count = $wpdb->get_var( $wpdb->prepare( “SELECT COUNT( 1 ) FROM $wpdb->posts WHERE post_type = %s AND post_status NOT IN (‘trash’, ‘auto-draft’) AND ID IN … Read more
Simply check if the comment has a parent before decrementing points. Reading the Codex entry for the get_comment() function, you’ll note that in the manner you use the function you will be returned an object containing keys that correspond to the column names of the wp_comments table. Viewing the wp_comments scehma, note that there is … Read more
There’s an action called trashed_post_comments that runs right after the comments are set to post-trashed status. You could hook into that: add_action( ‘trashed_post_comments’, ‘wpse134528_really_trash_comments’ ); function wpse134528_really_trash_comments( $post_id ) { $args = array( ‘post_id’ => $post_id, ‘status’ => ‘post-trashed’, ); $comments = get_comments( $args ); foreach( $comments as $comment ) { wp_trash_comment( $comment->comment_id ); } … Read more
The transition_comment_status action will get called whenever the status of a comment changes from one thing to another thing, regardless of what those things are. If you don’t want it to take action when going from trashed to approved, you need to recognize when the $old_status is trashed and not take action at that point … Read more
wp_trash_post retrashes already trashed comments?