gift_slide1_bk_all

PHOTO EMBED

Thu Feb 08 2024 14:21:52 GMT+0000 (Coordinated Universal Time)

Saved by @FOrestNAtion

/*gift_slide1_bk_all*/
function gift_slide_bkg_all($gift_slide) {
    $ua = strtolower($_SERVER["HTTP_USER_AGENT"]);
    $isMob = is_numeric(strpos($ua, "mobile"));
    if ($isMob != 'mobile') {
        if ($gift_slide == 'one') { $gift_slide_number = 'slide1_type'; }
        if ($gift_slide == 'two') { $gift_slide_number = 'slide2_type'; }
        if ($gift_slide == 'three') { $gift_slide_number = 'slide3_type'; }
        if ($gift_slide == 'four') { $gift_slide_number = 'slide4_type'; }
        $slidetype = get_field($gift_slide_number, get_the_ID());
        if ($slidetype == 'photo editor') {
            if ($gift_slide == 'one') { $gift_field = 'gift_image'; }
            if ($gift_slide == 'two') { $gift_field = 'gift_image_2'; }
            if ($gift_slide == 'three') { $gift_field = 'gift_image_3'; }
            if ($gift_slide == 'four') { $gift_field = 'gift_image_4'; }
            $img_id = get_field($gift_field, get_the_ID());
            if (!empty($img_id)) {
                $media_url = wp_get_attachment_image_url($img_id, 'full');
                if (!empty($media_url)) {
                    return $media_url;
                }
            }
        } else {
            if ($gift_slide == 'one') { $gift_field = 'gif1'; }
            if ($gift_slide == 'two') { $gift_field = 'gif2'; }
            if ($gift_slide == 'three') { $gift_field = 'gif3'; }
            if ($gift_slide == 'four') { $gift_field = 'gif4'; }
            $media_id = get_field($gift_field, get_the_ID());

            if (!empty($media_id) && is_numeric($media_id)) {
                // Try fetching from the _cloudinary meta field
                $cloudinary_data = get_post_meta($media_id, '_cloudinary', true);
                if (isset($cloudinary_data['_cloudinary_url'])) {
                    $media_url = $cloudinary_data['_cloudinary_url'];
                    // Check if the media URL is from Cloudinary
        if (strpos($media_url, "cloudinary.com") !== false) {
            // Insert transformations for all media types
            $parts = explode('/upload/', $media_url);
            $media_url = $parts[0]. '/upload/f_auto,q_auto,so_2,e_blur:5000/'.$parts[1];
        }
                } else {
                    $media_url = wp_get_attachment_url($media_id);
                }
                $filetype = wp_check_filetype($media_url);
                if ($filetype['ext'] == 'mp4') {
                    if (strpos($media_url, "cloudinary.com") !== false) {
                        $parts = explode('/upload/', $media_url);
                        $transformed_media_url = $parts[0]. '/upload/f_auto,q_auto,so_2,e_blur:5000/'.$parts[1];
                        $transformed_media_url = str_replace(".mp4", ".jpg", $transformed_media_url);
                        return $transformed_media_url;
                    }
                } else {
                    return $media_url;
                }
            }
        }
        if (!empty($media_id) && !is_numeric($media_id)) {
            $media_url = $media_id;
            $filetype = wp_check_filetype($media_id);
            if ($filetype['ext'] == 'mp4') {
                $media_name = basename(get_attached_file($media_id));
                $media_name_jpg = str_replace(".mp4", ".jpg", "$media_name");
                return "https://res.cloudinary.com/drt2tlz1j/video/upload/f_auto,q_auto,so_2,e_blur:5000/fn/$media_name_jpg";
            } else {
                return $media_url;
            }
        }
    }
}
// register shortcode
add_shortcode('gift_slide_bkg_all', 'gift_slide_bkg_all');
content_copyCOPY