From cd77f0a83d8a796d2d76938495a3207f1597b63f Mon Sep 17 00:00:00 2001 From: John Bintz Date: Wed, 8 Jul 2009 20:07:52 -0400 Subject: [PATCH] subclass global bits of addons --- addons/Core/Core.inc | 4 +++- classes/ComicPressAddon.inc | 27 +++++++++++++++++++++++++++ functions.php | 11 +++++++---- 3 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 classes/ComicPressAddon.inc diff --git a/addons/Core/Core.inc b/addons/Core/Core.inc index 5bc66f3..ecfe1ec 100644 --- a/addons/Core/Core.inc +++ b/addons/Core/Core.inc @@ -1,6 +1,6 @@ comicpress->save(); + + $this->info("ComicPress configuration updated."); } } diff --git a/classes/ComicPressAddon.inc b/classes/ComicPressAddon.inc new file mode 100644 index 0000000..ab9e4c0 --- /dev/null +++ b/classes/ComicPressAddon.inc @@ -0,0 +1,27 @@ + array(), + 'warn' => array(), + 'error' => array() + ); + + function info($message) { $this->messages['info'][] = $message; } + function warn($message) { $this->messages['warn'][] = $message; } + function error($message) { $this->messages['error'][] = $message; } + + function display_messages() { + foreach ($this->messages as $type => $messages) { + if (!empty($messages)) { + echo '
'; + foreach ($messages as $message) { + echo '

' . $message . '

'; + } + echo '
'; + } + } + } +} + +?> \ No newline at end of file diff --git a/functions.php b/functions.php index d280dfd..9a70ee1 100644 --- a/functions.php +++ b/functions.php @@ -57,10 +57,13 @@ function __comicpress_init() { if (class_exists($classname)) { $addon = new $classname(); $addon->init(&$comicpress); - if (is_array($_POST['cp'])) { - if (isset($_POST['cp']['_nonce'])) { - if (wp_verify_nonce($_POST['cp']['_nonce'], 'comicpress')) { - $addon->handle_update(); + if (is_admin()) { + add_action('admin_notices', array(&$addon, 'display_messages')); + if (is_array($_POST['cp'])) { + if (isset($_POST['cp']['_nonce'])) { + if (wp_verify_nonce($_POST['cp']['_nonce'], 'comicpress')) { + $addon->handle_update(); + } } } }