Make WordPress Core


Ignore:
Timestamp:
07/20/2011 10:04:35 PM (15 years ago)
Author:
ryan
Message:

Introduce register_meta(), get_metadata_by_mid(), and *_post_meta capabilities. fixes #17850

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/post.php

    r18386 r18445  
    211211                        if ( $meta->post_id != $post_ID )
    212212                                continue;
    213                         if ( is_protected_meta( $value['key'] ) )
     213                        if ( is_protected_meta( $value['key'], 'post' ) || ! current_user_can( 'edit_post_meta', $post_ID, $value['key'] ) )
    214214                                continue;
    215215                        update_meta( $key, $value['key'], $value['value'] );
     
    223223                        if ( $meta->post_id != $post_ID )
    224224                                continue;
    225                         if ( is_protected_meta( $meta->meta_key ) )
     225                        if ( is_protected_meta( $meta->meta_key, 'post' ) || ! current_user_can( 'delete_post_meta', $post_ID, $meta->meta_key ) )
    226226                                continue;
    227227                        delete_meta( $key );
     
    672672                $metavalue = trim( $metavalue );
    673673
    674         if ( ('0' === $metavalue || !empty ( $metavalue ) ) && ((('#NONE#' != $metakeyselect) && !empty ( $metakeyselect) ) || !empty ( $metakeyinput) ) ) {
     674        if ( ('0' === $metavalue || ! empty ( $metavalue ) ) && ((('#NONE#' != $metakeyselect) && !empty ( $metakeyselect) ) || !empty ( $metakeyinput) ) ) {
    675675                // We have a key/value pair. If both the select and the
    676676                // input for the key have data, the input takes precedence:
     
    682682                        $metakey = $metakeyinput; // default
    683683
    684                 if ( is_protected_meta( $metakey ) )
     684                if ( is_protected_meta( $metakey, 'post' ) || ! current_user_can( 'add_post_meta', $post_ID, $metakey ) )
    685685                        return false;
    686686
    687                 wp_cache_delete($post_ID, 'post_meta');
    688                 $wpdb->insert( $wpdb->postmeta, array( 'post_id' => $post_ID, 'meta_key' => $metakey, 'meta_value' => $metavalue ) );
    689                 $meta_id = $wpdb->insert_id;
    690                 do_action( 'added_postmeta', $meta_id, $post_ID, $metakey, $metavalue );
    691 
    692                 return $meta_id;
    693         }
     687                return add_post_meta($post_ID, $metakey, $metavalue);
     688        }
     689
    694690        return false;
    695691} // add_meta
     
    772768                        FROM $wpdb->postmeta WHERE post_id = %d
    773769                        ORDER BY meta_key,meta_id", $postid), ARRAY_A );
    774 
    775770}
    776771
     
    789784
    790785        $meta_key = stripslashes($meta_key);
    791 
    792         if ( is_protected_meta( $meta_key ) )
    793                 return false;
    794786
    795787        if ( '' === trim( $meta_value ) )
Note: See TracChangeset for help on using the changeset viewer.