Here’s reference from Codex
To use the add_action hook when your plugin or theme is built up using
classes, add $this to your add_action call together with the function
name within that class, like so:
class MyPluginClass {
public function __construct() {
//add your actions to the constructor!
add_action( 'save_post', array( $this, 'save_posts' ) );
}
public function save_posts() {
//do stuff here...
}
}
Related Posts:
- Where is the best place to use add_filter
- When can you get current page ID and initialize hooks right after?
- Using the ‘draft_to_publish’ hook (post status transition)
- Enqueue style inside shortcode but its loaded at the bottom of page (before footer scripts)
- How can I limit functionality in one version of a plugin?
- Shortcode display outside the div
- Good tools for locating hooks in a wordpress page/admin interface/blog post?
- Can a plugin add to header/footer/body content?
- Is it possible to add an action to the currently running action?
- Action on post publish
- How to add inline css/js inside a shortcode
- How to prevent action in ajax request, when in admin side?
- template_redirect not being called when using ajax
- add action wp_head not working
- What are the benefit in adding hook in the init() hook?
- add_action in functions.php, do_action in plugin?
- add action for displaying posts using a shortcode
- ‘wp_login’ action hook not working with wp-login.php file
- Any hook for pre-plugin-update -either bulk or single plugin update
- wordpress plugin is not activating from widget
- When to load auto-login code?
- How to get all of the activate_plugin action parameters?
- How to check current user before all actions and filters?
- Get Time Taken By Each Action Hook in WordPress
- Are functions in main plugin file called before function bound to register_activation_hook runs?
- Custom plugin init action causing general slowness
- Inject HTML meta tag inside wordpress tag using add_shortcode
- Add action to fire when a published post is updated
- How to pass variables to a function argument using add_action [duplicate]
- Submit Form data to another page via Ajax (WordPress Way)
- Does using `add_action( ‘init’…` cause performance issues?
- Hook for page Request?
- Custom CSS not being added by plugin
- How to use add_action for multiple instances of the same class
- How to append new form elements in “Add New” form of Users in WordPress admin panel?
- I cannot include a file in my plugin settings page
- Why do actions with class and public method don’t fire __construct()
- The function called on the wp head hook becomes null
- Nested Actions and Filters
- Passing function into add_action always returns the first argument
- Get post content inside plugin class method
- Remove action added in plugin class from theme
- echo plugin results on pages
- Plugin Hook: Get posts
- Is it possible to cancel a post status transition?
- How wordpress plugin hooks works? [duplicate]
- Passing a parameter to filter and action functions
- Get a list of all registered actions
- Update plugin from personal API
- Symlinked plugin directory doesn’t appear in Admin
- How can I include a setting that has a variable number of values in a settings page using register_setting?
- How to prepend to the_title for admin-side plugin’s use
- Custom data-id wp_enqueue_script
- Passing $this->get_field_name() to javascript
- Read text defined under __()
- WordPress Plugin Page is Loading in Admin Content Container Instead of Separate Page
- Is Wrapping intval() Around esc_attr() Redundant for Escaping Input?
- Plugin Options Not Saving to Database in WP 4.5
- how to disable blockrenderAppender inside all Innerblocks?
- Redirection of users away from wp-admin (but not administrators)
- Change commission_status paid when withdraw_status vendor is completed
- WordPress Plugin [closed]
- Proper way to replace the_content only for pages created by custom plugin
- register_activation_hook in oop approach
- Certain functions are undefined when called form mu-plugins
- Why is the ‘Gutenberg’ Plugin generating an ‘Inconsistent File Permissions’ error when other Plugins, with the same permissions, do not?
- WordPress front end AJAX. Return 0 :?
- Get Every Key & Value from Array then Display All in New Line
- WordPress 5.4 – How to prevent to enter only certain values in custom field
- DB Query not working in Plugin
- Make plugin php file called directly aware of WordPress?
- sending different email notification while registration based on user role
- Next Previous Post in wordpress with previous / next link with title?
- How to use existing hook in twentytwelve to all theme of wordpress?
- How to get a notification when the plugin is installed?
- WordPress Post HTML after Posting
- Settings options not showing up on Sub Menu page in WordPress plugin
- Custom Meta box change size
- Could add_query_arg() redirect user to external site?
- The Build menu theme is frozen with the wordpress theme
- How to translate to spanish wordpress hardcoded content/files?
- what functions to use to resize images and create DB metadata for them after/during upload?
- How to Create a Learning Management Plugin in WordPress to Manage Courses [LMS]
- How to prevent redoing get_posts queries and make results available to other scripts?
- Prefix WordPress Taxonomy Tags With Hashtag Symbol Like Twitter
- Overwriting Plugin’s Ajax callback function from theme
- How can I get the Post ID and Post Type within a Must Use Plugin?
- Can’t find variable is_single in my jQuery plugin
- WordPress Cron function is not working
- Adding custom cron_schedule prior to wp_schedule_event
- Get page type to display content
- Widget redirecting to home page
- Capturing POST data
- Is an Office a custom post type [closed]
- I am using multi image metabox plugin but I did get how to display the images in templete?
- How to open author url linked to a new tab in settings page in the WordPress plugin list
- How can I properly sanitize the update_option in WordPress?
- Why is my menu page not being displayed?
- how to make wordpress remember my choice
- wordpress admin-ajax bad request 400