Transfer thumbnail from any network blog to global blog
-
Hello everbody,
my name is Jan and i am new in WP multisite & BuddyPress. I am a designer&developer located in Solingen/Germany. Actually i am standing at a point where some help would be motivating and all documentation is readed :(.
I am coding a function which should push a custom post type(recipe) on hook
save_post
from any network blog where the hook is triggered to a main blog acting as a container to save all custom posts from the network as a draft, moderate them and publish or delete them.This is working well at this point except “transfering” the posts thumbnail from blog1_post1 to global_blog_post1.
I am working with(static filename for testing):
$filename = '2011/05/myimg.png'; $wp_filetype = wp_check_filetype(basename($filename), null ); $attachment = array( 'post_mime_type' => $wp_filetype['type'], 'post_title' => preg_replace('/\.[^.]+$/', '', basename($filename)), 'post_content' => '', 'post_status' => 'inherit' );
and save it after a
switch_to_blog($global_blog_id)
with/* finaly insert */ $p = wp_insert_post( $my_post ); $attach_id = wp_insert_attachment( $attachment, $filename, $p ); // you must first include the image.php file // for the function wp_generate_attachment_metadata() to work require_once(ABSPATH . "wp-admin" . '/includes/image.php'); $attach_data = wp_generate_attachment_metadata( $attach_id, $filename ); wp_update_attachment_metadata( $attach_id, $attach_data );
As i read in the docu wp_insert_attachment is only excepting files under the local upload dir, but the file is located in origins blogs.dir in this case. This and others facts causing malfunction… The post container and
_wp_attached_file
&_wp_attachment_metadata
are generated in the DB but _wp_attachment_metadata holds no/wrong serialized valuesa:0:{}
and the _thumbnail_id meta key isn’t generated at all.I will need a function/method which copies the file from
blogs.dir -ID (actual post) --YYYY ---MM ----filename
to the same dir and the ID of the global blog, the correct _wp_attachment_metadata and a small function to add the _thumbnail_id…
Am i right or another approach…? A smarter way? Any hints would be more than nice!
Thanks in advance & many regards
JanAttachments:
The _wp_attachment_metadata meta_value(serialized) should look like:[Code moderated as per the Forum Rules. Please use the pastebin]
- The topic ‘Transfer thumbnail from any network blog to global blog’ is closed to new replies.