public function set_notices($context, array $messages, $persistent = true)
{
// Clear any empty messages and avoid duplicates
$messages = array_unique(array_filter($messages));
if (empty($context) || empty($messages)) {
return false;
}
$this->notices[$context] = array_merge($this->get_notices($context), $messages);
if ($persistent) {
$new_notices = $notices = $this->get_persistent_notices();
// Make sure we merge new notices into to any existing notices
if (!empty($notices[$context])) {
$new_notices[$context] = array_unique(array_merge($new_notices[$context], $messages));
} else {
$new_notices[$context] = $messages;
}
// Only update the database if the notice array has changed
if ($new_notices !== $notices) {
update_option('hmbkp_notices', $new_notices);
}
}
return true;
}