What is the best way to handle deprecated functions?

WordPress 3.3 has deprecated the add_contextual_help() functions and it’s filters, so in order to continue supporting 3.0 – 3.2.1 and also comply with 3.3, I have done the following:

global $wp_version;
if ($wp_version >= '3.3') {
    // New method
    add_action("load-$admin_page", 'CrayonSettingsWP::help_screen');
} else {
    // Depreciated method
    add_filter('contextual_help', 'CrayonSettingsWP::cont_help', 10, 3);
}

Is there a better approach?

Related posts

Leave a Reply

2 comments

  1. I don’t see anything wrong with your approach. But I’m going to take a different track: don’t support older versions of WP.

    The general impression I’ve gotten from the WP community is one of progress. By supporting the current version and forward you’re helping to push the community towards using the most up to date version of WordPress.

    Excerpted from WordPress Plugin Development (which is a great book!):

    In the WordPress development community, backward compatibility may
    sometimes be even looked down upon. Users are expected to stay updated
    with the latest version of the software.

  2. Better for your version check is that you use the default functions of PHP for this requirement; see the example.

    if ( version_compare( $GLOBALS['wp_version'], '3.3alpha', '>=' ) ) {
    

    The version in PHP is more as the 3 strings, liek 3.3! that it is important to check for versions smaller the stable release.