Is there a way to extend the default image widget into a new custom widget and add additional fields to it?


Ultimately I’m wanting to add some custom widget fields to the existing default image widget, and define it as a new custom widget.

I’m trying to create my own by extending the WP_Widget_Media_Image class, like this:

class Theme_Image_Widget extends WP_Widget_Media_Image
     * Widget identifier.
    const WIDGET_SLUG = 'theme_image_widget';

     * Widget friendly name.
    const WIDGET_NAME = 'Theme Image Widget';

     * Widget description.
    const WIDGET_DESCRIPTION = 'foo';

    public function __construct()
                'classname'     => self::WIDGET_SLUG,
                'description'   => self::WIDGET_DESCRIPTION

This code gets the new widget to appear in the widgets area, but it doesn’t contain the normal UI that the default image widget has. I’m essentially looking to get the same UI over into this widget, and then add some additional fields to it.

Is there anyway to do this without having to re-write the JS UI code for the image widget?

Timothy Fisher 2 months 0 Answers 10 views 0

Leave an answer