I recently came across an issue whereby installing the popular Yoast SEO plugin caused the frontend of a production site to crash, stating that it couldn't find many of the custom PHP classes written and included in the project theme via the __autoload()
php function.
I found others had experienced similar issues when trying to use Yoast with custom PHP classes but not found a fix. Although this issue was also known to the Yoast plugin authors, a fix had yet to appear, so I started to try to find/create a fix myself.
It turns out that the way in which WP tries to handle autoloading from theme and plugin classes can cause a confliction when the wrapper function is told to load to early on, sometimes (in the case of Yoast SEO), resulting in a loading conflict where neither class is then loaded properly.
The code in the functions.php file is a way around this as the __autoload
method can only be defined/called once, whereas spl_autoload_register
adds methods to the autoload queue and prevents this conflict issue!