I believe you can just check if the post status is trash
, and if so, don’t run the rest of your code. E.g. (PS: I intentionally used strict comparison, i.e. using ===
as in $pagenow === 'post.php'
)
function post_extra_save( $post_id, $post ) {
global $pagenow;
if ($pagenow === 'post.php' && 'trash' !== $post->post_status) {
... your code.
}
}
Alternatively, run your code only if the post status is publish
or that it’s in one of a whitelisted/allowed statuses list. E.g.
function post_extra_save( $post_id, $post ) {
global $pagenow;
$allowed_statuses = array( 'publish', 'private' ); // list of allowed post statuses
if ($pagenow === 'post.php' && in_array( $post->post_status, $allowed_statuses )) {
... your code.
}
}
Related Posts:
- Upload Multiple Files With media_handle_upload
- How to get the image EXIF date/time and use it for the WP post date/time
- Possible to hook into Media Library preview File column and use a custom image?
- Is it possible to limit number of files a non-admin user can upload via the WordPress media library?
- How to add HTML into error message
- How to register images uploaded via FTP in media library?
- Customize WordPress Media Manager – Media Window
- delete uploaded file
- How to Removing fields from the Media Uploader/Gallery on a Custom Post Type Edit Page
- How to save Uploaded image in custom option panel?
- Max file size not updating
- Allowing SVG uploads in media uploader without plug-in
- Custom image size in Media Dropdown
- Make Categories a Dropdown Menu in Media Library
- Images uploaded using media uploader are appearing upside down
- How can I enable uploading excel files?
- Can I hide certain upload folders in media library [duplicate]
- WordPress upload_mimes not working for front-end uploads of 3D files
- Automatically assign video ‘poster’ value to ‘filename’ for archive listing
- Disable auto-resizing of uploaded images, but only for certain filename
- When sale price is 0.00 show only regular price
- Can’t generate thumbnail images
- Redirect to another page using contact form 7? [closed]
- Load custom css in functions.php causing library issue
- This code works, but the way I integrated it is breaking the media uploader. How can I integrate it properly?
- Function that prevents users from uploading photos more photos
- Custom image sizes showing in Classic Editor only when upladed directly to post
- How to upload large media file in chunks, without any plugin?
- How to add if statement on WordPress shortcode output
- Auto delete content in specific folder inside media library
- How to copy the all WordPress media items to another custom plugin folder?
- Serving cache from multiple domain names
- restrict uploaded image size and fixed image display size
- Function image_send_to_editor returns emty title tag
- Zip all (original) images from media gallery
- Figure inlined width trigger distorted layout
- wp_upload_bits – define (sub)folder / (sub)directory before filename?
- Additional folder where will Media Library look for files
- Rename file after title , one small problem
- When the WP_EDITOR button is pressed, the user is prompted to select a photo from their device
- How to overwrite image if it already exists – WordPress, Gravity form
- Convert Image to Webp on upload without plugin
- How to avoid saving empty data to sql while using add_meta_box
- How to assign php file(template) to several pages with same prefix page name/slug
- How to Display WooCommerce Product Price in WooCommerce Archive
- How to change text color depending on the number value (Using javascript)
- is_main_query() always returning false
- Woocommerce Variable Product Dropdown for Custom Shop Template
- Is this a backup door?
- Create Custom URL structure for specific Post category using Post ID instead of post name
- Include widget file in functions.php of child theme
- WordPress comment processing . Default unapproved comments detection before posting
- Astra theme – cannot set short product description under the product title (product name)
- Warning at top of website & top menu gone
- Featured Image and Tags problem
- Is posible to redirect a few URL?
- Need help making a short code work
- Filter Media by attached page or blog post in Library
- Add custom taxonomy using JS in post editor
- Use a filter for wp_robots to block CPT/feed/
- WordPress: Highlight search result exact matches
- Trigger email alert if file downloaded
- Completely Disable WordPress RSS Feeds
- Default click “I have read and agree to the website terms and conditions”
- How to use wp_enqueue_script properly?
- How to hide content on mobile in the functions.php file – woocommerce
- Woocommerce Default sorting product by product type
- Displaying registered sidebar after post content
- Hide Author By-Line if After Certain Date
- This code is supposed to only allow user to be authenticated if accountVerified is equal to 1, but it still allows user to be authenticated otherwise
- Get webpack to work on child theme
- Using One Function To Create Two Different Shortcodes
- Custom blog post summary on blog index page
- How to hide WooCommerce product title and short description to non logged in users?
- Create a CUstom Archive by Year, but just for a Single Category
- How to loop while adding data to database?
- Override a Post’s URL with Advanced Custom Fields Function
- How to locate the js code and php code for certain function?
- Change WooCommerce Payment Options From Radio Buttons to Dropdown Menu
- Is it possible to create a shortcode to link to a specific post/page where the tag is just an attribute?
- Prevent wp_signon redirect on failed login for ajax login
- How to redirect Subscribers on login to specific page, when logging in from a Page
- Fetch URL parameter
- how can I add filter in specfic field in my website?
- Updating custom query var with multiple values
- how can I change all wordpress media file url to custom cdn url?
- WordPress Function Assistance with Loop
- Different image using srcset function
- Using WP-CLI “wp media import” to sync files to the media library
- Cannot create new posts or upload images using media manager
- redirecting a URL if accessed directly
- Hide media library images from other roles uploaded by admin
- Save Meta when custom Taxonomy Saves
- Detect Ajax call inside pre_get_posts function
- Show metadata in users.php – wordpress
- Render page with specific id from functions.php
- Add version # to wp_register_style function
- Why should I use get_template_directory() when include files?
- Display Child Pages if no child Exists Display Siblings
- How to remove font awesome from loading in wp theme