The second parameter for add_action()
must be a function or a member of an object. In the second case you have to pass an array ( $object, 'method_name')
.
To register the widget from within the class, add the following method to your widget class:
/**
* Tell WP we want to use this widget.
*
* @wp-hook widgets_init
* @return void
*/
public static function register()
{
register_widget( __CLASS__ );
}
Then change your add_action()
call to:
add_action( 'widgets_init', array ( 'wp_my_plugin', 'register' ) );
Related Posts:
- Customizing subject in comment notification e-mails
- How to Loop Plugin Option Field Set?
- Saving Plugin settings to the database
- Shortcode display outside the div
- HELP: Integrating WP with raw PHP code once published button is hit
- I would like to use create a function in my custom plugin to tell WP to use a different header
- Scope for PHP Variables Assigned in functions.php or a plugin
- WordPress Plugin Page is Loading in Admin Content Container Instead of Separate Page
- How to stop or remove an action being called inside a function of an extended class
- Edit Yoast SEO breadcrumbs output [closed]
- Conditional attributes and logic per product category
- WordPress get_avatar function not correct working
- Redirect to another page using contact form 7? [closed]
- What is @Action in WordPress?
- Check if variable is set in filter
- execute function after one completed
- Are there action hooks for comments?
- Plugin onclick button activate other plugin
- Different registration form for different roles
- More gentle way to hook WordPress custom url
- How to add custom function to pluggable.php
- Checkbox show / hide output result
- Allow a particular user to access a particular plugin?
- Cookie value changes back to previous value after changing
- Is there any way to sync Facebook Comments and with comments on WordPress website?
- Custom Plugin: How to Include Install Buttons of other 3rd Party Plugins?
- The function called on the wp head hook becomes null
- adding dynamic/multiple slug values in ‘option_none_value’
- working code, not working – Plugin Dev
- Get post content inside plugin class method
- Is admin section completely customizable in terms of styling?
- register_activation_hook doesn’t fire at all
- My ajax request don´t work and return 0
- WordPress environment not loading properly
- Populate select option with JSON file
- Plugin Hook: Get posts
- Saving an array to get_options
- Saving plugin data returns “You do not have sufficient permissions to access this page.”
- How to add a handler for a button in plugin?
- Can anyone tell me why I can’t edit a plugin when it is installed without having to re-install?
- Doing action based on input from options menu
- How use Dynamic hyperlink on each wordpress post?
- How can I save the selected page in the dropdown after anyone clicks on Save Changes?
- How can I save the selected page in the dropdown after anyone clicks on Save Changes?
- Keep one user logged for a year?
- WordPress widget / plugin….fields not appearing in my widget
- How to list the Hooks and order of execution in current loading page? [duplicate]
- How to turn off email you receive when registered?
- Execute a function using ajax
- Fatal error: Class not found in
- Custom Shipping method not showing in checkout
- How to access function from outside of a class within this class in WP plugin?
- add_action in functions.php, do_action in plugin?
- The Point of Using apply_filters()
- How to get subscription key or id using Woocommerce Subscriptions [closed]
- How to include code into functions.php file via a plugin
- Missing argument 3 for wp_register_sidebar_widget()
- How can I get WordPress to save comments in markdown format?
- Shortcode button dosent work for all posts. Work for first post only
- Is Wrapping intval() Around esc_attr() Redundant for Escaping Input?
- Theme my Login plugin, how to update fields
- Date calculations from 2 custom fields
- How would I go about creating a user ranked post popularity page?
- Customize permalink wordpress category id
- Create a plugin from within WordPress
- Class variables not correct on page
- Load Javascript from Plugin in One Page Only?
- Why is one phpunit test throwing an error on one class when all other classes are similar without error?
- Why is my custom post type not being activated on plug-in activation?
- Plugin Development – Functions or Hooks?
- wp_dequeue_script for a Plugin
- How do I add $_SESSION[”] to my wordpress page?
- output html on post or page from custom plugin [closed]
- Built a second plugin but it overwrote the first one
- Way to send multiple values for column to MySQL?
- How can i list random author?
- Can you echo PHP code from a variable?
- how to validate input field in wordpress generated with wpform plugin
- Conditional delete metadata does not works
- Error using wordpress functions inside a plugin class
- Share my WordPress plugin for updating how?
- Submitting form to PHP
- Rename a folder via HTML POST request
- how override a define
- WordPress plugin blog creation
- How to Unhook actions/filters in within Class in plugin
- Nested Actions and Filters
- Configuring default woo commerce login with modal popup
- submit form data to wordpress existing database table using my plugin
- echo plugin results on pages
- Create csv file in plugin
- Posting code inside the post instead of in the template file using shortcode
- Plugin Breaking WordPress Login
- How to disable register and reset the password from WordPress admin panel?
- What is the source outline for a basic word press plugin?
- Submit posts in two different post types with the same form
- How to tweak a plugin without preventing it from updating
- Call a function with href
- Adding a script & php to functions.php
- Create WordPress category dynamically