您可以将消息保存在$_SESSION
变量这样,将保留这些值,直到您决定再次删除它们为止。
function save_message( $type, $message = \'\' ) {
$_SESSION[\'messages\'][$type] = $message;
}
function get_messages() {
$return = \'\';
if ( isset( $_SESSION[\'messages\'] ) && is_array( $_SESSION[\'messages\'] ) ) {
foreach( $_SESSION[\'messages\'] as $type => $message ) {
$return .= sprintf( \'<p class="%1$s">%2$s</p>\', $type, $message );
}
}
if ( strlen( $return ) > 0 )
return $return;
return false;
}
function clean_messages( $type = false ) {
if ( ! $type )
$_SESSION[\'messages\'] = array();
else
unset( $_SESSION[\'messages\'][$type];
}
像这样的
您可以按如下方式使用它:
save_message( \'success\', __( \'You have successfully Login.\', \'frontendprofile\' ) );
if ( $messages = get_messages() ) {
echo $messages;
clean_message(\'success\');
}