New custom field functionality.
git-svn-id: http://svn.automattic.com/wordpress/trunk@1197 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
07a395f685
commit
95a1e1d28f
|
@ -232,8 +232,8 @@ function list_meta($meta) {
|
|||
<tr $style>
|
||||
<td valign='top'><input name='meta[{$entry['meta_id']}][key]' tabindex='6' type='text' value='{$entry['meta_key']}' /></td>
|
||||
<td><textarea name='meta[{$entry['meta_id']}][value]' tabindex='6' rows='2' cols='40'>{$entry['meta_value']}</textarea></td>
|
||||
<td align='center'><input name='updatemeta' type='submit' id='updatemeta' tabindex='6' value='" . __('Update') ."' /></td>
|
||||
<td align='center'><input name='deletemeta[{$entry['meta_id']}]' type='submit' id='deletemeta' tabindex='6' value='" . __('Delete') ."' /></td>
|
||||
<td align='center'><input name='updatemeta' type='submit' class='updatemeta' tabindex='6' value='" . __('Update') ."' /></td>
|
||||
<td align='center'><input name='deletemeta[{$entry['meta_id']}]' type='submit' class='deletemeta' tabindex='6' value='" . __('Delete') ."' /></td>
|
||||
</tr>
|
||||
";
|
||||
}
|
||||
|
@ -256,9 +256,15 @@ function get_meta_keys() {
|
|||
}
|
||||
|
||||
function meta_form() {
|
||||
$keys = get_meta_keys();
|
||||
global $wpdb, $tablepostmeta;
|
||||
$keys = $wpdb->get_col("
|
||||
SELECT meta_key
|
||||
FROM $tablepostmeta
|
||||
GROUP BY meta_key
|
||||
ORDER BY meta_id DESC
|
||||
LIMIT 10");
|
||||
?>
|
||||
<h3><?php _e('Add new custom data to this post:') ?></h3>
|
||||
<h3><?php _e('Add a new custom field to this post:') ?></h3>
|
||||
<table width="100%" cellspacing="3" cellpadding="3">
|
||||
<tr>
|
||||
<th colspan="2"><?php _e('Key') ?></th>
|
||||
|
@ -279,7 +285,7 @@ function meta_form() {
|
|||
</tr>
|
||||
|
||||
</table>
|
||||
<p class="submit"><input type="submit" id="save" name="save" value="<?php _e('Add Custom Fields »') ?>"></p>
|
||||
<p class="submit"><input type="submit" name="updatemeta" value="<?php _e('Add Custom Field »') ?>"></p>
|
||||
<?php
|
||||
}
|
||||
|
||||
|
@ -308,10 +314,16 @@ function add_meta($post_ID) {
|
|||
}
|
||||
} // add_meta
|
||||
|
||||
function del_meta($mid) {
|
||||
function delete_meta($mid) {
|
||||
global $wpdb, $tablepostmeta;
|
||||
|
||||
$result = $wpdb->query("DELETE FROM $tablepostmeta WHERE meta_id = '$mid'");
|
||||
}
|
||||
|
||||
function update_meta($mid, $mkey, $mvalue) {
|
||||
global $wpdb, $tablepostmeta;
|
||||
|
||||
return $wpdb->query("UPDATE $tablepostmeta SET meta_key = '$mkey', meta_value = '$mvalue' WHERE meta_id = '$mid'");
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,4 +1,11 @@
|
|||
|
||||
<?php
|
||||
$messages[1] = __('Post updated');
|
||||
$messages[2] = __('Custom field updated');
|
||||
$messages[3] = __('Custom field deleted.');
|
||||
?>
|
||||
<?php if ($_GET['message']) : ?>
|
||||
<div class="updated"><p><?php echo $messages[$_GET['message']]; ?></p></div>
|
||||
<?php endif; ?>
|
||||
<div class="wrap">
|
||||
<?php
|
||||
|
||||
|
@ -47,7 +54,7 @@ $saveasdraft = '<input name="save" type="submit" id="save" tabindex="6" value="'
|
|||
<input type="hidden" name="user_ID" value="<?php echo $user_ID ?>" />
|
||||
<input type="hidden" name="action" value='<?php echo $form_action ?>' />
|
||||
<?php echo $form_extra ?>
|
||||
|
||||
<?php if (2 > $_GET['message']) : ?>
|
||||
<script type="text/javascript">
|
||||
<!--
|
||||
function focusit() {
|
||||
|
@ -57,7 +64,7 @@ function focusit() {
|
|||
window.onload = focusit;
|
||||
//-->
|
||||
</script>
|
||||
|
||||
<?php endif; ?>
|
||||
<div id="poststuff">
|
||||
<fieldset id="titlediv">
|
||||
<legend><a href="http://wordpress.org/docs/reference/post/#title" title="<?php _e('Help on titles') ?>"><?php _e('Title') ?></a></legend>
|
||||
|
|
|
@ -39,19 +39,6 @@ for ($i=0; $i<count($wpvarstoreset); $i += 1) {
|
|||
|
||||
switch($action) {
|
||||
|
||||
case 'deletemeta':
|
||||
$standalone = 1;
|
||||
require_once('./admin-header.php');
|
||||
|
||||
$post_ID = intval($_GET['post']);
|
||||
|
||||
$location = "post.php?action=edit&post=$post_ID";
|
||||
|
||||
del_meta($_GET['meta_id']);
|
||||
|
||||
header("Location: $location");
|
||||
|
||||
break;
|
||||
|
||||
case 'post':
|
||||
|
||||
|
@ -267,7 +254,7 @@ When you’re promoted, just reload this page and you’ll be able to bl
|
|||
break;
|
||||
|
||||
case 'editpost':
|
||||
|
||||
//die(var_dump('<pre>', $_POST));
|
||||
$standalone = 1;
|
||||
require_once('./admin-header.php');
|
||||
|
||||
|
@ -397,10 +384,27 @@ When you’re promoted, just reload this page and you’ll be able to bl
|
|||
}
|
||||
} // end if publish
|
||||
|
||||
// Meta Stuff
|
||||
if ($_POST['meta']) :
|
||||
foreach ($_POST['meta'] as $key => $value) :
|
||||
update_meta($key, $value['key'], $value['value']);
|
||||
endforeach;
|
||||
endif;
|
||||
|
||||
if ($_POST['deletemeta']) :
|
||||
foreach ($_POST['deletemeta'] as $key => $value) :
|
||||
delete_meta($key);
|
||||
endforeach;
|
||||
endif;
|
||||
|
||||
add_meta($post_ID);
|
||||
|
||||
if ($_POST['save']) {
|
||||
$location = $_SERVER['HTTP_REFERER'];
|
||||
} elseif ($_POST['updatemeta']) {
|
||||
$location = $_SERVER['HTTP_REFERER'] . '&message=2#postcustom';
|
||||
} elseif ($_POST['deletemeta']) {
|
||||
$location = $_SERVER['HTTP_REFERER'] . '&message=3#postcustom';
|
||||
} else {
|
||||
$location = 'post.php';
|
||||
}
|
||||
|
|
|
@ -353,7 +353,7 @@ textarea, input, select {
|
|||
padding: .3em;
|
||||
}
|
||||
|
||||
#postcustom #updatemeta, #postcustom #deletemeta {
|
||||
#postcustom .updatemeta, #postcustom .deletemeta {
|
||||
width: 90%;
|
||||
margin: auto;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue