Fixing the YD-Recent-Images widget


I’ve been using the handy YD-Recent-Images plugin for awhile now, to generate the /photos page here on my site. It provides a widget that displays the latest n images uploaded in posts here - and provides a nice photostream view for my photoblogging here as well 1. The plugin hasn’t been updated for… 7 years!… but it works. I’ve been expecting it to start misbehaving over time, though.

The /photos page here on my site. Self-hosted photostreamy goodness.

The plugin has been working flawlessly, but I noticed it was throwing an error after the latest WordPress update to 4.9.8. Something about:

Warning: Declaration of YD_RecentImageWidget::display() should be compatible with YD_Widget::display($args, $instance) in /[redacted]/wp-content/plugins/yd-recent-images/yd-recent-images.php on line 110

That’s weird. The plugin has been working flawlessly until now. And the recent images widget on the photos page is displaying normally, so it’s still working, but with an error message blasted at the top of the page. I’m guessing 2 something changed in WordPress to become more stringent about PHP classes and functions. So, I follow instructions and take a look at line 110… The display() function in yd-recent-images.php didn’t have any function parameters, but the YD_Widget::display function in the class had 2 parameters: $args and $instance.

So, being a reckless “let’s just modify it in production to see if I can get it working” “programmer”, I just modified yd-recent-images.php’s display() function (on line 110), to include the two parameters:

function display() {
became
function display( $args, $instance ) {

and hey, presto! the error message went away. Note, this is absolutely NOT the same thing as saying this fixed anything. It might be fixed. I don’t know. I just typed things until an error message went away. This is probably the absolute worst practice, but whatever. It worked. Functional trumps correct.

ps. this post was written in the fancy new Gutenberg editor. Dang. It’s slick! I don’t get the hate about it - this improves editing in many, many ways. And is backward compatible because it just creates normal HTML rather than some kind of freaky shortcode/embed nonsense.


  1. I use the Widget Shortcode plugin to embed the widget on the photos page. ↩︎

  2. totally guessing. I have no idea what might have changed, but there was a WordPress update yesterday. Who knows? could have been a coincidental PHP version update on the server… ↩︎


See Also

comments powered by Disqus