Make WordPress Core

Opened 8 years ago

Closed 8 years ago

Last modified 6 years ago

#44344 closed defect (bug) (maybelater)

Extending from WP_Widget_Media_Image not work

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

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 8 years ago.
Sampe class that extends from WP_Widget_Media_Image

Download all attachments as: .zip

Change History (5)

@hamedmoodi
8 years ago

Sampe class that extends from WP_Widget_Media_Image

#1 follow-up: @westonruter
8 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
8 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
8 years ago

  • Milestone Awaiting Review
  • Resolution → maybelater
  • Status new → closed

#4 @briandre
6 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.