notice_key = $notice_key;
$instance->message = $message;
$instance->type = $type;
$instance->dismissible = $dismissible;
$instance->remind_when = $remind_when;
return $instance;
}
/**
* Static function to recreate a Notice. Call using
* AdPlugg_Notice::recreate($data_array);
* See the to_array function below for the expected array structure.
* @param array $array An array containing the Notice data
* @return \self Works like a constructor.
*/
public static function recreate( $array ) {
$instance = new self();
$instance->notice_key = $array['notice_key'];
$instance->message = $array['message'];
$instance->type = $array['type'];
$instance->dismissible = $array['dismissible'];
if ( isset($array['remind_when'] ) ) {
$instance->remind_when = $array['remind_when'];
}
return $instance;
}
/**
* Get's the html for the notice.
*/
function get_rendered() {
$html = '';
if( ! $this->is_dismissed() ) {
$html .= '
';
$html .= '
' .
'AdPlugg: ' .
$this->get_message() .
'
';
if( $this->is_dismissible() ) {
$html .= '
' .
'' .
'' .
'
';
}
$html .= '
';
}
return $html;
}
/**
* Renders the html for the notice.
*/
function render() {
echo $this->get_rendered();
}
/**
* Gets the value of notice_key.
* @return string Returns the notice_key.
*/
public function get_notice_key() {
return $this->notice_key;
}
/**
* Gets the value of message.
* @return string Returns the Notice message.
*/
public function get_message() {
return $this->message;
}
/**
* Gets the value of type.
* @return string Returns the Notice type.
*/
public function get_type() {
return $this->type;
}
/**
* Gets the value of dismissible.
* @return string Returns whether or not the Notice is dismissible.
*/
public function is_dismissible() {
return $this->dismissible;
}
/**
* Converts the class into an array for inserting into a WordPress option.
* @param array An array representation of the object.
*/
public function to_array() {
$data_array = array(
'notice_key' => $this->notice_key,
'message' => $this->message,
'type' => $this->type,
'dismissible' => $this->dismissible,
'remind_when' => $this->remind_when
);
return $data_array;
}
/**
* Returns whether or not the notice is dismissed.
* @return boolean Whether or not the notice is dismissed.
*/
public function is_dismissed() {
$ret = false;
$dismissals = get_option( ADPLUGG_NOTICES_DISMISSED_NAME, array() );
if ( array_key_exists( $this->notice_key, $dismissals ) ) {
$remind_on = $dismissals[$this->notice_key];
if ( $remind_on != null ) {
if ( $remind_on > time() ) {
$ret = true;
}
} else {
$ret = true;
}
}
return $ret;
}
}