コード例 #1
12
 /**
  * Run the attachment deletion task.
  *
  * Uses transients to ensure that only small batches of posts are done each time.
  * Once a batch is complete, the post offset transient is iterated.
  */
 public function task()
 {
     // Set initial offset
     if (false == ($offset = get_transient('media_manager_offset'))) {
         set_transient('media_manager_offset', $offset = 0, DAY_IN_SECONDS);
     }
     $time = time();
     while (time() < $time + self::TIME_LIMIT) {
         // Get the post IDs
         $query = new WP_Query(array('post_type' => $this->get_post_types(), 'posts_per_page' => 1, 'post_status' => 'publish', 'offset' => $offset, 'no_found_rows' => true, 'update_post_meta_cache' => false, 'update_post_term_cache' => false, 'fields' => 'ids'));
         $post_ids = $query->posts;
         // Completed all posts, so delete offset and bail out
         if (empty($post_ids)) {
             delete_transient('media_manager_offset');
             return;
         }
         // Loop through the posts
         foreach ($post_ids as $key => $post_id) {
             $attached_media = get_attached_media('image', $post_id);
             $featured_id = get_post_thumbnail_id($post_id);
             // Loop through media attached to each post
             foreach ($attached_media as $x => $attachment) {
                 $attachment_id = $attachment->ID;
                 // If not a featured image, then delete the attachment
                 if ($attachment_id != $featured_id) {
                     wp_delete_post($attachment_id);
                 }
             }
             set_transient('media_manager_offset', $offset++, DAY_IN_SECONDS);
         }
         usleep(0.1 * 1000000);
         // Delaying the execution (reduces resource consumption)
     }
     return;
 }
コード例 #2
1
function vskb_columns($vskb_cats, $columns, $subcats = false, $excludes = null, $includes = null)
{
    $return = "";
    $columnNames = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine'];
    $return .= '<div id="vskb-' . $columnNames[$columns] . '">' . '<ul class="x-vskb-cat-list">';
    $content = '';
    // Get list of ICONs or images attached to the KB page, these can be icons.
    $media = get_attached_media('image');
    $icons = [];
    foreach ($media as $key => $val) {
        $icons[$val->post_name] = $val->guid;
    }
    $js = '';
    $count = 0;
    foreach ($vskb_cats as $cat) {
        if (!empty($excludes) && in_array($cat->slug, $excludes)) {
            continue;
        } else {
            if (!empty($includes) && !in_array($cat->slug, $includes)) {
                continue;
            }
        }
        // For each category we keep map in JS
        $js .= 'cats["' . $cat->slug . '"] = ' . $count . ';';
        $img = '';
        if (!empty($icons[$cat->slug . '-ico'])) {
            $img = '<img class="category-icon" src="' . $icons[$cat->slug . '-ico'] . '">';
        }
        // $return .= '<ul class="vskb-cat-list"><li class="vskb-cat-name"><a href="'. get_category_link( $cat->cat_ID ) .'" title="'. $cat->name .'" >'. $cat->name .'</a></li>';
        $return .= '<li class="x-vskb-cat-name"><a href="#' . $cat->slug . '" title="' . $cat->name . '" >' . $img . $cat->name . '</a></li>';
        $catColumn = $subCats ? 'category__in' : 'cat';
        $vskb_args = array('orderby' => 'menu_order', 'order' => 'ASC', 'posts_per_page' => -1, $catColumn => $cat->cat_ID);
        $vskb_posts = get_posts($vskb_args);
        $content .= '<div id="' . $cat->slug . '"><ul class="vskb-cat-list">';
        foreach ($vskb_posts as $single_post) {
            $content .= '<li class="vskb-post-name">';
            $content .= '<a href="' . get_permalink($single_post->ID) . '" rel="bookmark" title="' . get_the_title($single_post->ID) . '">' . get_the_title($single_post->ID) . '</a>';
            $content .= '</li>';
        }
        $content .= '</ul></div>';
        $count++;
    }
    $return .= '</ul>' . $content;
    $return .= '</div>';
    // Add jQuery
    $return .= '<script>
	jQuery( function() {
		var cats = {};
		' . $js . '
		console.log( window.location.hash, cats );
		whichTab = 0;
		jQuery( "#vskb-' . $columnNames[$columns] . '" ).tabs( { active : whichTab }).addClass( "ui-tabs-vertical ui-helper-clearfix" );
		jQuery( "#vskb-' . $columnNames[$columns] . ' li.x-vskb-cat-name" ).removeClass( "ui-corner-top" ).addClass( "ui-corner-left" );
	});
	</script>';
    return $return;
}
コード例 #3
0
 /**
  * Given information provided in an entry, get array of media IDs
  *
  * This is necessary because GF doesn't expect to need to update post images, only to create them.
  *
  * @see GFFormsModel::create_post()
  *
  * @since 1.17
  *
  * @param array $form Gravity Forms form array
  * @param array $entry Gravity Forms entry array
  *
  * @return array Array of "Field ID" => "Media IDs"
  */
 public static function get_post_field_images($form, $entry)
 {
     $post_data = self::get_post_fields($form, $entry);
     $media = get_attached_media('image', $entry['post_id']);
     $post_images = array();
     foreach ($media as $media_item) {
         foreach ((array) $post_data['images'] as $post_data_item) {
             if (rgar($post_data_item, 'title') === $media_item->post_title && rgar($post_data_item, 'description') === $media_item->post_content && rgar($post_data_item, 'caption') === $media_item->post_excerpt) {
                 $post_images["{$post_data_item['field_id']}"] = $media_item->ID;
             }
         }
     }
     return $post_images;
 }
 public function get_items($request)
 {
     $id = $request['id'];
     $type = $request['type'];
     $query_result = get_attached_media($type, $id);
     $medias = array();
     foreach ($query_result as $media) {
         //$mediaItem = json_decode(get_data(rest_url('wp/v2/media/' . $media->ID)));
         $data = $this->prepare_item_for_response($media, $request);
         $medias[] = $this->prepare_response_for_collection($data);
         //$medias[] = $data;
     }
     $response = rest_ensure_response($medias);
     return $response;
 }
コード例 #5
0
ファイル: micro-css-slider.php プロジェクト: dev-wl/torani
function delete_slider()
{
    global $wpdb;
    // this is how you get access to the database
    $postId = intval(substr($_POST['slide-id'], 6));
    //first, delete all images attached to the post
    $attaches = get_attached_media('image', $postId);
    foreach ($attaches as $image) {
        wp_delete_attachment($image->ID, true);
    }
    //second,delete the post itself
    $deleted = wp_delete_post($postId, true);
    if ($deleted != false) {
        echo '1';
    } else {
        echo '-1';
    }
    wp_die();
    // this is required to terminate immediately and return a proper response
}
コード例 #6
0
 /**
  * @test
  */
 public function post_helper_basic()
 {
     $num_categories = 3;
     $categories = $this->factory->category->create_many($num_categories);
     array_shift($categories);
     $args = array('post_name' => 'slug', 'post_author' => '1', 'post_date' => '2012-11-15 20:00:00', 'post_type' => 'post', 'post_status' => 'publish', 'post_title' => 'title', 'post_content' => 'content', 'post_category' => $categories, 'post_tags' => array('tag1', 'tag2'));
     $helper = new Helper($args);
     $post_id = $helper->insert();
     $post = get_post($post_id);
     foreach ($args as $key => $value) {
         if ('post_category' === $key || 'post_tags' === $key) {
             continue;
         }
         $this->assertSame($value, $post->{$key});
     }
     $this->assertSame(2, count(get_the_tags($post_id)));
     $this->assertSame(count($categories), count(wp_get_object_terms($post_id, 'category')));
     // it should be success to upload and should be attached to the post
     $attachment_id = $helper->add_media('http://placehold.jp/100x100.png', 'title', 'description', 'caption', false);
     $media = get_attached_media('image', $post_id);
     $this->assertSame($attachment_id, $media[$attachment_id]->ID);
 }
コード例 #7
0
 private function get_photos()
 {
     $media = get_attached_media('image', $this->post->ID);
     $photos = array();
     foreach ($media as $object) {
         $photos[] = ['href' => wp_get_attachment_url($object->ID), 'caption' => wptexturize($object->post_content), 'credit' => $object->post_excerpt];
     }
     return $photos;
 }
 function getThumbs($post_id)
 {
     $attatchments = get_attached_media('image', $post_id);
     $attatchments_uris = array();
     foreach ($attatchments as $attch) {
         $attatchments_uris[] = wp_get_attachment_url($attch->ID);
     }
     return $attatchments_uris;
 }
コード例 #9
0
ファイル: record.php プロジェクト: k-hasan-19/wp-all-import
 /**
  * Perform import operation
  * @param string $xml XML string to import
  * @param callback[optional] $logger Method where progress messages are submmitted
  * @return PMXI_Import_Record
  * @chainable
  */
 public function process($xml, $logger = NULL, $chunk = false, $is_cron = false, $xpath_prefix = '', $loop = 0)
 {
     add_filter('user_has_cap', array($this, '_filter_has_cap_unfiltered_html'));
     kses_init();
     // do not perform special filtering for imported content
     kses_remove_filters();
     $cxpath = $xpath_prefix . $this->xpath;
     $this->options += PMXI_Plugin::get_default_import_options();
     // make sure all options are defined
     $avoid_pingbacks = PMXI_Plugin::getInstance()->getOption('pingbacks');
     $cron_sleep = (int) PMXI_Plugin::getInstance()->getOption('cron_sleep');
     if ($avoid_pingbacks and !defined('WP_IMPORTING')) {
         define('WP_IMPORTING', true);
     }
     $postRecord = new PMXI_Post_Record();
     $tmp_files = array();
     // compose records to import
     $records = array();
     $is_import_complete = false;
     try {
         $chunk == 1 and $logger and call_user_func($logger, __('Composing titles...', 'wp_all_import_plugin'));
         if (!empty($this->options['title'])) {
             $titles = XmlImportParser::factory($xml, $cxpath, $this->options['title'], $file)->parse($records);
             $tmp_files[] = $file;
         } else {
             $loop and $titles = array_fill(0, $loop, '');
         }
         $chunk == 1 and $logger and call_user_func($logger, __('Composing excerpts...', 'wp_all_import_plugin'));
         $post_excerpt = array();
         if (!empty($this->options['post_excerpt'])) {
             $post_excerpt = XmlImportParser::factory($xml, $cxpath, $this->options['post_excerpt'], $file)->parse($records);
             $tmp_files[] = $file;
         } else {
             count($titles) and $post_excerpt = array_fill(0, count($titles), '');
         }
         if ("xpath" == $this->options['status']) {
             $chunk == 1 and $logger and call_user_func($logger, __('Composing statuses...', 'wp_all_import_plugin'));
             $post_status = array();
             if (!empty($this->options['status_xpath'])) {
                 $post_status = XmlImportParser::factory($xml, $cxpath, $this->options['status_xpath'], $file)->parse($records);
                 $tmp_files[] = $file;
             } else {
                 count($titles) and $post_status = array_fill(0, count($titles), '');
             }
         }
         if ("xpath" == $this->options['comment_status']) {
             $chunk == 1 and $logger and call_user_func($logger, __('Composing comment statuses...', 'wp_all_import_plugin'));
             $comment_status = array();
             if (!empty($this->options['comment_status_xpath'])) {
                 $comment_status = XmlImportParser::factory($xml, $cxpath, $this->options['comment_status_xpath'], $file)->parse($records);
                 $tmp_files[] = $file;
             } else {
                 count($titles) and $comment_status = array_fill(0, count($titles), 'open');
             }
         }
         if ("xpath" == $this->options['ping_status']) {
             $chunk == 1 and $logger and call_user_func($logger, __('Composing ping statuses...', 'wp_all_import_plugin'));
             $ping_status = array();
             if (!empty($this->options['ping_status_xpath'])) {
                 $ping_status = XmlImportParser::factory($xml, $cxpath, $this->options['ping_status_xpath'], $file)->parse($records);
                 $tmp_files[] = $file;
             } else {
                 count($titles) and $ping_status = array_fill(0, count($titles), 'open');
             }
         }
         if ("xpath" == $this->options['post_format']) {
             $chunk == 1 and $logger and call_user_func($logger, __('Composing post formats...', 'wp_all_import_plugin'));
             $post_format = array();
             if (!empty($this->options['post_format_xpath'])) {
                 $post_format = XmlImportParser::factory($xml, $cxpath, $this->options['post_format_xpath'], $file)->parse($records);
                 $tmp_files[] = $file;
             } else {
                 count($titles) and $post_format = array_fill(0, count($titles), 'open');
             }
         }
         if ("no" == $this->options['is_multiple_page_template']) {
             $chunk == 1 and $logger and call_user_func($logger, __('Composing page templates...', 'wp_all_import_plugin'));
             $page_template = array();
             if (!empty($this->options['single_page_template'])) {
                 $page_template = XmlImportParser::factory($xml, $cxpath, $this->options['single_page_template'], $file)->parse($records);
                 $tmp_files[] = $file;
             } else {
                 count($titles) and $page_template = array_fill(0, count($titles), 'default');
             }
         }
         if ($this->options['is_override_post_type'] and !empty($this->options['post_type_xpath'])) {
             $chunk == 1 and $logger and call_user_func($logger, __('Composing post types...', 'wp_all_import_plugin'));
             $post_type = array();
             $post_type = XmlImportParser::factory($xml, $cxpath, $this->options['post_type_xpath'], $file)->parse($records);
             $tmp_files[] = $file;
         } else {
             if ('post' == $this->options['type'] and '' != $this->options['custom_type']) {
                 $pType = $this->options['custom_type'];
             } else {
                 $pType = $this->options['type'];
             }
             count($titles) and $post_type = array_fill(0, count($titles), $pType);
         }
         if ("no" == $this->options['is_multiple_page_parent']) {
             $chunk == 1 and $logger and call_user_func($logger, __('Composing page parent...', 'wp_all_import_plugin'));
             $page_parent = array();
             if (!empty($this->options['single_page_parent'])) {
                 $page_parent = XmlImportParser::factory($xml, $cxpath, $this->options['single_page_parent'], $file)->parse($records);
                 $tmp_files[] = $file;
                 foreach ($page_parent as $key => $identity) {
                     $page = 0;
                     switch ($this->options['type']) {
                         case 'post':
                             if (!empty($identity)) {
                                 if (ctype_digit($identity)) {
                                     $page = get_post($identity);
                                 } else {
                                     $page = get_page_by_title($identity, OBJECT, $post_type[$key]);
                                     if (empty($page)) {
                                         $args = array('name' => $identity, 'post_type' => $post_type[$key], 'post_status' => 'any', 'numberposts' => 1);
                                         $my_posts = get_posts($args);
                                         if ($my_posts) {
                                             $page = $my_posts[0];
                                         }
                                     }
                                 }
                             }
                             break;
                         case 'page':
                             $page = get_page_by_title($identity) or $page = get_page_by_path($identity) or ctype_digit($identity) and $page = get_post($identity);
                             break;
                         default:
                             # code...
                             break;
                     }
                     $page_parent[$key] = !empty($page) ? $page->ID : 0;
                 }
             } else {
                 count($titles) and $page_parent = array_fill(0, count($titles), 0);
             }
         }
         $chunk == 1 and $logger and call_user_func($logger, __('Composing authors...', 'wp_all_import_plugin'));
         $post_author = array();
         $current_user = wp_get_current_user();
         if (!empty($this->options['author'])) {
             $post_author = XmlImportParser::factory($xml, $cxpath, $this->options['author'], $file)->parse($records);
             $tmp_files[] = $file;
             foreach ($post_author as $key => $author) {
                 $user = get_user_by('login', $author) or $user = get_user_by('slug', $author) or $user = get_user_by('email', $author) or ctype_digit($author) and $user = get_user_by('id', $author);
                 $post_author[$key] = !empty($user) ? $user->ID : $current_user->ID;
             }
         } else {
             count($titles) and $post_author = array_fill(0, count($titles), $current_user->ID);
         }
         $chunk == 1 and $logger and call_user_func($logger, __('Composing slugs...', 'wp_all_import_plugin'));
         $post_slug = array();
         if (!empty($this->options['post_slug'])) {
             $post_slug = XmlImportParser::factory($xml, $cxpath, $this->options['post_slug'], $file)->parse($records);
             $tmp_files[] = $file;
         } else {
             count($titles) and $post_slug = array_fill(0, count($titles), '');
         }
         $chunk == 1 and $logger and call_user_func($logger, __('Composing menu order...', 'wp_all_import_plugin'));
         $menu_order = array();
         if (!empty($this->options['order'])) {
             $menu_order = XmlImportParser::factory($xml, $cxpath, $this->options['order'], $file)->parse($records);
             $tmp_files[] = $file;
         } else {
             count($titles) and $menu_order = array_fill(0, count($titles), '');
         }
         $chunk == 1 and $logger and call_user_func($logger, __('Composing contents...', 'wp_all_import_plugin'));
         if (!empty($this->options['content'])) {
             $contents = XmlImportParser::factory((!empty($this->options['is_keep_linebreaks']) and intval($this->options['is_keep_linebreaks'])) ? $xml : preg_replace('%\\r\\n?|\\n%', ' ', $xml), $cxpath, $this->options['content'], $file)->parse($records);
             $tmp_files[] = $file;
         } else {
             count($titles) and $contents = array_fill(0, count($titles), '');
         }
         $chunk == 1 and $logger and call_user_func($logger, __('Composing dates...', 'wp_all_import_plugin'));
         if ('specific' == $this->options['date_type']) {
             $dates = XmlImportParser::factory($xml, $cxpath, $this->options['date'], $file)->parse($records);
             $tmp_files[] = $file;
             $warned = array();
             // used to prevent the same notice displaying several times
             foreach ($dates as $i => $d) {
                 if ($d == 'now') {
                     $d = current_time('mysql');
                 }
                 // Replace 'now' with the WordPress local time to account for timezone offsets (WordPress references its local time during publishing rather than the server’s time so it should use that)
                 $time = strtotime($d);
                 if (FALSE === $time) {
                     in_array($d, $warned) or $logger and call_user_func($logger, sprintf(__('<b>WARNING</b>: unrecognized date format `%s`, assigning current date', 'wp_all_import_plugin'), $warned[] = $d));
                     $logger and !$is_cron and PMXI_Plugin::$session->warnings++;
                     $time = time();
                 }
                 $dates[$i] = date('Y-m-d H:i:s', $time);
             }
         } else {
             $dates_start = XmlImportParser::factory($xml, $cxpath, $this->options['date_start'], $file)->parse($records);
             $tmp_files[] = $file;
             $dates_end = XmlImportParser::factory($xml, $cxpath, $this->options['date_end'], $file)->parse($records);
             $tmp_files[] = $file;
             $warned = array();
             // used to prevent the same notice displaying several times
             foreach ($dates_start as $i => $d) {
                 $time_start = strtotime($dates_start[$i]);
                 if (FALSE === $time_start) {
                     in_array($dates_start[$i], $warned) or $logger and call_user_func($logger, sprintf(__('<b>WARNING</b>: unrecognized date format `%s`, assigning current date', 'wp_all_import_plugin'), $warned[] = $dates_start[$i]));
                     $logger and !$is_cron and PMXI_Plugin::$session->warnings++;
                     $time_start = time();
                 }
                 $time_end = strtotime($dates_end[$i]);
                 if (FALSE === $time_end) {
                     in_array($dates_end[$i], $warned) or $logger and call_user_func($logger, sprintf(__('<b>WARNING</b>: unrecognized date format `%s`, assigning current date', 'wp_all_import_plugin'), $warned[] = $dates_end[$i]));
                     $logger and !$is_cron and PMXI_Plugin::$session->warnings++;
                     $time_end = time();
                 }
                 $dates[$i] = date('Y-m-d H:i:s', mt_rand($time_start, $time_end));
             }
         }
         // [custom taxonomies]
         require_once ABSPATH . 'wp-admin/includes/taxonomy.php';
         $taxonomies = array();
         $exclude_taxonomies = apply_filters('pmxi_exclude_taxonomies', class_exists('PMWI_Plugin') ? array('post_format', 'product_type', 'product_shipping_class') : array('post_format'));
         $post_taxonomies = array_diff_key(get_taxonomies_by_object_type(array($this->options['custom_type']), 'object'), array_flip($exclude_taxonomies));
         if (!empty($post_taxonomies)) {
             foreach ($post_taxonomies as $ctx) {
                 if ("" == $ctx->labels->name or class_exists('PMWI_Plugin') and strpos($ctx->name, "pa_") === 0 and $this->options['custom_type'] == "product") {
                     continue;
                 }
                 $chunk == 1 and $logger and call_user_func($logger, sprintf(__('Composing terms for `%s` taxonomy...', 'wp_all_import_plugin'), $ctx->labels->name));
                 $tx_name = $ctx->name;
                 $mapping_rules = !empty($this->options['tax_mapping'][$tx_name]) ? json_decode($this->options['tax_mapping'][$tx_name], true) : false;
                 $taxonomies[$tx_name] = array();
                 if (!empty($this->options['tax_logic'][$tx_name]) and !empty($this->options['tax_assing'][$tx_name])) {
                     switch ($this->options['tax_logic'][$tx_name]) {
                         case 'single':
                             if (!empty($this->options['tax_single_xpath'][$tx_name])) {
                                 $txes = XmlImportParser::factory($xml, $cxpath, $this->options['tax_single_xpath'][$tx_name], $file)->parse($records);
                                 $tmp_files[] = $file;
                                 foreach ($txes as $i => $tx) {
                                     $taxonomies[$tx_name][$i][] = wp_all_import_ctx_mapping(array('name' => $tx, 'parent' => false, 'assign' => isset($this->options['term_assing'][$tx_name]) ? $this->options['term_assing'][$tx_name] : true, 'is_mapping' => !empty($this->options['tax_enable_mapping'][$tx_name]), 'hierarchy_level' => 1, 'max_hierarchy_level' => 1), $mapping_rules, $tx_name);
                                 }
                             }
                             break;
                         case 'multiple':
                             if (!empty($this->options['tax_multiple_xpath'][$tx_name])) {
                                 $txes = XmlImportParser::factory($xml, $cxpath, $this->options['tax_multiple_xpath'][$tx_name], $file)->parse($records);
                                 $tmp_files[] = $file;
                                 foreach ($txes as $i => $tx) {
                                     $_tx = $tx;
                                     // apply mapping rules before splitting via separator symbol
                                     if (!empty($this->options['tax_enable_mapping'][$tx_name]) and !empty($this->options['tax_logic_mapping'][$tx_name])) {
                                         if (!empty($mapping_rules)) {
                                             foreach ($mapping_rules as $rule) {
                                                 if (!empty($rule[trim($_tx)])) {
                                                     $_tx = trim($rule[trim($_tx)]);
                                                     break;
                                                 }
                                             }
                                         }
                                     }
                                     $delimeted_taxonomies = explode(!empty($this->options['tax_multiple_delim'][$tx_name]) ? $this->options['tax_multiple_delim'][$tx_name] : ',', $_tx);
                                     if (!empty($delimeted_taxonomies)) {
                                         foreach ($delimeted_taxonomies as $cc) {
                                             $taxonomies[$tx_name][$i][] = wp_all_import_ctx_mapping(array('name' => $cc, 'parent' => false, 'assign' => isset($this->options['multiple_term_assing'][$tx_name]) ? $this->options['multiple_term_assing'][$tx_name] : true, 'is_mapping' => !empty($this->options['tax_enable_mapping'][$tx_name]) and empty($this->options['tax_logic_mapping'][$tx_name]), 'hierarchy_level' => 1, 'max_hierarchy_level' => 1), $mapping_rules, $tx_name);
                                         }
                                     }
                                 }
                             }
                             break;
                         case 'hierarchical':
                             if (!empty($this->options['tax_hierarchical_logic_entire'][$tx_name])) {
                                 if (!empty($this->options['tax_hierarchical_xpath'][$tx_name]) and is_array($this->options['tax_hierarchical_xpath'][$tx_name])) {
                                     count($titles) and $iterator = array_fill(0, count($titles), 0);
                                     $taxonomies_hierarchy_groups = array_fill(0, count($titles), array());
                                     // separate hierarchy groups via symbol
                                     if (!empty($this->options['is_tax_hierarchical_group_delim'][$tx_name]) and !empty($this->options['tax_hierarchical_group_delim'][$tx_name])) {
                                         foreach ($this->options['tax_hierarchical_xpath'][$tx_name] as $k => $tx_xpath) {
                                             if (empty($tx_xpath)) {
                                                 continue;
                                             }
                                             $txes = XmlImportParser::factory($xml, $cxpath, $tx_xpath, $file)->parse($records);
                                             $tmp_files[] = $file;
                                             foreach ($txes as $i => $tx) {
                                                 $_tx = $tx;
                                                 // apply mapping rules before splitting via separator symbol
                                                 if (!empty($this->options['tax_enable_mapping'][$tx_name]) and !empty($this->options['tax_logic_mapping'][$tx_name])) {
                                                     if (!empty($mapping_rules)) {
                                                         foreach ($mapping_rules as $rule) {
                                                             if (!empty($rule[trim($_tx)])) {
                                                                 $_tx = trim($rule[trim($_tx)]);
                                                                 break;
                                                             }
                                                         }
                                                     }
                                                 }
                                                 $delimeted_groups = explode($this->options['tax_hierarchical_group_delim'][$tx_name], $_tx);
                                                 if (!empty($delimeted_groups) and is_array($delimeted_groups)) {
                                                     foreach ($delimeted_groups as $group) {
                                                         if (!empty($group)) {
                                                             array_push($taxonomies_hierarchy_groups[$i], $group);
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     } else {
                                         foreach ($this->options['tax_hierarchical_xpath'][$tx_name] as $k => $tx_xpath) {
                                             if (empty($tx_xpath)) {
                                                 continue;
                                             }
                                             $txes = XmlImportParser::factory($xml, $cxpath, $tx_xpath, $file)->parse($records);
                                             $tmp_files[] = $file;
                                             foreach ($txes as $i => $tx) {
                                                 array_push($taxonomies_hierarchy_groups[$i], $tx);
                                             }
                                         }
                                     }
                                     foreach ($taxonomies_hierarchy_groups as $i => $groups) {
                                         if (empty($groups)) {
                                             continue;
                                         }
                                         foreach ($groups as $kk => $tx) {
                                             $_tx = $tx;
                                             // apply mapping rules before splitting via separator symbol
                                             if (!empty($this->options['tax_enable_mapping'][$tx_name]) and !empty($this->options['tax_logic_mapping'][$tx_name])) {
                                                 if (!empty($mapping_rules)) {
                                                     foreach ($mapping_rules as $rule) {
                                                         if (!empty($rule[trim($_tx)])) {
                                                             $_tx = trim($rule[trim($_tx)]);
                                                             break;
                                                         }
                                                     }
                                                 }
                                             }
                                             $delimeted_taxonomies = explode(!empty($this->options['tax_hierarchical_delim'][$tx_name]) ? $this->options['tax_hierarchical_delim'][$tx_name] : ',', $_tx);
                                             if (!empty($delimeted_taxonomies)) {
                                                 foreach ($delimeted_taxonomies as $j => $cc) {
                                                     $is_assign_term = isset($this->options['tax_hierarchical_assing'][$tx_name][$k]) ? $this->options['tax_hierarchical_assing'][$tx_name][$k] : true;
                                                     if (!empty($this->options['tax_hierarchical_last_level_assign'][$tx_name])) {
                                                         $is_assign_term = count($delimeted_taxonomies) == $j + 1 ? 1 : 0;
                                                     }
                                                     $taxonomies[$tx_name][$i][] = wp_all_import_ctx_mapping(array('name' => $cc, 'parent' => (!empty($taxonomies[$tx_name][$i][$iterator[$i] - 1]) and $j) ? $taxonomies[$tx_name][$i][$iterator[$i] - 1] : false, 'assign' => $is_assign_term, 'is_mapping' => !empty($this->options['tax_enable_mapping'][$tx_name]) and empty($this->options['tax_logic_mapping'][$tx_name]), 'hierarchy_level' => $j + 1, 'max_hierarchy_level' => count($delimeted_taxonomies)), $mapping_rules, $tx_name);
                                                     $iterator[$i]++;
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                             if (!empty($this->options['tax_hierarchical_logic_manual'][$tx_name])) {
                                 if (!empty($this->options['post_taxonomies'][$tx_name])) {
                                     $taxonomies_hierarchy = json_decode($this->options['post_taxonomies'][$tx_name], true);
                                     foreach ($taxonomies_hierarchy as $k => $taxonomy) {
                                         if ("" == $taxonomy['xpath']) {
                                             continue;
                                         }
                                         $txes_raw = XmlImportParser::factory($xml, $cxpath, $taxonomy['xpath'], $file)->parse($records);
                                         $tmp_files[] = $file;
                                         $warned = array();
                                         foreach ($txes_raw as $i => $cc) {
                                             $_tx = $cc;
                                             // apply mapping rules before splitting via separator symbol
                                             if (!empty($this->options['tax_enable_mapping'][$tx_name]) and !empty($this->options['tax_logic_mapping'][$tx_name])) {
                                                 if (!empty($mapping_rules)) {
                                                     foreach ($mapping_rules as $rule) {
                                                         if (!empty($rule[trim($_tx)])) {
                                                             $_tx = trim($rule[trim($_tx)]);
                                                             break;
                                                         }
                                                     }
                                                 }
                                             }
                                             if (!empty($this->options['tax_manualhierarchy_delim'][$tx_name])) {
                                                 $delimeted_taxonomies = explode($this->options['tax_manualhierarchy_delim'][$tx_name], $_tx);
                                             }
                                             if (empty($delimeted_taxonomies)) {
                                                 continue;
                                             }
                                             if (empty($taxonomies_hierarchy[$k]['txn_names'][$i])) {
                                                 $taxonomies_hierarchy[$k]['txn_names'][$i] = array();
                                             }
                                             if (empty($taxonomies[$tx_name][$i])) {
                                                 $taxonomies[$tx_name][$i] = array();
                                             }
                                             $count_cats = count($taxonomies[$tx_name][$i]);
                                             foreach ($delimeted_taxonomies as $j => $dc) {
                                                 if (!empty($taxonomy['parent_id'])) {
                                                     foreach ($taxonomies_hierarchy as $key => $value) {
                                                         if ($value['item_id'] == $taxonomy['parent_id'] and !empty($value['txn_names'][$i])) {
                                                             foreach ($value['txn_names'][$i] as $parent) {
                                                                 $taxonomies[$tx_name][$i][] = wp_all_import_ctx_mapping(array('name' => trim($dc), 'parent' => $parent, 'assign' => isset($taxonomy['assign']) ? $taxonomy['assign'] : true, 'is_mapping' => !empty($this->options['tax_enable_mapping'][$tx_name]) and empty($this->options['tax_logic_mapping'][$tx_name]), 'hierarchy_level' => 1, 'max_hierarchy_level' => 1), $mapping_rules, $tx_name);
                                                             }
                                                         }
                                                     }
                                                 } else {
                                                     $taxonomies[$tx_name][$i][] = wp_all_import_ctx_mapping(array('name' => trim($dc), 'parent' => false, 'assign' => isset($taxonomy['assign']) ? $taxonomy['assign'] : true, 'is_mapping' => !empty($this->options['tax_enable_mapping'][$tx_name]) and empty($this->options['tax_logic_mapping'][$tx_name]), 'hierarchy_level' => 1, 'max_hierarchy_level' => 1), $mapping_rules, $tx_name);
                                                 }
                                                 if ($count_cats < count($taxonomies[$tx_name][$i])) {
                                                     $taxonomies_hierarchy[$k]['txn_names'][$i][] = $taxonomies[$tx_name][$i][count($taxonomies[$tx_name][$i]) - 1];
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                             break;
                         default:
                             break;
                     }
                 }
             }
         }
         // [/custom taxonomies]
         // Composing featured images
         $image_sections = apply_filters('wp_all_import_image_sections', array(array('slug' => '', 'title' => __('Images', 'wp_all_import_plugin'), 'type' => 'images')));
         if (!(($uploads = wp_upload_dir()) && false === $uploads['error'])) {
             $logger and call_user_func($logger, __('<b>WARNING</b>', 'wp_all_import_plugin') . ': ' . $uploads['error']);
             $logger and call_user_func($logger, __('<b>WARNING</b>: No featured images will be created. Uploads folder is not found.', 'wp_all_import_plugin'));
             $logger and !$is_cron and PMXI_Plugin::$session->warnings++;
         } else {
             $images_bundle = array();
             foreach ($image_sections as $section) {
                 $chunk == 1 and $logger and call_user_func($logger, __('Composing URLs for ' . strtolower($section['title']) . '...', 'wp_all_import_plugin'));
                 $featured_images = array();
                 if ("no" == $this->options[$section['slug'] . 'download_images']) {
                     if ($this->options[$section['slug'] . 'featured_image']) {
                         $featured_images = XmlImportParser::factory($xml, $cxpath, $this->options[$section['slug'] . 'featured_image'], $file)->parse($records);
                         $tmp_files[] = $file;
                     } else {
                         count($titles) and $featured_images = array_fill(0, count($titles), '');
                     }
                 } else {
                     if ($this->options[$section['slug'] . 'download_featured_image']) {
                         $featured_images = XmlImportParser::factory($xml, $cxpath, $this->options[$section['slug'] . 'download_featured_image'], $file)->parse($records);
                         $tmp_files[] = $file;
                     } else {
                         count($titles) and $featured_images = array_fill(0, count($titles), '');
                     }
                 }
                 $images_bundle[empty($section['slug']) ? 'pmxi_gallery_image' : $section['slug']] = array('type' => $section['type'], 'files' => $featured_images);
                 // Composing images meta titles
                 $image_meta_titles_bundle = array();
                 if ($this->options[$section['slug'] . 'set_image_meta_title']) {
                     $chunk == 1 and $logger and call_user_func($logger, __('Composing ' . strtolower($section['title']) . ' meta data (titles)...', 'wp_all_import_plugin'));
                     $image_meta_titles = array();
                     if ($this->options[$section['slug'] . 'image_meta_title']) {
                         $image_meta_titles = XmlImportParser::factory($xml, $cxpath, $this->options[$section['slug'] . 'image_meta_title'], $file)->parse($records);
                         $tmp_files[] = $file;
                     } else {
                         count($titles) and $image_meta_titles = array_fill(0, count($titles), '');
                     }
                     $image_meta_titles_bundle[empty($section['slug']) ? 'pmxi_gallery_image' : $section['slug']] = $image_meta_titles;
                 }
                 // Composing images meta captions
                 $image_meta_captions_bundle = array();
                 if ($this->options[$section['slug'] . 'set_image_meta_caption']) {
                     $chunk == 1 and $logger and call_user_func($logger, __('Composing ' . strtolower($section['title']) . ' meta data (captions)...', 'wp_all_import_plugin'));
                     $image_meta_captions = array();
                     if ($this->options[$section['slug'] . 'image_meta_caption']) {
                         $image_meta_captions = XmlImportParser::factory($xml, $cxpath, $this->options[$section['slug'] . 'image_meta_caption'], $file)->parse($records);
                         $tmp_files[] = $file;
                     } else {
                         count($titles) and $image_meta_captions = array_fill(0, count($titles), '');
                     }
                     $image_meta_captions_bundle[empty($section['slug']) ? 'pmxi_gallery_image' : $section['slug']] = $image_meta_captions;
                 }
                 // Composing images meta alt text
                 $image_meta_alts_bundle = array();
                 if ($this->options[$section['slug'] . 'set_image_meta_alt']) {
                     $chunk == 1 and $logger and call_user_func($logger, __('Composing ' . strtolower($section['title']) . ' meta data (alt text)...', 'wp_all_import_plugin'));
                     $image_meta_alts = array();
                     if ($this->options[$section['slug'] . 'image_meta_alt']) {
                         $image_meta_alts = XmlImportParser::factory($xml, $cxpath, $this->options[$section['slug'] . 'image_meta_alt'], $file)->parse($records);
                         $tmp_files[] = $file;
                     } else {
                         count($titles) and $image_meta_alts = array_fill(0, count($titles), '');
                     }
                     $image_meta_alts_bundle[empty($section['slug']) ? 'pmxi_gallery_image' : $section['slug']] = $image_meta_alts;
                 }
                 // Composing images meta description
                 $image_meta_descriptions_bundle = array();
                 if ($this->options[$section['slug'] . 'set_image_meta_description']) {
                     $chunk == 1 and $logger and call_user_func($logger, __('Composing ' . strtolower($section['title']) . ' meta data (description)...', 'wp_all_import_plugin'));
                     $image_meta_descriptions = array();
                     if ($this->options[$section['slug'] . 'image_meta_description']) {
                         $image_meta_descriptions = XmlImportParser::factory($xml, $cxpath, $this->options[$section['slug'] . 'image_meta_description'], $file)->parse($records);
                         $tmp_files[] = $file;
                     } else {
                         count($titles) and $image_meta_descriptions = array_fill(0, count($titles), '');
                     }
                     $image_meta_descriptions_bundle[empty($section['slug']) ? 'pmxi_gallery_image' : $section['slug']] = $image_meta_descriptions;
                 }
                 $auto_rename_images_bundle = array();
                 $auto_extensions_bundle = array();
                 if ("yes" == $this->options[$section['slug'] . 'download_images']) {
                     // Composing images suffix
                     $chunk == 1 and $this->options[$section['slug'] . 'auto_rename_images'] and $logger and call_user_func($logger, __('Composing ' . strtolower($section['title']) . ' suffix...', 'wp_all_import_plugin'));
                     $auto_rename_images = array();
                     if ($this->options[$section['slug'] . 'auto_rename_images'] and !empty($this->options[$section['slug'] . 'auto_rename_images_suffix'])) {
                         $auto_rename_images = XmlImportParser::factory($xml, $cxpath, $this->options[$section['slug'] . 'auto_rename_images_suffix'], $file)->parse($records);
                         $tmp_files[] = $file;
                     } else {
                         count($titles) and $auto_rename_images = array_fill(0, count($titles), '');
                     }
                     $auto_rename_images_bundle[empty($section['slug']) ? 'pmxi_gallery_image' : $section['slug']] = $auto_rename_images;
                     // Composing images extensions
                     $chunk == 1 and $this->options[$section['slug'] . 'auto_set_extension'] and $logger and call_user_func($logger, __('Composing ' . strtolower($section['title']) . ' extensions...', 'wp_all_import_plugin'));
                     $auto_extensions = array();
                     if ($this->options[$section['slug'] . 'auto_set_extension'] and !empty($this->options[$section['slug'] . 'new_extension'])) {
                         $auto_extensions = XmlImportParser::factory($xml, $cxpath, $this->options[$section['slug'] . 'new_extension'], $file)->parse($records);
                         $tmp_files[] = $file;
                     } else {
                         count($titles) and $auto_extensions = array_fill(0, count($titles), '');
                     }
                     $auto_extensions_bundle[empty($section['slug']) ? 'pmxi_gallery_image' : $section['slug']] = $auto_extensions;
                 }
             }
         }
         // Composing attachments
         if (!(($uploads = wp_upload_dir()) && false === $uploads['error'])) {
             $logger and call_user_func($logger, __('<b>WARNING</b>', 'wp_all_import_plugin') . ': ' . $uploads['error']);
             $logger and call_user_func($logger, __('<b>WARNING</b>: No attachments will be created', 'wp_all_import_plugin'));
             $logger and !$is_cron and PMXI_Plugin::$session->warnings++;
         } else {
             $chunk == 1 and $logger and call_user_func($logger, __('Composing URLs for attachments files...', 'wp_all_import_plugin'));
             $attachments = array();
             if ($this->options['attachments']) {
                 // Detect if attachments is separated by comma
                 $atchs = explode(',', $this->options['attachments']);
                 if (!empty($atchs)) {
                     $parse_multiple = true;
                     foreach ($atchs as $atch) {
                         if (!preg_match("/{.*}/", trim($atch))) {
                             $parse_multiple = false;
                         }
                     }
                     if ($parse_multiple) {
                         foreach ($atchs as $atch) {
                             $posts_attachments = XmlImportParser::factory($xml, $cxpath, trim($atch), $file)->parse($records);
                             $tmp_files[] = $file;
                             foreach ($posts_attachments as $i => $val) {
                                 $attachments[$i][] = $val;
                             }
                         }
                     } else {
                         $attachments = XmlImportParser::factory($xml, $cxpath, $this->options['attachments'], $file)->parse($records);
                         $tmp_files[] = $file;
                     }
                 }
             } else {
                 count($titles) and $attachments = array_fill(0, count($titles), '');
             }
         }
         $chunk == 1 and $logger and call_user_func($logger, __('Composing unique keys...', 'wp_all_import_plugin'));
         if (!empty($this->options['unique_key'])) {
             $unique_keys = XmlImportParser::factory($xml, $cxpath, $this->options['unique_key'], $file)->parse($records);
             $tmp_files[] = $file;
         } else {
             count($titles) and $unique_keys = array_fill(0, count($titles), '');
         }
         $chunk == 1 and $logger and call_user_func($logger, __('Processing posts...', 'wp_all_import_plugin'));
         $addons = array();
         $addons_data = array();
         // data parsing for WP All Import add-ons
         $chunk == 1 and $logger and call_user_func($logger, __('Data parsing via add-ons...', 'wp_all_import_plugin'));
         $parsingData = array('import' => $this, 'count' => count($titles), 'xml' => $xml, 'logger' => $logger, 'chunk' => $chunk, 'xpath_prefix' => $xpath_prefix);
         $parse_functions = apply_filters('wp_all_import_addon_parse', array());
         foreach (PMXI_Admin_Addons::get_active_addons() as $class) {
             $model_class = str_replace("_Plugin", "_Import_Record", $class);
             if (class_exists($model_class)) {
                 $addons[$class] = new $model_class();
                 $addons_data[$class] = method_exists($addons[$class], 'parse') ? $addons[$class]->parse($parsingData) : false;
             } else {
                 if (!empty($parse_functions[$class])) {
                     if (is_array($parse_functions[$class]) and is_callable($parse_functions[$class]) or !is_array($parse_functions[$class]) and function_exists($parse_functions[$class])) {
                         $addons_data[$class] = call_user_func($parse_functions[$class], $parsingData);
                     }
                 }
             }
         }
         // save current import state to variables before import
         $created = $this->created;
         $updated = $this->updated;
         $skipped = $this->skipped;
         $specified_records = array();
         if ($this->options['is_import_specified']) {
             $chunk == 1 and $logger and call_user_func($logger, __('Calculate specified records to import...', 'wp_all_import_plugin'));
             foreach (preg_split('% *, *%', $this->options['import_specified'], -1, PREG_SPLIT_NO_EMPTY) as $chank) {
                 if (preg_match('%^(\\d+)-(\\d+)$%', $chank, $mtch)) {
                     $specified_records = array_merge($specified_records, range(intval($mtch[1]), intval($mtch[2])));
                 } else {
                     $specified_records = array_merge($specified_records, array(intval($chank)));
                 }
             }
         }
         $simpleXml = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA);
         $rootNodes = $simpleXml->xpath($cxpath);
         foreach ($titles as $i => $void) {
             $custom_type_details = get_post_type_object($post_type[$i]);
             if ($is_cron and $cron_sleep) {
                 sleep($cron_sleep);
             }
             $logger and call_user_func($logger, __('---', 'wp_all_import_plugin'));
             $logger and call_user_func($logger, sprintf(__('Record #%s', 'wp_all_import_plugin'), $this->imported + $this->skipped + $i + 1));
             wp_cache_flush();
             $logger and call_user_func($logger, __('<b>ACTION</b>: pmxi_before_post_import ...', 'wp_all_import_plugin'));
             do_action('pmxi_before_post_import', $this->id);
             if (empty($titles[$i])) {
                 if (!empty($addons_data['PMWI_Plugin']) and !empty($addons_data['PMWI_Plugin']['single_product_parent_ID'][$i])) {
                     $titles[$i] = $addons_data['PMWI_Plugin']['single_product_parent_ID'][$i] . ' Product Variation';
                 } else {
                     $logger and call_user_func($logger, __('<b>WARNING</b>: title is empty.', 'wp_all_import_plugin'));
                     $logger and !$is_cron and PMXI_Plugin::$session->warnings++;
                 }
             }
             if ($this->options['custom_type'] == 'import_users') {
                 $articleData = array('user_pass' => $addons_data['PMUI_Plugin']['pmui_pass'][$i], 'user_login' => $addons_data['PMUI_Plugin']['pmui_logins'][$i], 'user_nicename' => $addons_data['PMUI_Plugin']['pmui_nicename'][$i], 'user_url' => $addons_data['PMUI_Plugin']['pmui_url'][$i], 'user_email' => $addons_data['PMUI_Plugin']['pmui_email'][$i], 'display_name' => $addons_data['PMUI_Plugin']['pmui_display_name'][$i], 'user_registered' => $addons_data['PMUI_Plugin']['pmui_registered'][$i], 'first_name' => $addons_data['PMUI_Plugin']['pmui_first_name'][$i], 'last_name' => $addons_data['PMUI_Plugin']['pmui_last_name'][$i], 'description' => $addons_data['PMUI_Plugin']['pmui_description'][$i], 'nickname' => $addons_data['PMUI_Plugin']['pmui_nickname'][$i], 'role' => '' == $addons_data['PMUI_Plugin']['pmui_role'][$i] ? 'subscriber' : strtolower($addons_data['PMUI_Plugin']['pmui_role'][$i]));
                 $logger and call_user_func($logger, sprintf(__('Combine all data for user %s...', 'wp_all_import_plugin'), $articleData['user_login']));
             } else {
                 $articleData = array('post_type' => $post_type[$i], 'post_status' => "xpath" == $this->options['status'] ? $post_status[$i] : $this->options['status'], 'comment_status' => "xpath" == $this->options['comment_status'] ? $comment_status[$i] : $this->options['comment_status'], 'ping_status' => "xpath" == $this->options['ping_status'] ? $ping_status[$i] : $this->options['ping_status'], 'post_title' => !empty($this->options['is_leave_html']) ? html_entity_decode($titles[$i]) : $titles[$i], 'post_excerpt' => apply_filters('pmxi_the_excerpt', !empty($this->options['is_leave_html']) ? html_entity_decode($post_excerpt[$i]) : $post_excerpt[$i], $this->id), 'post_name' => $post_slug[$i], 'post_content' => apply_filters('pmxi_the_content', !empty($this->options['is_leave_html']) ? html_entity_decode($contents[$i]) : $contents[$i], $this->id), 'post_date' => $dates[$i], 'post_date_gmt' => get_gmt_from_date($dates[$i]), 'post_author' => $post_author[$i], 'menu_order' => (int) $menu_order[$i], 'post_parent' => "no" == $this->options['is_multiple_page_parent'] ? (int) $page_parent[$i] : (int) $this->options['parent']);
                 $logger and call_user_func($logger, sprintf(__('Combine all data for post `%s`...', 'wp_all_import_plugin'), $articleData['post_title']));
             }
             // Re-import Records Matching
             $post_to_update = false;
             $post_to_update_id = false;
             // if Auto Matching re-import option selected
             if ("manual" != $this->options['duplicate_matching']) {
                 // find corresponding article among previously imported
                 $logger and call_user_func($logger, sprintf(__('Find corresponding article among previously imported for post `%s`...', 'wp_all_import_plugin'), $articleData['post_title']));
                 $postRecord->clear();
                 $postRecord->getBy(array('unique_key' => $unique_keys[$i], 'import_id' => $this->id));
                 if (!$postRecord->isEmpty()) {
                     $logger and call_user_func($logger, sprintf(__('Duplicate post was founded for post %s with unique key `%s`...', 'wp_all_import_plugin'), $articleData['post_title'], $unique_keys[$i]));
                     if ($this->options['custom_type'] == 'import_users') {
                         $post_to_update = get_user_by('id', $post_to_update_id = $postRecord->post_id);
                     } else {
                         $post_to_update = get_post($post_to_update_id = $postRecord->post_id);
                     }
                 } else {
                     $logger and call_user_func($logger, sprintf(__('Duplicate post wasn\'t founded with unique key `%s`...', 'wp_all_import_plugin'), $unique_keys[$i]));
                 }
                 // if Manual Matching re-import option seleted
             } else {
                 if ('custom field' == $this->options['duplicate_indicator']) {
                     $custom_duplicate_value = XmlImportParser::factory($xml, $cxpath, $this->options['custom_duplicate_value'], $file)->parse($records);
                     $tmp_files[] = $file;
                     $custom_duplicate_name = XmlImportParser::factory($xml, $cxpath, $this->options['custom_duplicate_name'], $file)->parse($records);
                     $tmp_files[] = $file;
                 } else {
                     count($titles) and $custom_duplicate_name = $custom_duplicate_value = array_fill(0, count($titles), '');
                 }
                 $logger and call_user_func($logger, sprintf(__('Find corresponding article among database for post `%s`...', 'wp_all_import_plugin'), $articleData['post_title']));
                 // handle duplicates according to import settings
                 if ($duplicates = pmxi_findDuplicates($articleData, $custom_duplicate_name[$i], $custom_duplicate_value[$i], $this->options['duplicate_indicator'])) {
                     $duplicate_id = array_shift($duplicates);
                     if ($duplicate_id) {
                         $logger and call_user_func($logger, sprintf(__('Duplicate post was founded for post `%s`...', 'wp_all_import_plugin'), $articleData['post_title']));
                         if ($this->options['custom_type'] == 'import_users') {
                             $post_to_update = get_user_by('id', $post_to_update_id = $duplicate_id);
                         } else {
                             $post_to_update = get_post($post_to_update_id = $duplicate_id);
                         }
                     } else {
                         $logger and call_user_func($logger, sprintf(__('Duplicate post wasn\'n founded for post `%s`...', 'wp_all_import_plugin'), $articleData['post_title']));
                     }
                 }
             }
             if (!empty($specified_records)) {
                 if (!in_array($created + $updated + $skipped + 1, $specified_records)) {
                     if (!$postRecord->isEmpty()) {
                         $postRecord->set(array('iteration' => $this->iteration))->update();
                     }
                     $skipped++;
                     $logger and call_user_func($logger, __('<b>SKIPPED</b>: by specified records option', 'wp_all_import_plugin'));
                     $logger and !$is_cron and PMXI_Plugin::$session->warnings++;
                     $logger and !$is_cron and PMXI_Plugin::$session->chunk_number++;
                     $logger and !$is_cron and PMXI_Plugin::$session->save_data();
                     continue;
                 }
             }
             // Duplicate record is founded
             if ($post_to_update) {
                 $continue_import = true;
                 $continue_import = apply_filters('wp_all_import_is_post_to_update', $post_to_update_id, wp_all_import_xml2array($rootNodes[$i]));
                 if (!$continue_import) {
                     if (!$postRecord->isEmpty()) {
                         $postRecord->set(array('iteration' => $this->iteration))->update();
                     }
                     $skipped++;
                     $logger and call_user_func($logger, sprintf(__('<b>SKIPPED</b>: By filter wp_all_import_is_post_to_update `%s`', 'wp_all_import_plugin'), $articleData['post_title']));
                     $logger and !$is_cron and PMXI_Plugin::$session->warnings++;
                     $logger and !$is_cron and PMXI_Plugin::$session->chunk_number++;
                     $logger and !$is_cron and PMXI_Plugin::$session->save_data();
                     continue;
                 }
                 //$logger and call_user_func($logger, sprintf(__('Duplicate record is founded for `%s`', 'wp_all_import_plugin'), $articleData['post_title']));
                 // Do not update already existing records option selected
                 if ("yes" == $this->options['is_keep_former_posts']) {
                     if (!$postRecord->isEmpty()) {
                         $postRecord->set(array('iteration' => $this->iteration))->update();
                     }
                     do_action('pmxi_do_not_update_existing', $post_to_update_id, $this->id, $this->iteration);
                     $skipped++;
                     $logger and call_user_func($logger, sprintf(__('<b>SKIPPED</b>: Previously imported record found for `%s`', 'wp_all_import_plugin'), $articleData['post_title']));
                     $logger and !$is_cron and PMXI_Plugin::$session->warnings++;
                     $logger and !$is_cron and PMXI_Plugin::$session->chunk_number++;
                     $logger and !$is_cron and PMXI_Plugin::$session->save_data();
                     continue;
                 }
                 $articleData['ID'] = $post_to_update_id;
                 // Choose which data to update
                 if ($this->options['update_all_data'] == 'no') {
                     if (!in_array($this->options['custom_type'], array('import_users'))) {
                         // preserve date of already existing article when duplicate is found
                         if (!$this->options['is_update_categories'] and (is_object_in_taxonomy($post_type[$i], 'category') or is_object_in_taxonomy($post_type[$i], 'post_tag')) or $this->options['is_update_categories'] and $this->options['update_categories_logic'] != "full_update") {
                             $logger and call_user_func($logger, sprintf(__('Preserve taxonomies of already existing article for `%s`', 'wp_all_import_plugin'), $articleData['post_title']));
                             $existing_taxonomies = array();
                             foreach (array_keys($taxonomies) as $tx_name) {
                                 $txes_list = get_the_terms($articleData['ID'], $tx_name);
                                 if (is_wp_error($txes_list)) {
                                     $logger and call_user_func($logger, sprintf(__('<b>WARNING</b>: Unable to get current taxonomies for article #%d, updating with those read from XML file', 'wp_all_import_plugin'), $articleData['ID']));
                                     $logger and !$is_cron and PMXI_Plugin::$session->warnings++;
                                 } else {
                                     $txes_new = array();
                                     if (!empty($txes_list)) {
                                         foreach ($txes_list as $t) {
                                             $txes_new[] = $t->term_taxonomy_id;
                                         }
                                     }
                                     $existing_taxonomies[$tx_name][$i] = $txes_new;
                                 }
                             }
                         }
                         if (!$this->options['is_update_dates']) {
                             // preserve date of already existing article when duplicate is found
                             $articleData['post_date'] = $post_to_update->post_date;
                             $articleData['post_date_gmt'] = $post_to_update->post_date_gmt;
                             $logger and call_user_func($logger, sprintf(__('Preserve date of already existing article for `%s`', 'wp_all_import_plugin'), $articleData['post_title']));
                         }
                         if (!$this->options['is_update_status']) {
                             // preserve status and trashed flag
                             $articleData['post_status'] = $post_to_update->post_status;
                             $logger and call_user_func($logger, sprintf(__('Preserve status of already existing article for `%s`', 'wp_all_import_plugin'), $articleData['post_title']));
                         }
                         if (!$this->options['is_update_content']) {
                             $articleData['post_content'] = $post_to_update->post_content;
                             $logger and call_user_func($logger, sprintf(__('Preserve content of already existing article for `%s`', 'wp_all_import_plugin'), $articleData['post_title']));
                         }
                         if (!$this->options['is_update_title']) {
                             $articleData['post_title'] = $post_to_update->post_title;
                             $logger and call_user_func($logger, sprintf(__('Preserve title of already existing article for `%s`', 'wp_all_import_plugin'), $articleData['post_title']));
                         }
                         if (!$this->options['is_update_slug']) {
                             $articleData['post_name'] = $post_to_update->post_name;
                             $logger and call_user_func($logger, sprintf(__('Preserve slug of already existing article for `%s`', 'wp_all_import_plugin'), $articleData['post_title']));
                         }
                         if (!$this->options['is_update_excerpt']) {
                             $articleData['post_excerpt'] = $post_to_update->post_excerpt;
                             $logger and call_user_func($logger, sprintf(__('Preserve excerpt of already existing article for `%s`', 'wp_all_import_plugin'), $articleData['post_title']));
                         }
                         if (!$this->options['is_update_menu_order']) {
                             $articleData['menu_order'] = $post_to_update->menu_order;
                             $logger and call_user_func($logger, sprintf(__('Preserve menu order of already existing article for `%s`', 'wp_all_import_plugin'), $articleData['post_title']));
                         }
                         if (!$this->options['is_update_parent']) {
                             $articleData['post_parent'] = $post_to_update->post_parent;
                             $logger and call_user_func($logger, sprintf(__('Preserve post parent of already existing article for `%s`', 'wp_all_import_plugin'), $articleData['post_title']));
                         }
                         if (!$this->options['is_update_author']) {
                             $articleData['post_author'] = $post_to_update->post_author;
                             $logger and call_user_func($logger, sprintf(__('Preserve post author of already existing article for `%s`', 'wp_all_import_plugin'), $articleData['post_title']));
                         }
                     } else {
                         if (!$this->options['is_update_first_name']) {
                             $articleData['first_name'] = $post_to_update->first_name;
                         }
                         if (!$this->options['is_update_last_name']) {
                             $articleData['last_name'] = $post_to_update->last_name;
                         }
                         if (!$this->options['is_update_role']) {
                             unset($articleData['role']);
                         }
                         if (!$this->options['is_update_nickname']) {
                             $articleData['nickname'] = get_user_meta($post_to_update->ID, 'nickname', true);
                         }
                         if (!$this->options['is_update_description']) {
                             $articleData['description'] = get_user_meta($post_to_update->ID, 'description', true);
                         }
                         if (!$this->options['is_update_login']) {
                             $articleData['user_login'] = $post_to_update->user_login;
                         }
                         if (!$this->options['is_update_password']) {
                             unset($articleData['user_pass']);
                         }
                         if (!$this->options['is_update_nicename']) {
                             $articleData['user_nicename'] = $post_to_update->user_nicename;
                         }
                         if (!$this->options['is_update_email']) {
                             $articleData['user_email'] = $post_to_update->user_email;
                         }
                         if (!$this->options['is_update_registered']) {
                             $articleData['user_registered'] = $post_to_update->user_registered;
                         }
                         if (!$this->options['is_update_display_name']) {
                             $articleData['display_name'] = $post_to_update->display_name;
                         }
                         if (!$this->options['is_update_url']) {
                             $articleData['user_url'] = $post_to_update->user_url;
                         }
                     }
                     $logger and call_user_func($logger, sprintf(__('Applying filter `pmxi_article_data` for `%s`', 'wp_all_import_plugin'), $articleData['post_title']));
                     $articleData = apply_filters('pmxi_article_data', $articleData, $this, $post_to_update);
                 }
                 if (!in_array($this->options['custom_type'], array('import_users'))) {
                     if ($this->options['update_all_data'] == 'yes' or $this->options['update_all_data'] == 'no' and $this->options['is_update_attachments']) {
                         $logger and call_user_func($logger, sprintf(__('Deleting attachments for `%s`', 'wp_all_import_plugin'), $articleData['post_title']));
                         wp_delete_attachments($articleData['ID'], true, 'files');
                     }
                     // handle obsolete attachments (i.e. delete or keep) according to import settings
                     if ($this->options['update_all_data'] == 'yes' or $this->options['update_all_data'] == 'no' and $this->options['is_update_images'] and $this->options['update_images_logic'] == "full_update") {
                         $logger and call_user_func($logger, sprintf(__('Deleting images for `%s`', 'wp_all_import_plugin'), $articleData['post_title']));
                         wp_delete_attachments($articleData['ID'], !$this->options['do_not_remove_images'], 'images');
                     }
                 }
             } elseif (!$postRecord->isEmpty()) {
                 // existing post not found though it's track was found... clear the leftover, plugin will continue to treat record as new
                 $postRecord->clear();
             }
             // no new records are created. it will only update posts it finds matching duplicates for
             if (!$this->options['create_new_records'] and empty($articleData['ID'])) {
                 if (!$postRecord->isEmpty()) {
                     $postRecord->set(array('iteration' => $this->iteration))->update();
                 }
                 $logger and call_user_func($logger, __('<b>SKIPPED</b>: by do not create new posts option.', 'wp_all_import_plugin'));
                 $logger and !$is_cron and PMXI_Plugin::$session->warnings++;
                 $logger and !$is_cron and PMXI_Plugin::$session->chunk_number++;
                 $skipped++;
                 $logger and !$is_cron and PMXI_Plugin::$session->save_data();
                 continue;
             }
             // cloak urls with `WP Wizard Cloak` if corresponding option is set
             if (!empty($this->options['is_cloak']) and class_exists('PMLC_Plugin')) {
                 if (preg_match_all('%<a\\s[^>]*href=(?(?=")"([^"]*)"|(?(?=\')\'([^\']*)\'|([^\\s>]*)))%is', $articleData['post_content'], $matches, PREG_PATTERN_ORDER)) {
                     $hrefs = array_unique(array_merge(array_filter($matches[1]), array_filter($matches[2]), array_filter($matches[3])));
                     foreach ($hrefs as $url) {
                         if (preg_match('%^\\w+://%i', $url)) {
                             // mask only links having protocol
                             // try to find matching cloaked link among already registered ones
                             $list = new PMLC_Link_List();
                             $linkTable = $list->getTable();
                             $rule = new PMLC_Rule_Record();
                             $ruleTable = $rule->getTable();
                             $dest = new PMLC_Destination_Record();
                             $destTable = $dest->getTable();
                             $list->join($ruleTable, "{$ruleTable}.link_id = {$linkTable}.id")->join($destTable, "{$destTable}.rule_id = {$ruleTable}.id")->setColumns("{$linkTable}.*")->getBy(array("{$linkTable}.destination_type =" => 'ONE_SET', "{$linkTable}.is_trashed =" => 0, "{$linkTable}.preset =" => '', "{$linkTable}.expire_on =" => '0000-00-00', "{$ruleTable}.type =" => 'ONE_SET', "{$destTable}.weight =" => 100, "{$destTable}.url LIKE" => $url), NULL, 1, 1)->convertRecords();
                             if ($list->count()) {
                                 // matching link found
                                 $link = $list[0];
                             } else {
                                 // register new cloaked link
                                 global $wpdb;
                                 $slug = max(intval($wpdb->get_var("SELECT MAX(CONVERT(name, SIGNED)) FROM {$linkTable}")), intval($wpdb->get_var("SELECT MAX(CONVERT(slug, SIGNED)) FROM {$linkTable}")), 0);
                                 $i = 0;
                                 do {
                                     is_int(++$slug) and $slug > 0 or $slug = 1;
                                     $is_slug_found = !intval($wpdb->get_var("SELECT COUNT(*) FROM {$linkTable} WHERE name = '{$slug}' OR slug = '{$slug}'"));
                                 } while (!$is_slug_found and $i++ < 100000);
                                 if ($is_slug_found) {
                                     $link = new PMLC_Link_Record(array('name' => strval($slug), 'slug' => strval($slug), 'header_tracking_code' => '', 'footer_tracking_code' => '', 'redirect_type' => '301', 'destination_type' => 'ONE_SET', 'preset' => '', 'forward_url_params' => 1, 'no_global_tracking_code' => 0, 'expire_on' => '0000-00-00', 'created_on' => date('Y-m-d H:i:s'), 'is_trashed' => 0));
                                     $link->insert();
                                     $rule = new PMLC_Rule_Record(array('link_id' => $link->id, 'type' => 'ONE_SET', 'rule' => ''));
                                     $rule->insert();
                                     $dest = new PMLC_Destination_Record(array('rule_id' => $rule->id, 'url' => $url, 'weight' => 100));
                                     $dest->insert();
                                 } else {
                                     $logger and call_user_func($logger, sprintf(__('<b>WARNING</b>: Unable to create cloaked link for %s', 'wp_all_import_plugin'), $url));
                                     $logger and !$is_cron and PMXI_Plugin::$session->warnings++;
                                     $link = NULL;
                                 }
                             }
                             if ($link) {
                                 // cloaked link is found or created for url
                                 $articleData['post_content'] = preg_replace('%' . preg_quote($url, '%') . '(?=([\\s\'"]|$))%i', $link->getUrl(), $articleData['post_content']);
                             }
                         }
                     }
                 }
             }
             // insert article being imported
             if ($this->options['is_fast_mode']) {
                 foreach (array('transition_post_status', 'save_post', 'pre_post_update', 'add_attachment', 'edit_attachment', 'edit_post', 'post_updated', 'wp_insert_post', 'save_post_' . $post_type[$i]) as $act) {
                     remove_all_actions($act);
                 }
             }
             if (!in_array($this->options['custom_type'], array('import_users'))) {
                 if (empty($articleData['ID'])) {
                     $logger and call_user_func($logger, sprintf(__('<b>CREATING</b> `%s` `%s`', 'wp_all_import_plugin'), $articleData['post_title'], $custom_type_details->labels->singular_name));
                 } else {
                     $logger and call_user_func($logger, sprintf(__('<b>UPDATING</b> `%s` `%s`', 'wp_all_import_plugin'), $articleData['post_title'], $custom_type_details->labels->singular_name));
                 }
                 $pid = wp_insert_post($articleData, true);
             } else {
                 $pid = empty($articleData['ID']) ? wp_insert_user($articleData) : wp_update_user($articleData);
                 $articleData['post_title'] = $articleData['user_login'];
             }
             if (is_wp_error($pid)) {
                 $logger and call_user_func($logger, __('<b>ERROR</b>', 'wp_all_import_plugin') . ': ' . $pid->get_error_message());
                 $logger and !$is_cron and PMXI_Plugin::$session->errors++;
                 $skipped++;
             } else {
                 if ("manual" != $this->options['duplicate_matching'] or empty($articleData['ID'])) {
                     // associate post with import
                     $postRecord->isEmpty() and $postRecord->set(array('post_id' => $pid, 'import_id' => $this->id, 'unique_key' => $unique_keys[$i], 'product_key' => ($post_type[$i] == "product" and PMXI_Admin_Addons::get_addon('PMWI_Plugin')) ? $addons_data['PMWI_Plugin']['single_product_ID'][$i] : ''))->insert();
                     $postRecord->set(array('iteration' => $this->iteration))->update();
                     $logger and call_user_func($logger, sprintf(__('Associate post `%s` with current import ...', 'wp_all_import_plugin'), $articleData['post_title']));
                 }
                 // [post format]
                 if (current_theme_supports('post-formats') && post_type_supports($post_type[$i], 'post-formats')) {
                     set_post_format($pid, "xpath" == $this->options['post_format'] ? $post_format[$i] : $this->options['post_format']);
                     $logger and call_user_func($logger, sprintf(__('Associate post `%s` with post format %s ...', 'wp_all_import_plugin'), $articleData['post_title'], "xpath" == $this->options['post_format'] ? $post_format[$i] : $this->options['post_format']));
                 }
                 // [/post format]
                 // [addons import]
                 // prepare data for import
                 $importData = array('pid' => $pid, 'i' => $i, 'import' => $this, 'articleData' => $articleData, 'xml' => $xml, 'is_cron' => $is_cron, 'logger' => $logger, 'xpath_prefix' => $xpath_prefix, 'post_type' => $post_type[$i]);
                 $import_functions = apply_filters('wp_all_import_addon_import', array());
                 // deligate operation to addons
                 foreach (PMXI_Admin_Addons::get_active_addons() as $class) {
                     if (class_exists($class)) {
                         if (method_exists($addons[$class], 'import')) {
                             $addons[$class]->import($importData);
                         }
                     } else {
                         if (!empty($import_functions[$class])) {
                             if (is_array($import_functions[$class]) and is_callable($import_functions[$class]) or !is_array($import_functions[$class]) and function_exists($import_functions[$class])) {
                                 call_user_func($import_functions[$class], $importData, $addons_data[$class]);
                             }
                         }
                     }
                 }
                 // [/addons import]
                 // Page Template
                 if ('page' == $articleData['post_type'] and wp_all_import_is_update_cf('_wp_page_template', $this->options) and (!empty($this->options['page_template']) or "no" == $this->options['is_multiple_page_template'])) {
                     update_post_meta($pid, '_wp_page_template', "no" == $this->options['is_multiple_page_template'] ? $page_template[$i] : $this->options['page_template']);
                 }
                 // [featured image]
                 $is_allow_import_images = apply_filters('wp_all_import_is_allow_import_images', false, $articleData['post_type']);
                 if (!empty($uploads) and false === $uploads['error'] and ($articleData['post_type'] == "product" and class_exists('PMWI_Plugin') or $is_allow_import_images) and (empty($articleData['ID']) or $this->options['update_all_data'] == "yes" or $this->options['update_all_data'] == "no" and $this->options['is_update_images'])) {
                     if (!empty($images_bundle)) {
                         $is_show_add_new_images = apply_filters('wp_all_import_is_show_add_new_images', true, $post_type[$i]);
                         foreach ($images_bundle as $slug => $bundle_data) {
                             $featured_images = $bundle_data['files'];
                             $option_slug = $slug == 'pmxi_gallery_image' ? '' : $slug;
                             if (!empty($featured_images[$i])) {
                                 $targetDir = $uploads['path'];
                                 $targetUrl = $uploads['url'];
                                 $logger and call_user_func($logger, __('<b>IMAGES:</b>', 'wp_all_import_plugin'));
                                 if (!@is_writable($targetDir)) {
                                     $logger and call_user_func($logger, sprintf(__('<b>ERROR</b>: Target directory %s is not writable', 'wp_all_import_plugin'), $targetDir));
                                 } else {
                                     require_once ABSPATH . 'wp-admin/includes/image.php';
                                     $success_images = false;
                                     $gallery_attachment_ids = array();
                                     $imgs = array();
                                     $featured_delim = "yes" == $this->options[$option_slug . 'download_images'] ? $this->options[$option_slug . 'download_featured_delim'] : $this->options[$option_slug . 'featured_delim'];
                                     $line_imgs = explode("\n", $featured_images[$i]);
                                     if (!empty($line_imgs)) {
                                         foreach ($line_imgs as $line_img) {
                                             $imgs = array_merge($imgs, !empty($featured_delim) ? str_getcsv($line_img, $featured_delim) : array($line_img));
                                         }
                                     }
                                     // keep existing and add newest images
                                     if (!empty($articleData['ID']) and $this->options['is_update_images'] and $this->options['update_images_logic'] == "add_new" and $this->options['update_all_data'] == "no" and $is_show_add_new_images) {
                                         $logger and call_user_func($logger, __('- Keep existing and add newest images ...', 'wp_all_import_plugin'));
                                         $attachment_imgs = get_attached_media('image', $pid);
                                         if ($post_type[$i] == "product") {
                                             $gallery_attachment_ids = array_filter(explode(",", get_post_meta($pid, '_product_image_gallery', true)));
                                         }
                                         if ($attachment_imgs) {
                                             foreach ($attachment_imgs as $attachment_img) {
                                                 $post_thumbnail_id = get_post_thumbnail_id($pid);
                                                 if (empty($post_thumbnail_id) and $this->options[$option_slug . 'is_featured']) {
                                                     set_post_thumbnail($pid, $attachment_img->ID);
                                                 } elseif (!in_array($attachment_img->ID, $gallery_attachment_ids) and $post_thumbnail_id != $attachment_img->ID) {
                                                     $gallery_attachment_ids[] = $attachment_img->ID;
                                                 }
                                             }
                                             $success_images = true;
                                         }
                                         if (!empty($gallery_attachment_ids)) {
                                             foreach ($gallery_attachment_ids as $aid) {
                                                 do_action($slug, $pid, $aid, wp_get_attachment_url($aid), 'update_images');
                                             }
                                         }
                                     }
                                     if (!empty($imgs)) {
                                         if ($this->options[$option_slug . 'set_image_meta_title'] and !empty($image_meta_titles_bundle[$slug])) {
                                             $img_titles = array();
                                             $line_img_titles = explode("\n", $image_meta_titles_bundle[$slug][$i]);
                                             if (!empty($line_img_titles)) {
                                                 foreach ($line_img_titles as $line_img_title) {
                                                     $img_titles = array_merge($img_titles, !empty($this->options[$option_slug . 'image_meta_title_delim']) ? str_getcsv($line_img_title, $this->options[$option_slug . 'image_meta_title_delim']) : array($line_img_title));
                                                 }
                                             }
                                         }
                                         if ($this->options[$option_slug . 'set_image_meta_caption'] and !empty($image_meta_captions_bundle[$slug])) {
                                             $img_captions = array();
                                             $line_img_captions = explode("\n", $image_meta_captions_bundle[$slug][$i]);
                                             if (!empty($line_img_captions)) {
                                                 foreach ($line_img_captions as $line_img_caption) {
                                                     $img_captions = array_merge($img_captions, !empty($this->options[$option_slug . 'image_meta_caption_delim']) ? str_getcsv($line_img_caption, $this->options[$option_slug . 'image_meta_caption_delim']) : array($line_img_caption));
                                                 }
                                             }
                                         }
                                         if ($this->options[$option_slug . 'set_image_meta_alt'] and !empty($image_meta_alts_bundle[$slug])) {
                                             $img_alts = array();
                                             $line_img_alts = explode("\n", $image_meta_alts_bundle[$slug][$i]);
                                             if (!empty($line_img_alts)) {
                                                 foreach ($line_img_alts as $line_img_alt) {
                                                     $img_alts = array_merge($img_alts, !empty($this->options[$option_slug . 'image_meta_alt_delim']) ? str_getcsv($line_img_alt, $this->options[$option_slug . 'image_meta_alt_delim']) : array($line_img_alt));
                                                 }
                                             }
                                         }
                                         if ($this->options[$option_slug . 'set_image_meta_description'] and !empty($image_meta_descriptions_bundle[$slug])) {
                                             $img_descriptions = array();
                                             $line_img_descriptions = explode("\n", $image_meta_descriptions_bundle[$slug][$i]);
                                             if (!empty($line_img_descriptions)) {
                                                 foreach ($line_img_descriptions as $line_img_description) {
                                                     $img_descriptions = array_merge($img_descriptions, !empty($this->options[$option_slug . 'image_meta_description_delim']) ? str_getcsv($line_img_description, $this->options[$option_slug . 'image_meta_description_delim']) : array($line_img_description));
                                                 }
                                             }
                                         }
                                         $is_keep_existing_images = (!empty($articleData['ID']) and $this->options['is_update_images'] and $this->options['update_images_logic'] == "add_new" and $this->options['update_all_data'] == "no" and $is_show_add_new_images);
                                         foreach ($imgs as $k => $img_url) {
                                             if (empty($img_url)) {
                                                 continue;
                                             }
                                             $attid = false;
                                             $attch = null;
                                             $url = str_replace(" ", "%20", trim($img_url));
                                             $bn = basename($url);
                                             if ("yes" == $this->options[$option_slug . 'download_images'] and !empty($auto_extensions_bundle[$slug][$i]) and preg_match('%^(jpg|jpeg|png|gif)$%i', $auto_extensions_bundle[$slug][$i])) {
                                                 $img_ext = $auto_extensions_bundle[$slug][$i];
                                             } else {
                                                 $img_ext = pmxi_getExtensionFromStr($url);
                                                 $default_extension = pmxi_getExtension($bn);
                                                 if ($img_ext == "") {
                                                     $img_ext = pmxi_get_remote_image_ext($url);
                                                 }
                                             }
                                             $logger and call_user_func($logger, sprintf(__('- Importing image `%s` for `%s` ...', 'wp_all_import_plugin'), $img_url, $articleData['post_title']));
                                             // generate local file name
                                             $image_name = urldecode(($this->options[$option_slug . 'auto_rename_images'] and !empty($auto_rename_images_bundle[$slug][$i])) ? sanitize_file_name($img_ext ? str_replace("." . $default_extension, "", $auto_rename_images_bundle[$slug][$i]) : $auto_rename_images_bundle[$slug][$i]) : sanitize_file_name($img_ext ? str_replace("." . $default_extension, "", $bn) : $bn)) . ("" != $img_ext ? '.' . $img_ext : '');
                                             // if wizard store image data to custom field
                                             $create_image = false;
                                             $download_image = true;
                                             $wp_filetype = false;
                                             if ($bundle_data['type'] == 'images' and base64_decode($url, true) !== false) {
                                                 $img = @imagecreatefromstring(base64_decode($url));
                                                 if ($img) {
                                                     $logger and call_user_func($logger, __('- Founded base64_encoded image', 'wp_all_import_plugin'));
                                                     $image_filename = md5(time()) . '.jpg';
                                                     $image_filepath = $targetDir . '/' . $image_filename;
                                                     imagejpeg($img, $image_filepath);
                                                     if (!($image_info = @getimagesize($image_filepath)) or !in_array($image_info[2], array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG))) {
                                                         $logger and call_user_func($logger, sprintf(__('- <b>WARNING</b>: File %s is not a valid image and cannot be set as featured one', 'wp_all_import_plugin'), $image_filepath));
                                                         $logger and !$is_cron and PMXI_Plugin::$session->warnings++;
                                                     } else {
                                                         $create_image = true;
                                                     }
                                                 }
                                             } else {
                                                 $image_filename = wp_unique_filename($targetDir, $image_name);
                                                 $image_filepath = $targetDir . '/' . $image_filename;
                                                 // keep existing and add newest images
                                                 if ($is_keep_existing_images) {
                                                     $attch = $this->wpdb->get_row($this->wpdb->prepare("SELECT * FROM " . $this->wpdb->posts . " WHERE (post_title = %s OR post_title = %s OR post_name = %s) AND post_type = %s AND post_parent = %d;", $image_name, preg_replace('/\\.[^.\\s]{3,4}$/', '', $image_name), sanitize_title($image_name), "attachment", $pid));
                                                     if ($attch != null) {
                                                         $post_thumbnail_id = get_post_thumbnail_id($pid);
                                                         if ($post_thumbnail_id == $attch->ID or in_array($attch->ID, $gallery_attachment_ids)) {
                                                             continue;
                                                         }
                                                     } elseif (file_exists($targetDir . '/' . $image_name)) {
                                                         if ($bundle_data['type'] == 'images' and $img_meta = wp_read_image_metadata($targetDir . '/' . $image_name)) {
                                                             if (trim($img_meta['title']) && !is_numeric(sanitize_title($img_meta['title']))) {
                                                                 $img_title = $img_meta['title'];
                                                                 $attch = $this->wpdb->get_row($this->wpdb->prepare("SELECT * FROM " . $this->wpdb->posts . " WHERE post_title = %s AND post_type = %s AND post_parent = %d;", $img_title, "attachment", $pid));
                                                                 if ($attch != null) {
                                                                     $post_thumbnail_id = get_post_thumbnail_id($pid);
                                                                     if ($post_thumbnail_id == $attch->ID or in_array($attch->ID, $gallery_attachment_ids)) {
                                                                         continue;
                                                                     }
                                                                 }
                                                             }
                                                         }
                                                     }
                                                 }
                                                 // search existing attachment
                                                 if ($this->options[$option_slug . 'search_existing_images']) {
                                                     $image_filename = $image_name;
                                                     $attch = $this->wpdb->get_row($this->wpdb->prepare("SELECT * FROM " . $this->wpdb->posts . " WHERE (post_title = %s OR post_title = %s OR post_name = %s) AND post_type = %s;", $image_name, preg_replace('/\\.[^.\\s]{3,4}$/', '', $image_name), sanitize_title($image_name), "attachment"));
                                                     if ($attch != null) {
                                                         $download_image = false;
                                                         $attid = $attch->ID;
                                                     } elseif (@file_exists($targetDir . '/' . $image_name)) {
                                                         if ($bundle_data['type'] == 'images' and $img_meta = wp_read_image_metadata($targetDir . '/' . $image_name)) {
                                                             if (trim($img_meta['title']) && !is_numeric(sanitize_title($img_meta['title']))) {
                                                                 $img_title = $img_meta['title'];
                                                                 $attch = $this->wpdb->get_row($this->wpdb->prepare("SELECT * FROM " . $this->wpdb->posts . " WHERE post_title = %s AND post_type = %s AND post_parent = %d;", $img_title, "attachment", $pid));
                                                                 if ($attch != null) {
                                                                     $download_image = false;
                                                                     $attid = $attch->ID;
                                                                 }
                                                             }
                                                         }
                                                     }
                                                 }
                                                 if ($download_image) {
                                                     // do not download images
                                                     if ("yes" != $this->options[$option_slug . 'download_images']) {
                                                         $image_filename = $image_name;
                                                         $image_filepath = $targetDir . '/' . $image_filename;
                                                         $wpai_uploads = $uploads['basedir'] . DIRECTORY_SEPARATOR . PMXI_Plugin::FILES_DIRECTORY . DIRECTORY_SEPARATOR;
                                                         $wpai_image_path = $wpai_uploads . str_replace('%20', ' ', $url);
                                                         $logger and call_user_func($logger, sprintf(__('- Searching for existing image `%s` in `%s` folder', 'wp_all_import_plugin'), $wpai_image_path, $wpai_uploads));
                                                         if (@file_exists($wpai_image_path) and @copy($wpai_image_path, $image_filepath)) {
                                                             $download_image = false;
                                                             // valdate import attachments
                                                             if ($bundle_data['type'] == 'files') {
                                                                 if (!($wp_filetype = wp_check_filetype(basename($image_filepath), null))) {
                                                                     $logger and call_user_func($logger, sprintf(__('- <b>WARNING</b>: Can\'t detect attachment file type %s', 'wp_all_import_plugin'), trim($image_filepath)));
                                                                     $logger and !$is_cron and PMXI_Plugin::$session->warnings++;
                                                                     @unlink($image_filepath);
                                                                 } else {
                                                                     $create_image = true;
                                                                     $logger and call_user_func($logger, sprintf(__('- File `%s` has been successfully founded', 'wp_all_import_plugin'), $wpai_image_path));
                                                                 }
                                                             } elseif ($bundle_data['type'] == 'images') {
                                                                 if (!($image_info = @getimagesize($image_filepath)) or !in_array($image_info[2], array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG))) {
                                                                     $logger and call_user_func($logger, sprintf(__('- <b>WARNING</b>: File %s is not a valid image and cannot be set as featured one', 'wp_all_import_plugin'), $image_filepath));
                                                                     $logger and !$is_cron and PMXI_Plugin::$session->warnings++;
                                                                     @unlink($image_filepath);
                                                                 } else {
                                                                     $create_image = true;
                                                                     $logger and call_user_func($logger, sprintf(__('- Image `%s` has been successfully founded', 'wp_all_import_plugin'), $wpai_image_path));
                                                                 }
                                                             }
                                                         }
                                                     } else {
                                                         $logger and call_user_func($logger, sprintf(__('- Downloading image from `%s`', 'wp_all_import_plugin'), $url));
                                                         $request = get_file_curl($url, $image_filepath);
                                                         if ((is_wp_error($request) or $request === false) and !@file_put_contents($image_filepath, @file_get_contents($url))) {
                                                             @unlink($image_filepath);
                                                             // delete file since failed upload may result in empty file created
                                                         } else {
                                                             if ($bundle_data['type'] == 'images') {
                                                                 if ($image_info = @getimagesize($image_filepath) and in_array($image_info[2], array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG))) {
                                                                     $create_image = true;
                                                                     $logger and call_user_func($logger, sprintf(__('- Image `%s` has been successfully downloaded', 'wp_all_import_plugin'), $url));
                                                                 }
                                                             } elseif ($bundle_data['type'] == 'files') {
                                                                 if ($wp_filetype = wp_check_filetype(basename($image_filepath), null)) {
                                                                     $create_image = true;
                                                                     $logger and call_user_func($logger, sprintf(__('- File `%s` has been successfully downloaded', 'wp_all_import_plugin'), $url));
                                                                 }
                                                             }
                                                         }
                                                         if (!$create_image) {
                                                             $url = str_replace(" ", "%20", trim(pmxi_convert_encoding($img_url)));
                                                             $request = get_file_curl($url, $image_filepath);
                                                             if ((is_wp_error($request) or $request === false) and !@file_put_contents($image_filepath, @file_get_contents($url))) {
                                                                 $logger and call_user_func($logger, sprintf(__('- <b>WARNING</b>: File %s cannot be saved locally as %s', 'wp_all_import_plugin'), $url, $image_filepath));
                                                                 $logger and !$is_cron and PMXI_Plugin::$session->warnings++;
                                                                 @unlink($image_filepath);
                                                                 // delete file since failed upload may result in empty file created
                                                             } else {
                                                                 if ($bundle_data['type'] == 'images') {
                                                                     if (!($image_info = @getimagesize($image_filepath)) or !in_array($image_info[2], array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG))) {
                                                                         $logger and call_user_func($logger, sprintf(__('- <b>WARNING</b>: File %s is not a valid image and cannot be set as featured one', 'wp_all_import_plugin'), $url));
                                                                         $logger and !$is_cron and PMXI_Plugin::$session->warnings++;
                                                                         @unlink($image_filepath);
                                                                     } else {
                                                                         $create_image = true;
                                                                         $logger and call_user_func($logger, sprintf(__('- Image `%s` has been successfully downloaded', 'wp_all_import_plugin'), $url));
                                                                     }
                                                                 } elseif ($bundle_data['type'] == 'files') {
                                                                     if (!($wp_filetype = wp_check_filetype(basename($image_filepath), null))) {
                                                                         $logger and call_user_func($logger, sprintf(__('- <b>WARNING</b>: Can\'t detect attachment file type %s', 'wp_all_import_plugin'), trim($url)));
                                                                         $logger and !$is_cron and PMXI_Plugin::$session->warnings++;
                                                                         @unlink($image_filepath);
                                                                     } else {
                                                                         $create_image = true;
                                                                         $logger and call_user_func($logger, sprintf(__('- File `%s` has been successfully founded', 'wp_all_import_plugin'), $url));
                                                                     }
                                                                 }
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                             if ($create_image) {
                                                 $logger and call_user_func($logger, sprintf(__('- Creating an attachment for image `%s`', 'wp_all_import_plugin'), $targetUrl . '/' . $image_filename));
                                                 $attachment = array('post_mime_type' => $bundle_data['type'] == 'images' ? image_type_to_mime_type($image_info[2]) : $wp_filetype['type'], 'guid' => $targetUrl . '/' . $image_filename, 'post_title' => $image_name, 'post_content' => '', 'post_author' => $post_author[$i]);
                                                 if ($bundle_data['type'] == 'images' and $image_meta = wp_read_image_metadata($image_filepath)) {
                                                     if (trim($image_meta['title']) && !is_numeric(sanitize_title($image_meta['title']))) {
                                                         $attachment['post_title'] = $image_meta['title'];
                                                     }
                                                     if (trim($image_meta['caption'])) {
                                                         $attachment['post_content'] = $image_meta['caption'];
                                                     }
                                                 }
                                                 $attid = wp_insert_attachment($attachment, $image_filepath, $pid);
                                                 if (is_wp_error($attid)) {
                                                     $logger and call_user_func($logger, __('- <b>WARNING</b>', 'wp_all_import_plugin') . ': ' . $attid->get_error_message());
                                                     $logger and !$is_cron and PMXI_Plugin::$session->warnings++;
                                                 } else {
                                                     // 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';
                                                     wp_update_attachment_metadata($attid, wp_generate_attachment_metadata($attid, $image_filepath));
                                                     $update_attachment_meta = array();
                                                     if ($this->options[$option_slug . 'set_image_meta_title'] and !empty($img_titles[$k])) {
                                                         $update_attachment_meta['post_title'] = $img_titles[$k];
                                                     }
                                                     if ($this->options[$option_slug . 'set_image_meta_caption'] and !empty($img_captions[$k])) {
                                                         $update_attachment_meta['post_excerpt'] = $img_captions[$k];
                                                     }
                                                     if ($this->options[$option_slug . 'set_image_meta_description'] and !empty($img_descriptions[$k])) {
                                                         $update_attachment_meta['post_content'] = $img_descriptions[$k];
                                                     }
                                                     if ($this->options[$option_slug . 'set_image_meta_alt'] and !empty($img_alts[$k])) {
                                                         update_post_meta($attid, '_wp_attachment_image_alt', $img_alts[$k]);
                                                     }
                                                     if (!empty($update_attachment_meta)) {
                                                         $this->wpdb->update($this->wpdb->posts, $update_attachment_meta, array('ID' => $attid));
                                                     }
                                                 }
                                             }
                                             if ($attid) {
                                                 if ($attch != null and empty($attch->post_parent)) {
                                                     wp_update_post(array('ID' => $attch->ID, 'post_parent' => $pid));
                                                 }
                                                 $logger and call_user_func($logger, __('- <b>ACTION</b>: ' . $slug, 'wp_all_import_plugin'));
                                                 do_action($slug, $pid, $attid, $image_filepath, $is_keep_existing_images ? 'add_images' : 'update_images');
                                                 $success_images = true;
                                                 $post_thumbnail_id = get_post_thumbnail_id($pid);
                                                 if ($bundle_data['type'] == 'images' and empty($post_thumbnail_id) and $this->options[$option_slug . 'is_featured']) {
                                                     set_post_thumbnail($pid, $attid);
                                                 } elseif (!in_array($attid, $gallery_attachment_ids) and $post_thumbnail_id != $attid) {
                                                     $gallery_attachment_ids[] = $attid;
                                                 }
                                                 $logger and call_user_func($logger, sprintf(__('- Attachment has been successfully created for image `%s`', 'wp_all_import_plugin'), $targetUrl . '/' . $image_filename));
                                             }
                                         }
                                     }
                                     // Set product gallery images
                                     if ($post_type[$i] == "product") {
                                         update_post_meta($pid, '_product_image_gallery', !empty($gallery_attachment_ids) ? implode(',', $gallery_attachment_ids) : '');
                                     }
                                     // Create entry as Draft if no images are downloaded successfully
                                     if (!$success_images and "yes" == $this->options[$option_slug . 'create_draft']) {
                                         $this->wpdb->update($this->wpdb->posts, array('post_status' => 'draft'), array('ID' => $pid));
                                         $logger and call_user_func($logger, sprintf(__('- Post `%s` saved as Draft, because no images are downloaded successfully', 'wp_all_import_plugin'), $articleData['post_title']));
                                     }
                                 }
                             } else {
                                 // Create entry as Draft if no images are downloaded successfully
                                 if ("yes" == $this->options[$option_slug . 'create_draft']) {
                                     $this->wpdb->update($this->wpdb->posts, array('post_status' => 'draft'), array('ID' => $pid));
                                     $logger and call_user_func($logger, sprintf(__('Post `%s` saved as Draft, because no images are downloaded successfully', 'wp_all_import_plugin'), $articleData['post_title']));
                                 }
                             }
                         }
                     }
                 } else {
                     if (!empty($images_bundle)) {
                         foreach ($images_bundle as $slug => $bundle_data) {
                             if (!empty($bundle_data['images'][$i])) {
                                 $imgs = array();
                                 $featured_delim = "yes" == $this->options[$option_slug . 'download_images'] ? $this->options[$option_slug . 'download_featured_delim'] : $this->options[$option_slug . 'featured_delim'];
                                 $line_imgs = explode("\n", $bundle_data['images'][$i]);
                                 if (!empty($line_imgs)) {
                                     foreach ($line_imgs as $line_img) {
                                         $imgs = array_merge($imgs, !empty($featured_delim) ? str_getcsv($line_img, $featured_delim) : array($line_img));
                                     }
                                 }
                                 foreach ($imgs as $img) {
                                     do_action($slug, $pid, false, $img, false);
                                 }
                             }
                         }
                     }
                 }
                 // [/featured image]
                 // [attachments]
                 if (!empty($uploads) and false === $uploads['error'] and !empty($attachments[$i]) and (empty($articleData['ID']) or $this->options['update_all_data'] == "yes" or $this->options['update_all_data'] == "no" and $this->options['is_update_attachments'])) {
                     $targetDir = $uploads['path'];
                     $targetUrl = $uploads['url'];
                     $logger and call_user_func($logger, __('<b>ATTACHMENTS:</b>', 'wp_all_import_plugin'));
                     if (!@is_writable($targetDir)) {
                         $logger and call_user_func($logger, sprintf(__('- <b>ERROR</b>: Target directory %s is not writable', 'wp_all_import_plugin'), trim($targetDir)));
                     } else {
                         // 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';
                         if (!is_array($attachments[$i])) {
                             $attachments[$i] = array($attachments[$i]);
                         }
                         $logger and call_user_func($logger, sprintf(__('- Importing attachments for `%s` ...', 'wp_all_import_plugin'), $articleData['post_title']));
                         foreach ($attachments[$i] as $attachment) {
                             if ("" == $attachment) {
                                 continue;
                             }
                             $atchs = str_getcsv($attachment, $this->options['atch_delim']);
                             if (!empty($atchs)) {
                                 foreach ($atchs as $atch_url) {
                                     if (empty($atch_url)) {
                                         continue;
                                     }
                                     $download_file = true;
                                     $atch_url = str_replace(" ", "%20", trim($atch_url));
                                     $attachment_filename = urldecode(basename(parse_url(trim($atch_url), PHP_URL_PATH)));
                                     $attachment_filepath = $targetDir . '/' . sanitize_file_name($attachment_filename);
                                     if ($this->options['is_search_existing_attach']) {
                                         // search existing attachment
                                         $attch = $this->wpdb->get_row($this->wpdb->prepare("SELECT * FROM " . $this->wpdb->posts . " WHERE (post_title = %s OR post_title = %s OR post_name = %s OR post_name = %s) AND post_type = %s;", $attachment_filename, preg_replace('/\\.[^.\\s]{3,4}$/', '', $attachment_filename), sanitize_title($attachment_filename), sanitize_title(preg_replace('/\\.[^.\\s]{3,4}$/', '', $attachment_filename)), "attachment"));
                                         if ($attch != null) {
                                             $download_file = false;
                                             $attach_id = $attch->ID;
                                         }
                                     }
                                     if ($download_file) {
                                         $attachment_filename = wp_unique_filename($targetDir, $attachment_filename);
                                         $attachment_filepath = $targetDir . '/' . sanitize_file_name($attachment_filename);
                                         $logger and call_user_func($logger, sprintf(__('- Filename for attachment was generated as %s', 'wp_all_import_plugin'), $attachment_filename));
                                         $request = get_file_curl(trim($atch_url), $attachment_filepath);
                                         if ((is_wp_error($request) or $request === false) and !@file_put_contents($attachment_filepath, @file_get_contents(trim($atch_url)))) {
                                             $logger and call_user_func($logger, sprintf(__('- <b>WARNING</b>: Attachment file %s cannot be saved locally as %s', 'wp_all_import_plugin'), trim($atch_url), $attachment_filepath));
                                             is_wp_error($request) and $logger and call_user_func($logger, sprintf(__('- <b>WP Error</b>: %s', 'wp_all_import_plugin'), $request->get_error_message()));
                                             $logger and !$is_cron and PMXI_Plugin::$session->warnings++;
                                             unlink($attachment_filepath);
                                             // delete file since failed upload may result in empty file created
                                         } elseif (!($wp_filetype = wp_check_filetype(basename($attachment_filename), null))) {
                                             $logger and call_user_func($logger, sprintf(__('- <b>WARNING</b>: Can\'t detect attachment file type %s', 'wp_all_import_plugin'), trim($atch_url)));
                                             $logger and !$is_cron and PMXI_Plugin::$session->warnings++;
                                         } else {
                                             $logger and call_user_func($logger, sprintf(__('- File %s has been successfully downloaded', 'wp_all_import_plugin'), $atch_url));
                                             $attachment_data = array('guid' => $targetUrl . '/' . basename($attachment_filepath), 'post_mime_type' => $wp_filetype['type'], 'post_title' => preg_replace('/\\.[^.]+$/', '', basename($attachment_filepath)), 'post_content' => '', 'post_status' => 'inherit', 'post_author' => $post_author[$i]);
                                             $attach_id = wp_insert_attachment($attachment_data, $attachment_filepath, $pid);
                                             if (is_wp_error($attach_id)) {
                                                 $logger and call_user_func($logger, __('- <b>WARNING</b>', 'wp_all_import_plugin') . ': ' . $pid->get_error_message());
                                                 $logger and !$is_cron and PMXI_Plugin::$session->warnings++;
                                             } else {
                                                 wp_update_attachment_metadata($attach_id, wp_generate_attachment_metadata($attach_id, $attachment_filepath));
                                                 $logger and call_user_func($logger, sprintf(__('- Attachment has been successfully created for post `%s`', 'wp_all_import_plugin'), $articleData['post_title']));
                                                 $logger and call_user_func($logger, __('- <b>ACTION</b>: pmxi_attachment_uploaded', 'wp_all_import_plugin'));
                                                 do_action('pmxi_attachment_uploaded', $pid, $attach_id, $attachment_filepath);
                                             }
                                         }
                                     } else {
                                         $logger and call_user_func($logger, __('- <b>ACTION</b>: pmxi_attachment_uploaded', 'wp_all_import_plugin'));
                                         do_action('pmxi_attachment_uploaded', $pid, $attach_id, $attachment_filepath);
                                     }
                                 }
                             }
                         }
                     }
                 }
                 // [/attachments]
                 // [custom taxonomies]
                 if (!empty($taxonomies)) {
                     $logger and call_user_func($logger, __('<b>TAXONOMIES:</b>', 'wp_all_import_plugin'));
                     foreach ($taxonomies as $tx_name => $txes) {
                         // Skip updating product attributes
                         if (PMXI_Admin_Addons::get_addon('PMWI_Plugin') and strpos($tx_name, "pa_") === 0) {
                             continue;
                         }
                         if (empty($articleData['ID']) or $this->options['update_all_data'] == "yes" or $this->options['update_all_data'] == "no" and $this->options['is_update_categories']) {
                             $logger and call_user_func($logger, sprintf(__('- Importing taxonomy `%s` ...', 'wp_all_import_plugin'), $tx_name));
                             if (!empty($this->options['tax_logic'][$tx_name]) and $this->options['tax_logic'][$tx_name] == 'hierarchical' and !empty($this->options['tax_hierarchical_logic'][$tx_name]) and $this->options['tax_hierarchical_logic'][$tx_name] == 'entire') {
                                 $logger and call_user_func($logger, sprintf(__('- Auto-nest enabled with separator `%s` ...', 'wp_all_import_plugin'), !empty($this->options['tax_hierarchical_delim'][$tx_name]) ? $this->options['tax_hierarchical_delim'][$tx_name] : ','));
                             }
                             if (!empty($articleData['ID'])) {
                                 if ($this->options['update_all_data'] == "no" and $this->options['update_categories_logic'] == "all_except" and !empty($this->options['taxonomies_list']) and is_array($this->options['taxonomies_list']) and in_array($tx_name, $this->options['taxonomies_list'])) {
                                     $logger and call_user_func($logger, sprintf(__('- %s %s `%s` has been skipped attempted to `Leave these taxonomies alone, update all others`...', 'wp_all_import_plugin'), $custom_type_details->labels->singular_name, $tx_name, $single_tax['name']));
                                     continue;
                                 }
                                 if ($this->options['update_all_data'] == "no" and $this->options['update_categories_logic'] == "only" and (!empty($this->options['taxonomies_list']) and is_array($this->options['taxonomies_list']) and !in_array($tx_name, $this->options['taxonomies_list']) or empty($this->options['taxonomies_list']))) {
                                     $logger and call_user_func($logger, sprintf(__('- %s %s `%s` has been skipped attempted to `Update only these taxonomies, leave the rest alone`...', 'wp_all_import_plugin'), $custom_type_details->labels->singular_name, $tx_name, $single_tax['name']));
                                     continue;
                                 }
                             }
                             $assign_taxes = array();
                             if ($this->options['update_categories_logic'] == "add_new" and !empty($existing_taxonomies[$tx_name][$i])) {
                                 $assign_taxes = $existing_taxonomies[$tx_name][$i];
                                 unset($existing_taxonomies[$tx_name][$i]);
                             } elseif (!empty($existing_taxonomies[$tx_name][$i])) {
                                 unset($existing_taxonomies[$tx_name][$i]);
                             }
                             // create term if not exists
                             if (!empty($txes[$i])) {
                                 foreach ($txes[$i] as $key => $single_tax) {
                                     $is_created_term = false;
                                     if (is_array($single_tax) and !empty($single_tax['name'])) {
                                         $parent_id = !empty($single_tax['parent']) ? pmxi_recursion_taxes($single_tax['parent'], $tx_name, $txes[$i], $key) : '';
                                         $term = empty($this->options['tax_is_full_search_' . $this->options['tax_logic'][$tx_name]][$tx_name]) ? term_exists($single_tax['name'], $tx_name, (int) $parent_id) : term_exists($single_tax['name'], $tx_name);
                                         if (empty($term) and !is_wp_error($term)) {
                                             $term = empty($this->options['tax_is_full_search_' . $this->options['tax_logic'][$tx_name]][$tx_name]) ? term_exists(htmlspecialchars($single_tax['name']), $tx_name, (int) $parent_id) : term_exists(htmlspecialchars($single_tax['name']), $tx_name);
                                             if (empty($term) and !is_wp_error($term)) {
                                                 $term_attr = array('parent' => !empty($parent_id) ? $parent_id : 0);
                                                 $term = wp_insert_term($single_tax['name'], $tx_name, $term_attr);
                                                 if (!is_wp_error($term)) {
                                                     $is_created_term = true;
                                                     if (empty($parent_id)) {
                                                         $logger and call_user_func($logger, sprintf(__('- Creating parent %s %s `%s` ...', 'wp_all_import_plugin'), $custom_type_details->labels->singular_name, $tx_name, $single_tax['name']));
                                                     } else {
                                                         $logger and call_user_func($logger, sprintf(__('- Creating child %s %s for %s named `%s` ...', 'wp_all_import_plugin'), $custom_type_details->labels->singular_name, $tx_name, is_array($single_tax['parent']) ? $single_tax['parent']['name'] : $single_tax['parent'], $single_tax['name']));
                                                     }
                                                 }
                                             }
                                         }
                                         if (is_wp_error($term)) {
                                             $logger and call_user_func($logger, sprintf(__('- <b>WARNING</b>: `%s`', 'wp_all_import_plugin'), $term->get_error_message()));
                                             $logger and !$is_cron and PMXI_Plugin::$session->warnings++;
                                         } elseif (!empty($term)) {
                                             $cat_id = $term['term_id'];
                                             if ($cat_id and $single_tax['assign']) {
                                                 $term = get_term_by('id', $cat_id, $tx_name);
                                                 if ($term->parent != '0' and !empty($this->options['tax_is_full_search_' . $this->options['tax_logic'][$tx_name]][$tx_name]) and empty($this->options['tax_assign_to_one_term_' . $this->options['tax_logic'][$tx_name]][$tx_name])) {
                                                     $parent_ids = wp_all_import_get_parent_terms($cat_id, $tx_name);
                                                     if (!empty($parent_ids)) {
                                                         foreach ($parent_ids as $p) {
                                                             if (!in_array($p, $assign_taxes)) {
                                                                 $assign_taxes[] = $p;
                                                             }
                                                         }
                                                     }
                                                 }
                                                 if (!in_array($term->term_taxonomy_id, $assign_taxes)) {
                                                     $assign_taxes[] = $term->term_taxonomy_id;
                                                 }
                                                 if (!$is_created_term) {
                                                     if (empty($parent_id)) {
                                                         $logger and call_user_func($logger, sprintf(__('- Attempted to create parent %s %s `%s`, duplicate detected. Importing %s to existing `%s` %s, ID %d, slug `%s` ...', 'wp_all_import_plugin'), $custom_type_details->labels->singular_name, $tx_name, $single_tax['name'], $custom_type_details->labels->singular_name, $term->name, $tx_name, $term->term_id, $term->slug));
                                                     } else {
                                                         $logger and call_user_func($logger, sprintf(__('- Attempted to create child %s %s `%s`, duplicate detected. Importing %s to existing `%s` %s, ID %d, slug `%s` ...', 'wp_all_import_plugin'), $custom_type_details->labels->singular_name, $tx_name, $single_tax['name'], $custom_type_details->labels->singular_name, $term->name, $tx_name, $term->term_id, $term->slug));
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                             // associate taxes with post
                             $this->associate_terms($pid, empty($assign_taxes) ? false : $assign_taxes, $tx_name, $logger, $is_cron);
                         } else {
                             $logger and call_user_func($logger, sprintf(__('- %s %s `%s` has been skipped attempted to `Do not update Taxonomies (incl. Categories and Tags)`...', 'wp_all_import_plugin'), $custom_type_details->labels->singular_name, $tx_name, $single_tax['name']));
                         }
                     }
                     if ($this->options['update_all_data'] == "no" and ($this->options['is_update_categories'] and $this->options['update_categories_logic'] != 'full_update' or !$this->options['is_update_categories'] and (is_object_in_taxonomy($post_type[$i], 'category') or is_object_in_taxonomy($post_type[$i], 'post_tag')))) {
                         if (!empty($existing_taxonomies)) {
                             foreach ($existing_taxonomies as $tx_name => $txes) {
                                 // Skip updating product attributes
                                 if (PMXI_Admin_Addons::get_addon('PMWI_Plugin') and strpos($tx_name, "pa_") === 0) {
                                     continue;
                                 }
                                 if (!empty($txes[$i])) {
                                     $this->associate_terms($pid, $txes[$i], $tx_name, $logger, $is_cron);
                                 }
                             }
                         }
                     }
                 }
                 // [/custom taxonomies]
                 if (empty($articleData['ID'])) {
                     $logger and call_user_func($logger, sprintf(__('<b>CREATED</b> `%s` `%s` (ID: %s)', 'wp_all_import_plugin'), $articleData['post_title'], $custom_type_details->labels->singular_name, $pid));
                 } else {
                     $logger and call_user_func($logger, sprintf(__('<b>UPDATED</b> `%s` `%s` (ID: %s)', 'wp_all_import_plugin'), $articleData['post_title'], $custom_type_details->labels->singular_name, $pid));
                 }
                 // fire important hooks after custom fields are added
                 if (!$this->options['is_fast_mode'] and $this->options['custom_type'] != 'import_users') {
                     $post_object = get_post($pid);
                     $is_update = !empty($articleData['ID']);
                     do_action("save_post_" . $articleData['post_type'], $pid, $post_object, $is_update);
                     do_action('save_post', $pid, $post_object, $is_update);
                     do_action('wp_insert_post', $pid, $post_object, $is_update);
                 }
                 // [addons import]
                 // prepare data for import
                 $importData = array('pid' => $pid, 'import' => $this, 'logger' => $logger);
                 $saved_functions = apply_filters('wp_all_import_addon_saved_post', array());
                 // deligate operation to addons
                 foreach (PMXI_Admin_Addons::get_active_addons() as $class) {
                     if (class_exists($class)) {
                         if (method_exists($addons[$class], 'saved_post')) {
                             $addons[$class]->saved_post($importData);
                         }
                     } else {
                         if (!empty($saved_functions[$class])) {
                             if (is_array($saved_functions[$class]) and is_callable($saved_functions[$class]) or !is_array($saved_functions[$class]) and function_exists($saved_functions[$class])) {
                                 call_user_func($saved_functions[$class], $importData);
                             }
                         }
                     }
                 }
                 // [/addons import]
                 $logger and call_user_func($logger, __('<b>ACTION</b>: pmxi_saved_post', 'wp_all_import_plugin'));
                 do_action('pmxi_saved_post', $pid, $rootNodes[$i]);
                 // hook that was triggered immediately after post saved
                 if (empty($articleData['ID'])) {
                     $created++;
                 } else {
                     $updated++;
                 }
                 if (!$is_cron and "default" == $this->options['import_processing']) {
                     $processed_records = $created + $updated + $skipped;
                     $logger and call_user_func($logger, sprintf(__('<span class="processing_info"><span class="created_count">%s</span><span class="updated_count">%s</span><span class="percents_count">%s</span></span>', 'wp_all_import_plugin'), $created, $updated, ceil($processed_records / $this->count * 100)));
                 }
             }
             $logger and call_user_func($logger, __('<b>ACTION</b>: pmxi_after_post_import', 'wp_all_import_plugin'));
             do_action('pmxi_after_post_import', $this->id);
             $logger and !$is_cron and PMXI_Plugin::$session->chunk_number++;
         }
         wp_cache_flush();
         $this->set(array('imported' => $created + $updated, 'created' => $created, 'updated' => $updated, 'skipped' => $skipped, 'last_activity' => date('Y-m-d H:i:s')))->update();
         if (!$is_cron) {
             PMXI_Plugin::$session->save_data();
             $records_count = $this->created + $this->updated + $this->skipped;
             $is_import_complete = $records_count == $this->count;
             // Delete posts that are no longer present in your file
             if ($is_import_complete and !empty($this->options['is_delete_missing']) and $this->options['duplicate_matching'] == 'auto') {
                 $logger and call_user_func($logger, __('Removing previously imported posts which are no longer actual...', 'wp_all_import_plugin'));
                 $postList = new PMXI_Post_List();
                 $missing_ids = array();
                 $missingPosts = $postList->getBy(array('import_id' => $this->id, 'iteration !=' => $this->iteration));
                 if (!$missingPosts->isEmpty()) {
                     foreach ($missingPosts as $missingPost) {
                         $missing_ids[] = $missingPost['post_id'];
                     }
                 }
                 // Delete posts from database
                 if (!empty($missing_ids) && is_array($missing_ids)) {
                     $logger and call_user_func($logger, __('<b>ACTION</b>: pmxi_delete_post', 'wp_all_import_plugin'));
                     $logger and call_user_func($logger, __('Deleting posts from database', 'wp_all_import_plugin'));
                     $missing_ids_arr = array_chunk($missing_ids, 100);
                     foreach ($missing_ids_arr as $key => $ids) {
                         if (!empty($ids)) {
                             foreach ($ids as $k => $id) {
                                 $to_delete = true;
                                 // Instead of deletion, set Custom Field
                                 if ($this->options['is_update_missing_cf']) {
                                     update_post_meta($id, $this->options['update_missing_cf_name'], $this->options['update_missing_cf_value']);
                                     $to_delete = false;
                                     $logger and call_user_func($logger, sprintf(__('Instead of deletion post with ID `%s`, set Custom Field `%s` to value `%s`', 'wp_all_import_plugin'), $id, $this->options['update_missing_cf_name'], $this->options['update_missing_cf_value']));
                                 }
                                 // Instead of deletion, change post status to Draft
                                 if ($this->options['set_missing_to_draft']) {
                                     $this->wpdb->update($this->wpdb->posts, array('post_status' => 'draft'), array('ID' => $id));
                                     $to_delete = false;
                                     $logger and call_user_func($logger, sprintf(__('Instead of deletion, change post with ID `%s` status to Draft', 'wp_all_import_plugin'), $id));
                                 }
                                 if ($to_delete) {
                                     // Remove attachments
                                     empty($this->options['is_keep_attachments']) and wp_delete_attachments($id, true, 'files');
                                     // Remove images
                                     empty($this->options['is_keep_imgs']) and wp_delete_attachments($id, true, 'images');
                                     // Clear post's relationships
                                     if ($post_type[$i] != "import_users") {
                                         wp_delete_object_term_relationships($id, get_object_taxonomies('' != $this->options['custom_type'] ? $this->options['custom_type'] : 'post'));
                                     }
                                 } else {
                                     unset($ids[$k]);
                                 }
                             }
                             if (!empty($ids)) {
                                 do_action('pmxi_delete_post', $ids);
                                 if ($this->options['custom_type'] == "import_users") {
                                     $sql = "delete a,b\n\t\t\t\t\t\t\t\t\t\tFROM " . $this->wpdb->users . " a\n\t\t\t\t\t\t\t\t\t\tLEFT JOIN " . $this->wpdb->usermeta . " b ON ( a.ID = b.user_id )\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\tWHERE a.ID IN (" . implode(',', $ids) . ");";
                                 } else {
                                     $sql = "delete a,b,c\n\t\t\t\t\t\t\t\t\t\tFROM " . $this->wpdb->posts . " a\n\t\t\t\t\t\t\t\t\t\tLEFT JOIN " . $this->wpdb->term_relationships . " b ON ( a.ID = b.object_id )\n\t\t\t\t\t\t\t\t\t\tLEFT JOIN " . $this->wpdb->postmeta . " c ON ( a.ID = c.post_id )\t\t\t\t\n\t\t\t\t\t\t\t\t\t\tWHERE a.ID IN (" . implode(',', $ids) . ");";
                                 }
                                 $this->wpdb->query($sql);
                                 // Delete record form pmxi_posts
                                 $sql = "DELETE FROM " . PMXI_Plugin::getInstance()->getTablePrefix() . "posts WHERE post_id IN (" . implode(',', $ids) . ") AND import_id = %d";
                                 $this->wpdb->query($this->wpdb->prepare($sql, $this->id));
                                 $this->set(array('deleted' => $this->deleted + count($ids)))->update();
                             }
                         }
                     }
                 }
             }
             // Set out of stock status for missing records [Woocommerce add-on option]
             if ($is_import_complete and empty($this->options['is_delete_missing']) and $post_type[$i] == "product" and class_exists('PMWI_Plugin') and !empty($this->options['missing_records_stock_status'])) {
                 $logger and call_user_func($logger, __('Update stock status previously imported posts which are no longer actual...', 'wp_all_import_plugin'));
                 $postList = new PMXI_Post_List();
                 $missingPosts = $postList->getBy(array('import_id' => $this->id, 'iteration !=' => $this->iteration));
                 if (!$missingPosts->isEmpty()) {
                     foreach ($missingPosts as $missingPost) {
                         update_post_meta($missingPost['post_id'], '_stock_status', 'outofstock');
                         update_post_meta($missingPost['post_id'], '_stock', 0);
                         $missingPostRecord = new PMXI_Post_Record();
                         $missingPostRecord->getBy('id', $missingPost['id']);
                         if (!$missingPostRecord->isEmpty()) {
                             $missingPostRecord->set(array('iteration' => $this->iteration))->update();
                         }
                         unset($missingPostRecord);
                     }
                 }
             }
         }
     } catch (XmlImportException $e) {
         $logger and call_user_func($logger, __('<b>ERROR</b>', 'wp_all_import_plugin') . ': ' . $e->getMessage());
         $logger and !$is_cron and PMXI_Plugin::$session->errors++;
     }
     $logger and $is_import_complete and call_user_func($logger, __('Cleaning temporary data...', 'wp_all_import_plugin'));
     foreach ($tmp_files as $file) {
         // remove all temporary files created
         @unlink($file);
     }
     if (($is_cron or $is_import_complete) and $this->options['is_delete_source']) {
         $logger and call_user_func($logger, __('Deleting source XML file...', 'wp_all_import_plugin'));
         // Delete chunks
         foreach (PMXI_Helper::safe_glob($uploads['basedir'] . DIRECTORY_SEPARATOR . PMXI_Plugin::TEMP_DIRECTORY . DIRECTORY_SEPARATOR . 'pmxi_chunk_*', PMXI_Helper::GLOB_RECURSE | PMXI_Helper::GLOB_PATH) as $filePath) {
             $logger and call_user_func($logger, __('Deleting chunks files...', 'wp_all_import_plugin'));
             @file_exists($filePath) and wp_all_import_remove_source($filePath, false);
         }
         if ($this->type != "ftp") {
             if (!@unlink($this->path)) {
                 $logger and call_user_func($logger, sprintf(__('<b>WARNING</b>: Unable to remove %s', 'wp_all_import_plugin'), $this->path));
             }
         } else {
             $file_path_array = PMXI_Helper::safe_glob($this->path, PMXI_Helper::GLOB_NODIR | PMXI_Helper::GLOB_PATH);
             if (!empty($file_path_array)) {
                 foreach ($file_path_array as $path) {
                     if (!@unlink($path)) {
                         $logger and call_user_func($logger, sprintf(__('<b>WARNING</b>: Unable to remove %s', 'wp_all_import_plugin'), $path));
                     }
                 }
             }
         }
     }
     if (!$is_cron and $is_import_complete) {
         $this->set(array('processing' => 0, 'triggered' => 0, 'queue_chunk_number' => 0, 'registered_on' => date('Y-m-d H:i:s'), 'iteration' => ++$this->iteration))->update();
         $logger and call_user_func($logger, 'Done');
     }
     remove_filter('user_has_cap', array($this, '_filter_has_cap_unfiltered_html'));
     kses_init();
     // return any filtering rules back if they has been disabled for import procedure
     return $this;
 }
コード例 #10
0
 /**
  * Returns an HTML structure containing nested lists and list items
  * referring to any media attached to the given post ID.
  *
  * @param int $post_id The post ID from which to fetch attached media.
  *
  * @uses WP_Buoy_Alert::getIncidentMediaHtml()
  *
  * @return string HTML ready for insertion into an `<ul>` element.
  */
 private static function getIncidentMediaList($post_id)
 {
     $html = '';
     $posts = array('video' => get_attached_media('video', $post_id), 'image' => get_attached_media('image', $post_id), 'audio' => get_attached_media('audio', $post_id));
     foreach ($posts as $type => $set) {
         $html .= '<li class="' . esc_attr($type) . ' list-group">';
         $html .= '<div class="list-group-item">';
         $html .= '<h4 class="list-group-item-heading">';
         switch ($type) {
             case 'video':
                 $html .= esc_html('Video attachments', 'buoy');
                 break;
             case 'image':
                 $html .= esc_html('Image attachments', 'buoy');
                 break;
             case 'audio':
                 $html .= esc_html('Audio attachments', 'buoy');
                 break;
         }
         $html .= ' <span class="badge">' . count($set) . '</span>';
         $html .= '</h4>';
         $html .= '<ul>';
         foreach ($set as $post) {
             $html .= '<li id="incident-media-' . $post->ID . '" class="list-group-item">';
             $html .= '<h5 class="list-group-item-header">' . esc_html($post->post_title) . '</h5>';
             $html .= self::getIncidentMediaHtml($type, $post->ID);
             $html .= '<p class="list-group-item-text">';
             $html .= sprintf(esc_html_x('uploaded %1$s ago', 'Example: uploaded 5 mins ago', 'buoy'), human_time_diff(strtotime($post->post_date_gmt)));
             $u = get_userdata($post->post_author);
             $html .= ' ' . sprintf(esc_html_x('by %1$s', 'a byline, like "written by Bob"', 'buoy'), $u->display_name);
             $html .= '</p>';
             $html .= '</li>';
         }
         $html .= '</ul>';
         $html .= '</div>';
         $html .= '</li>';
     }
     return $html;
 }
コード例 #11
0
ファイル: edit.php プロジェクト: dev-wl/torani
$slidePosts = get_posts(array('numberposts' => -1, 'orderby' => 'menu_order', 'order' => 'ASC', 'post_parent' => $id, 'post_type' => 'Micro Slider'));
?>

<div id="all-slides">
<?php 
// wp_delete_post(431, true);
//+проверка на пустую картинку
?>
 <?php 
// echo "<pre>";
// print_r($slidePosts);
// echo "</pre>";
?>
	<?php 
foreach ($slidePosts as $slider) {
    $attach = get_attached_media('image', $slider->ID);
    $cleanedObject = reset($attach);
    // print_r(reset($attach)->guid);
    //echo "<img src='" . reset($attach)->guid . "' />" . "<br />";
    ?>

	<div class="single-slide" id="item-<?php 
    echo $cleanedObject->post_parent;
    ?>
">
		<div class="image">
			<img src="<?php 
    echo $cleanedObject->guid;
    ?>
" />
		</div> 
コード例 #12
0
ファイル: template-tags.php プロジェクト: allisonplus/wd_s
/**
 * Return an image URI, no matter what.
 *
 * @param  string  $size  The image size you want to return.
 * @return string         The image URI.
 */
function _s_get_post_image_uri($size = 'thumbnail')
{
    // If featured image is present, use that.
    if (has_post_thumbnail()) {
        $featured_image_id = get_post_thumbnail_id(get_the_ID());
        $media = wp_get_attachment_image_src($featured_image_id, $size);
        if (is_array($media)) {
            return current($media);
        }
    }
    // Check for any attached image.
    $media = get_attached_media('image', get_the_ID());
    $media = current($media);
    // Set up default image path.
    $media_url = get_stylesheet_directory_uri() . '/assets/images/placeholder.png';
    // If an image is present, then use it.
    if (is_array($media) && 0 < count($media)) {
        $media_url = 'thumbnail' === $size ? wp_get_attachment_thumb_url($media->ID) : wp_get_attachment_url($media->ID);
    }
    return $media_url;
}
コード例 #13
0
	/**
	 * @ticket 22960
	 */
	function test_get_attached_images() {
		$post_id = $this->factory->post->create();
		$attachment_id = $this->factory->attachment->create_object( $this->img_name, $post_id, array(
			'post_mime_type' => 'image/jpeg',
			'post_type' => 'attachment'
		) );

		$images = get_attached_media( 'image', $post_id );
		$this->assertEquals( $images, array( $attachment_id => get_post( $attachment_id ) ) );
	}
コード例 #14
0
ファイル: functions.php プロジェクト: nicowesse/nicowesse
function custom_video_shortcode($attr, $content = '')
{
    global $content_width;
    $post_id = get_post() ? get_the_ID() : 0;
    static $instances = 0;
    $instances++;
    /**
     * Override the default video shortcode.
     *
     * @since 3.7.0
     *
     * @param null              Empty variable to be replaced with shortcode markup.
     * @param array  $attr      Attributes of the shortcode.
     * @param string $content   Shortcode content.
     * @param int    $instances Unique numeric ID of this video shortcode instance.
     */
    $html = apply_filters('wp_video_shortcode_override', '', $attr, $content, $instances);
    if ('' !== $html) {
        return $html;
    }
    $video = null;
    $default_types = wp_get_video_extensions();
    $defaults_atts = array('src' => '', 'poster' => '', 'loop' => '', 'autoplay' => '', 'preload' => 'metadata', 'height' => 1080, 'width' => empty($content_width) ? 1920 : $content_width, 'size' => '');
    foreach ($default_types as $type) {
        $defaults_atts[$type] = '';
    }
    $atts = shortcode_atts($defaults_atts, $attr, 'video');
    extract($atts);
    $w = $width;
    $h = $height;
    if (is_admin() && $width > 600) {
        $w = 1920;
    } elseif (!is_admin() && $w > $defaults_atts['width']) {
        $w = $defaults_atts['width'];
    }
    if ($w < $width) {
        $height = round($h * $w / $width);
    }
    $width = $w;
    $primary = false;
    if (!empty($src)) {
        $type = wp_check_filetype($src, wp_get_mime_types());
        if (!in_array(strtolower($type['ext']), $default_types)) {
            return sprintf('<a class="wp-embedded-video" href="%s">%s</a>', esc_url($src), esc_html($src));
        }
        $primary = true;
        array_unshift($default_types, 'src');
    } else {
        foreach ($default_types as $ext) {
            if (!empty(${$ext})) {
                $type = wp_check_filetype(${$ext}, wp_get_mime_types());
                if (strtolower($type['ext']) === $ext) {
                    $primary = true;
                }
            }
        }
    }
    if (!$primary) {
        $videos = get_attached_media('video', $post_id);
        if (empty($videos)) {
            return;
        }
        $video = reset($videos);
        $src = wp_get_attachment_url($video->ID);
        if (empty($src)) {
            return;
        }
        array_unshift($default_types, 'src');
    }
    $library = apply_filters('wp_video_shortcode_library', 'mediaelement');
    /*if ( 'mediaelement' === $library && did_action( 'init' ) ) {
                    wp_enqueue_style( 'wp-mediaelement' );
                    wp_enqueue_script( 'wp-mediaelement' );
            }
    
            /*$atts = array(
                    'class'    => apply_filters( 'wp_video_shortcode_class', 'wp-video-shortcode' ),
                    'id'       => sprintf( 'video-%d-%d', $post_id, $instances ),
                    'width'    => absint( $width ),
                    'height'   => absint( $height ),
                    'poster'   => esc_url( $poster ),
                    'loop'     => $loop,
                    'autoplay' => $autoplay,
                    'preload'  => $preload,
            );*/
    // These ones should just be omitted altogether if they are blank
    foreach (array('poster', 'loop', 'autoplay', 'preload') as $a) {
        if (empty($atts[$a])) {
            unset($atts[$a]);
        }
    }
    $attr_strings = array();
    foreach ($atts as $k => $v) {
        $attr_strings[] = $k . '="' . esc_attr($v) . '"';
    }
    $html .= '<video id="videoplayer" class="video-js vjs-mnml ' . $size . '" controls="controls" data-setup>';
    $fileurl = '';
    $source = '<source type="%s" src="%s" />';
    foreach ($default_types as $fallback) {
        if (!empty(${$fallback})) {
            if (empty($fileurl)) {
                $fileurl = ${$fallback};
            }
            $type = wp_check_filetype(${$fallback}, wp_get_mime_types());
            // m4v sometimes shows up as video/mpeg which collides with mp4
            if ('m4v' === $type['ext']) {
                $type['type'] = 'video/m4v';
            }
            $html .= sprintf($source, $type['type'], esc_url(${$fallback}));
        }
    }
    if ('mediaelement' === $library) {
        $html .= wp_mediaelement_fallback($fileurl);
    }
    $html .= '</video>';
    $html = sprintf('<div class="wp-video">%s</div>', $html);
    return apply_filters('wp_video_shortcode', $html, $atts, $video, $post_id, $library);
}
コード例 #15
0
ファイル: page-main.php プロジェクト: valerol/artempol
}
// News
$news = artempol_get_posts('news-list', array('category_name' => 'news', 'posts_per_page' => get_theme_mod('news-main-number', 2)), array('image', 'title', 'url', 'date', 'content'));
if ($news) {
    $heading = artempol_container(array('tag' => 'h2', 'content' => __('News', 'artempol')));
    $news = artempol_container(array('tag' => 'div', 'content' => $heading . $news, 'class' => 'content_wrap news padding_tb_20 wow fadeInUp'));
    echo $news;
}
// Colored_blocks
$colored_blocks = artempol_get_posts('colored', array('category_name' => 'colorblocks'), array('counter', 'title', 'content'));
if ($colored_blocks) {
    $colored_blocks = artempol_container(array('tag' => 'div', 'content' => $colored_blocks, 'class' => 'content_wrap clearfix padding_tb_10 wow fadeInUp'));
    echo $colored_blocks;
}
// Achievements
$images = get_attached_media('image', get_theme_mod('achievements-page'));
$achievements = '';
foreach ($images as $post) {
    $achievements .= artempol_get_post($post, 'achievements', array('achievement_image', 'achievement_url', 'achievement_margin'));
}
if ($achievements) {
    $achievements = artempol_container(array('tag' => 'ul', 'content' => $achievements, 'class' => 'slides'));
    $achievements = artempol_container(array('tag' => 'div', 'content' => $achievements, 'class' => 'slider-achieve flexslider wow fadeInUp'));
    $achievements = artempol_container(array(), 'line') . $achievements;
    echo $achievements;
}
// Services
$services = get_post(get_theme_mod('services-page'));
if ($services) {
    $services = artempol_get_post($services, 'services', array('title', 'content'));
    echo $services;
コード例 #16
0
ファイル: test-cmb-types.php プロジェクト: Dovahkiin1991/CMB2
 public function test_file_list_field_after_value_update()
 {
     $images = get_attached_media('image', $this->post_id);
     $this->assertEquals($images, array($this->attachment_id => get_post($this->attachment_id), $this->attachment_id2 => get_post($this->attachment_id2)));
     update_post_meta($this->post_id, $this->text_type_field['id'], array($this->attachment_id => get_permalink($this->attachment_id), $this->attachment_id2 => get_permalink($this->attachment_id2)));
     $this->assertHTMLstringsAreEqual(sprintf('<input type="hidden" class="cmb2-upload-file cmb2-upload-list" name="field_test_field" id="field_test_field" value="" size="45" data-previewsize=\'[50,50]\' data-queryargs=\'\'/><input type="button" class="cmb2-upload-button button cmb2-upload-list" name="" id="" value="%7$s"/><p class="cmb2-metabox-description">This is a description</p><ul id="field_test_field-status" class="cmb2-media-status cmb-attach-list"><li class="file-status"><span>%6$s <strong>?attachment_id=%1$d</strong></span>&nbsp;&nbsp; (<a href="%3$s/?attachment_id=%1$d" target="_blank" rel="external">%4$s</a> / <a href="#" class="cmb2-remove-file-button">%5$s</a>)<input type="hidden" name="field_test_field[%1$d]" id="filelist-%1$d" value="%3$s/?attachment_id=%1$d" data-id=\'%1$d\'/></li><li class="file-status"><span>%6$s <strong>?attachment_id=%2$d</strong></span>&nbsp;&nbsp; (<a href="%3$s/?attachment_id=%2$d" target="_blank" rel="external">%4$s</a> / <a href="#" class="cmb2-remove-file-button">%5$s</a>)<input type="hidden" name="field_test_field[%2$d]" id="filelist-%2$d" value="%3$s/?attachment_id=%2$d" data-id=\'%2$d\'/></li></ul>', $this->attachment_id, $this->attachment_id2, site_url(), __('Download', 'cmb2'), __('Remove', 'cmb2'), __('File:', 'cmb2'), __('Add or Upload Files', 'cmb2')), $this->capture_render(array($this->get_field_type_object('file_list'), 'render')));
     delete_post_meta($this->post_id, $this->text_type_field['id']);
 }
コード例 #17
0
 /**
  * Gets media attached to the post.  Then, uses the WordPress [audio] or [video] shortcode to handle 
  * the HTML output of the media.
  *
  * @since  1.6.0
  * @access public
  * @return void
  */
 public function do_attached_media()
 {
     /* Gets media attached to the post by mime type. */
     $attached_media = get_attached_media($this->type, $this->args['post_id']);
     /* If media is found. */
     if (!empty($attached_media)) {
         /* Get the first attachment/post object found for the post. */
         $post = array_shift($attached_media);
         /* Gets the URI for the attachment (the media file). */
         $url = wp_get_attachment_url($post->ID);
         /* Run the media as a shortcode using WordPress' built-in [audio] and [video] shortcodes. */
         $this->media = do_shortcode("[{$this->type} src='{$url}']");
     }
 }
コード例 #18
0
ファイル: functions.php プロジェクト: Lumbe/dev_servus
    function et_gallery_images()
    {
        $output = $images_ids = '';
        if (function_exists('get_post_galleries')) {
            $galleries = get_post_galleries(get_the_ID(), false);
            if (empty($galleries)) {
                return false;
            }
            foreach ($galleries as $gallery) {
                if (isset($gallery['ids'])) {
                    // Grabs all attachments ids from one or multiple galleries in the post
                    $images_ids .= ('' !== $images_ids ? ',' : '') . $gallery['ids'];
                } else {
                    $image_ids = false;
                    // If user doesn't define ids of images on galleries, get attached media
                    $attached_media = get_attached_media('image', get_the_id());
                }
            }
            if ($images_ids) {
                $attachments_ids = explode(',', $images_ids);
            } elseif (isset($attached_media) && is_array($attached_media) && !empty($attached_media)) {
                $attachments_ids = wp_list_pluck($attached_media, 'ID');
            } else {
                $attachments_ids = false;
            }
            if (!$attachments_ids) {
                // Print no gallery found message
                ?>
			<div class="et_pb_module et_pb_slider et_pb_slider_fullwidth_off et_pb_bg_layout_light gallery-not-found">
				<div class="et_pb_slides">
					<div class="et_pb_slide et_pb_bg_layout_light et_pb_media_alignment_center et-pb-active-slide" style="background-color:#ffffff;">
						<div class="et_pb_container clearfix">
							<div class="et_pb_slide_description">
								<h2><?php 
                _e('No Gallery Found', 'Divi');
                ?>
</h2>
								<div class="et_pb_slide_content">
									<p><?php 
                _e('No items found', 'Divi');
                ?>
</p>
								</div>
							</div> <!-- .et_pb_slide_description -->
						</div> <!-- .et_pb_container -->
					</div> <!-- .et_pb_slide -->
				</div> <!-- .et_pb_slides -->
			</div>
			<?php 
                return;
            }
            // Removes duplicate attachments ids
            $attachments_ids = array_unique($attachments_ids);
        } else {
            $pattern = get_shortcode_regex();
            preg_match("/{$pattern}/s", get_the_content(), $match);
            $atts = shortcode_parse_atts($match[3]);
            if (isset($atts['ids'])) {
                $attachments_ids = explode(',', $atts['ids']);
            } else {
                return false;
            }
        }
        $slides = '';
        foreach ($attachments_ids as $attachment_id) {
            $attachment_attributes = wp_get_attachment_image_src($attachment_id, 'et-pb-post-main-image-fullwidth');
            $attachment_image = !is_single() ? $attachment_attributes[0] : wp_get_attachment_image($attachment_id, 'et-pb-portfolio-image');
            if (!is_single()) {
                $slides .= sprintf('<div class="et_pb_slide" style="background: url(%1$s);"></div>', esc_attr($attachment_image));
            } else {
                $full_image = wp_get_attachment_image_src($attachment_id, 'full');
                $full_image_url = $full_image[0];
                $attachment = get_post($attachment_id);
                $slides .= sprintf('<li class="et_gallery_item">
					<a href="%1$s" title="%3$s">
						<span class="et_portfolio_image">
							%2$s
							<span class="et_overlay"></span>
						</span>
					</a>
				</li>', esc_url($full_image_url), $attachment_image, esc_attr($attachment->post_title));
            }
        }
        if (!is_single()) {
            $output = '<div class="et_pb_slider et_pb_slider_fullwidth_off et_pb_gallery_post_type">
				<div class="et_pb_slides">
					%1$s
				</div>
			</div>';
        } else {
            $output = '<ul class="et_post_gallery clearfix">
				%1$s
			</ul>';
        }
        printf($output, $slides);
    }
コード例 #19
0
/**
 * @package grab-image
 * ajax function to attach image
 */
function ajax_attach_image_post()
{
    $id = intval($_REQUEST['id']);
    $post = get_post($id);
    if (empty($post)) {
        echo 'Wrong post ID';
        wp_die();
    }
    // call helper class
    $helper = new grabimage_helper();
    // extract image tag from post content
    $array = $helper->extract_image($post->post_content, false);
    $search = $replace = [];
    $count = 0;
    if (is_array($array) && count($array) > 0) {
        foreach ($array as $tag => $url) {
            // get attachment ID from url
            $attachment_id = $helper->get_attachment_id($url);
            if (empty($attachment_id)) {
                continue;
            }
            // get post attachment
            $attachments = get_attached_media('image', $post->ID);
            // ignore if image was attachment
            if (isset($attachments[$attachment_id])) {
                continue;
            }
            wp_update_post(['ID' => $attachment_id, 'post_parent' => $post->ID]);
            // search a|img tag
            $search[] = $tag;
            // replace with
            $image = wp_get_attachment_image_src($attachment_id, 'full');
            $id = $attachment_id;
            $src = $image[0];
            $replace[] = "<a href=\"{$src}\" rel=\"attachment wp-att-{$id}\">" . "<img class=\"alignnone size-full wp-image-{$id}\" src=\"{$src}\" alt=\"{$post->post_title}\" />" . "</a>";
            echo "success ; {$url} ; {$attachment_id} <br/>";
        }
        // update post data
        if (count($search) > 0 && count($replace) > 0) {
            $post_content = str_replace($search, $replace, $post->post_content);
            $my_post = ['ID' => $post->ID, 'post_content' => $post_content];
            wp_update_post($my_post);
        }
        $count = count($search);
    }
    echo 'Attached ' . $count . ' image';
    wp_die();
}
コード例 #20
0
ファイル: functions.php プロジェクト: jimrucinski/Vine
/**
 * @usage Create sample audio player for link template
 * @param $package
 * @param bool $return
 * @return mixed|string|void
 */
function wpdm_sample_audio_single($package, $return = false)
{
    $audios = get_attached_media('audio', $package['ID']);
    $audiohtml = "";
    if (count($audios) > 0) {
        $audio = array_shift($audios);
        $audiohtml = do_shortcode("[audio src='{$audio->guid}']");
    }
    if ($return) {
        return $audiohtml;
    }
    echo $audiohtml;
}
コード例 #21
0
 /**
  * Export the posts
  */
 public function doExport()
 {
     global $wpdb;
     $app = Bootstrap::getApplication();
     $cli = $app['cli'];
     $extractMedia = $app['extractmedia'];
     $exportMedia = $app['exportmedia'];
     $exportTaxonomies = $app['exporttaxonomies'];
     $helpers = $app['helpers'];
     $baseUrl = get_option('siteurl');
     $dumper = new Dumper();
     $count = 1;
     while ($count > 0) {
         $count = 0;
         foreach ($this->posts as $postType => &$posts) {
             foreach ($posts as &$post) {
                 if ($post->done == true) {
                     continue;
                 }
                 $postId = $wpdb->get_var($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_type = %s AND post_name = %s", $postType, $post->slug));
                 $arrPost = get_post($postId, ARRAY_A);
                 if (!$arrPost) {
                     $cli->debug("Post {$postId} not found");
                     continue;
                 }
                 $cli->debug("Exporting post {$post->slug} ({$postId})");
                 $meta = get_post_meta($arrPost['ID']);
                 $arrPost['taxonomies'] = array();
                 // extract media ids
                 // 1. from attached media:
                 $media = get_attached_media('', $postId);
                 foreach ($media as $item) {
                     $exportMedia->addMedia($item->ID);
                 }
                 // 2. from featured image:
                 if (has_post_thumbnail($postId)) {
                     $mediaId = get_post_thumbnail_id($postId);
                     $exportMedia->addMedia($mediaId);
                 }
                 // 3. Is this post actually an attachment?
                 if ($arrPost['post_type'] == 'attachment') {
                     $exportMedia->addMedia($arrPost['ID']);
                 }
                 // 4. referenced in the content
                 $ret = $extractMedia->getReferencedMedia($arrPost);
                 if (count($ret) > 0) {
                     $exportMedia->addMedia($ret);
                 }
                 // 5. referenced in meta data
                 $ret = $extractMedia->getReferencedMedia($meta);
                 if (count($ret) > 0) {
                     $exportMedia->addMedia($ret);
                 }
                 // terms
                 foreach (get_taxonomies() as $taxonomy) {
                     if (in_array($taxonomy, $this->excludedTaxonomies)) {
                         continue;
                     }
                     $terms = wp_get_object_terms($postId, $taxonomy);
                     if (count($terms)) {
                         $cli->debug('Adding ' . count($terms) . " terms from {$taxonomy}");
                     }
                     foreach ($terms as $objTerm) {
                         // add it to the exported terms
                         $exportTaxonomies->addTerm($taxonomy, $objTerm->slug);
                         if (!isset($arrPost['taxonomies'][$taxonomy])) {
                             $arrPost['taxonomies'][$taxonomy] = array();
                         }
                         $arrPost['taxonomies'][$taxonomy][] = $objTerm->slug;
                     }
                 }
                 $arrPost['post_meta'] = $meta;
                 $helpers->fieldSearchReplace($arrPost, $baseUrl, Bootstrap::NEUTRALURL);
                 $file = WPBOOT_BASEPATH . "/bootstrap/posts/{$arrPost['post_type']}/{$arrPost['post_name']}";
                 $cli->debug("Storing {$file}");
                 @mkdir(dirname($file), 0777, true);
                 file_put_contents($file, $dumper->dump($arrPost, 4));
                 $post->done = true;
                 ++$count;
             }
         }
     }
 }
コード例 #22
0
 /**
  * Manage special operation on wpshop plugin update
  */
 public static function make_specific_operation_on_update($version)
 {
     global $wpdb, $wp_rewrite;
     $wpshop_shop_type = get_option('wpshop_shop_type', WPSHOP_DEFAULT_SHOP_TYPE);
     switch ($version) {
         case 3:
         case 6:
             self::wpshop_insert_default_pages($wpshop_shop_type);
             wp_cache_flush();
             return true;
             break;
         case 8:
             /**	Change metaboxes order for product in case it already exists	*/
             $query = $wpdb->prepare("SELECT umeta_id, meta_value FROM {$wpdb->usermeta} WHERE meta_key = %s", 'meta-box-order_wpshop_product');
             $customer_metaboxes_order = $wpdb->get_results($query);
             if (!empty($customer_metaboxes_order)) {
                 foreach ($customer_metaboxes_order as $customer_metabox_order) {
                     $do_changes = false;
                     $current_order = unserialize($customer_metabox_order->meta_value);
                     if (array_key_exists('normal', $current_order) && false !== strpos('wpshop_product_important_datas', $current_order['normal'])) {
                         str_replace('wpshop_product_important_datas,', '', $current_order['normal']);
                         $do_changes = true;
                     }
                     if (array_key_exists('side', $current_order)) {
                         str_replace('wpshop_product_important_datas,', '', $current_order['side']);
                         str_replace('submitdiv,', 'submitdiv,wpshop_product_important_datas,', $current_order['side']);
                         $do_changes = true;
                     }
                     if (true === $do_changes) {
                         $wpdb->update($wpdb->usermeta, array('meta_value' => serialize($current_order)), array('umeta_id' => $customer_metabox_order->umeta_id));
                     }
                 }
             } else {
                 $users = get_users(array('role' => 'administrator'));
                 if (!empty($users)) {
                     foreach ($users as $user) {
                         $user_meta = array('side' => 'submitdiv,formatdiv,wpshop_product_important_datas,wpshop_product_categorydiv,pageparentdiv,wps_barcode_product,wpshop_product_actions,wpshop_product_options,postimagediv', 'normal' => 'wpshop_product_fixed_tab,postexcerpt,trackbacksdiv,postcustom,commentstatusdiv,slugdiv,authordiv,wpshop_wpshop_variations,wps_media_manager,wpshop_product_order_historic', 'advanced' => '');
                         update_user_meta($user->ID, 'meta-box-order_wpshop_product', $user_meta);
                     }
                 }
             }
             /*	Update the product prices into database	*/
             $query = $wpdb->prepare("\nSELECT\n(SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code = %s) AS product_price,\n(SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code = %s) AS price_ht,\n(SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code = %s) AS tx_tva,\n(SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code = %s) AS tva", 'product_price', 'price_ht', 'tx_tva', 'tva');
             $product_prices = $wpdb->get_row($query);
             $tax_id = $wpdb->get_var($wpdb->prepare("SELECT ATT_OPT.id FROM " . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . " AS ATT_OPT WHERE attribute_id = %d AND value = '20'", $product_prices->tx_tva));
             $query = $wpdb->prepare("SELECT * FROM " . WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL . " WHERE attribute_id = %d", $product_prices->product_price);
             $price_list = $wpdb->get_results($query);
             foreach ($price_list as $existing_ttc_price) {
                 $tax_rate = 1.2;
                 $price_ht = $existing_ttc_price->value / $tax_rate;
                 $tax_amount = $existing_ttc_price->value - $price_ht;
                 $wpdb->replace(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('entity_type_id' => $existing_ttc_price->entity_type_id, 'attribute_id' => $product_prices->price_ht, 'entity_id' => $existing_ttc_price->entity_id, 'unit_id' => $existing_ttc_price->unit_id, 'user_id' => $existing_ttc_price->user_id, 'language' => $existing_ttc_price->language, 'value' => $price_ht, 'creation_date_value' => current_time('mysql', 0)));
                 $wpdb->replace(WPSHOP_DBT_ATTRIBUTE_VALUES_INTEGER, array('entity_type_id' => $existing_ttc_price->entity_type_id, 'attribute_id' => $product_prices->tx_tva, 'entity_id' => $existing_ttc_price->entity_id, 'unit_id' => $existing_ttc_price->unit_id, 'user_id' => $existing_ttc_price->user_id, 'language' => $existing_ttc_price->language, 'value' => $tax_id, 'creation_date_value' => current_time('mysql', 0)));
                 $wpdb->replace(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('entity_type_id' => $existing_ttc_price->entity_type_id, 'attribute_id' => $product_prices->tva, 'entity_id' => $existing_ttc_price->entity_id, 'unit_id' => $existing_ttc_price->unit_id, 'user_id' => $existing_ttc_price->user_id, 'language' => $existing_ttc_price->language, 'value' => $tax_amount, 'creation_date_value' => current_time('mysql', 0)));
             }
             /*	Update orders structure into database	*/
             $orders_id = $wpdb->get_results('SELECT ID FROM ' . $wpdb->posts . ' WHERE post_type = "' . WPSHOP_NEWTYPE_IDENTIFIER_ORDER . '"');
             foreach ($orders_id as $o) {
                 $myorder = get_post_meta($o->ID, '_order_postmeta', true);
                 $neworder = array();
                 $items = array();
                 if (!isset($myorder['order_tva'])) {
                     $order_total_ht = 0;
                     $order_total_ttc = 0;
                     $order_tva = array('20' => 0);
                     foreach ($myorder['order_items'] as $item) {
                         /* item */
                         $pu_ht = $item['cost'] / 1.2;
                         $pu_tva = $item['cost'] - $pu_ht;
                         $total_ht = $pu_ht * $item['qty'];
                         $tva_total_amount = $pu_tva * $item['qty'];
                         $total_ttc = $item['cost'] * $item['qty'];
                         /* item */
                         $order_total_ht += $total_ht;
                         $order_total_ttc += $total_ttc;
                         $order_tva['20'] += $tva_total_amount;
                         $items[] = array('item_id' => $item['id'], 'item_ref' => 'Nc', 'item_name' => $item['name'], 'item_qty' => $item['qty'], 'item_pu_ht' => number_format($pu_ht, 2, '.', ''), 'item_pu_ttc' => number_format($item['cost'], 2, '.', ''), 'item_ecotaxe_ht' => number_format(0, 2, '.', ''), 'item_ecotaxe_tva' => 20, 'item_ecotaxe_ttc' => number_format(0, 2, '.', ''), 'item_discount_type' => 0, 'item_discount_value' => 0, 'item_discount_amount' => number_format(0, 2, '.', ''), 'item_tva_rate' => 20, 'item_tva_amount' => number_format($pu_tva, 2, '.', ''), 'item_total_ht' => number_format($total_ht, 2, '.', ''), 'item_tva_total_amount' => number_format($tva_total_amount, 2, '.', ''), 'item_total_ttc' => number_format($total_ttc, 2, '.', ''));
                     }
                     $neworder = array('order_key' => $myorder['order_key'], 'customer_id' => $myorder['customer_id'], 'order_status' => $myorder['order_status'], 'order_date' => $myorder['order_date'], 'order_payment_date' => $myorder['order_payment_date'], 'order_shipping_date' => $myorder['order_shipping_date'], 'payment_method' => $myorder['payment_method'], 'order_invoice_ref' => '', 'order_currency' => $myorder['order_currency'], 'order_total_ht' => $order_total_ht, 'order_total_ttc' => $order_total_ttc, 'order_grand_total' => $order_total_ttc, 'order_shipping_cost' => number_format(0, 2, '.', ''), 'order_tva' => array_map(array('wpshop_tools', 'number_format_hack'), $order_tva), 'order_items' => $items);
                     /* Update the order postmeta */
                     update_post_meta($o->ID, '_order_postmeta', $neworder);
                 }
             }
             self::wpshop_insert_default_pages($wpshop_shop_type);
             wp_cache_flush();
             return true;
             break;
         case 12:
             $query = "SELECT ID FROM " . $wpdb->users;
             $user_list = $wpdb->get_results($query);
             foreach ($user_list as $user) {
                 $user_first_name = get_user_meta($user->ID, 'first_name', true);
                 $user_last_name = get_user_meta($user->ID, 'last_name', true);
                 $shipping_info = get_user_meta($user->ID, 'shipping_info', true);
                 if ($user_first_name == '' && !empty($shipping_info['first_name'])) {
                     update_user_meta($user->ID, 'first_name', $shipping_info['first_name']);
                 }
                 if ($user_last_name == '' && !empty($shipping_info['last_name'])) {
                     update_user_meta($user->ID, 'last_name', $shipping_info['last_name']);
                 }
             }
             /*	Update orders structure into database	*/
             $orders_id = $wpdb->get_results('SELECT ID FROM ' . $wpdb->posts . ' WHERE post_type = "' . WPSHOP_NEWTYPE_IDENTIFIER_ORDER . '"');
             foreach ($orders_id as $o) {
                 $myorder = get_post_meta($o->ID, '_order_postmeta', true);
                 if (!empty($myorder)) {
                     $new_items = array();
                     foreach ($myorder['order_items'] as $item) {
                         $new_items = $item;
                         $new_items['item_discount_type'] = !empty($item['item_discount_rate']) ? $item['item_discount_rate'] : 'amount';
                         // unset($new_items['item_discount_rate']);
                         $new_items['item_discount_value'] = 0;
                     }
                     $myorder['order_items'] = $new_items;
                     /* Update the order postmeta */
                     update_post_meta($o->ID, '_order_postmeta', $myorder);
                 }
             }
             /*	Delete useless database table	*/
             $query = "DROP TABLE " . WPSHOP_DBT_CART;
             $wpdb->query($query);
             $query = "DROP TABLE " . WPSHOP_DBT_CART_CONTENTS;
             $wpdb->query($query);
             return true;
             break;
         case 13:
             $attribute_used_for_sort_by = wpshop_attributes::getElement('yes', "'valid', 'moderated', 'notused'", 'is_used_for_sort_by', true);
             foreach ($attribute_used_for_sort_by as $attribute) {
                 $data = query_posts(array('posts_per_page' => -1, 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT));
                 foreach ($data as $post) {
                     $postmeta = get_post_meta($post->ID, '_wpshop_product_metadata', true);
                     if (!empty($postmeta[$attribute->code])) {
                         update_post_meta($post->ID, '_' . $attribute->code, $postmeta[$attribute->code]);
                     }
                 }
                 wp_reset_query();
             }
             return true;
             break;
         case 17:
             $products = query_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT));
             $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " WHERE default_set = %s", 'yes');
             $default_attribute_set = $wpdb->get_var($query);
             foreach ($products as $product) {
                 $p_att_set_id = get_post_meta($product->ID, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true);
                 if (empty($p_att_set_id)) {
                     /*	Update the attribute set id for the current product	*/
                     update_post_meta($product->ID, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, $default_attribute_set);
                 }
                 wp_reset_query();
             }
             self::wpshop_insert_default_pages($wpshop_shop_type);
             wp_cache_flush();
             return true;
             break;
         case 18:
             self::wpshop_insert_default_pages($wpshop_shop_type);
             wp_cache_flush();
             return true;
             break;
         case 19:
             $wp_rewrite->flush_rules();
             return true;
             break;
         case 21:
             /**
              * Correction des valeurs pour l'attributs "gestion du stock" qui n'�taient pas cr�es automatiquement
              */
             $query = $wpdb->prepare("SELECT ATTR_OPT.id, ATTR_OPT.value, ATTR_OPT.label, ATTR_OPT.position, ATTR_OPT.attribute_id FROM " . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . " AS ATTR_OPT INNER JOIN " . WPSHOP_DBT_ATTRIBUTE . " AS ATTR ON (ATTR.id = ATTR_OPT.attribute_id) WHERE ATTR_OPT.status=%s AND ATTR.code=%s", 'valid', 'manage_stock');
             $manage_stock_option = $wpdb->get_results($query);
             if (!empty($manage_stock_option)) {
                 $no_is_present = false;
                 $attribute_id = $manage_stock_option[0]->attribute_id;
                 foreach ($manage_stock_option as $manage_definition) {
                     if (strtolower(__($manage_definition->value, 'wpshop')) == strtolower(__('no', 'wpshop'))) {
                         $no_is_present = true;
                     }
                 }
                 if (!$no_is_present) {
                     $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'last_update_date' => current_time('mysql', 0), 'attribute_id' => $attribute_id, 'value' => 'no', 'label' => __('No', 'wpshop')));
                 }
             }
             /** Change price attribute set section order for default set */
             $price_tab = unserialize(WPSHOP_ATTRIBUTE_PRICES);
             unset($price_tab[array_search(WPSHOP_COST_OF_POSTAGE, $price_tab)]);
             $query = "SELECT GROUP_CONCAT(id) FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code IN ('" . implode("','", $price_tab) . "')";
             $attribute_ids = $wpdb->get_var($query);
             $query = $wpdb->prepare("\nSELECT ATTR_DET.attribute_group_id\nFROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " AS ATTR_DET\n\tINNER JOIN " . WPSHOP_DBT_ATTRIBUTE_GROUP . " AS ATTR_GROUP ON ((ATTR_GROUP.id = ATTR_DET.attribute_group_id) AND (ATTR_GROUP.code = %s))\n\tINNER JOIN " . WPSHOP_DBT_ATTRIBUTE_SET . " AS ATTR_SET ON ((ATTR_SET.id = ATTR_GROUP.attribute_set_id) AND (ATTR_SET.name = %s))\nWHERE ATTR_DET.attribute_id IN (" . $attribute_ids . ")", 'prices', __('default', 'wpshop'));
             $list = $wpdb->get_results($query);
             if (!empty($list)) {
                 $change_order = true;
                 $old_value = $list[0]->attribute_group_id;
                 unset($list[0]);
                 if (!empty($list)) {
                     foreach ($list as $data) {
                         if ($old_value != $data->attribute_group_id) {
                             $change_order = false;
                         }
                     }
                     if ($change_order) {
                         foreach ($price_tab as $price_code) {
                             $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code = %s", $price_code);
                             $attribute_id = $wpdb->get_var($query);
                             switch ($price_code) {
                                 case WPSHOP_PRODUCT_PRICE_HT:
                                     $position = WPSHOP_PRODUCT_PRICE_PILOT == 'HT' ? 1 : 3;
                                     break;
                                 case WPSHOP_PRODUCT_PRICE_TAX:
                                     $position = 2;
                                     break;
                                 case WPSHOP_PRODUCT_PRICE_TTC:
                                     $position = WPSHOP_PRODUCT_PRICE_PILOT == 'HT' ? 3 : 1;
                                     break;
                                 case WPSHOP_PRODUCT_PRICE_TAX_AMOUNT:
                                     $position = 4;
                                     break;
                             }
                             $wpdb->update(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'valid', 'last_update_date' => current_time('mysql', 0), 'position' => $position), array('attribute_group_id' => $old_value, 'attribute_id' => $attribute_id));
                         }
                     }
                 }
             }
             return true;
             break;
         case 22:
             $query = $wpdb->prepare("SELECT ID FROM " . $wpdb->posts . " WHERE post_name = %s", WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
             $product_entity_id = $wpdb->get_var($query);
             if (empty($product_entityd_id) || $product_entity_id <= 0 || !$product_entity_id) {
                 /*	Create the product entity into post table	*/
                 $product_entity = array('post_title' => __('Products', 'wpshop'), 'post_name' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'post_content' => __('Define the entity allowing to manage product on your store. If you delete this entity you won\'t be able to manage your store', 'wpshop'), 'post_status' => 'publish', 'post_author' => 1, 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES);
                 $product_entity_id = wp_insert_post($product_entity);
             }
             /*	Update eav table with the new entity id for product	*/
             $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('entity_id' => $product_entity_id), array('entity_id' => 1));
             $wpdb->update(WPSHOP_DBT_ATTRIBUTE_SET, array('entity_id' => $product_entity_id), array('entity_id' => 1));
             $wpdb->update(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('entity_type_id' => $product_entity_id), array('entity_type_id' => 1));
             $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DATETIME, array('entity_type_id' => $product_entity_id), array('entity_type_id' => 1));
             $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('entity_type_id' => $product_entity_id), array('entity_type_id' => 1));
             $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_INTEGER, array('entity_type_id' => $product_entity_id), array('entity_type_id' => 1));
             $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_TEXT, array('entity_type_id' => $product_entity_id), array('entity_type_id' => 1));
             $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_VARCHAR, array('entity_type_id' => $product_entity_id), array('entity_type_id' => 1));
             $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_HISTO, array('entity_type_id' => $product_entity_id), array('entity_type_id' => 1));
             /*	Create an element of customer entity for each existing user	*/
             $user_list = get_users();
             foreach ($user_list as $user) {
                 wps_customer_ctr::create_entity_customer_when_user_is_created($user->ID);
             }
             return true;
             break;
         case 23:
             /*	Delete duplicate entities	*/
             $query = "SELECT ID FROM " . $wpdb->posts . " WHERE post_name LIKE '%" . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . "%' ";
             $product_entity_list = $wpdb->get_results($query);
             if (count($product_entity_list) > 1) {
                 $i = 0;
                 foreach ($product_entity_list as $product_entity) {
                     if ($i > 0) {
                         wp_delete_post($product_entity->ID);
                     }
                 }
             }
             return true;
             break;
         case 24:
             /*	Update the link status for disabled attribute set	*/
             $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_GROUP . " WHERE status = %s", 'deleted');
             $deleted_attribute_group = $wpdb->get_results($query);
             if (!empty($deleted_attribute_group)) {
                 foreach ($deleted_attribute_group as $group) {
                     $wpdb->update(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'deleted', 'last_update_date' => current_time('mysql', 0)), array('attribute_group_id' => $group->id));
                 }
             }
             /*	Update entities meta management	*/
             $entities = query_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES));
             if (!empty($entities)) {
                 foreach ($entities as $entity) {
                     $support = get_post_meta($entity->ID, '_wpshop_entity_support', true);
                     $rewrite = get_post_meta($entity->ID, '_wpshop_entity_rewrite', true);
                     update_post_meta($entity->ID, '_wpshop_entity_params', array('support' => $support, 'rewrite' => array('slug' => $rewrite)));
                 }
             }
             wp_reset_query();
             return true;
             break;
         case 25:
             /*	Get the first entities of product and customer	*/
             $query = $wpdb->prepare("SELECT ID FROM " . $wpdb->posts . " WHERE post_name=%s AND post_type=%s ORDER BY ID ASC LIMIT 1", WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES);
             $product_entity_id = $wpdb->get_var($query);
             /*	Update attributes that are not linked with entities	*/
             $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('entity_id' => $product_entity_id), array('entity_id' => 0));
             /*	Get entities that have been created a lot of time and delete them	*/
             $query = $wpdb->prepare("SELECT ID FROM " . $wpdb->posts . " WHERE (post_name LIKE '%%" . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . "-%%' OR post_name LIKE '%%" . WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS . "-%%') AND post_type=%s", WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES);
             $entities_to_delete = $wpdb->get_results($query);
             if (!empty($entities_to_delete) && is_array($entities_to_delete)) {
                 foreach ($entities_to_delete as $entity) {
                     wp_delete_post($entity->ID, true);
                 }
             }
             /*	Get post list that are children of entities created a lot of time */
             $query = $wpdb->prepare("SELECT ID FROM " . $wpdb->posts . " WHERE post_type LIKE %s", WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS . "-%");
             $entities_to_update = $wpdb->get_results($query);
             if (!empty($entities_to_update) && is_array($entities_to_update)) {
                 foreach ($entities_to_update as $entity) {
                     wp_update_post(array('ID' => $entity->ID, 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS));
                 }
             }
             $query = $wpdb->prepare("SELECT ID FROM " . $wpdb->posts . " WHERE post_type LIKE %s", WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . "-%");
             $entities_to_update = $wpdb->get_results($query);
             if (!empty($entities_to_update) && is_array($entities_to_update)) {
                 foreach ($entities_to_update as $entity) {
                     wp_update_post(array('ID' => $entity->ID, 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT));
                 }
             }
             /*	Change addons managament	*/
             $wpshop_addons_options = get_option('wpshop_addons_state', array());
             if (!empty($wpshop_addons_options)) {
                 foreach ($wpshop_addons_options as $addon_name => $addon_state) {
                     $options_args = array();
                     $options_args[$addon_name]['activate'] = $addon_state;
                     $options_args[$addon_name]['activation_date'] = current_time('mysql', 0);
                     if (!$addon_state) {
                         $options_args[$addon_name]['deactivation_date'] = current_time('mysql', 0);
                     }
                     add_option(WPSHOP_ADDONS_OPTION_NAME, $options_args);
                 }
                 delete_option('wpshop_addons_state');
             }
             /*	Update the different entities id into attribute set details table	*/
             $query = "UPDATE " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " AS ATT_DET INNER JOIN " . WPSHOP_DBT_ATTRIBUTE . " AS ATT ON (ATT.id = ATT_DET.attribute_id) SET ATT_DET.entity_type_id = ATT.entity_id";
             $wpdb->query($query);
             return true;
             break;
         case 26:
             $query = "SELECT post_id, meta_value FROM " . $wpdb->postmeta . " WHERE meta_key = '_order_postmeta' ";
             $results = $wpdb->get_results($query);
             foreach ($results as $result) {
                 $order_info = unserialize($result->meta_value);
                 update_post_meta($result->post_id, '_wpshop_order_customer_id', $order_info['customer_id']);
                 update_post_meta($result->post_id, '_wpshop_order_shipping_date', $order_info['order_shipping_date']);
                 update_post_meta($result->post_id, '_wpshop_order_status', $order_info['order_status']);
             }
             /*	Update the different entities id into attribute set details table	*/
             $query = "UPDATE " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " AS ATT_DET INNER JOIN " . WPSHOP_DBT_ATTRIBUTE . " AS ATT ON (ATT.id = ATT_DET.attribute_id) SET ATT_DET.entity_type_id = ATT.entity_id";
             $wpdb->query($query);
             return true;
             break;
         case 29:
             $billing_title = __('Billing address', 'wpshop');
             $shipping_title = __('Shipping address', 'wpshop');
             //UPDATE USERS ADDRESSES
             $billing_address_set_id_query = 'SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE name = "' . $billing_title . '"';
             $shipping_address_set_id_query = 'SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE name = "' . $shipping_title . '"';
             $billing_address_set_id = $wpdb->get_var($billing_address_set_id_query);
             $shipping_address_set_id = $wpdb->get_var($shipping_address_set_id_query);
             //Add Address & Google Map API KEY options
             add_option('wpshop_billing_address', array('choice' => $billing_address_set_id), '', 'yes');
             add_option('wpshop_shipping_address_choice', array('activate' => 'on', 'choice' => $shipping_address_set_id), '', 'yes');
             add_option('wpshop_google_map_api_key', '', '', 'yes');
             $query = 'SELECT * FROM ' . $wpdb->users . '';
             $results = $wpdb->get_results($query);
             foreach ($results as $result) {
                 $billing_infos = get_user_meta($result->ID, 'billing_info', true);
                 $shipping_infos = get_user_meta($result->ID, 'shipping_info', true);
                 if (!empty($billing_infos)) {
                     //Save Billing Infos
                     $billing_address = array();
                     if (!empty($billing_infos['civility'])) {
                         switch ($billing_infos['civility']) {
                             case 1:
                                 $civility = $mister_id;
                                 break;
                             case 2:
                                 $civility = $madam_id;
                                 break;
                             case 3:
                                 $civility = $miss_id;
                                 break;
                         }
                     } else {
                         $civility = $mister_id;
                     }
                     $billing_address = array('address_title' => $billing_title, 'address_last_name' => !empty($billing_infos['last_name']) ? $billing_infos['last_name'] : '', 'address_first_name' => !empty($billing_infos['first_name']) ? $billing_infos['first_name'] : '', 'company' => !empty($billing_infos['company']) ? $billing_infos['company'] : '', 'address' => !empty($billing_infos['address']) ? $billing_infos['address'] : '', 'postcode' => !empty($billing_infos['postcode']) ? $billing_infos['postcode'] : '', 'city' => !empty($billing_infos['city']) ? $billing_infos['city'] : '', 'state' => !empty($billing_infos['state']) ? $billing_infos['state'] : '', 'country' => !empty($billing_infos['country']) ? $billing_infos['country'] : '', 'address_user_email' => !empty($billing_infos['email']) ? $billing_infos['email'] : '', 'phone' => !empty($billing_infos['phone']) ? $billing_infos['phone'] : '', 'tva_intra' => !empty($billing_infos['company_tva_intra']) ? $billing_infos['company_tva_intra'] : '', 'civility' => $civility);
                     //Create the post and post_meta for the billing address
                     $post_address = array('post_author' => $result->ID, 'post_title' => $billing_title, 'post_status' => 'publish', 'post_name' => WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS, 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS, 'post_parent' => $result->ID);
                     $post_address_id = wp_insert_post($post_address);
                     //Create the post_meta with the address infos
                     update_post_meta($post_address_id, '_' . WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS . '_metadata', $billing_address);
                     update_post_meta($post_address_id, '_' . WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS . '_attribute_set_id', $billing_address_set_id);
                 }
                 if (!empty($shipping_infos)) {
                     //Save Shipping Infos
                     if (!empty($shipping_infos['civility'])) {
                         switch ($shipping_infos['civility']) {
                             case 1:
                                 $civility = $mister_id;
                                 break;
                             case 2:
                                 $civility = $madam_id;
                                 break;
                             case 3:
                                 $civility = $miss_id;
                                 break;
                         }
                     } else {
                         $civility = $mister_id;
                     }
                     $shipping_address = array();
                     $shipping_address = array('address_title' => $shipping_title, 'address_last_name' => !empty($shipping_infos['last_name']) ? $shipping_infos['last_name'] : '', 'address_first_name' => !empty($shipping_infos['first_name']) ? $shipping_infos['first_name'] : '', 'company' => !empty($shipping_infos['company']) ? $shipping_infos['company'] : '', 'address' => !empty($shipping_infos['address']) ? $shipping_infos['address'] : '', 'postcode' => !empty($shipping_infos['postcode']) ? $shipping_infos['postcode'] : '', 'city' => !empty($shipping_infos['city']) ? $shipping_infos['city'] : '', 'state' => !empty($shipping_infos['state']) ? $shipping_infos['state'] : '', 'country' => !empty($shipping_infos['country']) ? $shipping_infos['country'] : '', 'civility' => $civility);
                     //Create the post and post_meta for the billing address
                     $post_address = array('post_author' => $result->ID, 'post_title' => $shipping_title, 'post_status' => 'publish', 'post_name' => WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS, 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS, 'post_parent' => $result->ID);
                     $post_address_id = wp_insert_post($post_address);
                     //Create the post_meta with the address infos
                     update_post_meta($post_address_id, '_' . WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS . '_metadata', $shipping_address);
                     update_post_meta($post_address_id, '_' . WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS . '_attribute_set_id', $shipping_address_set_id);
                 }
             }
             // FORMATE THE ORDER ADDRESSES INFOS
             $results = query_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'posts_per_page' => -1));
             foreach ($results as $result) {
                 $address = get_post_meta($result->ID, '_order_info', true);
                 $billing_address = array();
                 if (!empty($address['billing'])) {
                     if (!empty($address['billing']['civility'])) {
                         switch ($address['billing']['civility']) {
                             case 1:
                                 $civility = $mister_id;
                                 break;
                             case 2:
                                 $civility = $madam_id;
                                 break;
                             case 3:
                                 $civility = $miss_id;
                                 break;
                             default:
                                 $civility = $mister_id;
                                 break;
                         }
                     } else {
                         $civility = $mister_id;
                     }
                     $billing_address = array('address_title' => $billing_title, 'address_last_name' => !empty($address['billing']['last_name']) ? $address['billing']['last_name'] : '', 'address_first_name' => !empty($address['billing']['first_name']) ? $address['billing']['first_name'] : '', 'company' => !empty($address['billing']['company']) ? $address['billing']['company'] : '', 'address' => !empty($address['billing']['address']) ? $address['billing']['address'] : '', 'postcode' => !empty($address['billing']['postcode']) ? $address['billing']['postcode'] : '', 'city' => !empty($address['billing']['city']) ? $address['billing']['city'] : '', 'state' => !empty($address['billing']['state']) ? $address['billing']['state'] : '', 'country' => !empty($address['billing']['country']) ? $address['billing']['country'] : '', 'address_user_email' => !empty($address['billing']['email']) ? $address['billing']['email'] : '', 'phone' => !empty($address['billing']['phone']) ? $address['billing']['phone'] : '', 'tva_intra' => !empty($address['billing']['company_tva_intra']) ? $address['billing']['company_tva_intra'] : '', 'civility' => $civility);
                 }
                 $shipping_address = array();
                 if (!empty($address['shipping'])) {
                     if (!empty($address['shipping']['civility'])) {
                         switch ($address['shipping']['civility']) {
                             case 1:
                                 $civility = $mister_id;
                                 break;
                             case 2:
                                 $civility = $madam_id;
                                 break;
                             case 3:
                                 $civility = $miss_id;
                                 break;
                         }
                     } else {
                         $civility = $mister_id;
                     }
                     $shipping_address = array('address_title' => $shipping_title, 'address_last_name' => !empty($address['shipping']['last_name']) ? $address['shipping']['last_name'] : '', 'address_first_name' => !empty($address['shipping']['first_name']) ? $address['shipping']['first_name'] : '', 'company' => !empty($address['shipping']['company']) ? $address['shipping']['company'] : '', 'address' => !empty($address['shipping']['address']) ? $address['shipping']['address'] : '', 'postcode' => !empty($address['shipping']['postcode']) ? $address['shipping']['postcode'] : '', 'city' => !empty($address['shipping']['city']) ? $address['shipping']['city'] : '', 'state' => !empty($address['shipping']['state']) ? $address['shipping']['state'] : '', 'country' => !empty($address['shipping']['country']) ? $address['shipping']['country'] : '', 'civility' => $civility);
                 }
                 $billing_array_content = array('id' => $billing_address_set_id, 'address' => $billing_address);
                 $shipping_array_content = array('id' => $shipping_address_set_id, 'address' => $shipping_address);
                 $array_new_format = array('billing' => $billing_array_content, 'shipping' => $shipping_array_content);
                 //Update the post meta
                 update_post_meta($result->ID, '_order_info', $array_new_format);
             }
             /*	Update entities meta management	*/
             $entities = query_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES, 'posts_per_page' => -1));
             if (!empty($entities)) {
                 foreach ($entities as $entity) {
                     $params = get_post_meta($entity->ID, '_wpshop_entity_params', true);
                     $support = !empty($params['support']) ? $params['support'] : '';
                     $rewrite = !empty($params['rewrite']) ? $params['rewrite'] : '';
                     $display_admin_menu = 'on';
                     update_post_meta($entity->ID, '_wpshop_entity_params', array('support' => $support, 'rewrite' => $rewrite, 'display_admin_menu' => $display_admin_menu));
                 }
             }
             wp_reset_query();
             // Default Weight unity and Currency Options
             add_option('wpshop_shop_weight_group', 3, '', 'yes');
             add_option('wpshop_shop_default_weight_unity', 6, '', 'yes');
             add_option('wpshop_shop_currency_group', 4, '', 'yes');
             $default_currency = get_option('wpshop_shop_default_currency');
             foreach (unserialize(WPSHOP_SHOP_CURRENCIES) as $k => $v) {
                 if ($default_currency == $k) {
                     $symbol = $v;
                 }
             }
             if (!empty($symbol)) {
                 $query = 'SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE name = "' . html_entity_decode($symbol, ENT_QUOTES, 'UTF-8') . '"';
                 $currency = $wpdb->get_row($query);
                 if (!empty($currency)) {
                     update_option('wpshop_shop_default_currency', $currency->id);
                     // Update the change rate of the default currency
                     $wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('change_rate' => 1), array('id' => $currency->id));
                 }
             }
             // Update the field for variation and user definition field
             $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('is_used_for_variation' => 'yes'), array('is_user_defined' => 'yes'));
             // Update field type for frontend output selection
             $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('frontend_input' => 'text'), array());
             $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('frontend_input' => 'textarea'), array('backend_input' => 'textarea'));
             $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('frontend_input' => 'select'), array('backend_input' => 'multiple-select'));
             $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('frontend_input' => 'select'), array('backend_input' => 'select'));
             add_option('wpshop_cart_option', array('product_added_to_cart' => array('dialog_msg'), 'product_added_to_quotation' => array('cart_page')));
             return true;
             break;
         case '30':
             /**	Update the current price piloting field for using it into variation specific attributes	*/
             $price_piloting_attribute = constant('WPSHOP_PRODUCT_PRICE_' . WPSHOP_PRODUCT_PRICE_PILOT);
             $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('is_used_in_variation' => 'yes', 'last_update_date' => current_time('mysql', 0)), array('code' => $price_piloting_attribute));
             /**	Update the product reference field for using it into variation specific attributes	*/
             $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('is_used_in_variation' => 'yes', 'last_update_date' => current_time('mysql', 0)), array('code' => 'product_reference'));
             /**	Insert new message for admin when a customer make an order	*/
             $admin_new_order_message = get_option('WPSHOP_NEW_ORDER_ADMIN_MESSAGE');
             if (empty($admin_new_order_message)) {
                 wps_message_ctr::createMessage('WPSHOP_NEW_ORDER_ADMIN_MESSAGE');
             }
             /**	Update all amount for paypal orders	*/
             $query = $wpdb->prepare("SELECT post_id FROM " . $wpdb->postmeta . " WHERE meta_key = %s AND meta_value = %s ", '_wpshop_payment_method', 'paypal');
             $paypal_payment_list = $wpdb->get_results($query);
             if (!empty($paypal_payment_list)) {
                 foreach ($paypal_payment_list as $post) {
                     $order_meta = get_post_meta($post->post_id, '_order_postmeta', true);
                     $order_payment_meta = get_post_meta($post->post_id, 'wpshop_payment_return_data', true);
                     if (!empty($order_meta['order_status']) && $order_meta['order_status'] == 'incorrect_amount') {
                         if (!empty($order_meta['order_grand_total']) && !empty($order_payment_meta['mc_gross'])) {
                             $order_amount_to_pay = number_format($order_meta['order_grand_total'], 5);
                             $order_amount_payed = number_format(floatval($order_payment_meta['mc_gross']), 5);
                             if ($order_amount_payed == $order_amount_to_pay) {
                                 wpshop_payment::setOrderPaymentStatus($order_id, 'completed');
                             }
                         }
                     }
                 }
             }
             /**	Save existing orders address information	*/
             $billing_title = __('Billing address', 'wpshop');
             $shipping_title = __('Shipping address', 'wpshop');
             $results = query_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'posts_per_page' => -1));
             foreach ($results as $result) {
                 $address = get_post_meta($result->ID, '_order_info', true);
                 $address_format = array();
                 $billing_address = array();
                 if (!empty($address['billing']) && empty($address['billing']['id'])) {
                     if (!empty($address['billing']['civility'])) {
                         switch ($address['billing']['civility']) {
                             case 1:
                                 $civility = $mister_id;
                                 break;
                             case 2:
                                 $civility = $madam_id;
                                 break;
                             case 3:
                                 $civility = $miss_id;
                                 break;
                             default:
                                 $civility = $mister_id;
                                 break;
                         }
                     } else {
                         $civility = $mister_id;
                     }
                     $billing_address = array('address_title' => $billing_title, 'address_last_name' => !empty($address['billing']['last_name']) ? $address['billing']['last_name'] : '', 'address_first_name' => !empty($address['billing']['first_name']) ? $address['billing']['first_name'] : '', 'company' => !empty($address['billing']['company']) ? $address['billing']['company'] : '', 'address' => !empty($address['billing']['address']) ? $address['billing']['address'] : '', 'postcode' => !empty($address['billing']['postcode']) ? $address['billing']['postcode'] : '', 'city' => !empty($address['billing']['city']) ? $address['billing']['city'] : '', 'state' => !empty($address['billing']['state']) ? $address['billing']['state'] : '', 'country' => !empty($address['billing']['country']) ? $address['billing']['country'] : '', 'address_user_email' => !empty($address['billing']['email']) ? $address['billing']['email'] : '', 'phone' => !empty($address['billing']['phone']) ? $address['billing']['phone'] : '', 'tva_intra' => !empty($address['billing']['company_tva_intra']) ? $address['billing']['company_tva_intra'] : '', 'civility' => $civility);
                     $billing_address_option = get_option('wpshop_billing_address');
                     $address_format['billing']['id'] = $billing_address_option['choice'];
                     $address_format['billing']['address'] = $shipping_address;
                 }
                 $shipping_address = array();
                 if (!empty($address['shipping']) && empty($address['shipping']['id'])) {
                     if (!empty($address['shipping']['civility'])) {
                         switch ($address['shipping']['civility']) {
                             case 1:
                                 $civility = $mister_id;
                                 break;
                             case 2:
                                 $civility = $madam_id;
                                 break;
                             case 3:
                                 $civility = $miss_id;
                                 break;
                         }
                     } else {
                         $civility = $mister_id;
                     }
                     $shipping_address = array('address_title' => $shipping_title, 'address_last_name' => !empty($address['shipping']['last_name']) ? $address['shipping']['last_name'] : '', 'address_first_name' => !empty($address['shipping']['first_name']) ? $address['shipping']['first_name'] : '', 'company' => !empty($address['shipping']['company']) ? $address['shipping']['company'] : '', 'address' => !empty($address['shipping']['address']) ? $address['shipping']['address'] : '', 'postcode' => !empty($address['shipping']['postcode']) ? $address['shipping']['postcode'] : '', 'city' => !empty($address['shipping']['city']) ? $address['shipping']['city'] : '', 'state' => !empty($address['shipping']['state']) ? $address['shipping']['state'] : '', 'country' => !empty($address['shipping']['country']) ? $address['shipping']['country'] : '', 'civility' => $civility);
                     $shipping_address_options = get_option('wpshop_shipping_address_choice');
                     $address_format['shipping']['id'] = $shipping_address_options['choice'];
                     $address_format['shipping']['address'] = $shipping_address;
                 }
                 if (!empty($address_format)) {
                     update_post_meta($result->ID, '_order_info', $address_format);
                 }
             }
             /**	Delete username from frontend form	*/
             $attribute_login = wpshop_attributes::getElement('user_login', "'valid'", 'code');
             if (!empty($attribute_login)) {
                 $wpdb->update(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'deleted', 'last_update_date' => current_time('mysql', 0), 'position' => 0), array('attribute_id' => $attribute_login->id));
             }
             $wpdb->update(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('last_update_date' => current_time('mysql', 0), 'position' => 0), array('status' => 'deleted'));
             return true;
             break;
         case '31':
             /**	Change order structure in order to support several payment	*/
             $existing_orders = query_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'posts_per_page' => -1, 'post_status' => array('draft', 'trash', 'publish')));
             if (!empty($existing_orders)) {
                 foreach ($existing_orders as $order_main_informations) {
                     /**	Transfer payment return data form old meta to new	*/
                     $order_payment_return_data = get_post_meta($order_main_informations->ID, 'wpshop_payment_return_data', true);
                     update_post_meta($order_main_informations->ID, '_wpshop_payment_return_data', $order_payment_return_data);
                     delete_post_meta($order_main_informations->ID, 'wpshop_payment_return_data');
                     /**	Transfer old payment storage method to new storage method	*/
                     $order_meta = get_post_meta($order_main_informations->ID, '_order_postmeta', true);
                     if (!empty($order_meta['order_status'])) {
                         $order_meta['order_payment']['customer_choice'] = array('method' => !empty($order_meta['payment_method']) ? $order_meta['payment_method'] : (!empty($order_meta['order_payment']['customer_choice']) ? $order_meta['order_payment']['customer_choice'] : ''));
                         unset($order_meta['payment_method']);
                         $order_meta['order_payment']['received'][0]['waited_amount'] = !empty($order_meta['order_grand_total']) ? $order_meta['order_grand_total'] : 0;
                         $order_meta['order_payment']['received'][0]['method'] = $order_meta['order_payment']['customer_choice']['method'];
                         $order_meta['order_payment']['received'][0]['date'] = $order_meta['order_date'];
                         $order_meta['order_payment']['received'][0]['status'] = 'waiting_payment';
                         $order_meta['order_payment']['received'][0]['comment'] = '';
                         $order_meta['order_payment']['received'][0]['author'] = $order_meta['order_payment']['customer_choice'] == 'check' ? 1 : $order_meta['customer_id'];
                         if (in_array($order_meta['order_status'], array('completed', 'shipped'))) {
                             $order_meta['order_payment']['received'][0]['received_amount'] = $order_meta['order_grand_total'];
                             $order_meta['order_payment']['received'][0]['payment_reference'] = wpshop_payment::get_payment_transaction_number_old_way($order_main_informations->ID);
                             $order_meta['order_payment']['received'][0]['date'] = $order_meta['order_payment_date'];
                             $order_meta['order_payment']['received'][0]['status'] = 'payment_received';
                             $order_meta['order_payment']['received'][0]['comment'] = '';
                             $order_meta['order_payment']['received'][0]['author'] = $order_meta['order_payment']['customer_choice'] == 'check' ? 1 : $order_meta['customer_id'];
                             $order_meta['order_payment']['received'][0]['invoice_ref'] = $order_meta['order_invoice_ref'];
                         }
                         update_post_meta($order_main_informations->ID, '_order_postmeta', $order_meta);
                         if (!empty($order_meta['order_payment']['customer_choice'])) {
                             switch ($order_meta['order_payment']['customer_choice']) {
                                 case 'check':
                                     delete_post_meta($order_main_informations->ID, '_order_check_number', get_post_meta($order_main_informations->ID, '_order_check_number', true));
                                     break;
                                 case 'paypal':
                                     delete_post_meta($order_main_informations->ID, '_order_paypal_txn_id', get_post_meta($order_main_informations->ID, '_order_paypal_txn_id', true));
                                     break;
                                 case 'cic':
                                     delete_post_meta($order_main_informations->ID, '_order_cic_txn_id', get_post_meta($order_main_informations->ID, '_order_cic_txn_id', true));
                                     break;
                             }
                         }
                     }
                 }
             }
             $wps_messages = new wps_message_ctr();
             $wps_messages->wpshop_messages_historic_correction();
             wp_reset_query();
             $default_currency = get_option('wpshop_shop_default_currency');
             foreach (unserialize(WPSHOP_SHOP_CURRENCIES) as $k => $v) {
                 if ($default_currency == $k) {
                     $symbol = $v;
                 }
             }
             if (!empty($symbol)) {
                 $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE name = "' . html_entity_decode($symbol, ENT_QUOTES, 'UTF-8') . '"', '');
                 $currency = $wpdb->get_row($query);
                 if (!empty($currency)) {
                     update_option('wpshop_shop_default_currency', $currency->id);
                     // Update the change rate of the default currency
                     $wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('change_rate' => 1), array('id' => $currency->id));
                 }
             }
             $shipping_confirmation_message = get_option('WPSHOP_SHIPPING_CONFIRMATION_MESSAGE');
             if (!empty($shipping_confirmation_message)) {
                 $message = __('Hello [customer_first_name] [customer_last_name], this email confirms that your order ([order_key]) has just been shipped (order date : [order_date], tracking number : [order_trackingNumber]). Thank you for your loyalty. Have a good day.', 'wpshop');
                 $post = array('ID' => $shipping_confirmation_message, 'post_content' => $message);
                 wp_update_post($post);
             }
             return true;
             break;
         case '32':
             /**	Update product set id that are null 	*/
             $query = $wpdb->prepare("UPDATE " . $wpdb->postmeta . " SET meta_value = (SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " WHERE default_set = 'yes' AND entity_id = '" . wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) . "') WHERE meta_key = %s AND ((meta_value = '') OR (meta_value = null))", '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_attribute_set_id');
             $wpdb->query($query);
             $addons_options = get_option(WPSHOP_ADDONS_OPTION_NAME);
             if (!empty($addons_options) && !empty($addons_options['WPSHOP_ADDONS_QUOTATION']) && !empty($addons_options['WPSHOP_ADDONS_QUOTATION']['activate']) && $addons_options['WPSHOP_ADDONS_QUOTATION']['activate']) {
                 $admin_new_quotation_message = get_option('WPSHOP_NEW_QUOTATION_ADMIN_MESSAGE');
                 if (empty($admin_new_quotation_message)) {
                     wps_message_ctr::createMessage('WPSHOP_NEW_QUOTATION_ADMIN_MESSAGE');
                 }
                 $admin_new_quotation_confirm_message = get_option('WPSHOP_QUOTATION_CONFIRMATION_MESSAGE');
                 if (empty($admin_new_quotation_confirm_message)) {
                     wps_message_ctr::createMessage('WPSHOP_QUOTATION_CONFIRMATION_MESSAGE');
                 }
             }
             /**	Allows the administrator to manage a little bit more the catalog rewrite parameters	*/
             $options = get_option('wpshop_catalog_product_option');
             $options['wpshop_catalog_product_slug_with_category'] = empty($options['wpshop_catalog_product_slug_with_category']) ? 'yes' : $options['wpshop_catalog_product_slug_with_category'];
             update_option('wpshop_catalog_product_option', $options);
             /**	Create a new page for unsuccessfull payment return	*/
             self::wpshop_insert_default_pages($wpshop_shop_type);
             wp_cache_flush();
             /**	Update the iso code of currencies	*/
             $wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('code_iso' => 'EUR'), array('name' => 'euro'));
             $wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('code_iso' => 'USD'), array('name' => 'dollar'));
             /** Update VAT Rate*/
             $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code = %s OR code = %s', 'tx_tva', 'eco_taxe_rate_tva');
             $attribute_ids = $wpdb->get_results($query);
             foreach ($attribute_ids as $attribute_id) {
                 $query = $wpdb->prepare('UPDATE ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' SET value = replace(value, "-", ".") WHERE attribute_id = %d', $attribute_id->id);
                 $wpdb->query($query);
             }
             return true;
             break;
         case '33':
             /** Update the user_mail for the new system of log in/register */
             $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "yes" WHERE code = "user_email"');
             /** Put discount attributes in price attribute set section*/
             $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_GROUP . ' WHERE code = %s', 'prices');
             $prices_section_id = $wpdb->get_var($query);
             $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code = %s OR code = %s', 'discount_rate', 'discount_amount');
             $attributes = $wpdb->get_results($query);
             if (!empty($attributes) && !empty($prices_section_id)) {
                 foreach ($attributes as $attribute) {
                     $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' SET attribute_group_id = ' . $prices_section_id . ' WHERE attribute_id = ' . $attribute->id);
                 }
             }
             return true;
             break;
         case '34':
             $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_GROUP . ' WHERE code = %s', 'prices');
             $prices_section_id = $wpdb->get_var($query);
             $query = $wpdb->prepare('SELECT MAX(position) AS max_position FROM ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE attribute_group_id = %d', $prices_section_id);
             $last_position_id = $wpdb->get_var($query);
             $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE  attribute_group_id = %d AND position = %d', $prices_section_id, $last_position_id);
             $attribute_example = $wpdb->get_row($query);
             $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code = %s OR code = %s', 'special_from', 'special_to');
             $attributes = $wpdb->get_results($query);
             $i = 1;
             if (!empty($attributes) && !empty($prices_section_id)) {
                 foreach ($attributes as $attribute) {
                     $wpdb->update(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('attribute_group_id' => $prices_section_id), array('attribute_id' => $attribute->id));
                     $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'entity_type_id' => $attribute_example->entity_type_id, 'attribute_set_id' => $attribute_example->attribute_set_id, 'attribute_group_id' => $prices_section_id, 'attribute_id' => $attribute->id, 'position' => $last_position_id + $i));
                     $i++;
                 }
             }
             $discount_options = get_option('wpshop_catalog_product_option');
             $status = !empty($discount_options) && !empty($discount_options['discount']) ? 'valid' : 'notused';
             $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('frontend_label' => __('Discount from', 'wpshop'), 'status' => $status), array('code' => 'special_from'));
             $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('frontend_label' => __('Discount to', 'wpshop'), 'status' => $status), array('code' => 'special_to'));
             return true;
             break;
         case '35':
             $wpdb->update($wpdb->posts, array('post_status' => 'draft'), array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS));
             return true;
             break;
         case '36':
             wpshop_entities::create_cpt_attributes_from_csv_file(WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS);
             @set_time_limit(900);
             /** Change the path for old categories pictures */
             @chmod(WPSHOP_UPLOAD_DIR . 'wpshop_product_category', 0755);
             $query = 'SELECT * FROM ' . $wpdb->terms;
             $terms = $wpdb->get_results($query);
             if (!empty($terms)) {
                 foreach ($terms as $term) {
                     @chmod(WPSHOP_UPLOAD_DIR . 'wpshop_product_category/' . $term->term_id, 0755);
                     /** Check if a picture exists **/
                     $term_option = get_option(WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '_' . $term->term_id);
                     if (!empty($term_option) && !empty($term_option['wpshop_category_picture']) && is_file(WPSHOP_UPLOAD_DIR . $term_option['wpshop_category_picture'])) {
                         $wp_upload_dir = wp_upload_dir();
                         $img_path = WPSHOP_UPLOAD_DIR . $term_option['wpshop_category_picture'];
                         $img_basename = basename($img_path);
                         $wp_filetype = wp_check_filetype($img_basename, null);
                         /** Check if there is an image with the same name, if yes we add a rand number to image's name **/
                         $rand_name = is_file($wp_upload_dir['path'] . '/' . $img_basename) ? rand() : '';
                         $img_basename = !empty($rand_name) ? $rand_name . '_' . $img_basename : $img_basename;
                         if (copy($img_path, $wp_upload_dir['path'] . '/' . $img_basename)) {
                             $attachment = array('guid' => $wp_upload_dir['url'] . '/' . $img_basename, 'post_mime_type' => $wp_filetype['type'], 'post_title' => preg_replace('/\\.[^.]+$/', '', $img_basename), 'post_content' => '', 'post_status' => 'inherit');
                             $attach_id = wp_insert_attachment($attachment, $wp_upload_dir['path'] . '/' . $img_basename);
                             /** Generate differnts sizes for this image **/
                             require_once ABSPATH . 'wp-admin/includes/image.php';
                             $attach_data = wp_generate_attachment_metadata($attach_id, $wp_upload_dir['path'] . '/' . $img_basename);
                             wp_update_attachment_metadata($attach_id, $attach_data);
                             /** Update option picture **/
                             $term_option['wpshop_category_picture'] = $attach_id;
                             update_option(WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '_' . $term->term_id, $term_option);
                         }
                     }
                 }
             }
             /** Change metabox Hidden Nav Menu Definition to display WPShop categories' metabox **/
             $query = $wpdb->prepare('SELECT * FROM ' . $wpdb->usermeta . ' WHERE meta_key = %s', 'metaboxhidden_nav-menus');
             $meta_keys = $wpdb->get_results($query);
             if (!empty($meta_keys) && is_array($meta_keys)) {
                 foreach ($meta_keys as $meta_key) {
                     $user_id = $meta_key->user_id;
                     $meta_value = unserialize($meta_key->meta_value);
                     if (!empty($meta_value) && is_array($meta_value)) {
                         $data_to_delete = array_search('add-wpshop_product_category', $meta_value);
                         if ($data_to_delete !== false) {
                             unset($meta_value[$data_to_delete]);
                         }
                     }
                     update_user_meta($user_id, 'metaboxhidden_nav-menus', $meta_value);
                 }
             }
             return true;
             break;
         case '37':
             @set_time_limit(900);
             /** Change the path for old categories pictures */
             @chmod(WPSHOP_UPLOAD_DIR . 'wpshop/wpshop_product_category', 0755);
             /** Read all categories folders **/
             $categories_main_dir = WPSHOP_UPLOAD_DIR . 'wpshop/wpshop_product_category';
             if (file_exists($categories_main_dir)) {
                 $main_folder_content = scandir($categories_main_dir);
                 /** For each category folder **/
                 foreach ($main_folder_content as $category_folder) {
                     if ($category_folder && substr($category_folder, 0, 1) != '.') {
                         $category_id = $category_folder;
                         @chmod(WPSHOP_UPLOAD_DIR . 'wpshop/wpshop_product_category/' . $category_id, 0755);
                         $scan_category_folder = opendir($categories_main_dir . '/' . $category_folder);
                         /** For each Picture of category **/
                         $file_time = 0;
                         $save_this_picture = false;
                         while (false !== ($fichier = readdir($scan_category_folder))) {
                             if ($fichier && substr($fichier, 0, 1) != '.') {
                                 if ($file_time < filemtime($categories_main_dir . '/' . $category_id . '/' . $fichier)) {
                                     $save_this_picture = true;
                                     $file_time = filemtime($categories_main_dir . '/' . $category_id . '/' . $fichier);
                                 }
                                 /** Select category option **/
                                 $term_option = get_option(WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '_' . $category_id);
                                 $wp_upload_dir = wp_upload_dir();
                                 $img_path = $categories_main_dir . '/' . $category_id . '/' . $fichier;
                                 $img_basename = basename($img_path);
                                 $wp_filetype = wp_check_filetype($img_basename, null);
                                 /** Check if there is an image with the same name, if yes we add a rand number to image's name **/
                                 $rand_name = is_file($wp_upload_dir['path'] . '/' . $img_basename) ? rand() : '';
                                 $img_basename = !empty($rand_name) ? $rand_name . '_' . $img_basename : $img_basename;
                                 if (copy($img_path, $wp_upload_dir['path'] . '/' . $img_basename)) {
                                     $attachment = array('guid' => $wp_upload_dir['url'] . '/' . $img_basename, 'post_mime_type' => $wp_filetype['type'], 'post_title' => preg_replace('/\\.[^.]+$/', '', $img_basename), 'post_content' => '', 'post_status' => 'inherit');
                                     $attach_id = wp_insert_attachment($attachment, $wp_upload_dir['path'] . '/' . $img_basename);
                                     /** Generate differnts sizes for this image **/
                                     require_once ABSPATH . 'wp-admin/includes/image.php';
                                     $attach_data = wp_generate_attachment_metadata($attach_id, $wp_upload_dir['path'] . '/' . $img_basename);
                                     wp_update_attachment_metadata($attach_id, $attach_data);
                                     /** Update option picture **/
                                     $term_option['wpshop_category_picture'] = $attach_id;
                                     if ($save_this_picture) {
                                         update_option(WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '_' . $category_id, $term_option);
                                     }
                                     $save_this_picture = false;
                                 }
                             }
                         }
                     }
                 }
             }
             return true;
             break;
         case '38':
             wps_message_ctr::createMessage('WPSHOP_QUOTATION_UPDATE_MESSAGE');
             return true;
             break;
         case '39':
             $attribute_def = wpshop_attributes::getElement('tx_tva', "'valid'", 'code');
             /** Check if the 7% VAT Rate is not already created **/
             $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE attribute_id = %d AND value = %s', $attribute_def->id, '7');
             $exist_vat_rate = $wpdb->get_results($query);
             if (empty($exist_vat_rate)) {
                 /** Get Max Position **/
                 $query = $wpdb->prepare('SELECT MAX(position) as max_position FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE attribute_id = %d', $attribute_def->id);
                 $max_position = $wpdb->get_var($query);
                 if (!empty($attribute_def) && !empty($attribute_def->id)) {
                     $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'attribute_id' => $attribute_def->id, 'position' => (int) $max_position + 1, 'value' => '7', 'label' => '7'));
                 }
             }
             /** Filter Search optimization **/
             @set_time_limit(900);
             $query = $wpdb->prepare('SELECT term_id FROM ' . $wpdb->term_taxonomy . ' WHERE taxonomy = %s ', WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES);
             $categories = $wpdb->get_results($query);
             $cats = array();
             if (!empty($categories)) {
                 foreach ($categories as $category) {
                     $cats[] = $category->term_id;
                 }
                 $wpshop_filter_search = new wps_filter_search();
                 $wpshop_filter_search->stock_values_for_attribute($cats);
             }
             return true;
             break;
         case '40':
             /**	Store watt in puissance unit group	*/
             $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP . " WHERE name = %s", __('puissance', 'wpshop'));
             $puissance_unit_group_id = $wpdb->get_var($query);
             $wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('group_id' => $puissance_unit_group_id), array('unit' => 'watt'));
             /**	Store day/week/year in duration unit group	*/
             $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP . " WHERE name = %s", __('duration', 'wpshop'));
             $duration_unit_group_id = $wpdb->get_var($query);
             $wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('group_id' => $duration_unit_group_id), array('unit' => 'day'));
             $wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('group_id' => $duration_unit_group_id), array('unit' => 'week'));
             $wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('group_id' => $duration_unit_group_id), array('unit' => 'year'));
             /**	Store day/week/year in duration unit group	*/
             $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP . " WHERE name = %s", __('length', 'wpshop'));
             $length_unit_group_id = $wpdb->get_var($query);
             $wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('group_id' => $length_unit_group_id), array('unit' => 'cm'));
             return true;
             break;
         case '41':
             /**	Get distinct attribute set and delete doublons	*/
             $query = "SELECT DISTINCT( name ) AS name, MIN( id ) as min_id FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " GROUP BY name HAVING COUNT(id) > 1";
             $list_of_set = $wpdb->get_results($query);
             foreach ($list_of_set as $set_infos) {
                 $query = $wpdb->prepare("DELETE FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " WHERE name = %s AND id != %d", $set_infos->name, $set_infos->min_id);
                 $wpdb->query($query);
             }
             $wpdb->query("OPTIMIZE TABLE " . WPSHOP_DBT_ATTRIBUTE_SET);
             /**	Get and delete attribute set section	*/
             $query = "DELETE FROM " . WPSHOP_DBT_ATTRIBUTE_GROUP . " WHERE attribute_set_id NOT IN ( SELECT DISTINCT(id) FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " )";
             $wpdb->query($query);
             $wpdb->query("OPTIMIZE TABLE " . WPSHOP_DBT_ATTRIBUTE_GROUP);
             /**	Get and delete attribute set details	*/
             $query = "DELETE FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " WHERE attribute_set_id NOT IN ( SELECT DISTINCT(id) FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " ) OR attribute_group_id NOT IN ( SELECT DISTINCT(id) FROM " . WPSHOP_DBT_ATTRIBUTE_GROUP . " )";
             $wpdb->query($query);
             $wpdb->query("OPTIMIZE TABLE " . WPSHOP_DBT_ATTRIBUTE_DETAILS);
             $query = "SELECT attribute_set_id, attribute_group_id, attribute_id, MIN(id) as min_id FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " GROUP BY attribute_set_id, attribute_group_id, attribute_id HAVING COUNT(id) > 1";
             $affectation_list = $wpdb->get_results($query);
             foreach ($affectation_list as $affectation_to_treat) {
                 $query = $wpdb->prepare("DELETE FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " WHERE attribute_set_id = %d AND attribute_group_id = %d AND attribute_id = %d AND id != %d", $affectation_to_treat->attribute_set_id, $affectation_to_treat->attribute_group_id, $affectation_to_treat->attribute_id, $affectation_to_treat->min_id);
                 $wpdb->query($query);
             }
             $wpdb->query("OPTIMIZE TABLE " . WPSHOP_DBT_ATTRIBUTE_DETAILS);
             /**	Get and delete double unit	*/
             $query = "SELECT DISTINCT( unit ) AS unit, MIN( id ) as min_id FROM " . WPSHOP_DBT_ATTRIBUTE_UNIT . " GROUP BY unit HAVING COUNT(id) > 1";
             $list_of_set = $wpdb->get_results($query);
             foreach ($list_of_set as $set_infos) {
                 $query = $wpdb->prepare("DELETE FROM " . WPSHOP_DBT_ATTRIBUTE_UNIT . " WHERE unit = %s AND id != %d", $set_infos->unit, $set_infos->min_id);
                 $wpdb->query($query);
             }
             $wpdb->query("OPTIMIZE TABLE " . WPSHOP_DBT_ATTRIBUTE_UNIT);
             $query = "SELECT DISTINCT( name ) AS name, MIN( id ) as min_id FROM " . WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP . " GROUP BY name HAVING COUNT(id) > 1";
             $list_of_set = $wpdb->get_results($query);
             foreach ($list_of_set as $set_infos) {
                 $query = $wpdb->prepare("DELETE FROM " . WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP . " WHERE name = %s AND id != %d", $set_infos->name, $set_infos->min_id);
                 $wpdb->query($query);
             }
             $wpdb->query("OPTIMIZE TABLE " . WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP);
             /**	Get and delete attribute set details	*/
             $query = "DELETE FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " WHERE attribute_set_id NOT IN ( SELECT DISTINCT(id) FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " ) OR attribute_group_id NOT IN ( SELECT DISTINCT(id) FROM " . WPSHOP_DBT_ATTRIBUTE_GROUP . " )";
             $wpdb->query($query);
             $query = "SELECT GROUP_CONCAT( id ) AS list_id, MIN( id ) as min_id FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " GROUP BY attribute_set_id, attribute_group_id, attribute_id HAVING COUNT(id) > 1";
             $affectation_list = $wpdb->get_results($query);
             foreach ($affectation_list as $list) {
                 $query = $wpdb->prepare("DELETE FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " WHERE id IN (" . (substr($list->list_id, -1) == ',' ? substr($list->list_id, 0, -1) : $list->list_id) . ") AND id != %d", $list->min_id, '');
                 $wpdb->query($query);
             }
             $wpdb->query("OPTIMIZE TABLE " . WPSHOP_DBT_ATTRIBUTE_DETAILS);
             return true;
             break;
         case '42':
             $available_downloadable_product = get_option('WPSHOP_DOWNLOADABLE_FILE_IS_AVAILABLE');
             if (empty($available_downloadable_product)) {
                 wps_message_ctr::createMessage('WPSHOP_DOWNLOADABLE_FILE_IS_AVAILABLE');
             }
             return true;
             break;
         case '43':
             $available_downloadable_product = get_option('WPSHOP_ORDER_IS_CANCELED');
             if (empty($available_downloadable_product)) {
                 wps_message_ctr::createMessage('WPSHOP_ORDER_IS_CANCELED');
             }
             return true;
             break;
         case '44':
             $display_option = get_option('wpshop_display_option');
             if (!empty($display_option) && empty($display_option['latest_products_ordered'])) {
                 $display_option['latest_products_ordered'] = 3;
                 update_option('wpshop_display_option', $display_option);
             }
             /** Check messages for customization **/
             $messages = array('WPSHOP_SIGNUP_MESSAGE' => WPSHOP_SIGNUP_MESSAGE, 'WPSHOP_PAYPAL_PAYMENT_CONFIRMATION_MESSAGE' => WPSHOP_PAYPAL_PAYMENT_CONFIRMATION_MESSAGE, 'WPSHOP_OTHERS_PAYMENT_CONFIRMATION_MESSAGE' => WPSHOP_OTHERS_PAYMENT_CONFIRMATION_MESSAGE, 'WPSHOP_SHIPPING_CONFIRMATION_MESSAGE' => WPSHOP_SHIPPING_CONFIRMATION_MESSAGE, 'WPSHOP_ORDER_UPDATE_MESSAGE' => WPSHOP_ORDER_UPDATE_MESSAGE, 'WPSHOP_ORDER_UPDATE_PRIVATE_MESSAGE' => WPSHOP_ORDER_UPDATE_PRIVATE_MESSAGE, 'WPSHOP_NEW_ORDER_ADMIN_MESSAGE' => WPSHOP_NEW_ORDER_ADMIN_MESSAGE, 'WPSHOP_NEW_QUOTATION_ADMIN_MESSAGE' => WPSHOP_NEW_QUOTATION_ADMIN_MESSAGE, 'WPSHOP_QUOTATION_CONFIRMATION_MESSAGE' => WPSHOP_QUOTATION_CONFIRMATION_MESSAGE, 'WPSHOP_QUOTATION_UPDATE_MESSAGE' => WPSHOP_QUOTATION_UPDATE_MESSAGE, 'WPSHOP_DOWNLOADABLE_FILE_IS_AVAILABLE' => WPSHOP_DOWNLOADABLE_FILE_IS_AVAILABLE, 'WPSHOP_ORDER_IS_CANCELED' => WPSHOP_ORDER_IS_CANCELED);
             if (!empty($messages)) {
                 foreach ($messages as $key => $message) {
                     $message_option = get_option($key);
                     if (!empty($message_option)) {
                         $post_message = get_post($message_option);
                         $original_message = !empty($post_message) && !empty($post_message->post_content) ? $post_message->post_content : '';
                         $tags = array('<p>', '</p>');
                         if (str_replace($tags, '', $original_message) == str_replace($tags, '', __($message, 'wpshop'))) {
                             wp_update_post(array('ID' => $message_option, 'post_content' => wps_message_ctr::customize_message($original_message)));
                         }
                     }
                 }
             }
             return true;
             break;
         case '45':
             $shipping_mode_ctr = new wps_shipping_mode_ctr();
             $shipping_mode_ctr->migrate_default_shipping_mode();
             return true;
             break;
         case '46':
             wps_message_ctr::createMessage('WPSHOP_FORGOT_PASSWORD_MESSAGE');
             wps_message_ctr::customize_message(WPSHOP_FORGOT_PASSWORD_MESSAGE);
             return true;
             break;
         case '47':
             wps_payment_mode::migrate_payment_modes();
             return true;
             break;
         case '48':
             @ini_set('max_execution_time', '500');
             $count_products = wp_count_posts(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
             $output_type_option = get_option('wpshop_display_option');
             $output_type = $output_type_option['wpshop_display_list_type'];
             for ($i = 0; $i <= $count_products->publish; $i += 20) {
                 $query = $wpdb->prepare('SELECT * FROM ' . $wpdb->posts . ' WHERE post_type = %s AND post_status = %s ORDER BY ID DESC LIMIT ' . $i . ', 20', WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'publish');
                 $products = $wpdb->get_results($query);
                 if (!empty($products)) {
                     foreach ($products as $product) {
                         $p = wpshop_products::get_product_data($product->ID);
                         $price = wpshop_prices::get_product_price($p, 'just_price_infos', array('mini_output', $output_type));
                         update_post_meta($product->ID, '_wps_price_infos', $price);
                     }
                 }
             }
             return true;
             break;
         case '49':
             update_option('wpshop_send_invoice', true);
             return true;
             break;
         case '50':
             $price_display_option = get_option('wpshop_catalog_product_option');
             $price_display_option['price_display']['text_from'] = 'on';
             $price_display_option['price_display']['lower_price'] = 'on';
             update_option('wpshop_catalog_product_option', $price_display_option);
             self::wpshop_insert_default_pages();
             return true;
             break;
         case '51':
             /**	Insert new message for direct payment link	*/
             $direct_payment_link_message = get_option('WPSHOP_DIRECT_PAYMENT_LINK_MESSAGE');
             if (empty($direct_payment_link_message)) {
                 wps_message_ctr::createMessage('WPSHOP_DIRECT_PAYMENT_LINK_MESSAGE');
             }
             return true;
             break;
         case '52':
             $account_page_option = get_option('wpshop_myaccount_page_id');
             if (!empty($account_page_option)) {
                 $page_account = get_post($account_page_option);
                 $page_content = !empty($page_account) && !empty($page_account->post_content) ? str_replace('[wpshop_myaccount]', '[wps_account_dashboard]', $page_account->post_content) : '[wps_account_dashboard]';
                 wp_update_post(array('ID' => $account_page_option, 'post_content' => $page_content));
             }
             return true;
             break;
         case '53':
             $payment_modes_option = get_option('wps_payment_mode');
             if (!empty($payment_modes_option) && !empty($payment_modes_option['mode'])) {
                 $payment_modes_option['mode']['cash_on_delivery'] = array('name' => __('Cash on delivery', 'wpshop'), 'logo' => WPSHOP_TEMPLATES_URL . 'wpshop/cheque.png', 'description' => __('Pay your order on delivery', 'wpshop'));
                 update_option('wps_payment_mode', $payment_modes_option);
             }
             // Mass action on products to add a flag on variation definition
             $products = get_posts(array('posts_per_page' => -1, 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT));
             if (!empty($products)) {
                 foreach ($products as $p) {
                     $post_id = $p->ID;
                     $check_product_have_variations = wpshop_products::get_variation($post_id);
                     if (!empty($check_product_have_variations)) {
                         $variation_flag = wpshop_products::check_variation_type($post_id);
                         $variation_defining = get_post_meta($post_id, '_wpshop_variation_defining', true);
                         $variation_defining['variation_type'] = $variation_flag;
                         update_post_meta($post_id, '_wpshop_variation_defining', $variation_defining);
                     }
                 }
             }
             return true;
             break;
         case '54':
             // Change shortcode of sign up page
             $signup_page_id = get_option('wpshop_signup_page_id');
             if (!empty($signup_page_id)) {
                 $signup_page = get_post($signup_page_id);
                 $signup_page_content = !empty($signup_page) && !empty($signup_page->post_content) ? str_replace('[wpshop_signup]', '[wps_account_dashboard]', $signup_page->post_content) : '[wps_account_dashboard]';
                 wp_update_post(array('ID' => $signup_page_id, 'post_content' => $signup_page_content));
             }
             // Change Terms of sale default content
             $terms_page_id = get_option('wpshop_terms_of_sale_page_id');
             if (!empty($terms_page_id)) {
                 $terms_sale_page = get_post($terms_page_id);
                 if (!empty($terms_sale_page) && !empty($terms_sale_page->post_content) && $terms_sale_page->post_content == '[wpshop_terms_of_sale]') {
                     $data = '<h1>' . __('Your terms of sale', 'wpshop') . '</h1>';
                     $data .= '<h3>' . __('Rule', 'wpshop') . ' 1</h3>';
                     $data .= '<p>Ut enim quisque sibi plurimum confidit et ut quisque maxime virtute et sapientia sic munitus est, ut nullo egeat suaque omnia in se ipso posita iudicet, ita in amicitiis expetendis colendisque maxime excellit.</p>';
                     $data .= '<h3>' . __('Rule', 'wpshop') . ' 2</h3>';
                     $data .= '<p>Ut enim quisque sibi plurimum confidit et ut quisque maxime virtute et sapientia sic munitus est, ut nullo egeat suaque omnia in se ipso posita iudicet, ita in amicitiis expetendis colendisque maxime excellit.</p>';
                     $data .= '<h3>' . __('Rule', 'wpshop') . ' 3</h3>';
                     $data .= '<p>Ut enim quisque sibi plurimum confidit et ut quisque maxime virtute et sapientia sic munitus est, ut nullo egeat suaque omnia in se ipso posita iudicet, ita in amicitiis expetendis colendisque maxime excellit.</p>';
                     $data .= '<h3>' . __('Credits', 'wpshop') . '</h3>';
                     $data .= sprintf(__('%s uses <a href="http://www.wpshop.fr/" target="_blank" title="%s uses WPShop e-commerce plug-in for Wordpress">WPShop e-commerce for Wordpress</a>', 'wpshop'), get_bloginfo('name'), get_bloginfo('name'));
                     wp_update_post(array('ID' => $terms_page_id, 'post_content' => $data));
                 }
             }
             return true;
             break;
         case '55':
             $checkout_page_id = get_option('wpshop_checkout_page_id');
             $checkout_page = get_post($checkout_page_id);
             $checkout_page_content = !empty($checkout_page) && !empty($checkout_page->post_content) ? str_replace('[wpshop_checkout]', '[wps_checkout]', $checkout_page->post_content) : '[wps_checkout]';
             wp_update_post(array('ID' => $checkout_page_id, 'post_content' => $checkout_page_content));
             // Update cart page id
             update_option('wpshop_cart_page_id', $checkout_page_id);
             return true;
             break;
         case '56':
             $wps_entities = new wpshop_entities();
             $customer_entity_id = $wps_entities->get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS);
             $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d ORDER BY id LIMIT 1', $customer_entity_id);
             $set = $wpdb->get_row($query);
             if (!empty($set)) {
                 $wpdb->update(WPSHOP_DBT_ATTRIBUTE_SET, array('default_set' => 'yes'), array('id' => $set->id));
             }
             // Update Opinions activation option
             update_option('wps_opinion', array('active' => 'on'));
             return true;
             break;
         case '57':
             $wpshop_cart_option = get_option('wpshop_cart_option');
             $wpshop_cart_option['display_newsletter']['site_subscription'][] = 'yes';
             $wpshop_cart_option['display_newsletter']['partner_subscription'][] = 'yes';
             update_option('wpshop_cart_option', $wpshop_cart_option);
             return true;
             break;
         case '58':
             /** Turn customers publish into draft **/
             $query = $wpdb->prepare("UPDATE {$wpdb->posts} SET post_status = %s WHERE post_type = %s", "draft", WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS);
             $wpdb->query($query);
             $attribute_def = wpshop_attributes::getElement('tx_tva', "'valid'", 'code');
             /** Check if the 0% VAT Rate is not already created **/
             $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE attribute_id = %d AND value = %s', $attribute_def->id, '0');
             $exist_vat_rate = $wpdb->get_results($query);
             if (empty($exist_vat_rate)) {
                 /** Get Max Position **/
                 $query = $wpdb->prepare('SELECT MAX(position) as max_position FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE attribute_id = %d', $attribute_def->id);
                 $max_position = $wpdb->get_var($query);
                 if (!empty($attribute_def) && !empty($attribute_def->id)) {
                     $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'attribute_id' => $attribute_def->id, 'position' => (int) $max_position + 1, 'value' => '0', 'label' => '0'));
                 }
             }
             return true;
             break;
         case '59':
             /** Move old images gallery to the new gallery, and remove old links **/
             $allowed = get_allowed_mime_types();
             $args = array('posts_per_page' => -1, 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'post_status' => array('publish', 'draft', 'trash'));
             $posts = get_posts($args);
             $result = array();
             foreach ($posts as $post) {
                 $array = array();
                 $array['Post'] = $post;
                 $array['PrincipalThumbnailID'] = get_post_meta($post->ID, '_thumbnail_id', true);
                 $array['Attachments'] = get_attached_media($allowed, $post->ID);
                 $array['TrueAttachmentsString'] = get_post_meta($post->ID, '_wps_product_media', true);
                 if (!empty($array['TrueAttachmentsString'])) {
                     $TrueAttachments_id = explode(',', $array['TrueAttachmentsString']);
                 }
                 $array['OldAttachmentsString'] = '';
                 foreach ($array['Attachments'] as $attachment) {
                     $filename = basename(get_attached_file($attachment->ID));
                     $pos_ext = strrpos($filename, '.');
                     $filename_no_ext = substr($filename, 0, $pos_ext);
                     if ((empty($TrueAttachments_id) || !in_array($attachment->ID, $TrueAttachments_id)) && !preg_match('#' . $filename_no_ext . '#', $post->post_content) && (empty($array['PrincipalThumbnailID']) || $attachment->ID != $array['PrincipalThumbnailID'])) {
                         $array['OldAttachmentsString'] .= $attachment->ID . ',';
                     }
                 }
                 unset($TrueAttachments_id);
                 $result[$post->ID] = $array['TrueAttachmentsString'] . $array['OldAttachmentsString'];
                 update_post_meta($post->ID, '_wps_product_media', $result[$post->ID]);
             }
             return true;
             break;
         case '60':
             /* Create default emails */
             wps_message_ctr::create_default_message();
             /** Update entries for quick add */
             $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_required = "yes", is_used_in_quick_add_form = "yes" WHERE code = "barcode"');
             $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "yes" WHERE code = "product_stock"');
             $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "yes" WHERE code = "manage_stock"');
             switch (WPSHOP_PRODUCT_PRICE_PILOT) {
                 case 'HT':
                     $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "yes", is_used_in_variation = "yes" WHERE code = "price_ht"');
                     $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "no" WHERE code = "tx_tva"');
                     $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "no", is_used_in_variation = "no" WHERE code = "product_price"');
                     break;
                 default:
                     $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "yes", is_used_in_variation = "yes" WHERE code = "product_price"');
                     $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "yes" WHERE code = "tx_tva"');
                     $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "no", is_used_in_variation = "no" WHERE code = "price_ht"');
                     break;
             }
             /* Default country with WP language */
             $wpshop_country_default_choice_option = get_option('wpshop_country_default_choice');
             if (empty($wpshop_country_default_choice_option)) {
                 update_option('wpshop_country_default_choice', substr(get_bloginfo('language'), 3));
             }
             return true;
             break;
         case '61':
             /** Import the xml for guided tour */
             wpsBubble_ctr::import_xml();
             /* Hide admin bar */
             $wpshop_display_option = get_option('wpshop_display_option');
             if (!empty($wpshop_display_option) && empty($wpshop_display_option['wpshop_hide_admin_bar'])) {
                 $wpshop_display_option['wpshop_hide_admin_bar'] = 'on';
                 update_option('wpshop_display_option', $wpshop_display_option);
             }
             return true;
             break;
         case '62':
             /** Install user default for POS */
             wps_pos_addon::action_to_do_on_activation();
             return true;
             break;
         case '63':
             $data = get_option('wps_shipping_mode');
             if (empty($data['modes']['default_shipping_mode_for_pos'])) {
                 $data['modes']['default_shipping_mode_for_pos']['name'] = __('No Delivery', 'wpshop');
                 $data['modes']['default_shipping_mode_for_pos']['explanation'] = __('Delivery method for point of sale.', 'wpshop');
                 update_option('wps_shipping_mode', $data);
             }
             return true;
             break;
         case '64':
             $options = get_option('wpshop_catalog_product_option');
             if (!empty($options['wpshop_catalog_product_slug_with_category'])) {
                 unset($options['wpshop_catalog_product_slug_with_category']);
                 update_option('wpshop_catalog_product_option', $options);
             }
             return true;
             break;
             /*	Always add specific case before this bloc	*/
         /*	Always add specific case before this bloc	*/
         case 'dev':
             wp_cache_flush();
             // Newsletters options
             $wp_rewrite->flush_rules();
             return true;
             break;
         default:
             return true;
             break;
     }
 }
コード例 #23
0
function mw_getPostAttachments($args)
{
    global $wp_xmlrpc_server;
    $wp_xmlrpc_server->escape($args);
    $blog_ID = (int) $args[0];
    $username = $args[1];
    $password = $args[2];
    $post_id = $args[3];
    // Let's run a check to see if credentials are okay
    if (!($user = $wp_xmlrpc_server->login($username, $password))) {
        return $wp_xmlrpc_server->error;
    }
    $struct = array();
    $images = get_attached_media('image', $post_id);
    $audios = get_attached_media('audio', $post_id);
    $videos = get_attached_media('video', $post_id);
    foreach ($images as $image) {
        $struct[] = array("file" => $image['post_title'], "type" => $image['post_mime_type'], "url" => $image['guid'], "attachment_id" => $image['ID']);
    }
    return $struct;
}
コード例 #24
0
ファイル: TlsPostImageImporter.php プロジェクト: dannyoz/tls
 /**
  * Post Featured Images Ajax Callback Method
  */
 public function post_featured_image_action_callback()
 {
     $category_term_id = isset($_POST['post_category']) ? intval($_POST['post_category']) : null;
     if ($category_term_id == null) {
         echo 'No Category';
         wp_die();
     }
     $post_query = new WP_Query(array('post_type' => 'post', 'posts_per_page' => '-1', 'tax_query' => array(array('taxonomy' => 'category', 'field' => 'term_id', 'terms' => (int) $category_term_id))));
     $message = "Found " . $post_query->found_posts . " Posts with that Category <br /><br />";
     $posts_with_internal_images = 0;
     $featured_images_set = 0;
     foreach ($post_query->posts as $single_post) {
         // Search for internal images. Needs to set second parameter as true
         $post_content_images = $this->search_content($single_post->post_content, true);
         if (!empty($post_content_images['urls'])) {
             if (has_post_thumbnail($single_post->ID) === false) {
                 $first_internal_img_array = explode('/', (string) $post_content_images['urls'][0]);
                 $first_internal_img_name = array_pop($first_internal_img_array);
                 $attached_images = get_attached_media('image', $single_post->ID);
                 foreach ($attached_images as $attached_image) {
                     $attached_image_url_array = explode('/', $attached_image->guid);
                     $attached_image_name = array_pop($attached_image_url_array);
                     $attached_image_bool = (bool) ($attached_image_name === $first_internal_img_name);
                     if ($attached_image_bool === true) {
                         // Set Featured Image
                         add_post_meta($single_post->ID, '_thumbnail_id', $attached_image->ID);
                         $message .= "Featured image set for the Post: <a href=\"" . get_permalink($single_post->ID) . "\" target=\"_blank\">" . $single_post->post_title . "</a><br />";
                         $featured_images_set++;
                         break;
                     }
                 }
             }
             $posts_with_internal_images++;
         }
     }
     if (!$featured_images_set > 0) {
         $message .= "All posts with images have Featured images set <br />";
     }
     if (!$posts_with_internal_images > 0) {
         $message .= "No Local Images Found in any of the posts";
     }
     echo $message;
     wp_die();
 }
コード例 #25
0
ファイル: single-cars.php プロジェクト: zruiz/NG
                        </div>
                        <div class="btn btn-info price"><?php 
        echo esc_attr($unique_value);
        ?>
</div>
                    </div>
                    <div class="row">
                        <div class="col-md-8">
                            <div class="single-listing-images">
                            
                            	<div class="listing-slider">
                                    <div id="listing-images" class="flexslider format-gallery">
                                    <?php 
        $cars_images = get_post_meta(get_the_ID(), 'imic_plugin_vehicle_images', false);
        if (empty($cars_images)) {
            $attachments = get_attached_media('image', get_the_ID());
            if (!empty($attachments)) {
                $cars_images = array();
                foreach ($attachments as $attachment) {
                    $cars_images[] = $attachment->ID;
                }
            }
        }
        ?>
                                      <ul class="slides">
                                      	<?php 
        foreach ($cars_images as $car_image) {
            $image = wp_get_attachment_image_src($car_image, '1000x800', '');
            $image_full = wp_get_attachment_image_src($car_image, 'full', '');
            ?>
                                        <?php 
コード例 #26
0
ファイル: upload-jrrny.php プロジェクト: dqishmirian/jrrny
 if ($imageFileType == "jpg" || $imageFileType == "png" || $imageFileType == "jpeg" || $imageFileType == "gif") {
     if ($uploadOk !== 0) {
         if (isset($_POST["_draft_token"]) && $_POST["_draft_token"] !== "") {
             $token = $_POST["_draft_token"];
             move_uploaded_file($file_tmp_name, $target_file);
             set_post_format(intval($token), 'gallery');
             $attachment = array('guid' => $target_file, 'post_mime_type' => $file_type, 'post_title' => preg_replace('/\\.[^.]+$/', '', $target_file), 'post_content' => '', 'post_status' => 'inherit');
             $attach_id = wp_insert_attachment($attachment, $target_file, intval($token));
             // 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, $target_file);
             wp_update_attachment_metadata($attach_id, $attach_data);
             //set_post_thumbnail( intval($token), $attach_id );
             if ($attach_id !== 0) {
                 $attachments = get_attached_media("image", intval($token));
                 foreach ($attachments as $attachment) {
                     array_push($attachments_ids, $attachment->ID);
                 }
             }
             if (isset($attachments_ids) && sizeof($attachments_ids) !== 0) {
                 if (get_post(intval($token))->post_status == 'pending') {
                     wp_publish_post(intval($token));
                     if (!has_post_thumbnail(intval($token))) {
                         set_post_thumbnail(intval($token), $attachments_ids[0]);
                     }
                 }
                 update_field('featured_gallery', $attachments_ids, intval($token));
                 update_post_meta(intval($token), '_featured_gallery', '');
                 update_post_meta(intval($token), '_featured_gallery', 'field_5287d441bb41b');
             }
コード例 #27
0
ファイル: media.php プロジェクト: nakamuraagatha/reseptest
/**
 * Builds the Video shortcode output.
 *
 * This implements the functionality of the Video Shortcode for displaying
 * WordPress mp4s in a post.
 *
 * @since 3.6.0
 *
 * @global int $content_width
 * @staticvar int $instance
 *
 * @param array  $attr {
 *     Attributes of the shortcode.
 *
 *     @type string $src      URL to the source of the video file. Default empty.
 *     @type int    $height   Height of the video embed in pixels. Default 360.
 *     @type int    $width    Width of the video embed in pixels. Default $content_width or 640.
 *     @type string $poster   The 'poster' attribute for the `<video>` element. Default empty.
 *     @type string $loop     The 'loop' attribute for the `<video>` element. Default empty.
 *     @type string $autoplay The 'autoplay' attribute for the `<video>` element. Default empty.
 *     @type string $preload  The 'preload' attribute for the `<video>` element.
 *                            Default 'metadata'.
 *     @type string $class    The 'class' attribute for the `<video>` element.
 *                            Default 'wp-video-shortcode'.
 * }
 * @param string $content Shortcode content.
 * @return string|void HTML content to display video.
 */
function wp_video_shortcode($attr, $content = '')
{
    global $content_width;
    $post_id = get_post() ? get_the_ID() : 0;
    static $instance = 0;
    $instance++;
    /**
     * Filter the default video shortcode output.
     *
     * If the filtered output isn't empty, it will be used instead of generating
     * the default video template.
     *
     * @since 3.6.0
     *
     * @see wp_video_shortcode()
     *
     * @param string $html     Empty variable to be replaced with shortcode markup.
     * @param array  $attr     Attributes of the video shortcode.
     * @param string $content  Video shortcode content.
     * @param int    $instance Unique numeric ID of this video shortcode instance.
     */
    $override = apply_filters('wp_video_shortcode_override', '', $attr, $content, $instance);
    if ('' !== $override) {
        return $override;
    }
    $video = null;
    $default_types = wp_get_video_extensions();
    $defaults_atts = array('src' => '', 'poster' => '', 'loop' => '', 'autoplay' => '', 'preload' => 'metadata', 'width' => 640, 'height' => 360);
    foreach ($default_types as $type) {
        $defaults_atts[$type] = '';
    }
    $atts = shortcode_atts($defaults_atts, $attr, 'video');
    if (is_admin()) {
        // shrink the video so it isn't huge in the admin
        if ($atts['width'] > $defaults_atts['width']) {
            $atts['height'] = round($atts['height'] * $defaults_atts['width'] / $atts['width']);
            $atts['width'] = $defaults_atts['width'];
        }
    } else {
        // if the video is bigger than the theme
        if (!empty($content_width) && $atts['width'] > $content_width) {
            $atts['height'] = round($atts['height'] * $content_width / $atts['width']);
            $atts['width'] = $content_width;
        }
    }
    $is_vimeo = $is_youtube = false;
    $yt_pattern = '#^https?://(?:www\\.)?(?:youtube\\.com/watch|youtu\\.be/)#';
    $vimeo_pattern = '#^https?://(.+\\.)?vimeo\\.com/.*#';
    $primary = false;
    if (!empty($atts['src'])) {
        $is_vimeo = preg_match($vimeo_pattern, $atts['src']);
        $is_youtube = preg_match($yt_pattern, $atts['src']);
        if (!$is_youtube && !$is_vimeo) {
            $type = wp_check_filetype($atts['src'], wp_get_mime_types());
            if (!in_array(strtolower($type['ext']), $default_types)) {
                return sprintf('<a class="wp-embedded-video" href="%s">%s</a>', esc_url($atts['src']), esc_html($atts['src']));
            }
        }
        if ($is_vimeo) {
            wp_enqueue_script('froogaloop');
        }
        $primary = true;
        array_unshift($default_types, 'src');
    } else {
        foreach ($default_types as $ext) {
            if (!empty($atts[$ext])) {
                $type = wp_check_filetype($atts[$ext], wp_get_mime_types());
                if (strtolower($type['ext']) === $ext) {
                    $primary = true;
                }
            }
        }
    }
    if (!$primary) {
        $videos = get_attached_media('video', $post_id);
        if (empty($videos)) {
            return;
        }
        $video = reset($videos);
        $atts['src'] = wp_get_attachment_url($video->ID);
        if (empty($atts['src'])) {
            return;
        }
        array_unshift($default_types, 'src');
    }
    /**
     * Filter the media library used for the video shortcode.
     *
     * @since 3.6.0
     *
     * @param string $library Media library used for the video shortcode.
     */
    $library = apply_filters('wp_video_shortcode_library', 'mediaelement');
    if ('mediaelement' === $library && did_action('init')) {
        wp_enqueue_style('wp-mediaelement');
        wp_enqueue_script('wp-mediaelement');
    }
    /**
     * Filter the class attribute for the video shortcode output container.
     *
     * @since 3.6.0
     *
     * @param string $class CSS class or list of space-separated classes.
     */
    $html_atts = array('class' => apply_filters('wp_video_shortcode_class', 'wp-video-shortcode'), 'id' => sprintf('video-%d-%d', $post_id, $instance), 'width' => absint($atts['width']), 'height' => absint($atts['height']), 'poster' => esc_url($atts['poster']), 'loop' => wp_validate_boolean($atts['loop']), 'autoplay' => wp_validate_boolean($atts['autoplay']), 'preload' => $atts['preload']);
    // These ones should just be omitted altogether if they are blank
    foreach (array('poster', 'loop', 'autoplay', 'preload') as $a) {
        if (empty($html_atts[$a])) {
            unset($html_atts[$a]);
        }
    }
    $attr_strings = array();
    foreach ($html_atts as $k => $v) {
        $attr_strings[] = $k . '="' . esc_attr($v) . '"';
    }
    $html = '';
    if ('mediaelement' === $library && 1 === $instance) {
        $html .= "<!--[if lt IE 9]><script>document.createElement('video');</script><![endif]-->\n";
    }
    $html .= sprintf('<video %s controls="controls">', join(' ', $attr_strings));
    $fileurl = '';
    $source = '<source type="%s" src="%s" />';
    foreach ($default_types as $fallback) {
        if (!empty($atts[$fallback])) {
            if (empty($fileurl)) {
                $fileurl = $atts[$fallback];
            }
            if ('src' === $fallback && $is_youtube) {
                $type = array('type' => 'video/youtube');
            } elseif ('src' === $fallback && $is_vimeo) {
                $type = array('type' => 'video/vimeo');
            } else {
                $type = wp_check_filetype($atts[$fallback], wp_get_mime_types());
            }
            $url = add_query_arg('_', $instance, $atts[$fallback]);
            $html .= sprintf($source, $type['type'], esc_url($url));
        }
    }
    if (!empty($content)) {
        if (false !== strpos($content, "\n")) {
            $content = str_replace(array("\r\n", "\n", "\t"), '', $content);
        }
        $html .= trim($content);
    }
    if ('mediaelement' === $library) {
        $html .= wp_mediaelement_fallback($fileurl);
    }
    $html .= '</video>';
    $width_rule = '';
    if (!empty($atts['width'])) {
        $width_rule = sprintf('width: %dpx; ', $atts['width']);
    }
    $output = sprintf('<div style="%s" class="wp-video">%s</div>', $width_rule, $html);
    /**
     * Filter the output of the video shortcode.
     *
     * @since 3.6.0
     *
     * @param string $output  Video shortcode HTML output.
     * @param array  $atts    Array of video shortcode attributes.
     * @param string $video   Video file.
     * @param int    $post_id Post ID.
     * @param string $library Media library used for the video shortcode.
     */
    return apply_filters('wp_video_shortcode', $output, $atts, $video, $post_id, $library);
}
コード例 #28
0
ファイル: page-publicbenefit.php プロジェクト: jqjjian/fcye
$myvedios = array('post_type' => 'publicbenefit', 'posts_per_page' => 9, 'orderby' => 'date', 'category__in' => 18);
?>
    <?php 
$myvedio = new WP_Query($myvedios);
?>
    <?php 
if ($myvedio->have_posts()) {
    ?>
      <?php 
    while ($myvedio->have_posts()) {
        $myvedio->the_post();
        ?>
        <?php 
        $vedios = array('order' => 'ASC', 'post_parent' => get_the_ID(), 'post_type' => 'attachment', 'post_mime_type' => 'video');
        $video = array_values(get_children($vedios));
        $vatta = get_attached_media('video', $post_id);
        ?>
        <div class="col-sm-5ths">
        	<a href="<?php 
        the_permalink();
        ?>
" class="pic-preview">
        		<img src="<?php 
        echo wp_get_attachment_image_src(get_field('video-cover'), 'thumbnail')[0];
        ?>
" class="img-responsive">
        		<p class="pic-preview-title"><?php 
        the_title();
        ?>
</p>
        		<p class="pic-preview-time"><?php 
コード例 #29
0
ファイル: section3.php プロジェクト: lazymonster/mathapp
$args = array('post_type' => 'section-3', 'order' => 'ASC');
$query = new WP_Query($args);
$ctr2 = 0;
while ($query->have_posts()) {
    $query->the_post();
    ?>
		<?php 
    $post_group = types_render_field("sect3-group-name", array("row" => true));
    ?>
		<?php 
    if ($post_group == "Parents") {
        ?>
	
		<div class="item">
			<?php 
        $media = get_attached_media('image');
        $images = array();
        foreach ($media as $image) {
            array_push($images, $image->guid);
        }
        ?>
			<div class="item-image">
			<div class="blue_overlay"></div>
				<div class="item-images">
					<div class="images owl-carousel owl-theme" id="img1<?php 
        echo $ctr2;
        ?>
">
					<?php 
        foreach ($images as $image) {
            ?>
コード例 #30
0
ファイル: sstfg.php プロジェクト: skotperez/sstfg
function sstfg_ticket_file_move_s2member()
{
    include_once ABSPATH . 'wp-admin/includes/plugin.php';
    if (!is_plugin_active('s2member/s2member.php')) {
        return;
    }
    global $post;
    if ($post) {
        // If this is just a revision, don't continue
        if (wp_is_post_revision($post->ID)) {
            return;
        }
        if ($post->post_type == 'billet' && $post->post_status == 'publish') {
            $pdfs = get_attached_media('application/pdf', $post->ID);
            if (count($pdfs) >= 1) {
                foreach ($pdfs as $p) {
                    $name = $p->post_name . ".pdf";
                    $pdf_url = $p->guid;
                }
                if ($name == get_post_meta($post->ID, '_sstfg_protected_pdf', true)) {
                    return;
                }
                $docroot = $_SERVER['DOCUMENT_ROOT'];
                //$upload_dir = wp_upload_dir();
                $pdf_rel = str_replace(get_bloginfo('url'), '', $pdf_url);
                //$file = $upload_dir['basedir'];
                $old = $docroot . $pdf_rel;
                $new = $docroot . "/wp-content/plugins/s2member-files/access-s2member-ccap-sstfg/" . $name;
                update_post_meta($post->ID, '_sstfg_protected_pdf', $name);
                copy($old, $new) or die("Unable to copy {$old} to {$new}.");
            }
        }
    }
}