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

git-svn-id: http://svn.automattic.com/wordpress/trunk@18445 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan
2011-07-20 22:04:35 +00:00
parent 8d7a97abf9
commit 4ad0954961
8 changed files with 118 additions and 45 deletions

View File

@@ -210,7 +210,7 @@ function edit_post( $post_data = null ) {
continue;
if ( $meta->post_id != $post_ID )
continue;
if ( is_protected_meta( $value['key'] ) )
if ( is_protected_meta( $value['key'], 'post' ) || ! current_user_can( 'edit_post_meta', $post_ID, $value['key'] ) )
continue;
update_meta( $key, $value['key'], $value['value'] );
}
@@ -222,7 +222,7 @@ function edit_post( $post_data = null ) {
continue;
if ( $meta->post_id != $post_ID )
continue;
if ( is_protected_meta( $meta->meta_key ) )
if ( is_protected_meta( $meta->meta_key, 'post' ) || ! current_user_can( 'delete_post_meta', $post_ID, $meta->meta_key ) )
continue;
delete_meta( $key );
}
@@ -671,7 +671,7 @@ function add_meta( $post_ID ) {
if ( is_string($metavalue) )
$metavalue = trim( $metavalue );
if ( ('0' === $metavalue || !empty ( $metavalue ) ) && ((('#NONE#' != $metakeyselect) && !empty ( $metakeyselect) ) || !empty ( $metakeyinput) ) ) {
if ( ('0' === $metavalue || ! empty ( $metavalue ) ) && ((('#NONE#' != $metakeyselect) && !empty ( $metakeyselect) ) || !empty ( $metakeyinput) ) ) {
// We have a key/value pair. If both the select and the
// input for the key have data, the input takes precedence:
@@ -681,16 +681,12 @@ function add_meta( $post_ID ) {
if ( $metakeyinput)
$metakey = $metakeyinput; // default
if ( is_protected_meta( $metakey ) )
if ( is_protected_meta( $metakey, 'post' ) || ! current_user_can( 'add_post_meta', $post_ID, $metakey ) )
return false;
wp_cache_delete($post_ID, 'post_meta');
$wpdb->insert( $wpdb->postmeta, array( 'post_id' => $post_ID, 'meta_key' => $metakey, 'meta_value' => $metavalue ) );
$meta_id = $wpdb->insert_id;
do_action( 'added_postmeta', $meta_id, $post_ID, $metakey, $metavalue );
return $meta_id;
return add_post_meta($post_ID, $metakey, $metavalue);
}
return false;
} // add_meta
@@ -771,7 +767,6 @@ function has_meta( $postid ) {
return $wpdb->get_results( $wpdb->prepare("SELECT meta_key, meta_value, meta_id, post_id
FROM $wpdb->postmeta WHERE post_id = %d
ORDER BY meta_key,meta_id", $postid), ARRAY_A );
}
/**
@@ -789,9 +784,6 @@ function update_meta( $meta_id, $meta_key, $meta_value ) {
$meta_key = stripslashes($meta_key);
if ( is_protected_meta( $meta_key ) )
return false;
if ( '' === trim( $meta_value ) )
return false;