Last active
September 9, 2026 07:48
-
-
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 | |
| static::add_action('wp_ajax_validate_email_domain', 'validate_email_domain'); | |
| static::add_action('wp_ajax_nopriv_validate_email_domain', 'validate_email_domain'); | |
| public static function validate_email_domain() { | |
| // check_ajax_referer( 'validate_email_domain_nonce' ); | |
| Theme::var_dump([ | |
| 'request' => $_REQUEST | |
| ]); die(); | |
| $email = isset( $_POST['email'] ) ? sanitize_email( wp_unslash( $_POST['email'] ) ) : ''; | |
| if ( ! $email || ! filter_var( $email, FILTER_VALIDATE_EMAIL ) ) { | |
| wp_send_json_error( array( | |
| 'message' => 'Invalid email address.', | |
| ), 400 ); | |
| } | |
| $domain = substr( strrchr( $email, '@' ), 1 ); | |
| if ( ! $domain ) { | |
| wp_send_json_error( array( | |
| 'message' => 'Missing email domain.', | |
| ), 400 ); | |
| } | |
| $has_mx = function_exists( 'checkdnsrr' ) && checkdnsrr( $domain, 'MX' ); | |
| $has_a = function_exists( 'checkdnsrr' ) && checkdnsrr( $domain, 'A' ); | |
| $has_aaaa = function_exists( 'checkdnsrr' ) && checkdnsrr( $domain, 'AAAA' ); | |
| if ( $has_mx || $has_a || $has_aaaa ) { | |
| wp_send_json_success( array( | |
| 'message' => 'Email domain looks valid.', | |
| 'domain' => $domain, | |
| 'checks' => array( | |
| 'mx' => $has_mx, | |
| 'a' => $has_a, | |
| 'aaaa' => $has_aaaa, | |
| ), | |
| ) ); | |
| } | |
| wp_send_json_error( array( | |
| 'message' => 'Email domain does not appear to accept mail.', | |
| 'domain' => $domain, | |
| ), 422 ); | |
| } | |
| async validateEmailRemote(raw) { | |
| const email = raw.trim(); | |
| try { | |
| const response = await $.ajax({ | |
| url: F4WP.ajaxurl, | |
| type: 'POST', | |
| cache: false, | |
| data: { | |
| action: 'validate_email', | |
| email: email, | |
| }, | |
| contentType : false, | |
| dataType: 'json', | |
| processData : false, | |
| complete: () => { | |
| this.xhr = null; | |
| }, | |
| success: (response) => { | |
| if(response.success) { | |
| return { valid: true }; | |
| } else { | |
| if(typeof Message !== 'undefined') { | |
| Message.showError(); | |
| } | |
| return { valid: false, reason: response.data.message }; | |
| } | |
| }, | |
| error: (err, textStatus, errorThrown) => { | |
| if(textStatus !== 'abort') { | |
| if(typeof Message !== 'undefined') { | |
| Message.showError(); | |
| } | |
| return { valid: false, reason: 'Could not validate email domain right now' }; | |
| } | |
| } | |
| }); | |
| } catch (e) { | |
| if (e.name !== 'AbortError') { | |
| return { valid: false, reason: 'Could not validate email domain right now' }; | |
| } | |
| } | |
| return response; | |
| } |
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 | |
| if(!current_user_can('administrator')) { | |
| /** | |
| * Remove site health dashboard widget | |
| */ | |
| function remove_site_health_widget() { | |
| global $wp_meta_boxes; | |
| unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_site_health']); | |
| } | |
| add_action('wp_dashboard_setup', 'remove_site_health_widget'); | |
| /** | |
| * Remove site health submenu | |
| */ | |
| function remove_site_health_submenu() { | |
| remove_submenu_page('tools.php', 'site-health.php'); | |
| } | |
| add_action('admin_menu', 'remove_site_health_submenu', 999); | |
| /** | |
| * Remove admin update and maintenace notices | |
| */ | |
| function remove_admin_update_notices() { | |
| remove_action('admin_notices', 'update_nag', 3); | |
| remove_action('admin_notices', 'update_nag_nopriv', 3); | |
| remove_action('admin_notices', 'maintenance_nag', 10); | |
| remove_action('admin_notices', 'maintenance_nag_nopriv', 10); | |
| } | |
| add_action('admin_init', 'remove_admin_update_notices'); | |
| /** | |
| * Remove Yoast admin notices | |
| */ | |
| function remove_yoast_admin_notices() { | |
| // Remove the main Yoast notification center | |
| if (class_exists('Yoast_Notification_Center')) { | |
| $ync = \Yoast_Notification_Center::get(); | |
| remove_action('admin_notices', array($ync, 'display_notifications')); | |
| remove_action('all_admin_notices', array($ync, 'display_notifications')); | |
| } | |
| } | |
| add_action('admin_init', 'remove_yoast_admin_notices'); | |
| /** | |
| * Hide Yoast premium admin update notices | |
| */ | |
| function hide_yoast_premium_admin_update_notices() { | |
| echo '<style> | |
| #yoast-update-premium-notification { | |
| display: none !important; | |
| } | |
| </style>'; | |
| } | |
| add_action('admin_head', 'hide_yoast_premium_admin_update_notices'); | |
| } |
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([ | |
| 'value' => $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 | |
| /** | |
| * locate the error causing php-error class in wp-admin body tag | |
| * open the file wp-admin/admin-header.php and search for php-error | |
| * add the following code to the file | |
| * save and refresh the page | |
| */ | |
| if ( error_get_last() ) { | |
| echo '<pre style="background:#fff; color:#000; padding:20px; z-index:99999; position:relative;">'; | |
| print_r( error_get_last() ); | |
| echo '</pre>'; | |
| die(); | |
| } |
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); | |
| // put this lines to function wp_trigger_error in wp-includes/functions.php to suppress _load_textdomain_just_in_time errors | |
| if(str_contains($message, '_load_textdomain_just_in_time')) { | |
| return; | |
| } |
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