• A quick question.

    I am trying to create a plugin that adds a custom widget to the widgets area of the admin backend.

    Does the following code (for registering the widget) go in the theme’s “functions.php” file or does it go in the plugin file that adds the new custom widget class that extends the WP_Widget class?

    add_action( 'widgets_init', 'register_my_widgets' );
    
    function register_my_widgets()
      {
    	register_widget('Advert_Widget');
      }

    When i place this code in my theme’s “functions.php” file, the custom widget appears in the widgets area of the admin backend and it works fine except for when you deactivate the plugin – then i get an error message saying:-

    PHP Fatal error: Class ‘Advert_Widget’ not found in C:\Server\Apache\htdocs\wp-includes\widgets.php

    However, i then tried removing that code from my theme’s “functions.php” file and placing it in the plugin file that adds the new custom widget class that extends the WP_Widget class. When i did this, the active plugin did not show the widget in the widgets area of the admin backend.

    How can i solve this problem?

    Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi
    Have you found any solution? I’ve got the same issue when i try to deactivate my plugin.

    I’ve tryied a

    unregister_widget( “myWidgetName” );

    on a

    register_deactivation_hook( __FILE__, ‘myFn’ );

    but same result…

    Sorry, it was just a copy/paste mistake, and so an incompatibility with my other custom widget… (same name for register_widget……)

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘problem with registering a custom widget’ is closed to new replies.