Multisite – Dateien über das Netzwerk zugänglich machen

Die Anhänge werden nur im selben Block kopiert und in einer Schleife fixiert Ich verwende die Multi-Site-function des WP, um eine Website mit mehreren Sprachen zu erstellen. Daher möchte ich die gleichen Medien in allen Blogs verwenden. Ich habe diese function bereits für meine benutzerdefinierten Beitragstypen, aber es funktionierte nicht für meine Anhänge.

Meine Quelle: https://codex.wordpress.org/Function_Reference/wp_insert_attachment

function bZive_create_TranslatedContent( $post_id ) { // Get the current blog id $original_site_id = get_current_blog_id(); $postTypes = array('profile', 'article'); $postType = get_post_type( $post_id ); $randomString = get_post_meta( $post_id, 'alphanumeric_id', true ); if (in_array( $postType, $postTypes ) and empty( get_post_meta( $post_id, 'translatedContent', true ) ) ) { $args = array( 'public' => true, 'limit' => 500 ); $sites = wp_get_sites($args); foreach ($sites as $site) { switch_to_blog($site['blog_id']); if( get_current_blog_id() != $original_site_id and get_current_blog_id() != 1 ){ $TranslatedContent = array( 'post_title' => 'Auto translate', 'post_content' => '', 'post_status' => 'draft', 'post_author' => '', 'post_type' => $postType, 'meta_input' => array( 'alphanumeric_id' => $randomString, 'translatedContent' => 'true', 'default_column_0_content_title' => 'Auto translate', ) ); // Insert the post into the database $translate = wp_insert_post( $TranslatedContent ); } restore_current_blog(); } add_post_meta($post_id, 'translatedContent', 'true'); } if ( $postType == 'attachment' and empty( get_post_meta( $post_id, 'translatedContent', true ) ) ) { $file = wp_get_attachment_url( $post_id ); $filename = basename($file); $post_title = get_the_title( $post_id ); $post_mime_type = get_post_mime_type( $post_id ); $wp_filetype = wp_check_filetype($filename, null ); $args = array( 'public' => true, 'limit' => 500 ); $sites = wp_get_sites($args); foreach ($sites as $site) { switch_to_blog($site['blog_id']); if( get_current_blog_id() != $original_site_id and get_current_blog_id() != 1 ){ // Prepare an array of post data for the attachment. $attachment = array( 'guid' => $file, 'post_mime_type' => $post_mime_type, 'post_title' => $post_title, 'post_content' => '', 'post_status' => 'inherit' ); // Insert the attachment. $attach_id = wp_insert_attachment( $attachment, $filename ); // Make sure that this file is included, as wp_generate_attachment_metadata() depends on it. require_once( ABSPATH . 'wp-admin/includes/image.php' ); // Generate the metadata for the attachment, and update the database record. $attach_data = wp_generate_attachment_metadata( $attach_id, $filename ); wp_update_attachment_metadata( $attach_id, $attach_data ); add_post_meta($attach_id, 'translatedContent', 'true'); add_post_meta($attach_id, 'alphanumeric_id', $randomString ); } restore_current_blog(); } add_post_meta($post_id, 'translatedContent', 'true'); } } add_action('wp_insert_post', 'bZive_create_TranslatedContent', 15, 3); add_action('add_attachment', 'bZive_create_TranslatedContent', 15, 1); 

Die Anhänge werden nur im selben Block kopiert und in einer Schleife gespeichert – Der Code funktioniert gut für die benutzerdefinierten Post-Typen

Solutions Collecting From Web of "Multisite – Dateien über das Netzwerk zugänglich machen"