Support

Home Forums Event Espresso Premium table template error ee4

table template error ee4

Posted: October 27, 2015 at 4:25 am

Viewing 8 reply threads


Kim Shiely

October 27, 2015 at 4:25 am

Hi,

What does this error mean? – *redacted*

Thanks.

  • This topic was modified 9 years, 1 month ago by Josh. Reason: removed screenshot that includes server folder paths, this is a public forum


Tony

  • Support Staff

October 27, 2015 at 5:34 am

Hi,

Its means array_shift() was called on a variable (expecting and array) to pull the first element from the array so you can use, but the function was given a string rather than an array.

This can happen for multiple reasons, the custom template you are using does not match the default template as that doesn’t contain array_shift() so I can’t say what is actually causing it.

Are you passing any parameters over with the shortcode?


Kim Shiely

October 27, 2015 at 10:36 am

Thanks Tony,

Here is the shortcode that I’ve used –
[ESPRESSO_EVENTS_TABLE_TEMPLATE category_slug=”village-fall” table_search=”false” reg_button_text=”ENROLL NOW” category_filter=”false” sort=”ASC” sold_out_button_text=”FULL” limit=”20″ table_paging=”false” table_pages=100]

We just got it working following our previous post here – https://eventespresso.com/topic/ee4-table-template-limit-more-than-10-no-pagination/

We have the template ‘espresso-events-table-template.template.php’ in the uploads/espresso/templates folder.

Is the shortcode not right now?

Thanks.


Josh

  • Support Staff

October 27, 2015 at 10:58 am

Was the template customized by Ben? Does the error go away if you switch to the built in template?

It may help to see the actual code that’s throwing the error. Can you post to a pastebin or a gist?


Kim Shiely

October 27, 2015 at 3:06 pm

Yes, he’s done an excellent job building our site with event espresso 4. Yes, the error goes away by removing the template, the template has been working fine until today. Could some translation phrases in the .mo file effect the template, as those were the only changes we made yesterday?

Here is the actual table template code, that is now causing the error – http://pastebin.com/PqdE9097


Josh

  • Support Staff

October 27, 2015 at 4:00 pm

Hi Kim,

I checked and do not see any translation phrases in espresso_event_tickets_available(), so I don’t think it’s a case where the translation phrases would affect this. It looks more like events with no tickets though. Like a sold out event.

Can you contact Ben and ask him to look into the error in the custom template code he wrote. The code in question appears to be:

$tickets = espresso_event_tickets_available( $post->ID, FALSE, FALSE );
// grab first ticket from array
$ticket = array_shift( $tickets );

He should be able to add an is_array() check before doing the array_shift() to prevent errors.


Ben

October 28, 2015 at 10:23 am

Hi Josh,
Hope your well, may I take this opportunity to say EE4 is a fantastic upgrade to EE3, well done to you and the whole team! 🙂

In regards to this error appearing for the table template;
We’ve retested this, and as you can see here – http://www.kindermusikwithfriend.us/schedule-registration/fall/
The table is now working ok.

However, this is because we have removed the .mo translation file with 16 translations on it. The moment we re-add the .mo file in the uploads/espresso/languages then the error appears.

We made the amendments to the table using Lorenzo’s code for the table from here –
https://gist.github.com/lorenzocaum/ef6afefd07c9c5f6f681

Can you explain why we need to add is_array() please, as it appears to be the .mo translation file that is causing the error when uploaded? What check needs to be added before the array_shift( $tickets ); if it is not the .mo file causing the error?


Josh

  • Support Staff

October 28, 2015 at 10:53 am

Hi Ben,

The .mo file isn’t causing the error, it’s more of a symptom. The error will also show up under other conditions. The root cause of the issue is your code assumes there will always be an array of tickets, no matter what. The thing is though, you might get an array, you might get nothing, or even a string (especially if you have debugging turned on). Again, this can happen with or without your .mo file customizations.

So to make your code more bulletproof and not fire a warning when you try to run array_shift() on something that’s not an array, you test for an array first. That’s why I suggest using is_array() to check first and make sure that you have an array before you run array_shift().


Ben

October 29, 2015 at 9:29 am

Thanks Josh,

The is_array() has been added now and all working correctly for the table. Let me know if you want the code to share. Thanks!

Viewing 8 reply threads

The support post ‘table template error ee4’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso