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
- Objective Best Practices for Plugin Development? [closed]
- Difference Between Filter and Action Hooks?
- How do i best handle custom plugin page actions?
- Is it ever okay to include inline CSS in plugins?
- Plugins in symlinked directories?
- 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?
- How can I configure Docker for developing and deploying a custom theme?
- How to add sub-menu to a menu generated by wp_nav_menu by using plugin
- What do you think about custom designed plugin/theme options UIs?
- No Error Log File, no debug info
- How can I load a page template from a plugin?
- Where to put third party PHP library?
- Is the new WordPress 3.1 admin bar pluggable and how can I extend it?
- How to use PanelColorSettings in custom Gutenberg block?
- Getting a peer review for my new plugin?
- Optimize shortcode callbacks
- Using query_vars filter
- How to integrate a PHP webmail script into the backend of WordPress?
- Using filters and actions for plugin API?
- Is There A Hook To Process The Content Of The Text Widget?
- How to Change the Entire WordPress Admin panel Look and Feel?
- How to get Post ID with the Add Filter Function
- Explanation of the “posts_join” and “posts_fields” filter hooks?
- How to log plugin errors to plugin error_log file
- How do you use the plugin boilerplate loader class to hook actions and filters?
- add_filter OO with parameters
- How Can I Add a Filter to Class Instance Only?
- Which to use to execute code during the saving of a plugin settings page?
- Allowing for multiple template views on the Gallery Settings page when using the Visual Editor
- Is it possible to remove next-post / previous-post with out creating a custom template?
- How do I Make a Theme “plugin-ready”?
- How to remove unwanted panels inside InspectorControls from core blocks in Gutenberg
- Using Primary Color in Plugin Block
- function triggered by “manage_users_custom_column” filter not working
- Proper way to use apply_filters() with class functions?
- When is it appropriate to put functions on page template vs. functions.php?
- add_filter and remove_filter added before and after wp_query
- How to modify post content before writing to database?
- Actions or filters fired when data is saved in a custom table
- Some nav-menu filters do nothing
- Filter on the_content ignores shortcodes
- Custom theme sufficient or custom plugin neccessary for this feature set?
- Determine which theme location a wp_get_nav_menu_items is for
- How to change wordpress post title?
- Display only certain posts based on visitor’s country?
- When to check if a function exists
- What’s the difference between hooks, filters and actions? [duplicate]
- How to use filter hook ‘post_updated_messages’ in coherence with action hook ‘save_post’
- Conditional add_filter?
- How to create custom home page via plugin?
- How to list the Hooks and order of execution in current loading page? [duplicate]
- 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
- Calling apply_filters on non-documented hooks
- Featured Image not showing in admin
- How to use wp_set_password in a plugin?
- WordPress Media mime type filter problem 4.0
- Failed to invoke other hook from the init hook
- How to allow Unfiltered HTML in a wordpress multisite install
- How to add custom content under plugin row in WordPress admin plugin list?
- Changing bloginfo description from a plugin
- How Can I setup WP CLI on Windows development machine running AMPPS?
- WP_LOCALIZE_SCRIPT doesn’t work
- Is there a way to verified if an add_filter is already applied?
- Define a function outside a class and call the function using action or filter hook
- Does add_filter work outside functions.php
- Nuance in adding CPT and TAX to a submenu
- Can I differentiate between “Delete Post Permanently” and “Empty Trash” and do something for each accordingly?
- Synchronize Custom post type tags to WordPress default posts tags
- Delete a specific item menu when I deactivate my plugin
- multiple functions with same filter
- Woocommerce – Hide a Column in Cart Table
- Are we allowed to use the Allman (BSD) indent style when coding WordPress plugins and themes?
- 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
- Order properties should not be accessed directly
- 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?
- Executing a function upon webhook calling wordpress
- Customizer: widget-synced triggers twice
- WordPress not working on localhost
- WordPress after content Hook & external template part
- Adding functions to hooks from within a class
- 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
- Two functions utilizing registration_errors filter
- Where to store the name of a custom table?
- Applying OO patterns and principles to plugin development
- 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?
- best practice for query string values – get_query_var always empty for my value supplied in query string