1 | <?php |
---|
2 | |
---|
3 | public function set_custom_fields($post_id, $fields) { |
---|
4 | $post_id = (int) $post_id; |
---|
5 | |
---|
6 | foreach ( (array) $fields as $meta ) { |
---|
7 | if ( isset($meta['id']) ) { |
---|
8 | $meta['id'] = (int) $meta['id']; |
---|
9 | $pmeta = get_metadata_by_mid( 'post', $meta['id'] ); |
---|
10 | if ( isset($meta['key']) ) { |
---|
11 | $meta['key'] = ( $meta['key'] ); |
---|
12 | if ( $meta['key'] !== $pmeta->meta_key ) |
---|
13 | continue; |
---|
14 | $meta['value'] = ( $meta['value'] ); |
---|
15 | if ( current_user_can( 'edit_post_meta', $post_id, $meta['key'] ) ) |
---|
16 | update_metadata_by_mid( 'post', $meta['id'], $meta['value'] ); |
---|
17 | } elseif ( current_user_can( 'delete_post_meta', $post_id, $pmeta->meta_key ) ) { |
---|
18 | delete_metadata_by_mid( 'post', $meta['id'] ); |
---|
19 | } |
---|
20 | } else{ |
---|
21 | update_post_meta( $post_id, $meta['key'], $meta['value'] ); |
---|
22 | } |
---|
23 | } |
---|
24 | } |
---|
25 | |
---|
26 | ?> |
---|