I took a code straight out of one of my themes I created, and it’s a list of all 50 states in an unordered list packed into a widget you can just drag and drop on the sidebar.
The problem is, when I try using this code in a PLUGIN file, I get the following error:
Fatal error: Call to a member function register() on a non-object in C:xampphtdocswordpresswp-includeswidgets.php on line 431
Why would it work in the theme, but not in the plugin? By the way, the active theme is NOT the theme I took the code out of.
Here’s my code: http://pastebin.com/ZeRWW3yb
Thanks.
try replacing :
with:
Let us assume that you need to initialize a widget inside a class method by passing the widget name as an argument. To accomplish this you would do this:
Note that we need to pass the variable
$widget_name
name to our lambda function in order to use it. The part doing this isuse (&$widget_name)
. As already noted hooks initialized like this cannot be removed byremove_action
.