From 9641d10cc9fbfab5d7911f590809725f631886e7 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Wed, 9 Dec 2009 21:15:08 -0500 Subject: [PATCH] rework commit action handling --- .../ComicPressPostMediaHandlingMetabox.inc | 34 ++++++++----------- functions.php | 18 +++++----- 2 files changed, 22 insertions(+), 30 deletions(-) diff --git a/classes/ComicPressPostMediaHandlingMetabox.inc b/classes/ComicPressPostMediaHandlingMetabox.inc index fab0b76..59d5088 100644 --- a/classes/ComicPressPostMediaHandlingMetabox.inc +++ b/classes/ComicPressPostMediaHandlingMetabox.inc @@ -1,34 +1,25 @@ $value) { - if (in_array($field, $valid_types)) { - $result[$field] = strip_tags($value); - } + function save_post($post_id) { + if (__comicpress_verify_nonce() == 'post-media-update') { + $info = $_REQUEST['cp']; + $result = array(); + if (isset($info['urls'])) { + if (is_array($info['urls'])) { + $valid_types = ComicPressPostMediaHandlingMetabox::_get_valid_types(); + foreach ($info['urls'] as $field => $value) { + if (in_array($field, $valid_types)) { + $result[$field] = strip_tags($value); } } } - update_post_meta($info['post_id'], 'backend_url_images', $result); } + update_post_meta($post_id, 'backend_url_images', $result); } } @@ -51,3 +42,6 @@ class ComicPressPostMediaHandlingMetabox { include('partials/post-media-handling/metabox.inc'); } } + +add_action('admin_menu', array('ComicPressPostMediaHandlingMetabox', 'admin_menu')); +add_action('save_post', array('ComicPressPostMediaHandlingMetabox', 'save_post')); \ No newline at end of file diff --git a/functions.php b/functions.php index 6df5d2d..ffd96d5 100644 --- a/functions.php +++ b/functions.php @@ -42,23 +42,20 @@ function __comicpress_init() { do_action('comicpress_init'); + if ($verified_nonce = __comicpress_verify_nonce()) { + do_action("comicpress_init-${verified_nonce}"); + } +} + +function __comicpress_verify_nonce() { 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($_REQUEST['cp']['_nonce'], 'comicpress')) { if (isset($_REQUEST['cp']['action'])) { if (isset($_REQUEST['cp']['_action_nonce'])) { if (wp_verify_nonce($_REQUEST['cp']['_action_nonce'], 'comicpress-' . $_REQUEST['cp']['action'])) { - $method_name = 'handle_' . str_replace('-', '_', $_REQUEST['cp']['action']); - foreach ($__comicpress_handlable_classes as $class_name) { - if (method_exists($class_name, $method_name)) { - call_user_func(array($class_name, $method_name), $_REQUEST['cp']); - } - } + return $_REQUEST['cp']['action']; } } } @@ -66,6 +63,7 @@ function __comicpress_init() { } } } + return false; } add_action('widgets_init', '__comicpress_widgets_init');