UUA Services Plugin error

By Chris W. Jordan
May 22, 2022, 2:39 pm EDT

Recently I started seeing the error below from the UUA Services Plugin. I didn't change anything, and I can't reproduce it on my local webserver, so presumably the hosting provider (aplus.net) changed something. At any rate, the error is:

Warning: require_once(widgets/class-uua-widget-featured-service.php): failed to open stream: No such file or directory in uua-widget-functions.php on line 14

Fatal error: require_once(): Failed opening required 'widgets/class-uua-widget-featured-service.php' (include_path='.') in uua-widget-functions.php on line 14

The line of code triggering the error is:

require_once 'widgets/class-uua-widget-featured-service.php';

I tried changing that to:

require_once __DIR__ . '/widgets/class-uua-widget-featured-service.php';

to try and force it into the correct directory, which didn't work, and gave the error:

Warning: require_once(/services16/webpages/util/s/e/sedonauu.site.aplus.net/public/wordpress/wp-admin/widgets/class-uua-widget-featured-service.php): failed to open stream: No such file or directory in uua-widget-functions.php on line 14

Fatal error: require_once(): Failed opening required '/services16/webpages/util/s/e/sedonauu.site.aplus.net/public/wordpress/wp-admin/widgets/class-uua-widget-featured-service.php' (include_path='.') in uua-widget-functions.php on line 14

so looks like the magic constant __DIR__ is expanding into the path to wp-admin for some reason. No idea why.

Anyway, I changed that line (and the following one) to:

require_once dirname( UUAS_PLUGIN_FILE ) . '/includes/widgets/class-uua-widget-featured-service.php';
require_once dirname( UUAS_PLUGIN_FILE ) . '/includes/widgets/class-uua-widget-upcoming-services.php';

Which works fine. That should also work fine on other sites, although I haven't tested it. It might be a reasonable change to make to the plugin, to prevent the problem from happening for anyone else. After all you already went to the trouble to define UUAS_PLUGIN_FILE earlier in the code, you may as well use it.

Anyway, the above works for me. If anyone more skilled with PHP than I am can suggest why the original line broke in the first place, I'd be interested in any ideas (although I'm not planning on playing with it much more).