WordPress.org

Make WordPress Core

Ticket #17850: 17850.17.diff

File 17850.17.diff, 2.4 KB (added by xknown, 7 years ago)

Do not call stripslashes two times and add verify if the new meta_key is not protected when editing an existing meta

  • wp-admin/admin-ajax.php

     
    869869                        die(__('Please provide a custom field value.'));
    870870                if ( !$meta = get_post_meta_by_id( $mid ) )
    871871                        die('0'); // if meta doesn't exist
    872                 if ( is_protected_meta( $meta->meta_key, 'post' ) || !current_user_can( 'edit_post_meta', $meta->post_id, $meta->meta_key ) )
     872                if ( is_protected_meta( $meta->meta_key, 'post' ) || is_protected_meta( $key, 'post' ) || !current_user_can( 'edit_post_meta', $meta->post_id, $meta->meta_key ) )
    873873                        die('-1');
    874874                if ( $meta->meta_value != stripslashes($value) || $meta->meta_key != stripslashes($key) ) {
    875875                        if ( !$u = update_meta( $mid, $key, $value ) )
  • wp-admin/includes/post.php

     
    665665        global $wpdb;
    666666        $post_ID = (int) $post_ID;
    667667
    668         $metakeyselect = isset($_POST['metakeyselect']) ? stripslashes( trim( $_POST['metakeyselect'] ) ) : '';
    669         $metakeyinput = isset($_POST['metakeyinput']) ? stripslashes( trim( $_POST['metakeyinput'] ) ) : '';
    670         $metavalue = isset($_POST['metavalue']) ? maybe_serialize( stripslashes_deep( $_POST['metavalue'] ) ) : '';
    671         if ( is_string($metavalue) )
    672                 $metavalue = trim( $metavalue );
     668        $metakeyselect = isset($_POST['metakeyselect']) ? trim( $_POST['metakeyselect'] ) : '';
     669        $metakeyinput = isset($_POST['metakeyinput']) ? trim( $_POST['metakeyinput'] ) : '';
     670        $metavalue = isset($_POST['metavalue']) ? $_POST['metavalue'] : '';
    673671
    674         if ( ('0' === $metavalue || ! empty ( $metavalue ) ) && ((('#NONE#' != $metakeyselect) && !empty ( $metakeyselect) ) || !empty ( $metakeyinput) ) ) {
     672        if ( ('0' === $metavalue || ! empty ( $metavalue ) ) && ( ( ( '#NONE#' != $metakeyselect ) && !empty ( $metakeyselect) ) || !empty ( $metakeyinput ) ) ) {
    675673                // We have a key/value pair. If both the select and the
    676674                // input for the key have data, the input takes precedence:
    677675
    678                 if ('#NONE#' != $metakeyselect)
     676                if ( '#NONE#' != $metakeyselect )
    679677                        $metakey = $metakeyselect;
    680678
    681                 if ( $metakeyinput)
     679                if ( $metakeyinput )
    682680                        $metakey = $metakeyinput; // default
    683681
    684682                if ( is_protected_meta( $metakey, 'post' ) || ! current_user_can( 'add_post_meta', $post_ID, $metakey ) )