# media-cloud-sync/1.2.2/includes/base/cdn.php

Media Cloud Sync, version 1.2.2. 59 lines.

- Page: https://pluginprobe.com/plugins/media-cloud-sync/1.2.2/code/includes/base/cdn.php
- Raw: https://pluginprobe.com/plugins/media-cloud-sync/1.2.2/raw/includes/base/cdn.php
- Modified: 2025-06-01T21:16:02+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/media-cloud-sync/1.2.2/code/includes/base/cdn.php#L10-L20`.

```php
<?php
namespace Dudlewebs\WPMCS;

defined('ABSPATH') || exit;

class Cdn {
    private static $instance = null;
    private $assets_url;
    private $version;
    private $token;

    /**
     * Admin constructor.
     * @since 1.0.0
     */
    public function __construct() {
        $this->assets_url   = WPMCS_ASSETS_URL;
        $this->version      = WPMCS_VERSION;
        $this->token        = WPMCS_TOKEN;

        // Initialize setup
        // $this->init();
    }
    /**
     * 
     * CDN url generate
     * @since 1.0.0
     *
     */
    public static function may_generate_cdn_url($url, $key) {
    $settings = Utils::get_settings();

    if (
        isset($settings['enable_cdn'], $settings['cdn_url']) &&
        $settings['enable_cdn'] && !empty($settings['cdn_url']) &&
        isset($url, $key) && !Utils::is_empty($url) && !Utils::is_empty($key)
    ) {
        $url_parts = explode($key, $url);
        if (!empty($url_parts[0])) {
            $cdn_url = 'https://' . preg_replace('#^https?://#i', '', trim($settings['cdn_url']));
            $new_url = str_replace(trailingslashit($url_parts[0]), trailingslashit($cdn_url), $url);
            $new_url = apply_filters('wpmcs_cdn_url', $new_url, $url, $cdn_url);
            return preg_replace('/([^:])(\/{2,})/', '$1/', $new_url); // remove double slashes
        }
    }

    return $url;
}



    
    public static function instance(){
        if (is_null(self::$instance)) {
            self::$instance = new self();
        }
        return self::$instance;
    }
}
```
