WordPress.org

Make WordPress Core

Changeset 10957


Ignore:
Timestamp:
04/16/09 21:55:35 (6 years ago)
Author:
azaozz
Message:

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

Location:
trunk/wp-admin
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/admin-ajax.php

    r10943 r10957  
    771771        if ( !current_user_can( 'edit_post', $pid ) ) 
    772772            die('-1'); 
    773         if ( '#NONE#' == $_POST['metakeyselect'] && empty($_POST['metakeyinput']) ) 
     773        if ( isset($_POST['metakeyselect']) && '#NONE#' == $_POST['metakeyselect'] && empty($_POST['metakeyinput']) ) 
    774774            die('1'); 
    775775        if ( $pid < 0 ) { 
     
    785785                    $x->send(); 
    786786                } 
    787                 $mid = add_meta( $pid ); 
     787                if ( !$mid = add_meta( $pid ) )  
     788                    die(__('Please provide a custom field value.')); 
    788789            } else { 
    789790                die('0'); 
    790791            } 
    791792        } else if ( !$mid = add_meta( $pid ) ) { 
    792             die('0'); 
     793            die(__('Please provide a custom field value.')); 
    793794        } 
    794795 
     
    812813            die('-1'); 
    813814        if ( !$u = update_meta( $mid, $key, $value ) ) 
    814             die('1'); // We know meta exists; we also know it's unchanged (or DB error, in which case there are bigger problems). 
     815            die('0'); // We know meta exists; we also know it's unchanged (or DB error, in which case there are bigger problems). 
     816     
    815817        $key = stripslashes($key); 
    816818        $value = stripslashes($value); 
  • trunk/wp-admin/includes/post.php

    r10847 r10957  
    678678        return false; 
    679679 
     680    if ( '' === trim( $meta_value ) ) 
     681        return false; 
     682 
    680683    $post_id = $wpdb->get_var( $wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_id = %d", $meta_id) ); 
    681684    wp_cache_delete($post_id, 'post_meta'); 
    682685 
    683     $meta_value = maybe_serialize( stripslashes( $meta_value )); 
     686    $meta_value = maybe_serialize( stripslashes( $meta_value ) ); 
    684687    $meta_id = (int) $meta_id; 
    685688 
Note: See TracChangeset for help on using the changeset viewer.