public function pim_pim_images($post_id, $title_image = true)
 {
     $images = PIM_Gallery::get_list($post_id, true);
     if (!empty($images) && $images) {
         if (count($images) > 1) {
             reset($images);
             $key = key($images);
             $retArr = array();
             if ($title_image) {
                 $retArr['title_image'] = $images[$key];
                 unset($images[$key]);
             }
             foreach ($images as $image) {
                 $retArr['thumbs'][] = $image;
             }
             if ($title_image) {
                 return $retArr;
             }
             return $retArr['thumbs'];
         }
     }
     return $images;
 }
        return self::getImageAttachments($images, $key_to_ids, $to_object);
    }
    public static function getImageAttachments($images, $key_to_ids = false, $to_object = false)
    {
        if (empty($images)) {
            return array();
        }
        $args = array('post_type' => self::$post_type, 'post__in' => $images, 'post_mime_type' => 'image', 'posts_per_page' => '-1', 'orderby' => 'post__in', 'order' => 'ASC');
        $posts = get_posts($args);
        if ($key_to_ids) {
            $posts_filtered = array();
            array_filter($posts, function ($post) use(&$posts_filtered) {
                $posts_filtered[$post->ID] = $post;
            });
            $posts = $posts_filtered;
        }
        if ($to_object) {
            array_walk($posts, array(__CLASS__, 'translate_to_class_object'));
        }
        return $posts;
    }
    /**
     * Getting current class post_type
     */
    public static function get_class_post_type()
    {
        return self::$post_type;
    }
}
return PIM_Gallery::getInstance();
 function meta_box_save($post_id)
 {
     if (in_array(get_post_type($post_id), $this->post_types)) {
         if (!isset($_POST['_inline_edit'])) {
             $attachments = PIM_Gallery::get_list($post_id, true);
             if (isset($_POST['pim-save-form-nonce']) && wp_verify_nonce($_POST['pim-save-form-nonce'], 'pim-form-save')) {
                 // see if image data was submitted:
                 // sanitize the data and save it in the term_images array
                 if (!empty($_POST[$this->upload_id])) {
                     $images = $_POST[$this->upload_id];
                     if (!empty($_POST['uploaded_img'])) {
                         $images .= implode(',', $_POST['uploaded_img']);
                     }
                     delete_post_meta($post_id, $this->upload_id);
                     add_post_meta($post_id, $this->upload_id, json_encode($images), true);
                 }
             }
             if (isset($_POST['images_order']) && !empty($_POST['images_order'])) {
                 delete_post_meta($post_id, $this->upload_id);
                 update_post_meta($post_id, $this->upload_id, json_encode(implode(',', $_POST['images_order'])));
             }
             if (!isset($_POST['images_order']) && !isset($_POST['uploaded_img']) && empty($_POST[$this->upload_id])) {
                 delete_post_meta($post_id, $this->upload_id);
             }
         }
     }
 }