Create action running on trashed_post hook to modify post_meta value

I have a custom post type that always do math operation to its post_meta and other custom post type post_meta. For example: post-type 1 = cpt_product_order post-type 1 post_meta = cpt_pm_product_order post-type 2 = cpt_product post-type 2 post_meta = cpt_pm_product_stock There's a cpt_product with cpt_pm_product_stock = 100, frontend operation enable specific user made order by inserting new cpt_product with post_meta cpt_product_order of 10 will substract cpt_pm_product_stock to 90 100 cpt_pm_product_stock - 10 cpt_product_order = 90 cpt_pm_product_stock cancelling order will delete/trash …
Category: Web

Prevent users to delete comments from trash

As told in the title, I am looking for a way to prevent users to delete comments from the trash. Only admins should be able to. I tested the scripts at: Function to prevent users from trashing comments But it doesn't work, probably since 2013 a few things have changed :) Thank you for help!
Category: Web

How to cancel the trash action inside wp_trash_post

I need to restrict the button "EMPTY TRASH" and make it delete only the posts only if the logged in user is the creator. I tried to use the wp_trash_post and i need to decide in the function if i need to continue to trash or not. How do i tell WordPress NOT to empty the trash from specific posts?
Category: Web

How to display "Trash" in my custom post type?

what does it take to display the Recycle Bin in my own Custom Post Type? function my_custom_post_specialist() { $labels = array( 'name' => _x( 'Terapeuci', 'post type general name' ), 'singular_name' => _x( 'Terapeuci', 'post type singular name' ), 'add_new' => _x( 'Dodaj nowego specjalistę', 'book' ), 'add_new_item' => __( 'Dodaj nowego specjalistę' ), 'edit_item' => __( 'Edytuj specjalistę' ), 'new_item' => __( 'Nowy specjalista' ), 'all_items' => __( 'Wszyscy specjaliści' ), 'view_item' => __( 'Pokaż specjalistę' ), 'search_items' => …
Category: Web

Exclude trash from save_post

I have a function which processes custom metabox data on saving my custom post type: add_action('save_post_customtypehere','myown_save_customtype_fn'); function myown_save_customtype_fn($ID) { ... } However, the function also runs when I trash items within this CPT (I guess it's effectively saving the post to change post_status to trash). Without the metabox being present, my function ends up clearing things like post_name (not great if I need to restore from trash!). I have two thoughts but can't quite get across the finishing line with …
Category: Web

is possible to interupt a post deletion when empty the trash

it is possible once called a before_delete_post action not to allow WP to delete post on certain condition? something like e this: add_action( 'before_delete_post', 'my_custom_delete', 10); function my_custom_delete($wp_post_id) { if (get_post_type($wp_post_id) == 'my_custom_post_type') { if(condition_is_true($wp_post_id)){ error_log("do something to block WP deleting the post"); notify_the_user(); } else { error_log("we can delete the post"); } } }
Category: Web

How to recover permanently deleted blog posts?

I accidentally deleted about 20 blog posts and they were in my trash folder for over a month and now have permanently deleted. I was wondering if there's a way to recover these? For example I have seen mention of MySql database and phpMyAdmin, and was wondering if these would be applicable in my case and, if so, how do I use them? Thanks in advance!
Category: Web

Set "move to trash" as the default bulk action

I need only "move to trash" bulk action and I want to set it as the default bulk action. Then, I will hide the select field with css. To delete a post, I will just put a tick in a checkbox and then hit the ok button to delete. How can I set "move to trash" as the default bulk action?
Category: Web

posts comments goes to trash

My website was working fine until today, I just discovered that all comments made goes straight to trash. I did not install new plugins, I don't have akismet. It just started. I have deactivated all my plugins and yet the issue persists. I don't know what the issue is. Is there any code I need to add to my functions.php file to make this stop ?
Category: Web

How can I specify the post status of an untrashed post?

By default Wordpress assigns the draft status to a post that has been untrashed. I would like to assign the pending status to posts that are untrashed. This seems to be possible with wp_untrash_post_status, but I can't seem to find the proper way to use it. I have this in my code : add_action( 'untrash_post', 'my_function' ); function my_function( $post_id ) { apply_filters( 'wp_untrash_post_status', 'pending', $post_id, 'pending' ); } What am I doing wrong ?
Category: Web

How can Reusable Blocks be fully deleted?

All of the reusable blocks on one of my sites were deleted last week. Not just deleted, but the trash emptied. I've already had a security vendor audit the site, and they concluded there was no hack, it was done by a legitimate user. No one was using the database directly, so it had to be done in wp-admin. The only way I can find for reusable blocks to be completely deleted is to visit the page http://example.com/wp-admin/edit.php?post_status=trash&post_type=wp_block. (On that …
Category: Web

wp_delete_post() deletes post instead of moving it to trash

I have set up a custom post type, which user can edit from the frontend. I'm using wp_delete_post() to allow users to delete a post they created. It works, but the posts get deleted instead of being moved to trash.I have tried moving a post to the bin via the backend and it works like you would expect it, the post is moved to the Bin. So I'm not sure why the wp_delete_post doesn't work the same way, but permanently …
Category: Web

Can I differentiate between "Delete Post Permanently" and "Empty Trash" and do something for each accordingly?

I'm currently working on developing a plugin with a custom post type of "Dealer Location". (Not relevant to question, just a bit of background) When a post is in the trash and "delete permanently" is pressed, I need to remove this piece of meta from each user. When a post/posts are in the trash and "empty trash" is pressed, I need to run through EACH location being deleted and do something. I have an extremely basic function just to test …
Category: Web

Shortcode to delete post from front end

I'm trying to create a short code to delete post that user publish from the front end of my site. I've tried the short-code below but I keep getting the error "The link you followed has expired." Kindly see image screenshot below. //Shortcode to delete post function delete_my_posts() { ob_start(); $url = get_bloginfo('url'); if (current_user_can('edit_post', $post->ID)){ echo '<a class="delete-post" rel=”nofollow” href="'; echo wp_nonce_url("$url/wp-admin/post.php?action=trash&post=$id", 'delete-post_' . $post->ID); echo '">Delete post</a>'; } return ob_get_clean(); } add_shortcode( 'delete_me', 'delete_my_posts' ); Screenshot: https://imgur.com/a/PMB1uU4 Can …
Category: Web

How to cancel an action hooked to untrash_post? or any hook

I want to do the following in a plugin: - hook to untrash_postwith a custom function - do some checking inside custom function - cancel actual post restoring (untrashing) I've tried with remove_action but doesn't seem to work. Can you point me into the right direction? Code sample: add_action( 'untrash_post', array( __CLASS__, 'static_untrash_handler' ) ); ..... public static function static_untrash_handler( $post ) { // check stuff // prevent post from being restored. How ? } Should I return something to …
Category: Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.