Make WordPress Core

Opened 5 years ago

Closed 5 years ago

Last modified 2 years ago

#44344 closed defect (bug) (maybelater)

Extending from WP_Widget_Media_Image not work

Reported by: hamedmoodi's profile hamedmoodi Owned by:
Milestone: Priority: normal
Severity: major Version: 4.9.6
Component: Widgets Keywords:
Focuses: Cc:

Description

Hi
i am writing widget that just some change in WP_Widget_Media_Image class. so i extends WP_Widget_Media_Image and call 'register_widget()' in 'widgets_init' action.
but id do not see my widget in widgets area.
is that a bug? or not posible in wordpress development?
thanks

Attachments (1)

sampleClass.JPG (59.8 KB) - added by hamedmoodi 5 years ago.
Sampe class that extends from WP_Widget_Media_Image

Download all attachments as: .zip

Change History (5)

@hamedmoodi
5 years ago

Sampe class that extends from WP_Widget_Media_Image

#1 follow-up: @westonruter
5 years ago

@hamedmoodi Take a look at the WP_Widget_Media_Image class's constructor:

https://github.com/WordPress/wordpress-develop/blob/4.9.6/src/wp-includes/widgets/class-wp-widget-media-image.php#L24-L28

Note that it does not pass along any arguments it takes. Maybe this is a bug, but it should be easy to work around. In your constructor, just try setting the class variables manually after calling the parent constructor. For example:

<?php
// ...
        public function __construct() {
                parent::__construct();
                $this->id_base = 'custom_image';
                $this->name = __( 'Custom Image', 'custom' );
// ...

#2 in reply to: ↑ 1 @hamedmoodi
5 years ago

Thanks. its work. its my fault.
Replying to westonruter:

@hamedmoodi Take a look at the WP_Widget_Media_Image class's constructor:

https://github.com/WordPress/wordpress-develop/blob/4.9.6/src/wp-includes/widgets/class-wp-widget-media-image.php#L24-L28

Note that it does not pass along any arguments it takes. Maybe this is a bug, but it should be easy to work around. In your constructor, just try setting the class variables manually after calling the parent constructor. For example:

<?php
// ...
        public function __construct() {
                parent::__construct();
                $this->id_base = 'custom_image';
                $this->name = __( 'Custom Image', 'custom' );
// ...

#3 @westonruter
5 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to maybelater
  • Status changed from new to closed

#4 @briandre
2 years ago

Hi, I wonder if there is any working example using "extends WP_Widget_Media_Image"?

I need to add some additional fields to the built-in image widget. I followed this thread and https://wordpress.org/support/topic/wp_widget_media_image-new-field/ but still no luck.

Thank you.

Note: See TracTickets for help on using tickets.