-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCdnUrlReplace.php
More file actions
52 lines (47 loc) · 1.18 KB
/
CdnUrlReplace.php
File metadata and controls
52 lines (47 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
/**
* Plugin Name: WP CDN Url Replace
* Plugin URI: https://github.com/kfuchs/wp-cdn-url-replace
* Description: Easily replace existing urls to point to your CDN using regex. Instead of using the database to store
* rewrite rules like other plugins it utilizes the $_ENV global to provide the developer control over multiple envs settings.
* Version: 1.0
* Author: Kirill Fuchs
* Author URI: https://github.com/kfuchs
* License: MIT
*/
/**
* Class CdnUrlReplace
*/
class CdnUrlReplace
{
/**
* @var string
*/
public $envSearchKey = 'CDN_URL_SEARCH_FOR';
/**
* @var string
*/
public $envReplaceWithKey = 'CDN_URL_REPLACE_WITH';
/**
* @param $content
*
* @return mixed
*/
public function replace($content)
{
$search = $_ENV[$this->envSearchKey];
$replace = $_ENV[$this->envReplaceWithKey];
return str_replace($search, $replace, $content);
}
}
/**
*
*/
function bufferHandler()
{
$CdnUrlReplace = new CdnUrlReplace();
ob_start(array(&$CdnUrlReplace, 'replace'));
}
if ($_ENV['CDN_URL_SEARCH_FOR'] && $_ENV['CDN_URL_REPLACE_WITH']) {
add_action('template_redirect', 'bufferHandler');
}