Show proper error when adding a custom field without a value, props scohoust, fixes #7541

git-svn-id: http://svn.automattic.com/wordpress/trunk@10957 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
azaozz 2009-04-16 21:55:35 +00:00
parent c69b14d5b6
commit dee602f501
2 changed files with 10 additions and 5 deletions

View File

@ -770,7 +770,7 @@ case 'add-meta' :
if ( isset($_POST['metakeyselect']) || isset($_POST['metakeyinput']) ) { if ( isset($_POST['metakeyselect']) || isset($_POST['metakeyinput']) ) {
if ( !current_user_can( 'edit_post', $pid ) ) if ( !current_user_can( 'edit_post', $pid ) )
die('-1'); die('-1');
if ( '#NONE#' == $_POST['metakeyselect'] && empty($_POST['metakeyinput']) ) if ( isset($_POST['metakeyselect']) && '#NONE#' == $_POST['metakeyselect'] && empty($_POST['metakeyinput']) )
die('1'); die('1');
if ( $pid < 0 ) { if ( $pid < 0 ) {
$now = current_time('timestamp', 1); $now = current_time('timestamp', 1);
@ -784,12 +784,13 @@ case 'add-meta' :
) ); ) );
$x->send(); $x->send();
} }
$mid = add_meta( $pid ); if ( !$mid = add_meta( $pid ) )
die(__('Please provide a custom field value.'));
} else { } else {
die('0'); die('0');
} }
} else if ( !$mid = add_meta( $pid ) ) { } else if ( !$mid = add_meta( $pid ) ) {
die('0'); die(__('Please provide a custom field value.'));
} }
$meta = get_post_meta_by_id( $mid ); $meta = get_post_meta_by_id( $mid );
@ -811,7 +812,8 @@ case 'add-meta' :
if ( !current_user_can( 'edit_post', $meta->post_id ) ) if ( !current_user_can( 'edit_post', $meta->post_id ) )
die('-1'); die('-1');
if ( !$u = update_meta( $mid, $key, $value ) ) if ( !$u = update_meta( $mid, $key, $value ) )
die('1'); // We know meta exists; we also know it's unchanged (or DB error, in which case there are bigger problems). die('0'); // We know meta exists; we also know it's unchanged (or DB error, in which case there are bigger problems).
$key = stripslashes($key); $key = stripslashes($key);
$value = stripslashes($value); $value = stripslashes($value);
$x = new WP_Ajax_Response( array( $x = new WP_Ajax_Response( array(

View File

@ -677,10 +677,13 @@ function update_meta( $meta_id, $meta_key, $meta_value ) {
if ( in_array($meta_key, $protected) ) if ( in_array($meta_key, $protected) )
return false; return false;
if ( '' === trim( $meta_value ) )
return false;
$post_id = $wpdb->get_var( $wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_id = %d", $meta_id) ); $post_id = $wpdb->get_var( $wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_id = %d", $meta_id) );
wp_cache_delete($post_id, 'post_meta'); wp_cache_delete($post_id, 'post_meta');
$meta_value = maybe_serialize( stripslashes( $meta_value )); $meta_value = maybe_serialize( stripslashes( $meta_value ) );
$meta_id = (int) $meta_id; $meta_id = (int) $meta_id;
$data = compact( 'meta_key', 'meta_value' ); $data = compact( 'meta_key', 'meta_value' );