/**
Template Name: checkorder

* The template for displaying all pages.
* @package commercegurus
*/
$user_ID = get_current_user_id();
$totalcredit = intval(do_shortcode("[usercreditwoocommerce]"));
if (!$user_ID) {
    header("Location:" . get_bloginfo("url"));
    exit;
}
if ($_POST['creditupdate'] == "yes") {
    if ($totalcredit > 0) {
        foreach ($_POST['mediid'] as $id) {
            updatcredit($id);
        }
        header("Location:" . get_permalink("url") . "?assign=done");
        exit;
    } else {
        header("Location:" . get_permalink("url") . "?assign=no");
        exit;
    }
}
get_header();
cg_get_page_title();
// Get our page banner if it exists
$cg_page_banner_image = '';
if (function_exists('get_field')) {
    $page_banner = get_field('banner_image');
    $page_banner_height = get_field('page_banner_height');
 /**
  * Handle Attachment
  *
  * @since 1.0.0
  */
 public function add_attachment($url, $filepath)
 {
     $meta = $this->create_image_sizes($filepath);
     $wp_upload_dir = wp_upload_dir();
     $filename = str_replace($wp_upload_dir['url'] . '/', '', $url);
     $wp_filetype = wp_check_filetype(basename($filename), null);
     $attachment = array('guid' => $url, 'post_mime_type' => $wp_filetype['type'], 'post_title' => preg_replace('/\\.[^.]+$/', '', basename($filename)), 'post_content' => '', 'post_status' => 'inherit');
     $attach_id = wp_insert_attachment($attachment, $url);
     if (wp_attachment_is_image($attach_id)) {
         if (!function_exists('wp_generate_attachment_metadata') or !function_exists('wp_update_attachment_metadata')) {
             require_once ABSPATH . 'wp-admin/includes/image.php';
         }
         $attach_data = wp_generate_attachment_metadata($attach_id, $filepath);
         // code by ayaz
         $user_ID = get_current_user_id();
         $project_id = get_post_meta($user_ID, 'my_temp_field', true);
         if (empty($project_id) || $project_id == 0) {
             $my_post = array('post_title' => 'My Project', 'post_content' => 'This is my post.', 'post_status' => 'publish', 'post_author' => $user_ID, 'post_type' => 'projects');
             // Insert the post into the database
             $post_id = wp_insert_post($my_post, $wp_error);
             update_post_meta($post_id, 'image_project_status', '1');
             update_post_meta($attach_id, 'group_id', $post_id);
             update_post_meta($user_ID, 'my_temp_field', $post_id);
         } else {
             update_post_meta($attach_id, 'group_id', $project_id);
         }
         // code by ayaz
         wp_update_attachment_metadata($attach_id, $attach_data);
     }
     // if()
     updatcredit($attach_id, "inner");
     return $attach_id;
 }