Sabuj Kundu 10th Nov 2025

When developing WordPress plugins or themes, there may come a time when you need to deprecate an existing action or filter hook. Deprecation allows you to maintain backward compatibility while informing developers that they should switch to a newer, modern hook. WordPress provides built-in functions for this purpose: do_action_deprecated() for actions and apply_filters_deprecated() for filters.

Why Deprecate Hooks?

  • Maintain backward compatibility with older plugins and themes.
  • Give developers clear guidance about which hooks to use instead.
  • Keep your codebase clean and modern without breaking existing functionality.

Deprecating an Action Hook

Suppose you have an action hook show_cbxbookmark_btn that you want to deprecate in favor of cbxbookmark_button_show. Here’s the correct approach:


do_action_deprecated(
    'show_cbxbookmark_btn',      // Old hook name
    array( $post_id, $user_id ), // Arguments passed to the hook
    '3.2.0',                     // Version where it was deprecated
    'cbxbookmark_button_show',   // New hook name (optional)
    'The hook show_cbxbookmark_btn is deprecated. Use cbxbookmark_button_show instead.'
);

do_action( 'cbxbookmark_button_show', $post_id, $user_id );

This ensures that:

  • The old hook still fires, maintaining backward compatibility.
  • Developers see a deprecation notice in debug mode.
  • New code can immediately use the modern hook.

Deprecating a Filter Hook

Filters are very similar. Suppose you want to deprecate cbxwpbookmarks_mybookmark_page_url in favor of cbxbookmark_mybookmark_page_url:


// Deprecated filter
$value = apply_filters_deprecated(
    'cbxwpbookmarks_mybookmark_page_url',
    array( esc_url( $my_bookmark_page_url ) ),
    '3.2.0',
    'cbxbookmark_mybookmark_page_url',
    'The filter cbxwpbookmarks_mybookmark_page_url is deprecated. Use cbxbookmark_mybookmark_page_url instead.'
);

// Modern replacement filter
return apply_filters( 'cbxbookmark_mybookmark_page_url', $value );

This pattern ensures:

  • Old filter calls still work for existing code.
  • Developers get a clear notice about the deprecation.
  • All new code can adopt the modern filter.

Optional: Cleaner Variable Handling

For filters, you can assign the value first to a variable and return it after applying both deprecated and modern hooks:


$value = esc_url( $my_bookmark_page_url );

$value = apply_filters_deprecated(
    'cbxwpbookmarks_mybookmark_page_url',
    array( $value ),
    '3.2.0',
    'cbxbookmark_mybookmark_page_url',
    'The filter cbxwpbookmarks_mybookmark_page_url is deprecated. Use cbxbookmark_mybookmark_page_url instead.'
);

return apply_filters( 'cbxbookmark_mybookmark_page_url', $value );

Best Practices for Deprecating Hooks

  • Always include the version number when deprecating a hook.
  • Provide a replacement hook whenever possible.
  • Document deprecated hooks clearly in your plugin/theme documentation.
  • Use WP_DEBUG mode to test that deprecation notices appear correctly.
  • Never remove a hook abruptly without providing backward compatibility.

Summary Table

Type Function Example
Action Hook do_action_deprecated() do_action_deprecated('old_hook', array($args), '3.2.0', 'new_hook');
Filter Hook apply_filters_deprecated() $value = apply_filters_deprecated('old_filter', array($value), '3.2.0', 'new_filter');

By following this approach, you ensure your WordPress plugins and themes stay modern, backward-compatible, and developer-friendly.

Need to build a Website or Application?

Since 2011, Codeboxr has been transforming client visions into powerful, user-friendly web experiences. We specialize in building bespoke web applications that drive growth and engagement.

Our deep expertise in modern technologies like Laravel and Flutter allows us to create robust, scalable solutions from the ground up. As WordPress veterans, we also excel at crafting high-performance websites and developing advanced custom plugins that extend functionality perfectly to your needs.

Let’s build the advanced web solution your business demands.