Last active
April 29, 2025 17:59
-
-
Save haze83/3120675bc51dba66a4bf187ede77d08b to your computer and use it in GitHub Desktop.
WP/WC Hooks
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 | |
function debug_wp_rewrite_dump(&$wp) { | |
echo '<pre>'; | |
global $wp_rewrite; | |
echo '<h2>rewrite rules</h2>'; | |
echo var_export($wp_rewrite->wp_rewrite_rules(), true); | |
echo '<h2>permalink structure</h2>'; | |
echo var_export($wp_rewrite->permalink_structure, true); | |
echo '<h2>page permastruct</h2>'; | |
echo var_export($wp_rewrite->get_page_permastruct(), true); | |
echo '<h2>matched rule and query</h2>'; | |
echo var_export($wp->matched_rule, true); | |
echo '<h2>matched query</h2>'; | |
echo var_export($wp->matched_query, true); | |
echo '<h2>request</h2>'; | |
echo var_export($wp->request, true); | |
global $wp_the_query; | |
echo '<h2>the query</h2>'; | |
echo var_export($wp_the_query, true); | |
echo '</pre>'; | |
} | |
add_action('parse_request', 'debug_wp_rewrite_dump'); |
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 | |
$logger = wc_get_logger(); | |
$logger_context = ['source' => 'f4t']; | |
$logger->debug(wc_print_r(['key' => 'value'], true), $logger_context); |
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 | |
// disable error reporting for doing_it_wrong | |
add_filter('doing_it_wrong_trigger_error', '__return_false'); | |
/** | |
* Fires when the given function triggers a user-level error/warning/notice/deprecation message. | |
* Runs only in WP_DEBUG mode. | |
* wp_trigger_error() is used by WordPress to trigger errors. | |
* | |
* Can be used for debug backtracking. | |
* | |
* @since 6.4.0 | |
* | |
* @param string $function_name The function that was called. | |
* @param string $message A message explaining what has been done incorrectly. | |
* @param int $error_level The designated error type for this error. | |
*/ | |
add_action('wp_trigger_error_run', function($function_name, $message, $error_level) { | |
echo '<pre>'; | |
var_export([ | |
'function' => $function_name, | |
'message' => $message, | |
'level' => $error_level, | |
]); | |
debug_print_backtrace(); | |
echo '</pre>'; | |
die(); | |
}, 30, 3); |
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 | |
add_action('wp_mail_failed', 'f4t_mail_error_log', 10, 1); | |
function f4t_mail_error_log($wp_error) { | |
$fn = WP_CONTENT_DIR . DS . 'mail.log'; // say you've got a mail.log file in your wp-content dir | |
$fp = fopen($fn, 'a'); | |
fputs($fp, date('[Y-m-d H:i:s] ') . 'Mailer error: ' . $wp_error->get_error_message() ."\n"); | |
fclose($fp); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment