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?
- Mixed results with is_page() WordPress function, when using $this, or self
- add_action() not working for admin
- Read page- or post-content across different builder-plugins
- Using require_once in a Plugin?
- Why does including a file in theme’s functions.php not work?
- Add Top-Level Menu that opens URL
- Sanitizing, Validating and Escaping in WordPress (Plugin)
- Avoiding Duplicate function names in Post Loop (WP_Footer script)
- How to add class in plugin only for network site?
- Plugin Development sqlite or WordPress’ database
- WooCommerce get_price returning wrong price when used via ajax
- Open Post Thumbnail in New Child Theme File in WordPress
- Pulling data from custom plugin settings using PHP shortcode and Javascript
- Executing my function once on a specific time
- When to load auto-login code?
- Creating a custom post type, adding custom meta fields, preventing all future editability of posts of this type
- How to fetch products with the price in a page on woocommerce using a form or live search with php
- Creating a Callback URL for WordPress Woocommerce to update Order Status
- Get Time Taken By Each Action Hook in WordPress
- How to replace WordPress Media Upload Window with user’s device window?
- Difference and examples of esc_attr__() and esc_attr_e()
- Add action to fire when a published post is updated
- Issue running db create table query from static method
- How to make multiple admin pages for one plugin?
- How to translate wordpress error message
- strange shortcode error: does shortcodes requires any dependency?
- All custom widgets are not showing in widget area at the same time
- I want to generate the pdf and save it in library?
- Custom CSS not being added by plugin
- Create “new pages” within the admin section of plugin
- How to display results from a data table with an encrypted user id?
- I cannot include a file in my plugin settings page
- How to Call Specific .PHP file on add_submenu_page selection in Plugin Development?
- How to Add text value in Automatically in this conditions?
- Creating an array from form inputs before it is posted to the options database
- Hide content for specific users with id
- How to assign a specific service to a specific provider based on location
- 500 Internal server error wp_handle_upload_prefilter
- Can’t access 3rd party API, code works on local server but not on wordpress
- Ajax call to php function doesn’t work PHP code
- Compare Ajax Data Results
- How can I make the search bar in my wordpress site search all of the pages rather than just the blog posts?
- Nested DIV’s across functions in PHP, do not seem to work
- WordPress Add advertising ads befor and after content with periority [closed]
- Every time I use wp_get_current_user() my plugin breaks
- Can plugin automatically update if i hide the update notification?
- How to limit each front-end user to view just his own uploaded files on Amazon S3?
- AJAX login without a plugin does not work. when add a action to function.php
- Call current post parameters inside a plugin
- How to list posts that appear in two categories
- Load my plugin before cache
- Move related products after product summary? [closed]
- Adminimize Plugin — Is there an alternative to limiting Editor to ‘Appearance > Widgets’ only?
- Woocommerce disable checkout on specific day
- Gravity Forms and Gravity View Permissions
- Woocommerce attatch files and custom input meta to cart items and then to order