One of the challenges of building your site, plugin, or theme on top of the WordPress application is having to stay up-to-date with all of the changes that get folded into the WordPress core application code.
These changes are typically documented in the Codex and provide good examples of what was changed and how to update your code. Case in point: the register_sidebar_widget function was deprecated and replaced with the wp_register_sidebar_widget function.
Using these two functions as an example, here’s the typical process you can use to ensure that you keep your code current.
1. Identify The Deprecated Functions
Depending on the nature of your project, you may or may not be leveraging a ton of functionality from the WordPress API.
Regardless, set WordPress into debug mode and it will let you know if you have any functions that are out of date.
For purposes of this article, we’re assuming that we’ve identified the register_sidebar_widget as being deprecated.
2. Locate The Documentation
From there, head over to the Codex page for the deprecated function. If you can’t easily locate them from the Codex itself, a quick Google search for the function name usually returns the function’s page.
On the function’s page, the documentation will display a notification that the function is no longer supported and will also offer the updated function.
Next, click on the new function’s link to be taken to its page. In our case, we’d land on the wp_register_sidebar_widget function page.
3. Update Your Code
At this point, you will need to play close attention to the new function and the arguments that it accepts because this dictates how we’ll be hooking into the API.
The original register_sidebar_widget function call looked like this:
[cc lang=”php”]
register_sidebar_widget(__(‘Title of the Widget’), ‘widgetFunctionCall’);
[/cc]
Where as the new one accepts four arguments (three of which are required):
- ID
- name
- output callback
- options
At this point, it’s a matter of updating your function call to the new function and passing the correct arguments.
In our case, our code would look like this:
[cc lang=”php”]
wp_register_sidebar_widget(‘widgetID’, __(‘Title of the Widget’), ‘widgetFunctionCall’, null);
[/cc]
4. Test The Changes
As with all code that you write, you should test it. Specifically, make sure that the functionality that existed before works exactly as expected and in the same manner as the previous version of the code.
Generally speaking, this process holds true regardless of what functions you’re working with.
Speak your mind...