I would take a look at http://codex.wordpress.org/Plugin_API/Action_Reference/delete_post as the example seems to be doing exactly what you want to do in a situation. Your actual code as far as hooking into WordPress looks fine to me, but a key note to remember from the page I linked to is that this event is triggered by post deletion from the database, and not directly from clicking the button to trash a post in the admin panel.
So yeah, test with delete_post() and get back to me.
Related Posts:
- Should all plugins be encapsulated in a Class?
- Consuming an external API in WordPress?
- How can I import a class privately into a plugin?
- How do I extend one plugin I’m writing with another I’m writing using classes?
- Generate custom output for page/URL in a plugin
- Post source link plugin – small modification
- Add CSS animation as Preloader to WordPress
- How to list the Hooks and order of execution in current loading page? [duplicate]
- Setting up widgets in wordpress with a unique ID for the after_title argument
- Modifying Footnote Plugin for Descriptive Title Attributes
- How to Replace Words with Hypertext Link But Ignore Previously Existed Links?
- force customers to add only single item to card per purchase EDD [closed]
- Auto delete WordPress users according to time
- Edit Yoast SEO breadcrumbs output [closed]
- How would I go about creating a user ranked post popularity page?
- How to fetch products with the price in a page on woocommerce using a form or live search with php
- Redirect to another page using contact form 7? [closed]
- Inserting custom PHP script on homepage
- Loop in elementor custom widget not working
- I am trying to make a field show and save from quickedit screen
- .php file for woocommerce edit category? [closed]
- Customize Menu | Styling LESS/SCSS code formats
- Why is it important to check for isset and is_array before checking in_array in this example?
- Comment “like” problem – “users who like this” avatar linking to current user profile instead of “liker’s” profile
- Calling a save function from a “submit” button
- same user role or copy the user role to be same as the other role
- How to fix these PHP Warnings with the “Feed JSON” plug-in?
- woocommerce remove coupon link does not work
- implement custom roles in custom plugin
- Post source link plugin – small modification
- Custom Plugin: How to Include Install Buttons of other 3rd Party Plugins?
- Adding discount functionality to the cart
- How to assign a specific service to a specific provider based on location
- Precheck fields when I add a new post
- Rename a folder via HTML POST request
- Move plugin pages from dashboard to front-end
- working code, not working – Plugin Dev
- Cron job shedules replace?
- Custom shortcode being shown in WPBakery backend rather than the block
- Move plugin upload folder from mywebsite.com/wp-content/uploads/pdfuploads to mywebsite.com/pdfs?
- Woocommerce list variations that are added already to cart in Single Product
- Flexslider empty slide
- Custom SportsPress list
- How to fix vanilla comments extra iframe space
- I want to remove the register/login WordPress top bar from my website
- What can I do to customize a widget provided with this plugin? from where have I to start?
- WordPress: code structure
- How to make a Template page to show the information of different things Shop and Product page?
- Get a button for in the Editor
- Errors while using ajax from external wordpress page
- Image Crop/Resize Function/Code Sinppet/Plugin to adjust/crop images during upload
- WP get_permalink Return Wrong URL
- post expire after x days
- How to get all events from ‘All in one Events calender’ plugin in JSON format?
- MailChimp integration that allows users to select from multiple lists [closed]
- cURL error 60: SSL certificate problem: unable to get local issuer certificate
- Apple push notification doesn’t work
- Override Plugin Script Fucnction in WordPress
- Conditional attributes and logic per product category
- Subdomains with almost the same content
- How create Group Blogs based on user created Groups
- How to include this jQuery File in wordpress?
- Best practice for including plugin output in a template without using shortcode?
- Include a php file from another plugin
- How to change the wp_upload_dir() path in plugin
- How can I fetch data from another website to my wordpress website with mysql database
- Advanced WordPress plugin activation detection
- Switch from wp-cron to a server cron job
- how to change wp-admin url using function file
- Renaming Custom Taxonomy Values
- Theme Functions run a function upon activation or preview
- Is this plugin safe to run?
- Custom Module, Extending WP with a Plugin?
- Custom Plugin scripts from admin working in frontend
- How to make PDF books readable on site with woo-commerce?
- get_post_meta shortcode returns empty field
- How to add a prefix to a WordPress post preview url?
- i can not access the post in custom template of my wordpress plugin
- How to get a specific string from a url
- How to avoid the 403 Forbidden error in a WP Plugin with Ajax and PHP
- WordPress logout appends cache/all/index.php to the site_url()
- Change (replace) word in metabox
- How to remove a css class for any wordpress page
- How can I save cookies to members
- Creating wordpress admin page panel [Theme Option]
- Should I paste CDN links in a JS file or use a Bootstrap CDN plugin?
- export high ress images to pdf
- custom url with custom post
- Saving an array to get_options
- Variable passed to each() is not an array
- show Visual form builder in the front end
- Some of my php is rendered only when logged as admin
- Pulling sub-site content into specific pages
- Custom Slider Per Page created
- Help me with my first very basic plugin
- How to execute init or woocommerce_init only for checkout page
- how to restore wordpress backup(.rar) manually?
- WordPress Code Access to Restricted Content without Registration
- wordpress jquery is not defined because the head tag is empty
- How to pre-set WordPress settings for specific posts?