コード例 #1
0
 /**
  * Add a message.
  *
  * Messages will be displayed to the user through the UI.
  *
  * @param int    $post_id Post this message belongs to.
  * @param string $message The message.
  * @param string $type    What type of message this is, can be any of:
  *                        info, warning, error, success
  * @param string $group   Group this message is part of, use this to categorize different kind
  *                        of messages, e.g. preflight, deploy, etc.
  * @param int    $code    Set a specific code for this message.
  *
  * @throws Exception
  */
 public function add_message($post_id, $message, $type = 'info', $group = null, $code = 0)
 {
     // Supported message types.
     $types = array('info', 'warning', 'error', 'success');
     $types = apply_filters('sme_message_types', $types);
     if (!in_array($type, $types)) {
         throw new Exception('Unsupported message type: ' . $type);
     }
     $key = $this->get_message_key($group);
     $value = array('message' => $message, 'level' => $type, 'code' => $code);
     $this->postmeta_dao->add_post_meta($post_id, $key, $value);
 }