-
Notifications
You must be signed in to change notification settings - Fork 1
/
plugin.php
87 lines (75 loc) · 2.38 KB
/
plugin.php
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
/**
* Plugin Name: Content Style Saviour
* Plugin URI: http://visualcomposer.io/deactivate/
* Description: Automatically loads saved CSS for the content.
*
* Version: 1.0
* Author: Visual Composer
* Author URI: http://visualcomposer.com
* Requires at least: 4.1
*/
/**
* Check for direct call file.
*/
if (!defined('ABSPATH')) {
header('Status: 403 Forbidden');
header('HTTP/1.1 403 Forbidden');
exit;
}
if (defined('VCV_VERSION')) {
return;
}
class VcwbEnqueueController
{
public function __construct()
{
add_action('wp_enqueue_scripts', [$this, 'enqueueGlobalAssets']);
add_action('wp_enqueue_scripts', [$this, 'enqueueAssets']);
add_action('wp_enqueue_scripts', [$this, 'enqueueSourceAssets']);
}
public function enqueueGlobalAssets()
{
$bundleUrl = get_option('vcv-globalElementsCssFileUrl');
if ($bundleUrl) {
wp_enqueue_style('vcv:assets:global:styles:' . $this->slugify($bundleUrl), $bundleUrl);
}
}
public function enqueueSourceAssets()
{
$sourceId = get_the_ID();
$bundleUrl = get_post_meta($sourceId, 'vcvSourceCssFileUrl', true);
if ($bundleUrl) {
wp_enqueue_style('vcv:assets:source:main:styles:' . $this->slugify($bundleUrl), $bundleUrl);
}
}
public function enqueueAssets()
{
$sourceId = get_the_ID();
$assetsFiles = get_post_meta($sourceId, 'vcvSourceAssetsFiles', true);
if (!is_array($assetsFiles)) {
return;
}
if (isset($assetsFiles['cssBundles']) && is_array($assetsFiles['cssBundles'])) {
foreach ($assetsFiles['cssBundles'] as $asset) {
wp_enqueue_style('vcv:assets:source:styles:' . $this->slugify($asset), $asset);
}
unset($asset);
}
if (isset($assetsFiles['jsBundles']) && is_array($assetsFiles['jsBundles'])) {
foreach ($assetsFiles['jsBundles'] as $asset) {
wp_enqueue_script('vcv:assets:source:scripts:' . $this->slugify($asset), $asset);
}
unset($asset);
}
}
public function slugify($str)
{
$str = strtolower($str);
$str = html_entity_decode($str);
$str = preg_replace('/[^\w\s]+/', '', $str);
$str = preg_replace('/\s+/', '-', $str);
return $str;
}
}
new VcwbEnqueueController();