/**
     * Display the Planner images
     * @static
     * @param $planner_id
     * @since 1.0
     */
    public static function display_images($planner_id)
    {
        global $post_planner_images_mb, $post;
        $post_planner_images_mb->the_meta($planner_id);
        echo '<div class="post-planner-box">';
        do_action('post_planner_before_images');
        if ($post_planner_images_mb->have_value('post-planner-images')) {
            echo apply_filters('post_planner_images_description', '<p class="description">' . esc_html__('Organize the images in the order you want them to appear by dragging and dropping the items.', 'post-planner') . '<br />' . esc_html__('Use the Insert button to add only that specific image.', 'post-planner') . (current_theme_supports('post-thumbnails') ? ' ' . esc_html__('Use the Star icon to set the image as the Featured Image.', 'post-planner') : '') . ' ' . esc_html__('Use Insert All Images to add all of the images.', 'post-planner') . '</p>');
            ?>

			<ul id="post-planner-sortable-grid" class="images">
				<?php 
            while ($post_planner_images_mb->have_fields('post-planner-images')) {
                ?>

					<?php 
                if ($post_planner_images_mb->have_value('image')) {
                    $attachment_id = PostPlanner_Lib::get_attachment_id_from_src($post_planner_images_mb->get_the_value('image'));
                    $inserted = PostPlanner_Lib::is_attached($attachment_id, $post->ID) ? ' inserted' : '';
                    ?>

						<li class="ui-state-default<?php 
                    echo $inserted;
                    ?>
" id="<?php 
                    echo absint($attachment_id);
                    ?>
">
							<?php 
                    $resized_image = PostPlanner_Lib::aq_resize($post_planner_images_mb->get_the_value('image'), '90', '60', true);
                    ?>
							<a href="<?php 
                    esc_url($post_planner_images_mb->the_value('image'));
                    ?>
" class="image-info">
								<img src="<?php 
                    echo esc_url($resized_image);
                    ?>
" alt="<?php 
                    esc_attr($post_planner_images_mb->the_value('alt'));
                    ?>
" title="<?php 
                    esc_attr($post_planner_images_mb->the_value('title'));
                    ?>
" />
							</a>
							<input type="button" class="button-secondary planner-insert-image" value="<?php 
                    esc_attr_e('Insert', 'post-planner');
                    ?>
" />
							<?php 
                    if (current_theme_supports('post-thumbnails')) {
                        ?>
								<img src="<?php 
                        echo POSTPLANNER_PLUGIN_URL;
                        ?>
/css/images/bookmark.png" alt="" class="planner-insert-featured" />
							<?php 
                    }
                    ?>
						</li>

					<?php 
                }
                ?>

				<?php 
            }
            ?>
			</ul>

			<div class="clear"></div><br />
			<input type="button" class="button-secondary" id="planner-insert-all_images" value="<?php 
            echo apply_filters('post_planner_insert_images', esc_attr__('Insert All Images', 'post-planner'));
            ?>
"/>

		<?php 
        } else {
            echo '<p>' . apply_filters('post_planner_no_images', esc_html__('No images found', 'post-planner')) . '</p>';
        }
        do_action('post_planner_after_images');
        echo '</div>';
    }
 /**
  * Insert all images into a Post Ajax Callback
  *
  * Changes the post parent of the image attachments from the ID of the Planner to the ID of the Associated Post.
  * This can be prevented by using the post_planner_associate_images filter and setting it to false.
  * @static
  * @since 1.0
  */
 public static function insert_all_images_callback()
 {
     check_ajax_referer('postplanner');
     $associate = apply_filters('post_planner_associate_images', true);
     if ($associate == true) {
         $image_ids = $_POST['post_planner_image_ids'];
         $post_id = absint($_POST['post_planner_post_id']);
         $planner_id = absint($_POST['post_planner_planner_id']);
         $type = esc_attr($_POST['postplanner_type']);
         if ($type == 'post') {
             $permission = current_user_can('edit_post', $post_id);
         } elseif ($type == 'page') {
             $permission = current_user_can('edit_page', $post_id);
         } else {
             $permission = apply_filters('post_planner_associated_permissions', current_user_can('edit_post', $post_id), $type);
         }
         if ($permission == true) {
             foreach ($image_ids as $key => $id) {
                 // if the image is attached to the Planner, change the post parent to the Associated Post
                 if (PostPlanner_Lib::is_attached($id, $planner_id)) {
                     $args = array('ID' => absint($id), 'post_parent' => $post_id);
                     $updated_post_id = wp_update_post($args);
                     $status = $updated_post_id == 0 ? -1 : 1;
                 } else {
                     $status = 1;
                 }
             }
         } else {
             $status = 1;
         }
     } else {
         $status = 1;
     }
     echo $status;
     die;
     // this is required to return a proper result
 }