It depends what you want to do.
If you look into the function definition, you’ll notice some do_action():
For example:
do_action( 'delete_attachment', $post_id );
do_action( 'delete_post', $post_id );
do_action( 'deleted_post', $post_id );
These are points, called hooks in WordPress, where you can actually run your stuff. Hooks will help you to modify the core behaviour without modifying the WordPress core itself.
Let’s assume you want to hook into the code before the attachment is deleted, you can then use add_action('delete_attachement', 'yourfunction');
in your plugin or theme’s functions.php
to run any code you want.
For example:
add_action('delete_attachement', 'yourfunction');
function yourfunction( $post_id ){
echo 'sample';
die;
}
Related Posts:
- How to create an API for my plugin?
- WordPress is automatically linking plain text email addresses
- In Which Contexts are Plugins Responsible for Data Validation/Sanitization?
- Plugin Form Submission Best Practice
- Best way to abort plugin in case of insufficient PHP version?
- What do you think about custom designed plugin/theme options UIs?
- How can I load a page template from a plugin?
- Where to put third party PHP library?
- Optimize shortcode callbacks
- Using query_vars filter
- How to integrate a PHP webmail script into the backend of WordPress?
- How to get Post ID with the Add Filter Function
- How to log plugin errors to plugin error_log file
- Which to use to execute code during the saving of a plugin settings page?
- How do I Make a Theme “plugin-ready”?
- Using Primary Color in Plugin Block
- When is it appropriate to put functions on page template vs. functions.php?
- How to modify post content before writing to database?
- Filter on the_content ignores shortcodes
- Custom theme sufficient or custom plugin neccessary for this feature set?
- How to change wordpress post title?
- Display only certain posts based on visitor’s country?
- How to use filter hook ‘post_updated_messages’ in coherence with action hook ‘save_post’
- How to create custom home page via plugin?
- Adding callback function for wp_ajax_ has no effect
- Is it possible to create an action hook using do_action() within add_action()?
- Sessions not creating correctly in custom function
- Hook for post permalink update
- Dynamically Override Fancy Title
- Featured Image not showing in admin
- Failed to invoke other hook from the init hook
- How to allow Unfiltered HTML in a wordpress multisite install
- Changing bloginfo description from a plugin
- multiple functions with same filter
- Woocommerce – Hide a Column in Cart Table
- Version upgrade: can my plugin filter the SQL statements issued during a database upgrade?
- Get the password key when using the wp_new_user_notification_email filter
- add_filter : Passing an array instead of the callback function?
- How do I alter the comment form ‘allowed tags’ text in a plugin?
- How to deal with equal & similar arguments for a function?
- Customizer: widget-synced triggers twice
- WordPress after content Hook & external template part
- how to use hook deleted_user into custom function to delete user from custom table
- Namespaced action and filter tags
- Disable The Events Calendar plugin from loading its scripts
- Is there a Filter that I can use to filter the tags before they are inserted in to the database?
- Is Using WordPress Supplied WYSIWYG Advisable?
- Maximum lifetime for nonce
- Custom Taxonomy to dropdown box on adminside wordpress
- Why doesn’t my simple the_title filter get applied?
- How to modify the comments to be displayed in a post?
- Can’t get woocommerce_get_price_html to work [closed]
- Search and Filter
- WordPress custom taxonomy check box to dropdown
- Using ob_get_content to get_search_form puts into infinite loop
- Redirect to another page using contact form 7? [closed]
- How to modify files inside wp-includes directory in wordpress
- Remove an action by extending class and replacing it
- Show message from backend
- Create Widget or Enable Shortcodes in Sidebar
- Call to undefined function is_home() or any conditional tags
- WooCommerce change Tax Class programmatically when Recalculating an existing Order [closed]
- how to save wp_editor html content in options table
- Include HTML (Bootstrap Modal Box) with a plugin into my header
- How to use a WP_Customize_Control outside of the Customizer?
- WP_NAV_MENU filter targets all menus
- How to remove/replace current page template?
- Is there an action_filter hook to add content before the post title?
- Adding tables to dashboard pages programmatically?
- How to determine which capability to use?
- Custom Endpoint – Does it possible to use PUT method with WP API Rest?
- Why won’t this submenu page show? – My First WordPress Plugin
- Limit get_next_post to posts from the same author
- Any way, hook to add content right before the “read more” link?
- Redirect theme directory to plugin theme directory
- WordPress Reset password Strength set to medium
- Determine if the current page, is being edited
- external Integration with wordpress timeout error
- Modify search form with plugin
- Single_template for a custom post type created from a plugin is returning an empty page
- Making adding info to an overlay bio easy for average user?
- Implementing Select2 plugin into WordPress
- Confusing $tag specification for apply_filters call, in core options.php code
- Associating special meaning with user id 0
- WordPress permalink setting
- Can I access WordPress API’s from within plugin scripts?
- Theming Custom Plugin Page
- Link to a admin submenu item using a custom link
- Change the search results header from plugin
- Dynamic banner for use on external sites
- Apply Filters Causing a 500 Internal Server Error
- add_filter adds output in the head
- Developing Themes on WordPress, Looking for Excellent Tutorials [closed]
- How to Implement SAM Broadcaster with WordPress? [closed]
- Apply function on all action hooks?
- Custom plugin not appearing
- Extend WP_List_Table class – Edit wp_usermeta – WPPB.me Boilerplate – Action error
- Is there any other ways to replicating changes on live from staging without pushing from git
- Can I log the searches that are returning 404 in the DB?
- Do Not Back Up? Is there any accepted way to tell backup and clone plugins to skip a certain file? [closed]