How to use Wordpress classes in Views

Hey, how can I use Wordpress classes (eg WP_Error) in views included in app/ View / Composers /? I want to use WP_Error but I get an error message - Class ‘App \ View \ Composers \ WP_Error’ not found.

Sage 10
Linux Ubuntu 20.04

You need to call them from the root namespace, like so:

new \WP_Error();

I’d recommend reading this to better understand namespacing: https://roots.io/namespacing-and-autoloading/

3 Likes

This topic was automatically closed after 42 days. New replies are no longer allowed.