Edit plugin files for namespacing? - Eventbrite API

I’m using trellis/bedrock/sage and am trying to implement the Eventbrite API plugin: https://github.com/Automattic/eventbrite-api

The API reports that it is connected in the admin - so I’m assuming that part of the setup is correct. In my theme (sage) I’m getting an error on the designated ‘eventbrite’ page:
Fatal error: Class 'Eventbrite_Query' not found in /srv/www/myurl.dev/current/web/app/themes/sage/eventbrite/eventbrite-index.php on line 16

which is:
$events = new Eventbrite_Query( apply_filters( 'eventbrite_query_args', array(

I think this is an issue with namespacing - so my question is:

a) Is this actually a namespacing issue - if so how do I go about resolving it given the structure of this plugin
b) do I need to edit the actual plugin files to add namespace Roots/Eventbrite; etc. ? This would then require commiting the plugin to my repo rather than using composer… or is there another method to namespace a plugin.
bonus question
c) Why does this particular plugin (perhaps) require namespacing - when others don’t?

I assume you are in a PHP file with a namespace. You need to either set at the top of the file, below the namespace: use Eventbrite_Query; to tell PHP that the EventBrite_Query class is in the global namespace. Alternatively, you can also do that by writing $events = new \Eventbrite_Query( apply_filters( 'eventbrite_query_args', []);

No, the issue is not with the plugin’s namespace, it’s with how you are having PHP look for the class. Copying files from a plugin or PHP package should never be an option.

Oh boy

It doesn’t, as explained. Generally, since WP requires only PHP 5.2 and namespaces were not introduced until PHP 5.3, there are almost no mainstream plugins that have true namespacing. The namespacing that takes place is in the class name, which is why you get Eventbrite_Query instead of Eventbrite\Query

1 Like

Hi - thanks for taking the time to help

The file I’m working on to output the events is a template which is set up as per the plugins readme ie.
"…compare your markup to that of the plugin’s included templates. Make your own copies, adjusting the markup as needed, and then assign your templates in an add_theme_support call."

register theme support add_theme_support( 'eventbrite' ); (in lib/setup ‘after_setup_theme’ action)

The file is in themes/sage/eventbrite folder and this is the file content:
http://pastebin.com/3zdhUm3m

from reading around in the forum I tried $events = new \Eventbrite_Query( apply_filters( 'eventbrite_query_args',[]);
as the first solution, but the error remains the same

If that’s the case then PHP cannot find that class. I assume you’ve followed all the requirements: https://github.com/Automattic/eventbrite-api/blob/master/README.md#requirements

In any case, this actually has nothing to do with namespaces

Hi - yeah it’s all setup correctly.

Thanks for the help - I just wasn’t sure if namespaces were playing a part (need to read up -again!) anyway I’ll work on the assumption that this is a plugin issue.

Are you sure you have Keyring installed and activated with Eventbrite set up with it?

It seems like plugin won’t load unless everything is set up correctly, that’s really the only explanation I could give as to why the class cannot be found.