HM\BackUpWordPress\Notices::set_notices PHP Method

set_notices() public method

Set an array of notice messages for a specific context
public set_notices ( string $context, array $messages, boolean $persistent = true )
$context string The context of the notice message
$messages array The array of messages
$persistent boolean Whether the notice should persist via the database. Defaults to true.
    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;
    }