Im using a function to share a collection of bookmarks with other users and i need to get the id after the new item is created in wordpress userpro bookmarks plugin
function share_collection($id,$name,$cbcolor,$user) {
$user_id = get_user_by( 'email', $user );
$user_id_current = get_current_user_id();
$collectionscurrent = $this->get_collections($user_id_current);
$collections = $this->get_collections($user_id->ID);
$collections[] = array('label' => $name);
// transfer bookmarks to shared collection
foreach($collectionscurrent[$coll_id] as $k => $arr) {
if ($k != 'label') {
$collections["This is where id should go"][$k] = 1;
}
}
update_user_meta($user_id->ID, '_wpb_collections', $collections);
}
How do i retrive the id created from $collections[] = array('label' => $name); and use it in the place where i mentioned "This is where id should go"
get_collections function is as follows
function get_collections($user_id) {
return (array)get_user_meta($user_id, '_wpb_collections', true);
}
Thanks in advance!
It's called array index. Assuming $collections
is zero based numerical array without any "holes" in it (hole would be eg index 1 in [0 => 'a', 2 => 'b']
), you can use:
$collections[] = array('label' => $name);
$idx = count($collections) - 1;
If it's not numerical or there can be holes, you have to figure out index to use first:
$idx = count($collections);
$collections[$idx] = array('label' => $name);