# Log Deprecated and "Doing It Wrong" Notices With Their Source

> Writes every deprecated function, argument, hook or "doing it wrong" notice to the PHP error log with the plugin or theme file that caused it, even when WP_DEBUG is off.

- Type: PHP
- Runs: Run everywhere
- Category: [Developer](https://wpide.com/library/category/developer/)
- Tags: debugging, deprecated, logging
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/debug-log-deprecated-notices/

## Code

```php
$wpide_log_notice = function ( $kind, $message ) {
    static $seen = array();
    $key = md5( $kind . $message );
    if ( isset( $seen[ $key ] ) ) {
        return;
    }
    $seen[ $key ] = true;

    // Find the first frame outside WordPress core.
    $source = '';
    foreach ( debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, 25 ) as $frame ) {
        if ( empty( $frame['file'] ) || false !== strpos( $frame['file'], ABSPATH . WPINC ) || false !== strpos( $frame['file'], ABSPATH . 'wp-admin' ) ) {
            continue;
        }
        $source = str_replace( ABSPATH, '', $frame['file'] ) . ':' . ( $frame['line'] ?? 0 );
        break;
    }

    error_log( sprintf( '[WP %s] %s%s', $kind, $message, $source ? ' (from ' . $source . ')' : '' ) );
};

add_action( 'deprecated_function_run', function ( $function, $replacement, $version ) use ( $wpide_log_notice ) {
    $wpide_log_notice( 'deprecated function', "$function() since $version" . ( $replacement ? ", use $replacement" : '' ) );
}, 10, 3 );

add_action( 'deprecated_argument_run', function ( $function, $message, $version ) use ( $wpide_log_notice ) {
    $wpide_log_notice( 'deprecated argument', "$function() since $version: $message" );
}, 10, 3 );

add_action( 'deprecated_hook_run', function ( $hook, $replacement, $version ) use ( $wpide_log_notice ) {
    $wpide_log_notice( 'deprecated hook', "$hook since $version" . ( $replacement ? ", use $replacement" : '' ) );
}, 10, 3 );

add_action( 'doing_it_wrong_run', function ( $function, $message, $version ) use ( $wpide_log_notice ) {
    $wpide_log_notice( 'doing it wrong', "$function(): " . wp_strip_all_tags( $message ) );
}, 10, 3 );
```

## Notes

Turn it on before upgrading WordPress or PHP, then check the error log; each distinct message is logged once per request.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Log Deprecated and "Doing It Wrong" Notices With Their Source" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
