PluginProbe
Booking Calendar / 10.1.3
Booking Calendar v10.1.3
11.8.3 11.8.2 11.8.1 11.8 11.7 11.6.1 11.6 11.5 11.4.3 11.4.2 11.4.1 11.4 11.3 11.2.1 11.2 11.1 11.0 10.15.7 10.15.6 10.1.3 10.10 10.10.1 10.10.2 10.11 10.11.2 All 203 releases
booking / core / any / class-css-js.php

class-css-js.php in Booking Calendar 10.1.3, at core/any/class-css-js.php

159 lines 5.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php /**
2 * @version 1.1
3 * @package Any
4 * @category Load JS and CSS files
5 * @author wpdevelop
6 *
7 * @web-site https://wpbookingcalendar.com/
8 * @email info@wpbookingcalendar.com
9 *
10 * @modified 2015-10-28
11 */
12
13 abstract class WPBC_JS_CSS {
14
15 public $objects = array();
16 public $type; // css || js
17
18 function __construct() {
19 $this->define();
20 add_action( 'admin_enqueue_scripts', array( $this, 'registerScripts' ) );
21 add_action( 'wp_enqueue_scripts', array( $this, 'registerScripts' ) );
22
23 add_action( 'wpbc_load_js_on_admin_page', array( $this, 'load_js_on_admin_page' ) ); // Load JS. Hook fire only in admin pages of plugin. CLASS: WPBC_Admin_Menus (..\any\class\class-admin-menu.php)
24 add_action( 'wpbc_load_css_on_admin_page', array( $this, 'load_css_on_admin_page' ) ); // Load CSS. Hook fire only in admin pages of plugin. CLASS: WPBC_Admin_Menus (..\any\class\class-admin-menu.php)
25 }
26
27 public function load_css_on_admin_page() {
28
29 if ( $this->getType() == 'css' )
30 $this->load();
31 }
32
33 public function load_js_on_admin_page() {
34
35 if ( $this->getType() == 'js' )
36 $this->load();
37 }
38
39 /** Define all Scripts or Styles here */
40 abstract public function define();
41
42 /**
43 * Enqueue Scripts or Styles.
44 *
45 * @param type $where_to_load - can be "admin" or "client"
46 */
47 abstract public function enqueue( $where_to_load );
48
49
50 /**
51 * Deregister some Conflict scripts from other plugins.
52 *
53 * @param type $where_to_load - can be "admin" or "client"
54 */
55 abstract public function remove_conflicts( $where_to_load );
56
57
58 // Define CSS or JavaScript
59 public function setType($param) {
60 $this->type = $param;
61 }
62
63 // Get type of this script
64 public function getType() {
65 return $this->type;
66 }
67
68 // Add new Style or Script
69 public function add($param) {
70 $this->objects[] = $param;
71 }
72
73
74 private function isLoad( $whereToLoadArray ) {
75 $is_load = false;
76
77 if ( ( is_admin() ) && ( in_array('admin', $whereToLoadArray ) ) )
78 $is_load = true;
79
80 if ( ( ! is_admin() ) && ( in_array('client', $whereToLoadArray ) ) )
81 $is_load = true;
82
83 return $is_load;
84 }
85
86
87 // Register
88 public function registerScripts() {
89
90 //if ( function_exists( 'wp_dequeue_script' ) )
91 $this->remove_conflicts( ( is_admin() ? 'admin': 'client' ) );
92
93 foreach( $this->objects as $script ) {
94
95 if ( $this->isLoad( $script['where_to_load'] ) ) {
96
97 if ( $this->getType() == 'css' )
98 wp_register_style( $script['handle'], $script['src'], $script['deps'], $script['version'] );
99 else
100 wp_register_script( $script['handle'], $script['src'], $script['deps'], $script['version'] );
101 }
102 }
103 }
104
105
106 // Load scripts or styles here
107 public function load(){
108
109 $is_load_scripts = true;
110
111 $is_load_scripts = apply_filters( 'wpbc_is_load_script_on_this_page', $is_load_scripts );
112
113 if ( ! $is_load_scripts ) return; // Exist, if on some page we do not need to load scripts
114
115
116 foreach( $this->objects as $num => $script ) {
117
118 if ( $this->isLoad( $script['where_to_load'] ) ) {
119
120 if ( $this->getType() == 'css' ) {
121
122 if ( $script['condition'] === false )
123
124 wp_enqueue_style( $script['handle'] );
125
126 else {
127
128 if (! function_exists('wp_style_add_data') ) { // This function is available only since WordPress 3.6.0 Update
129 wp_enqueue_style( $script['handle'] );
130 wp_style_add_data( $script['handle'], 'conditional', $script['condition'] );
131 } else { // Add additional "dynamic CSS" if the WP version older than 3.6.0 (its function suport since WP 3.3)
132 if ( ($num-1) > -1 ) { // Its because "wp_add_inline_style" add the CSS to the already added style. So its require that some other simple style was added before
133 wp_enqueue_style( $this->objects[($num-1)]['handle'] );
134 wp_add_inline_style( $this->objects[($num-1)]['handle'],
135 sprintf("<!--[if ".$script['condition']."]>\n" .
136 "<link rel='stylesheet' id='".$script['handle']."-css' href='". $script['src'] ."?ver=" . $script['version'] . "' type='text/css' media='all' />\n" .
137 "<![endif]-->\n")
138 );
139 }
140 }
141 }
142
143 } else {
144 wp_enqueue_script( $script['handle'] );
145 }
146
147 }
148 }
149
150 $this->enqueue( ( is_admin() ? 'admin': 'client' ) );
151
152 if ( $this->getType() == 'css' )
153 do_action( 'wpbc_enqueue_style', ( is_admin() ? 'admin': 'client' ) );
154
155 if ( $this->getType() == 'js' )
156 do_action( 'wpbc_enqueue_script', ( is_admin() ? 'admin': 'client' ) );
157 }
158
159 }