Support #17450 » export-import-links.php
1 |
<?php
|
---|---|
2 |
|
3 |
$from = [ 20613, 22677 ]; |
4 |
$to = 25691; |
5 |
|
6 |
$links = []; |
7 |
foreach ( $from as $from_id ) { |
8 |
switch_to_blog( $from_id ); |
9 |
$from_links = get_bookmarks(); |
10 |
|
11 |
foreach ( $from_links as $from_link ) { |
12 |
$bookmark = get_bookmark( $from_link->link_id, ARRAY_A ); |
13 |
|
14 |
$cat_names = array_map( |
15 |
function( $cat_id ) { |
16 |
$cat = get_term( $cat_id, 'link_category' ); |
17 |
return $cat->name; |
18 |
},
|
19 |
$bookmark['link_category'] |
20 |
);
|
21 |
|
22 |
$bookmark['cat_names'] = $cat_names; |
23 |
|
24 |
unset( $bookmark['link_id'] ); |
25 |
|
26 |
$links[] = $bookmark; |
27 |
}
|
28 |
restore_current_blog(); |
29 |
}
|
30 |
|
31 |
switch_to_blog( $to ); |
32 |
|
33 |
foreach ( $links as $link ) { |
34 |
$link_id = wp_insert_link( $link ); |
35 |
|
36 |
if ( ! $link_id ) { |
37 |
print_r( $link ); |
38 |
die; |
39 |
}
|
40 |
|
41 |
wp_set_object_terms( $link_id, $link['cat_names'], 'link_category' ); |
42 |
}
|
43 |
|
44 |
restore_current_blog(); |