Skip to content

Instantly share code, notes, and snippets.

@mAAdhaTTah
Created November 19, 2015 02:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mAAdhaTTah/1599752d5a01392d0c11 to your computer and use it in GitHub Desktop.
Save mAAdhaTTah/1599752d5a01392d0c11 to your computer and use it in GitHub Desktop.
Using Redirect Args to Display Errors
if ($error) {
    add_filter('redirect_post_location', function( $location ) use ( $error ) {
        return add_query_arg( 'my-plugin-error', $error->get_error_message(), $location );
    });
}
if ( array_key_exists( 'my-plugin-error', $_GET) ) { ?>
    <div class="error">
        <p><?php echo 'The post saved with error: ' . esc_html($_GET['my-plugin-error']); ?></p>
    </div><?php
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment