Last active
August 13, 2019 17:32
-
-
Save cferdinandi/6608545 to your computer and use it in GitHub Desktop.
Simple functions to set and retrieve alert messages in a browser session in WordPress. (Find and replace `_s_` with your own namespacing.)
This file contains 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 | |
// Start browser session (to store alert messages) | |
function _s_start_browser_session() { | |
if(!isset($_SESSION)) { | |
session_start(); | |
} | |
} | |
add_action('init', '_s_start_browser_session'); | |
// Store alert message in browser session | |
function _s_set_alert_message( $category, $code, $message ) { | |
$_SESSION[$category][$code] = $message; | |
} | |
// Get alert message from browser session | |
function _s_get_alert_message( $category, $code ) { | |
$message = ''; | |
if ( isset($_SESSION[$category][$code]) && $_SESSION[$category][$code] != '' ) { | |
$message = $_SESSION[$category][$code]; | |
unset($_SESSION[$category]); | |
} | |
return $message; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment