Skip to content

Instantly share code, notes, and snippets.

@mAAdhaTTah
Created February 16, 2015 01:10
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/b610bb3833d1689198ba to your computer and use it in GitHub Desktop.
Save mAAdhaTTah/b610bb3833d1689198ba to your computer and use it in GitHub Desktop.
Using $_SESSION to Display Errors
if ( array_key_exists( 'my_plugin_errors', $_SESSION ) ) {
    foreach( $_SESSION['my_plugin_errors'] as $error ) {?>
        <div class="error"><p>
            <?php echo $error; ?>
        </p></div><?php
    }
    unset( $_SESSION['my_plugin_errors'] );
}
if ( ! empty( $errors ) ) {
    $_SESSION['my_plugin_errors'] = $errors;
}
if ( !session_id() ) {
    session_start();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment