Last updated on October 18, 2023

WP Forms troubleshooting

Don’t know where to add this snippet? Read our guide: How to add code snippets.

Solve common WP Forms issues.

If you are experiencing issues with WP Forms on your WordPress website, there are a few troubleshooting steps you can take to identify and resolve the problem. Here’s a code snippet that can help you troubleshoot WP Forms:

/**
 * Enable WP Forms debug logging.
 */
define( 'WPFORMS_DEBUG', true );

This code snippet enables debug logging for WP Forms, which can help you identify any errors or issues that may be occurring. By defining the constant WPFORMS_DEBUG as true, WP Forms will log debug information to the WordPress debug log file.

To use this code snippet, you can add it to your theme’s functions.php file or create a custom plugin. Once added, make sure to reproduce the issue you are experiencing with WP Forms, and then check the WordPress debug log file for any relevant debug information.

By enabling debug logging, you can gain insights into any potential errors or conflicts that may be causing issues with WP Forms. This can be particularly helpful when troubleshooting issues related to form submissions, validation, or email notifications.

Examples

Example 1: Troubleshooting WP Forms email delivery issues

This use case demonstrates how to troubleshoot email delivery issues with WP Forms. The code example shows how to use the wp_mail_failed hook to log any failed email attempts and send a notification to the site administrator.

function wpsnippets_wp_mail_failed( $wp_error ) {
    error_log( 'WP Forms email delivery failed: ' . $wp_error->get_error_message() );
    wp_mail( 'admin@example.com', 'WP Forms Email Delivery Failed', 'Please check the error log for details.' );
}
add_action( 'wp_mail_failed', 'wpsnippets_wp_mail_failed' );

Explanation: The code adds a custom function wpsnippets_wp_mail_failed as a callback to the wp_mail_failed hook. This function logs the error message to the error log using error_log() and sends a notification email to the site administrator using wp_mail().

Example 2: Troubleshooting WP Forms submission issues

This use case demonstrates how to troubleshoot submission issues with WP Forms. The code example shows how to use the wpforms_process_complete hook to log form submissions and send a notification to the site administrator.

function wpsnippets_wpforms_process_complete( $fields, $entry, $form_data ) {
    error_log( 'WP Forms submission: ' . print_r( $fields, true ) );
    wp_mail( 'admin@example.com', 'WP Forms Submission', 'A new form submission has been received.' );
}
add_action( 'wpforms_process_complete', 'wpsnippets_wpforms_process_complete', 10, 3 );

Explanation: The code adds a custom function wpsnippets_wpforms_process_complete as a callback to the wpforms_process_complete hook. This function logs the form submission data to the error log using error_log() and sends a notification email to the site administrator using wp_mail().

Example 3: Troubleshooting WP Forms validation errors

This use case demonstrates how to troubleshoot validation errors with WP Forms. The code example shows how to use the wpforms_frontend_errors filter to modify the error messages displayed to the user.

function wpsnippets_wpforms_frontend_errors( $errors, $form_data ) {
    $errors['custom_error'] = 'This is a custom validation error message.';
    return $errors;
}
add_filter( 'wpforms_frontend_errors', 'wpsnippets_wpforms_frontend_errors', 10, 2 );

Explanation: The code adds a custom function wpsnippets_wpforms_frontend_errors as a callback to the wpforms_frontend_errors filter. This function adds a custom error message to the $errors array and returns the modified array to override the default validation error messages.

Last updated on October 18, 2023. Originally posted on December 2, 2023.

Leave a Reply

Your email address will not be published. Required fields are marked *