From 28e967e804e1d3da4c8302c26026a7d1abf2ece9 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Fri, 4 Dec 2009 21:35:23 -0500 Subject: [PATCH] start framework for classes that can receive updates --- .../ComicPressPostMediaHandlingMetabox.inc | 23 +------------ functions.php | 33 ++++++++++++++++--- 2 files changed, 30 insertions(+), 26 deletions(-) diff --git a/classes/ComicPressPostMediaHandlingMetabox.inc b/classes/ComicPressPostMediaHandlingMetabox.inc index 7c85320..9bf1afa 100644 --- a/classes/ComicPressPostMediaHandlingMetabox.inc +++ b/classes/ComicPressPostMediaHandlingMetabox.inc @@ -3,28 +3,7 @@ class ComicPressPostMediaHandlingMetabox { function __comicpress_init() { $n = new ComicPressPostMediaHandlingMetabox(); - - if (isset($_REQUEST['cp'])) { - if (is_array($_REQUEST['cp'])) { - if (isset($_REQUEST['cp']['_nonce'])) { - if (wp_verify_nonce('comicpress', $_REQUEST['cp']['_nonce'])) { - if (isset($_REQUEST['cp']['action'])) { - if (isset($_REQUEST['cp']['_action_nonce'])) { - if (wp_verify_nonce('comicpress-' . $_REQUEST['cp']['action'], $_REQUEST['cp']['_action_nonce'])) { - $method_name = str_replace('-', '_', $_REQUEST['cp']['_action_nonce']); - if (method_exists($n, $method_name)) { - $n->{$method_name}($_REQUEST['cp']); - } - } - } - } - } - } - } - } } - function handle_update($info) { - - } + function handle_update() {} } diff --git a/functions.php b/functions.php index 4549e9a..9de1cc2 100644 --- a/functions.php +++ b/functions.php @@ -33,7 +33,7 @@ function __comicpress_widgets_init() { } function __comicpress_init() { - global $comicpress_options; + global $comicpress_options, $__comicpress_handlable_classes; // Check if the $comicpress_options exist, if not set defaults $comicpress_options = comicpress_load_options(); // xili-language plugin check @@ -52,10 +52,30 @@ function __comicpress_init() { remove_filter('comments_number','id_get_comment_number'); } - if (($_REQUEST['cp']['post_id'] <= 0) && ($_POST['post_ID'] > 0)) { - $_REQUEST['cp']['post_id'] = $_POST['post_ID']; - } + if (isset($_REQUEST['cp'])) { + if (is_array($_REQUEST['cp'])) { + if (($_REQUEST['cp']['post_id'] <= 0) && ($_POST['post_ID'] > 0)) { + $_REQUEST['cp']['post_id'] = $_POST['post_ID']; + } + if (isset($_REQUEST['cp']['_nonce'])) { + if (wp_verify_nonce('comicpress', $_REQUEST['cp']['_nonce'])) { + if (isset($_REQUEST['cp']['action'])) { + if (isset($_REQUEST['cp']['_action_nonce'])) { + if (wp_verify_nonce('comicpress-' . $_REQUEST['cp']['action'], $_REQUEST['cp']['_action_nonce'])) { + $method_name = 'handle_' . str_replace('-', '_', $_REQUEST['cp']['_action_nonce']); + foreach ($__comicpress_handlable_classes as $class_name) { + if (method_exists($class_name, $method_name)) { + $class_name->{$method_name}($_REQUEST['cp']); + } + } + } + } + } + } + } + } + } } add_action('widgets_init', '__comicpress_widgets_init'); @@ -197,6 +217,7 @@ if ($comicpress_options['remove_wptexturize']) { // WIDGETS WP 2.8 compatible ONLY, no backwards compatibility here. $dirs_to_search = array_unique(array(get_template_directory(), get_stylesheet_directory())); +$__comicpress_handlable_classes = array(); foreach ($dirs_to_search as $dir) { foreach (array('widgets' => 'php', 'functions' => 'php', 'classes' => 'inc') as $folder => $extension) { foreach (glob($dir . "/${folder}/*.${extension}") as $__file) { @@ -206,6 +227,10 @@ foreach ($dirs_to_search as $dir) { if (method_exists($__class_name, '__comicpress_init')) { add_action('comicpress_init', array($__class_name, '__comicpress_init')); } + + if (method_exists($__class_name, 'handle_update')) { + $__comicpress_handlable_classes[] = $__class_name; + } } } }