Skip to content

Instantly share code, notes, and snippets.

@wp-kitten
Created October 17, 2015 21:08
Show Gist options
  • Select an option

  • Save wp-kitten/aed14374440a9ca85175 to your computer and use it in GitHub Desktop.

Select an option

Save wp-kitten/aed14374440a9ca85175 to your computer and use it in GitHub Desktop.
admin notice transient
<?php
/**
* Display the admin notice. This is an internal function. Do not call directly. Use uwtAdminNotice() instead.
* @internal
* @param string $type The type: error, updated
* @param string $message The message to display
* @return string
*/
function _uwt_admin_notice($type = 'error', $message = ''){
return '<div class="'.$type.'"><p>'.$message.'</p></div>';
}
/**
* Display an admin notice. Stores the notice as a transient for 10 seconds if $save = true.
* @param string $type The type: error, updated
* @param string $message The message to display
* @param bool $save Whether or not to save the message as a transient
*/
function uwtAdminNotice( $type = 'error', $message = '', $save = false ) {
if( $save )
{
$fn = (UwtPlugin::isMultisite() ? 'set_site_transient' : 'set_transient');
$fn('uwt_admin_notice_trans', _uwt_admin_notice($type, $message), 10);
return;
}
echo _uwt_admin_notice($type, $message);
}
/**
* Retrieve the admin notice transient
*/
function uwtGetAdminNotice(){
$fn = (UwtPlugin::isMultisite() ? 'get_site_transient' : 'get_transient');
$val = $fn('uwt_admin_notice_trans');
return (empty($val) ? '' : $val);
}
/**
* Delete the admin notice transient
*/
function uwtDeleteAdminNotice(){
$fn = (UwtPlugin::isMultisite() ? 'delete_site_transient' : 'delete_transient');
$fn('uwt_admin_notice_trans');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment