Plugin/Package methods are undefined after upgrading from Sage 9x to Sage 10x

While our theme was still running on Sage 9x, I had a feature branch that used the DeepL php library and Polylang to add multilingual pages. Both were working as expected. However, I wanted to wait until after our upgrades to Sage 10x before merging them into main trunk.

After the upgrade, I am now getting errors such as :

Undefined function DeepL\Translator 

I’ve tried doing \DeepL\Translator and importing to DeepL into my class file, but nothing has worked. The same errors are popping up for PolyLang methods as well.

I believe it’s a namespacing issue, but I have no clue what namespace these plugins belong to.

I’ve searched the documentation and the forum but it seems like no one else is having this issue, so I am assuming I’ve missed a step somewhere.

Some notes on my theme that could be helpful or pointless:

  1. All classes that handle translating are in a directory under app in the sage directory. Polylang and DeepL are being used in that directory. That directory is being registered in the functions.php by adding the file names to the collect array like so:
collect(['setup', 'filters', 'Translation/AlgoliaTranslationLinks','Translation/FeaturedPostCardTranslationLinks', 'Translation/Languages', 'Translation/Posts', 'Translation/Translate', 'Translation/TranslationSelectBox'])

Side note: I also couldn’t get glob to pull in array of the files under Translation like I could in Sage 9x.

  1. The plugins are installed in Bedrock. PolyLang Pro is installed via a zip file. (I’ll add that the admin side polylang plugin is working as expected. I just can’t reference the methods in my codebase.)

  2. Acorn is installed at the Bedrock level.

Could you post some code showing how these functions are being used?

Ah sorry to drop the ball on responding. Two unrelated issues.

With DeepL I accidentally deleted the new keyword before instatiation. I was surprised the error wasn’t more explicit about that instead of just saying the method is undefined.

The Polylang issue was solved by this note at the top of methods page in the polylang docs that I hadn’t seen before:

IMPORTANT: when using one or more of these function, you *must* check for its existence before using it, otherwise your site will badly break with a fatal error at next Polylang update (as WordPress deletes the plugin when updating it).

Checking for the functions’ existence seemed to have solve the issue.