Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: WP All Import - Additional Variation images
- Description: Importing additional variation images with WP ALL IMPORT plugin
- Version: 1.0
- Author: Disain24 OĆ - Kristo Meerits
- */
- // Include'ing WP ALL IMPORT structure
- include "rapid-addon.php";
- $d24_images_addon = new RapidAddon('Additional variation images', 'd24_images_addon');
- // Multiple images upload form
- //$d24_images_addon->import_images( 'd24_gallery', 'All additional variation images', 'image' );
- // First image upload form
- $d24_images_addon->add_field('d24_variation_image1', 'Additional variation image # 1', 'image');
- // Second image upload form
- $d24_images_addon->add_field('d24_variation_image2', 'Additional variation image # 2', 'image');
- // Third image upload form
- $d24_images_addon->add_field('d24_variation_image3', 'Additional variation image # 3', 'image');
- // Fourth image upload form
- $d24_images_addon->add_field('d24_variation_image4', 'Additional variation image # 4', 'image');
- // Fifth image upload form
- $d24_images_addon->add_field('d24_variation_image5', 'Additional variation image # 5', 'image');
- // Sixth image upload form
- $d24_images_addon->add_field('d24_variation_image6', 'Additional variation image # 6', 'image');
- // For importing
- $d24_images_addon->set_import_function('d24_variation_images_import');
- // Lets run all actions befrore and show form in WP All import plugin. Nothing will be imported yet.
- $d24_images_addon->run();
- // Create import functions for importing
- function d24_variation_images_import($post_id, $data, $import_options) {
- global $d24_images_addon;
- // Prepare functions and progress then update post_meta
- // Also get uploaded image ID with progressing image filename
- // Source from Github: https://gist.github.com/wpscholar/3b00af01863c9dc562e5#file-get-attachment-id-php
- // Create array
- $gallery_array = array("post_ID" => $post_id, "gallery" => array() );
- // First image progressing and uploading
- if ($d24_images_addon->can_update_image($import_options)) {
- $image_url = wp_get_attachment_url($data['d24_variation_image1']['attachment_id']);
- $attachment_id = get_attachment_id( $image_url );
- array_push($gallery_array["gallery"], $attachment_id);
- if( get_post_meta( $post_id, 'd24_variation_image1' ) ){
- update_post_meta( $post_id, 'd24_variation_image1', $attachment_id );
- } else {
- add_post_meta( $post_id, 'd24_variation_image1', $attachment_id );
- }
- }
- // Second image progressing and uploading
- if ($d24_images_addon->can_update_image($import_options)) {
- $image_url = wp_get_attachment_url($data['d24_variation_image2']['attachment_id']);
- $attachment_id = get_attachment_id( $image_url );
- array_push($gallery_array["gallery"], $attachment_id);
- if( get_post_meta( $post_id, 'd24_variation_image2' ) ){
- update_post_meta( $post_id, 'd24_variation_image2', $attachment_id );
- } else {
- add_post_meta( $post_id, 'd24_variation_image2', $attachment_id );
- }
- }
- // Third image progressing and uploading
- if ($d24_images_addon->can_update_image($import_options)) {
- $image_url = wp_get_attachment_url($data['d24_variation_image3']['attachment_id']);
- $attachment_id = get_attachment_id( $image_url );
- array_push($gallery_array["gallery"], $attachment_id);
- if( get_post_meta( $post_id, 'd24_variation_image3' ) ){
- update_post_meta( $post_id, 'd24_variation_image3', $attachment_id );
- } else {
- add_post_meta( $post_id, 'd24_variation_image3', $attachment_id );
- }
- }
- // Fourth image progressing and uploading
- if ($d24_images_addon->can_update_image($import_options)) {
- $image_url = wp_get_attachment_url($data['d24_variation_image4']['attachment_id']);
- $attachment_id = get_attachment_id( $image_url );
- array_push($gallery_array["gallery"], $attachment_id);
- if( get_post_meta( $post_id, 'd24_variation_image4' ) ){
- update_post_meta( $post_id, 'd24_variation_image4', $attachment_id );
- } else {
- add_post_meta( $post_id, 'd24_variation_image4', $attachment_id );
- }
- }
- // Fifth image progressing and uploading
- if ($d24_images_addon->can_update_image($import_options)) {
- $image_url = wp_get_attachment_url($data['d24_variation_image5']['attachment_id']);
- $attachment_id = get_attachment_id( $image_url );
- array_push($gallery_array["gallery"], $attachment_id);
- if( get_post_meta( $post_id, 'd24_variation_image5' ) ){
- update_post_meta( $post_id, 'd24_variation_image5', $attachment_id );
- } else {
- add_post_meta( $post_id, 'd24_variation_image5', $attachment_id );
- }
- }
- // Sixth image progressing and uploading
- if ($d24_images_addon->can_update_image($import_options)) {
- $image_url = wp_get_attachment_url($data['d24_variation_image6']['attachment_id']);
- $attachment_id = get_attachment_id( $image_url );
- array_push($gallery_array["gallery"], $attachment_id);
- if( get_post_meta( $post_id, 'd24_variation_image6' ) ){
- update_post_meta( $post_id, 'd24_variation_image6', $attachment_id );
- } else {
- add_post_meta( $post_id, 'd24_variation_image6', $attachment_id );
- }
- }
- // Update gallery metakey
- $gallery_array_to_string = implode(',', $gallery_array["gallery"]);
- if( get_post_meta( $post_id, 'variation_image_gallery' ) ){
- update_post_meta( $post_id, 'variation_image_gallery', $gallery_array_to_string );
- } else {
- add_post_meta( $post_id, 'variation_image_gallery', $gallery_array_to_string );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement