We don't want the headache of fixing the deprecated code during the upgrade from Craft 3 to Craft 4, so let's take of it now.
Back in 2018, when Craft 3.0 was released, the Craft CMS officially deprecated some Craft 2 and prior configuration settings, PHP constants, template tags, template functions, query parameters, query methods, element properties, model methods, and locales methods.
So, a lot of stuff.
But some of those deprecated items might still be lurking in ours projects. Maybe we’ve avoided looking that Deprecation Warnings sections of Utilities in the Craft control panel. Or new deprecation warnings popped up because some old code wasn’t called frequently.
Either way, we need to fix our sh‑t.
Why? Because what is now deprecated and still working in Craft 3 will likely be completely removed and broken in Craft 4.
When the Craft CMS team deprecated a template function, for example, they kindly log a deprecation warning to alert you, and then call the new function for you so everything would work.
But that support for the old function will be gone in Craft 4. And, as a result, your code will just fail and error.
We don’t want the headache of fixing the deprecated code during the upgrade from Craft 3 to Craft 4, so let’s take of it now.
The one challenge, especially on larger projects with several dozen templates, is that deprecation warnings are only logged when the code is executed. If you have a infrequently-visited rendered template containing some deprecated code, it might not yet be logged.
For that reason, I suggest a multi-pronged approach to ridding your project of all deprecated code.
The first method is to use the Deprecation Warnings utlitiy in the Craft control panel. This gives you a historical view of all deprecation warnings since the log was last cleared. These warnings are saved in your Craft CMS database, so they persist between control panel sessions.
P.S. If you want to keep the deprecation warnings in your face between now and Craft 4, you can use the Deprec Widget we build in the Building a Craft CMS Dashboard Widget
What I do is review the Deprecation Warning Utility first and, one-by-one, and clear each warning as I fix it. After I clear out all deprecation warnings, I then re-test the site and monitor for anything I missed.
One good way to catch any deprecation warnings as you work is to use the Yii Debug Toolbar.
Load your site locally and open the debug toolbar. If you don’t have the debug toolbar enabled, read this or watch this video to learn how it works.
There’s a Deprecation Warning tab. You can navigate through the main pages of the site and keep and eye on the tab to see if it reads out anything other than zero.
Here’s a table of the areas of Craft where there are deprecations in Craft 3 and removal in Craft 4.
|Config settings||Eight config settings are going away in Craft.||Learn more|
|PHP Constants||For plugin developers, two Craft PHP constants have changed.||Learn more|
|Template Tags||Some template tags related to including assets will be removed or changed.||Learn more|
|Template Functions||Several template functions are going away completely, while others will have replacements. Too many to list!||Learn more|
|Element Queries||This is where you’ll likely have the majority of your deprecation warnings throughout your Twig templates. The big one is treating queries as arrays. Use ||Learn more|
|Elements||One change with the tag element and the removal of the locale properties from all elements (because of multi-site in Craft 3)||Learn more|
Note: This does not cover changes to plugin development in Craft 4.