improve hooks and add url backend saving

This commit is contained in:
John Bintz 2009-12-08 21:12:24 -05:00
parent 7b2b06deef
commit 7bc761938c
3 changed files with 64 additions and 30 deletions

View File

@ -18,6 +18,7 @@ class ComicPressAdmin {
} }
add_action('edit_form_advanced', array(&$this, 'edit_form_advanced')); add_action('edit_form_advanced', array(&$this, 'edit_form_advanced'));
add_action('save_post', array(&$this, 'save_post'), 10, 1);
add_filter('comicpress_core_version', array(&$this, 'comicpress_core_version')); add_filter('comicpress_core_version', array(&$this, 'comicpress_core_version'));
@ -418,16 +419,14 @@ class ComicPressAdmin {
} }
} }
function handle_update_comic_ordering() { function save_post($post_id) {
if (isset($_POST['post_ID'])) { if (ComicPressAdmin::verify_nonces() === 'handle_update_edit_form_advanced') {
if (is_numeric($_POST['post_ID'])) { if ($post = get_post($psot_id)) {
if ($post = get_post($_POST['post_ID'])) { $comic_post = new ComicPressComicPost($post);
$comic_post = new ComicPressComicPost($post); $data = $this->_json_decode(stripslashes($_POST['cp']['comic_order']));
$data = $this->_json_decode(stripslashes($_POST['cp']['comic_order'])); if (!empty($data)) {
if (!empty($data)) { if (is_array($data)) {
if (is_array($data)) { $comic_post->update_post_media_data($data);
$comic_post->update_post_media_data($data);
}
} }
} }
} }
@ -477,27 +476,17 @@ class ComicPressAdmin {
* Handle an update. * Handle an update.
*/ */
function handle_update() { function handle_update() {
if (isset($_REQUEST['cp'])) { if ($method = ComicPressAdmin::verify_nonces()) {
if (is_array($_REQUEST['cp'])) { switch ($method) {
if (isset($_REQUEST['cp']['_nonce'])) { case 'attachments':
if (wp_verify_nonce($_REQUEST['cp']['_nonce'], 'comicpress')) { $this->handle_update_attachments();
if (isset($_POST['attachments'])) { break;
//coming from media editor default:
$this->handle_update_attachments(); if (method_exists($this, $method)) {
} else if (isset($_REQUEST['cp']['action'])) { $this->{$method}($_REQUEST['cp']);
$action = $_REQUEST['cp']['action'];
if (isset($_REQUEST['cp']['_action_nonce'])) {
if (wp_verify_nonce($_REQUEST['cp']['_action_nonce'], "comicpress-${action}")) {
$method = 'handle_update_' . strtolower(str_replace('-', '_', $action));
if (method_exists($this, $method)) {
$this->{$method}($_REQUEST['cp']);
}
do_action("comicpress-${method}", $_REQUEST['cp']);
}
}
}
} }
} do_action("comicpress-${method}", $_REQUEST['cp']);
break;
} }
} }
} }
@ -525,4 +514,28 @@ class ComicPressAdmin {
} }
} }
// @codeCoverageIgnoreEnd // @codeCoverageIgnoreEnd
function verify_nonces() {
if (isset($_REQUEST['cp'])) {
if (is_array($_REQUEST['cp'])) {
if (isset($_REQUEST['cp']['_nonce'])) {
if (wp_verify_nonce($_REQUEST['cp']['_nonce'], 'comicpress')) {
if (isset($_POST['attachments'])) {
//coming from media editor
return 'attachments';
} else if (isset($_REQUEST['cp']['action'])) {
$action = $_REQUEST['cp']['action'];
if (isset($_REQUEST['cp']['_action_nonce'])) {
if (wp_verify_nonce($_REQUEST['cp']['_action_nonce'], "comicpress-${action}")) {
$method = 'handle_update_' . strtolower(str_replace('-', '_', $action));
return $method;
}
}
}
}
}
}
}
return false;
}
} }

View File

@ -34,6 +34,7 @@ class ComicPressBackendURL extends ComicPressBackend {
} }
} }
} }
update_post_meta($post->ID, 'backend_url_image_urls', $valid_url_groups); update_post_meta($post->ID, 'backend_url_image_urls', $valid_url_groups);
} }
} }
@ -130,7 +131,16 @@ class ComicPressBackendURLAdmin {
include('partials/backend-url/_editor.inc'); include('partials/backend-url/_editor.inc');
exit(0); exit(0);
} }
function save_post($post_id) {
if (ComicPressAdmin::verify_nonces() === 'handle_update_edit_form_advanced') {
if ($post = get_post($post_id)) {
ComicPressBackendURL::update_post_urls($post_id, $_REQUEST['cp']['url']);
}
}
}
} }
add_action('admin_menu', array('ComicPressBackendURLAdmin', 'admin_menu')); add_action('admin_menu', array('ComicPressBackendURLAdmin', 'admin_menu'));
add_action('comicpress-handle_update_backend_url_new_editor', array('ComicPressBackendURLAdmin', 'handle_update_backend_url_new_editor')); add_action('comicpress-handle_update_backend_url_new_editor', array('ComicPressBackendURLAdmin', 'handle_update_backend_url_new_editor'));
add_action('save_post', array('ComicPressBackendURLAdmin', 'save_post'), 10, 1);

View File

@ -9,6 +9,17 @@
</tr> </tr>
<?php <?php
} }
foreach (array(
'alt_text' => __('Image alt text', 'comicpress'),
'hover_text' => __('Hover/title text', 'comicpress')
) as $type => $label) {
$value = isset($backend->{$type}) ? $backend->{$type} : ''; ?>
<tr>
<th scope="row"><?php echo $label ?></th>
<td><input type="text" style="width: 100%" name="cp[url][<?php echo esc_attr($backend->id) ?>][__<?php echo $type ?>]" value="<?php echo esc_attr($value) ?>" />
</tr>
<?php }
?> ?>
</table> </table>
</div> </div>