WordPress.org

Make WordPress Core

Changeset 18502


Ignore:
Timestamp:
08/03/2011 07:14:06 PM (7 years ago)
Author:
ryan
Message:

Use *_metadata_by_mid() API when updating post meta in admin ajax. Fix slashing. see #18195

File:
1 edited

Legend:

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

    r18498 r18502  
    862862    } else { // Update?
    863863        $mid = (int) array_pop( array_keys($_POST['meta']) );
    864         $key = $_POST['meta'][$mid]['key'];
    865         $value = $_POST['meta'][$mid]['value'];
     864        $key = stripslashes( $_POST['meta'][$mid]['key'] );
     865        $value = stripslashes( $_POST['meta'][$mid]['value'] );
    866866        if ( '' == trim($key) )
    867867            die(__('Please provide a custom field name.'));
    868868        if ( '' == trim($value) )
    869869            die(__('Please provide a custom field value.'));
    870         if ( !$meta = get_post_meta_by_id( $mid ) )
     870        if ( ! $meta = get_metadata_by_mid( 'post', $mid ) )
    871871            die('0'); // if meta doesn't exist
    872872        if ( is_protected_meta( $meta->meta_key, 'post' ) || is_protected_meta( $key, 'post' ) ||
     
    874874            ! current_user_can( 'edit_post_meta', $meta->post_id, $key ) )
    875875            die('-1');
    876         if ( $meta->meta_value != stripslashes($value) || $meta->meta_key != stripslashes($key) ) {
    877             if ( !$u = update_meta( $mid, $key, $value ) )
     876        if ( $meta->meta_value != $value || $meta->meta_key != $key ) {
     877            if ( !$u = update_metadata_by_mid( 'post', $mid, $value, $key ) )
    878878                die('0'); // We know meta exists; we also know it's unchanged (or DB error, in which case there are bigger problems).
    879879        }
    880880
    881         $key = stripslashes($key);
    882         $value = stripslashes($value);
    883881        $x = new WP_Ajax_Response( array(
    884882            'what' => 'meta',
Note: See TracChangeset for help on using the changeset viewer.