WordPress.org

Make WordPress Core

Opened 2 years ago

Closed 2 years ago

#44344 closed defect (bug) (maybelater)

Extending from WP_Widget_Media_Image not work

Reported by: 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 2 years ago.
Sampe class that extends from WP_Widget_Media_Image

Download all attachments as: .zip

Change History (4)

@hamedmoodi
2 years ago

Sampe class that extends from WP_Widget_Media_Image

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

  • Milestone Awaiting Review deleted
  • Resolution set to maybelater
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.