I have my theme, with a folder called classes, with a single class:
wp-content
|- themes
|- mycustomtheme
|- classes
|- FooBar.php
In FooBar, I would like to use this package here: Soundasleep / HTML2Text.
And use it like this:
In FooBar.php
doSomethingBadass( $some_html ){
wp_mail( '[email protected]', 'test', \Soundasleep\Html2Text::convert( $some_html ) );
}
But whatever I do, I keep getting this error:
Fatal error: Uncaught Error: Class 'Soundasleep\Html2Text' not found in /app/public/wp-content/themes/mycustomtheme/classes/FooBar.php:60
My attempt
I assume that it's something to do with the namespacing.
I'm including FooBar.php
by requiring the class in the functions.php.
How do I get past this? And if possible, then please link to a documentation or a place where I could have figured this out. I've been on this for 2 hours now.
Update
I'm including Composer with these lines inside functions.php
:
if( file_exists( get_template_directory() . '/vendor/autoload.php' ) ){
require get_template_directory() . '/vendor/autoload.php';
}
doSomethingBadass()
used?/wp-content/themes/mycustomtheme/inc/some-other-file.php
... And I've included that in functions.php. Should I set a namespace in there? Or write:use Soundasleep\Html2Text
in there?