function delete_project($post_id)
{
    global $wpdb;
    $post = get_post($post_id);
    if ($post->post_type == 'ignition_product') {
        $product = getProductbyPostID($post->ID);
        if (!empty($product)) {
            $project_id = get_post_meta($post_id, 'ign_project_id', true);
            do_action('idcf_before_delete_project', $post_id, $project_id);
            $remove_query = $wpdb->prepare('DELETE FROM ' . $wpdb->prefix . 'ign_products WHERE id = %d', $product->id);
            $remove_res = $wpdb->query($remove_query);
            $sql_prod_settings = "DELETE FROM " . $wpdb->prefix . "ign_product_settings WHERE product_id = '" . $product->id . "'";
            $wpdb->query($sql_prod_settings);
            do_action('idcf_delete_project', $post_id, $project_id);
        }
    }
}
function projectPageof($current_post_id, $prod_id)
{
    if (isset($_GET['preview']) && $_GET['preview'] == true) {
        $current_post_id = $_GET['preview_id'];
    }
    global $wpdb;
    // First check whether the current Page/Post is the Project page of the Product_id set in the widget options
    $product_post_details = getPostDetailbyProductID($prod_id);
    $current_post = get_post($current_post_id);
    if (get_post_meta($product_post_details->ID, 'ign_post_name', true) == $current_post->post_name) {
        return $prod_id;
    }
    // If current page is a project page, and option selected for that project is also the Current_page as project page then
    if ($current_post->post_type == "ignition_product" && get_post_meta($current_post_id, 'ign_option_project_url', true) == 'current_page') {
        $product_details = getProductbyPostID($current_post_id);
        return $product_details->id;
    }
    // Check if this post is project page of any project
    // $current_post->post_name is name of any ign_post_name in the post meta, if yes, get post id and check if it is same as $product_post_details->ID
    $sql_check_post_name = "SELECT * FROM " . $wpdb->prefix . "postmeta WHERE meta_key = 'ign_post_name' AND meta_value = '" . $current_post->post_name . "' LIMIT 1";
    $postmeta_from_name = $wpdb->get_row($sql_check_post_name);
    if (count($postmeta_from_name) > 0) {
        $product_details = getProductbyPostID($postmeta_from_name->post_id);
        return $product_details->id;
    }
    // Nothing found yet, the last search
    $sql_check_post_address = "SELECT * FROM " . $wpdb->prefix . "postmeta WHERE meta_key = 'id_project_URL' AND meta_value = '" . $current_post->guid . "' LIMIT 1";
    $postmeta_post_address = $wpdb->get_row($sql_check_post_address);
    if (count($postmeta_post_address) > 0) {
        $product_details = getProductbyPostID($postmeta_post_address->post_id);
        return $product_details->id;
    }
    return 0;
}