Title: Missing array element protection in ect-class-vc.php
Last modified: December 2, 2024

---

# Missing array element protection in ect-class-vc.php

 *  Resolved [Paul](https://wordpress.org/support/users/headwall/)
 * (@headwall)
 * [1 year, 6 months ago](https://wordpress.org/support/topic/missing-array-element-protection-in-ect-class-vc-php/)
 * Hi
 * We’ve been picking up lots of PHP warnings regarding “**ect-class-vc.php**” with
   versions 2.4.3 and 2.4.4 (**line 26**). Can you please add some protection when
   accessing $term->name and $term->slug, maybe like this?
 *     ```wp-block-code
       if( is_array( $term ) && !array_key_exists( 'name', $term ) ) {   // ...} else {   $ect_categories[$term->name] = $term->slug;}
       ```
   
 * We’re having to patch this at our end for now to keep the error-log size manageable.
 * Thanks

Viewing 6 replies - 1 through 6 (of 6 total)

 *  Plugin Support [Vishali Tayal](https://wordpress.org/support/users/vishali009/)
 * (@vishali009)
 * [1 year, 6 months ago](https://wordpress.org/support/topic/missing-array-element-protection-in-ect-class-vc-php/#post-18172926)
 * Hi [@headwall](https://wordpress.org/support/users/headwall/),
   We have tested
   this at our end and did not get this issue. Could you please share the scenario
   of exactly what you are doing? This will help us to assist you better.Thanks &
   Regards
 *  Thread Starter [Paul](https://wordpress.org/support/users/headwall/)
 * (@headwall)
 * [1 year, 6 months ago](https://wordpress.org/support/topic/missing-array-element-protection-in-ect-class-vc-php/#post-18172952)
 * Hi
 * This is a redacted version of what we were seeing in the logs this morning. The
   logs were full of it :
 *     ```wp-block-code
       [Mon Dec 02 06:14:31.223317 2024] [proxy_fcgi:error] [pid XXX:tid XXX] [remote XX.XX.XX.XX]AH01071: Got error 'PHP message: PHP Warning:  Attempt to read property "name" on array in /XXX/XXX/wp-content/plugins/template-events-calendar/admin/visual-composer/ect-class-vc.php on line 26;PHP message: PHP Warning:  Attempt to read property "slug" on array in /XXX/XXX/wp-content/plugins/template-events-calendar/admin/visual-composer/ect-class-vc.php on line 26;PHP message: PHP Warning:  Attempt to read property "name" on array in /XXX/XXX/wp-content/plugins/template-events-calendar/admin/visual-composer/ect-class-vc.php on line 26;PHP message: PHP Warning:  Attempt to read property "slug" on array in /XXX/XXX/wp-content/plugins/template-events-calendar/admin/visual-composer/ect-class-vc.php on line 26', referer: https://XXX.XXX.XXX/wp-admin/index.php
       ```
   
 * I suspect it’s actually caused by another plugin that filtering the event taxonomy
   terms, but I don’t have time to chase that down.
 * Does that help?
 *  Plugin Support [Vishali Tayal](https://wordpress.org/support/users/vishali009/)
 * (@vishali009)
 * [1 year, 6 months ago](https://wordpress.org/support/topic/missing-array-element-protection-in-ect-class-vc-php/#post-18175224)
 * Hi [@headwall](https://wordpress.org/support/users/headwall/),
   Please share the
   list of plugins so we can check it. Additionally, it would be helpful if you 
   could provide a video recording of the issue you are experiencing. Also, could
   you clarify what you mean by “redacted version”?Thanks & Regards
 *  Thread Starter [Paul](https://wordpress.org/support/users/headwall/)
 * (@headwall)
 * [1 year, 6 months ago](https://wordpress.org/support/topic/missing-array-element-protection-in-ect-class-vc-php/#post-18179209)
 * Sorry for the delay – it’s been a busy couple of days.
 * By “redacted”, I just mean I removed some IP addresses and filesystem paths from
   the log.
 * When I investigate further with this patch in “**ect-class-vc.php**” (around 
   line 26)…
 *     ```wp-block-code
       if( is_array( $term ) && !array_key_exists( 'name', $term ) ) {   error_log( 'FAIL: ' . json_encode( $term ) ); // << Added diagnostic info} else {   $ect_categories[$term->name] = $term->slug;}
       ```
   
 * …I get this in the error logs…
 *     ```wp-block-code
       PHP message: FAIL: {"invalid_taxonomy":["Invalid taxonomy."]}; PHP message: FAIL: []
       ```
   
 * So that’s two iterations of the foreach() loop where $term->name and $term->slug
   do not exist, which is causing an error in PHP8.3. One iteration returns some
   invalid taxonomy error, and the other iteration seems to have $term as an empty
   array? Weird.
 * Can you please just add some protection in the loop to check that $term contains
   valid data before you access the name and slug?
 * Thanks
 * Paul
 *  Plugin Support [Vishali Tayal](https://wordpress.org/support/users/vishali009/)
 * (@vishali009)
 * [1 year, 6 months ago](https://wordpress.org/support/topic/missing-array-element-protection-in-ect-class-vc-php/#post-18182464)
 * Hi [@headwall](https://wordpress.org/support/users/headwall/),
   Sorry for the 
   late reply.Please replace the code with the one provided below, and let us know
   if you still face the same issue.
 * For more, you can refer to the [screenshot](https://prnt.sc/jbWL0w3YD9uM).
 *     ```wp-block-code
       if (!empty($terms) && !is_wp_error($terms)) {     foreach ($terms as $term) {      if (is_object($term) && isset($term->name, $term->slug)) {         $ect_categories[$term->name] = $term->slug;      } else {         error_log('Invalid term: ' . json_encode($term));      }     } }
       ```
   
 * I hope this will help you.
 * Thanks & Regards
 *  Plugin Support [Vishali Tayal](https://wordpress.org/support/users/vishali009/)
 * (@vishali009)
 * [1 year, 4 months ago](https://wordpress.org/support/topic/missing-array-element-protection-in-ect-class-vc-php/#post-18278497)
 * Hi there,
   I just wanted to follow up and see if the solution we provided worked
   for you. Since we haven’t heard back, I’ll close this ticket for now.
 * If you still need any help, feel free to open a new ticket—we’re always happy
   to assist you!
 * Thanks for reaching out, and have a great day!

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Missing array element protection in ect-class-vc.php’ is closed to new
replies.

 * ![](https://ps.w.org/template-events-calendar/assets/icon-256x256.gif?rev=3346193)
 * [Events Shortcodes For The Events Calendar](https://wordpress.org/plugins/template-events-calendar/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/template-events-calendar/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/template-events-calendar/)
 * [Active Topics](https://wordpress.org/support/plugin/template-events-calendar/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/template-events-calendar/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/template-events-calendar/reviews/)

 * 6 replies
 * 2 participants
 * Last reply from: [Vishali Tayal](https://wordpress.org/support/users/vishali009/)
 * Last activity: [1 year, 4 months ago](https://wordpress.org/support/topic/missing-array-element-protection-in-ect-class-vc-php/#post-18278497)
 * Status: resolved