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 well1 . 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 guessing2 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() {
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… []

2 replies on “Fixing the YD-Recent-Images widget”

  1. Shame there’s no way for WordPress to gracefully degrade on errors like that, I hate coming across stuff like that where I realize the site has been down for awhile and I had no idea. Would be cool if they found a way to be like “Hey, we’re emailing you because this PHP error showed up so we just disabled the plugin but you may want to take some action.” One can dream anyway. I agree about Gutenberg, looks pretty damn awesome for folks who have been itching to do fancier layout stuff without a handful of plugins and themes carrying the weight.

    1. I’d be happy with it gracefully eating PHP error messages and throwing a big RED ALERT PHP ERROR IN PLUGIN! thing in the dashboard.

      Gutenberg feels kinds like H5P combined with Aesop. I wouldn’t be surprised if it’s possible to build plugins to add new block types for interactivity or richer media types…

Comments are closed.