[wp-trac] [WordPress Trac] #32863: set_custom_fields function in wp_xmlrpc_server class
WordPress Trac
noreply at wordpress.org
Thu Jul 2 10:04:34 UTC 2015
#32863: set_custom_fields function in wp_xmlrpc_server class
-------------------------------------------+-----------------------------
Reporter: marifamir | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: XML-RPC | Version: 4.2.2
Severity: normal | Keywords:
Focuses: accessibility, administration |
-------------------------------------------+-----------------------------
Hi,
I was working with wp_xmlrpc_server class to insert and update woocommerce
products but i found that my custom fields are not working properly. When
i inspected the code of function set_custom_fields , i noticed that we are
using wp_unslash to remove underscores from custom field keys. So keys
like _price , _quantity and _stock were not working for the product custom
post type. Secondly we are using add_post_meta to insert the meta data.
Can we change it to the update_post_meta ?
I have attached the updated function.Please test it and let me know.
{{{
public function set_custom_fields($post_id, $fields) {
$post_id = (int) $post_id;
foreach ( (array) $fields as $meta ) {
if ( isset($meta['id']) ) {
$meta['id'] = (int) $meta['id'];
$pmeta = get_metadata_by_mid( 'post', $meta['id']
);
if ( isset($meta['key']) ) {
$meta['key'] = ( $meta['key'] );
if ( $meta['key'] !== $pmeta->meta_key )
continue;
$meta['value'] = ( $meta['value'] );
if ( current_user_can( 'edit_post_meta',
$post_id, $meta['key'] ) )
update_metadata_by_mid( 'post',
$meta['id'], $meta['value'] );
} elseif ( current_user_can( 'delete_post_meta',
$post_id, $pmeta->meta_key ) ) {
delete_metadata_by_mid( 'post',
$meta['id'] );
}
} else{
update_post_meta( $post_id, $meta['key'],
$meta['value'] );
}
}
}
}}}
Regards,
Arif
Skype: arifamir33
--
Ticket URL: <https://core.trac.wordpress.org/ticket/32863>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list