Dealing with PHP deprecation notices after updating to 3.10

After updating to The Events Calendar 3.10 you might see some PHP Notices mentioning a deprecated file. While it is easy to conclude that these are scary errors, they are actually just helpful alerts (notices) for PHP developers who write themes and plugins. If you are not a developer you can usually just hide them and forget about them, as you were not meant to see those notices in the first place.

This article will cover three things relating to those PHP deprecation notices:

  1. What these notices mean
  2. How to hide PHP Messages in WordPress
  3. Updating your code based on the information provided

What these notices mean

Let us look at an example notice:

Notice: …/src/deprecated/[FileName].php is deprecated since version 3.10! Use [Class__Name] instead.

This notice is happening because PHP included a class file that was renamed in version 3.10. Many of The Events Calendar’s classes were given new uniform names in 3.10. The new names make our plugin easier to customize and develop themes for, and will help with stability. This notice states that code on your site is calling one of the classes by its old deprecated name.

How to hide PHP Messages in WordPress

By default WordPress hides Notices like these, because this information is intended solely for PHP developers. However, sometimes WordPress is accidentally or otherwise configured to display this information on a public site.

If you have never made any modifications to the PHP Code on your site, then you probably want to tell WordPress to hide these notices. There is little reason for you to see them. To hide them you want to set “WP_DEBUG” to “false”. This article from the WP Codex tells you what WP_DEBUG is and how to set it to false.  Once you have followed that guide you should be all set! Just keep your plugins and themes up to date.

If however you have made modifications to your site or can’t update your plugins, there is a possibility you will  need to do more work. If the only modification you have made was copy/pasting a snippet from one of our tutorials into your functions.php file, then you should double check to see if that tutorial has an updated version of the snippet. All of our current snippets should be compatible with 3.10 unless otherwise marked. Using the latest version of the snippet should remove any deprecation notices.

If you have made more in-depth modifications or written code which implements our classes, then you should read the next section.

Updating your code based on the information provided

As mentioned earlier these classes have merely been renamed. The old class names are deprecated, and alternate new class names are now available. Correcting these Notices is usually as simple as doing a search and replace throughout your code, replacing the old name with new.

The filename within the error message corresponds to the old class name. For instance  a Notice which mentions “…/src/deprecated/TribeEvents.php” is for the old class “TribeEvents”. The error message mentions the new class you should use instead, which in this case would be “Tribe__Events__Main”. So if you are calling “TribeEvents::TAXONOMY”, simply change that to “Tribe__Events__Main::TAXONOMY”.

In areas where your code removed filters and actions from the old class names, deprecation notices will not be generated. However, those filters and actions will not be removed either, since WordPress has queued them based on their new class names. For example this line of code will not generate a notice but also will not work as of 3.10:

remove_filter( 'posts_fields', array( 'TribeEventsQuery', 'multi_type_posts_fields' ) );

You would again want to replace the old class name with the new, like this:

remove_filter( 'posts_fields', array( 'Tribe__Events__Query', 'multi_type_posts_fields' ) );

You can find a list of all deprecated class names inside of the [plugin-name]/src/deprecated/ folder. Each file in the folder is a deprecated class, and inside of each file it specifies the new name of that class. Whatever class the old name extends, is the new name. For example, in the file “TribeEventsQuery.php” you can see that the new class name is “Tribe__Events__Query”:

class TribeEventsQuery extends Tribe__Events__Query { }

Happy developing!