Created
September 25, 2021 13:03
-
-
Save felipeelia/2fe5e7686ec2cdadef6bc859513fa33a to your computer and use it in GitHub Desktop.
Log DB Queries for WordPress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace TenUp_QueryLog; | |
function log_queries( $query ) { | |
if ( ! preg_match( '/^\s*(create|alter|truncate|drop|insert|delete|update|replace)\s/i', $query ) ) { | |
return $query; | |
} | |
// Not interested in any operations with transients | |
if ( false !== strpos( $query, 'transient_' ) ) { | |
return $query; | |
} | |
error_log( $query . "\n", 3, WP_CONTENT_DIR . '/queries.log' ); | |
return $query; | |
} | |
add_filter( 'query', __NAMESPACE__ . '\log_queries' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment