Some WordPress php errors or notices are annoying because they dont show the exact trace of the errors and then you spend hours to get rid of it. But there is a better way.
Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in \wp-includes\functions.php on line 7360 Deprecated: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in \wp-includes\functions.php on line 2195 Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in \wp-includes\functions.php on line 7360 Deprecated: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in \wp-includes\functions.php on line 2195
add this code to the top of your wp-config.php file and then trigger the Deprecated output pages after that in your error.log file there will be trace records that to show you where exactly in your code these Deprecated issues causing.
// you already have WP_DEBUG line in the config do not add double just make it TRUE // define( 'WP_DEBUG', true ); define( 'WP_DEBUG_LOG', true ); define( 'WP_DEBUG_DISPLAY', true ); /** * A fully automatic, "abstract" error handler for WordPress. * * It automatically detects if a file in the backtrace belongs to any plugin or theme, * then names that component as the likely source of the error. No manual slug needed. */ set_error_handler(function($errno, $errstr, $errfile, $errline) { // We are only interested in E_DEPRECATED messages for this logger. if ($errno !== E_DEPRECATED || !defined('WP_CONTENT_DIR')) { return false; } $error_id = 'DEP_AUTO_' . uniqid(); // --- Automatic Path Detection (No manual slugs needed) --- $plugins_dir = wp_normalize_path(WP_PLUGIN_DIR); $themes_dir = wp_normalize_path(get_theme_root()); $culprit_slug = ''; $culprit_type = ''; // 'PLUGIN' or 'THEME' // --- Build a detailed backtrace --- $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); $backtrace_log = []; foreach ($backtrace as $i => $trace) { if (!isset($trace['file'])) { $backtrace_log[] = " #{$i} [internal function]: " . ($trace['class'] ?? '') . ($trace['type'] ?? '') . ($trace['function'] ?? ''); continue; } $file = wp_normalize_path($trace['file']); $line = $trace['line'] ?? 'N/A'; $call = ($trace['class'] ?? '') . ($trace['type'] ?? '') . ($trace['function'] ?? '[closure]'); $marker = ' '; // --- Identify the culprit component automatically --- if (!$culprit_slug) { // Find the first (most recent) culprit if (strpos($file, $plugins_dir) === 0) { $culprit_type = 'PLUGIN'; $relative_path = str_replace($plugins_dir . '/', '', $file); $culprit_slug = explode('/', $relative_path)[0]; $marker = '->'; } elseif (strpos($file, $themes_dir) === 0) { $culprit_type = 'THEME'; $relative_path = str_replace($themes_dir . '/', '', $file); $culprit_slug = explode('/', $relative_path)[0]; $marker = '->'; } } $backtrace_log[] = "{$marker} #{$i} {$call}() at {$file}:{$line}"; } // --- Start Logging --- error_log("=======================[ AUTO-DEBUGGER LOG ]======================="); error_log("[ERROR ID: {$error_id}] NOTICE: $errstr"); error_log(" LOCATION: {$errfile} (Line: {$errline})"); error_log("-------------------------------------------------------------------"); // --- Analysis & Actionable Steps --- error_log("[ERROR ID: {$error_id}] ANALYSIS:"); if ($culprit_slug) { error_log(" 🎯 CULPRIT IDENTIFIED: The error trace points to the following component:"); error_log(" Type: {$culprit_type}"); error_log(" Slug: {$culprit_slug}"); error_log(" ✅ ACTION: Check the code in the '{$culprit_slug}' {$culprit_type} for the root cause."); error_log(" Look for filters or actions that might be passing a NULL value to a core function."); } else { error_log(" ⚠️ Could not automatically identify a specific plugin or theme in the backtrace."); error_log(" The issue might be in mu-plugins or advanced customizations."); } error_log("-------------------------------------------------------------------"); // --- Full Backtrace for Context --- error_log("[ERROR ID: {$error_id}] FULL BACKTRACE (most recent call first):"); error_log(implode("\n", $backtrace_log)); error_log("==================================================================="); // Return false to allow the default PHP/WordPress handler to also process the error. return false; });
this will give you ability to see very detailed error logs in your error.log file be sure to enable your php error logs on your hosting or server.
for example like this;
