contents = $contents; $this->type = $type; $this->dismissible = $dismissible; $this->uid = $uid; if($this->dismissible) { $this->dismissed = $this->was_dismissed(); } } /** * Attempts to retrieve the dismissal transient for this message * * @return bool Whether or not the message has been dismissed */ public function was_dismissed() { $this->dismissed = get_transient($this->uid); return $this->dismissed; } /** * Dismisses the message, preventing it from being rendered */ public function dismiss() { if($this->dismissible && isset($_POST['uid']) && esc_attr($_POST['uid']) === $this->uid) { check_ajax_referer($this->uid . '_dismiss', 'nonce'); $this->dismissed = true; //If the message was dismissed, update the transient for 30 days $result = set_transient($this->uid, $this->dismissed, 2592000); } } /** * Function that prints out the message if not already dismissed */ public function render() { if($this->dismissible) { //Don't render dismissed messages if($this->was_dismissed()) { return; } wp_enqueue_script('mtekk_adminkit_messages'); printf('

%2$s

', esc_attr($this->type), $this->contents, esc_attr($this->uid), wp_create_nonce($this->uid . '_dismiss')); } else { printf('

%2$s

', esc_attr($this->type), $this->contents); } } }