initHooks(); } /** * Init hooks **/ protected function initHooks() { add_action( 'all_admin_notices', array( $this, 'adminNotices' ) ); } /** * Notices **/ /** * Called in hook "all_admin_notices" * * @uses $this->noticeMessages **/ public function adminNotices() { if ( array( current_filter(), array( 'all_admin_notices' ) ) ) { return; } $notice_messages = $this->getNoticeMessages(); if ( 0 < count( $notice_messages ) ) { foreach( $notice_messages as $notice_message ) { echo $this->wrapAsNotices( $notice_message['text'], $notice_message['type'] ); } } } /** * Wrap the text in notice format * * @param string $notice_message : Message to be wrapped * @param string $type : 'notice', 'warning', 'updated' * * @see ntvwc_is_string_and_not_empty( $string ) * * @return string **/ protected function wrapAsNotices( $notice_message = '', $type = 'notice' ) { // Check the param if ( ! is_string( $notice_message ) ) { ob_start(); var_dump( $notice_message ); $notice_message = ob_get_clean(); ob_start(); echo '
';
				echo esc_html( $notice_message );
				echo '
'; $notice_message = ob_get_clean(); } // Init Message $format = '

%s

' . PHP_EOL; $notice_type = ( in_array( $type, array( 'warning' ) ) ? 'notice-' . $type : $type ); $notice = sprintf( $format, $notice_type, $notice_message ); // End return $notice; } /** * Get * * @return [array] description **/ public function getNoticeMessages() { return apply_filters( $this->getPrefixedFilterHook( 'notice_messages' ), $this->noticeMessages ); } /** * Add * * @param [string] $message * @param [string] $type * * @return [bool] **/ public function addNoticeMessage( $text, $type = 'notice' ) { if ( ! is_string( $text ) || '' === $text ) { ob_start(); echo '
';
				var_dump( $text );
				echo '
'; $text = ob_get_clean(); } if ( ! is_string( $type ) || ! in_array( $type, apply_filters( ace()->getPrefixedFilterHook( 'notice_types' ), array( 'succeed', 'notice', 'warning', 'error' ) ) ) ) { return false; } if ( did_action( 'all_admin_notices' ) ) { echo $this->wrapAsNotices( $text, $type ); return true; } if ( 0 < count( $this->noticeMessages ) ) { foreach ( $this->noticeMessages as $notice_message ) { if ( $text === $notice_message['text'] ) { return false; } } } array_push( $this->noticeMessages, array( 'type' => $type, 'text' => $text ) ); return true; } /** * Set messages * * @param [array] $messages * * @return [array] **/ public function setNoticeMessages( $messages = array() ) { if ( 0 < count( $messages ) ) { foreach ( $messages as $message ) { $this->addNoticeMessage( $message['text'], $message['type'] ); } } return apply_filters( $this->getPrefixedFilterHook( 'notice_messages' ), $this->noticeMessages ); } }