PluginProbe
Booking Calendar / 10.10.2
Booking Calendar v10.10.2
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 10.11.3 All 202 releases
booking / core / any / class-css-js.php

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

159 lines 5.5 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 Scripts
88 *
89 * @return void
90 */
91 public function registerScripts() {
92
93 $this->remove_conflicts( ( is_admin() ? 'admin' : 'client' ) );
94
95 foreach ( $this->objects as $script ) {
96
97 if ( $this->isLoad( $script['where_to_load'] ) ) {
98
99 if ( 'css' === $this->getType() ) {
100 wp_register_style( $script['handle'], $script['src'], $script['deps'], $script['version'] );
101 } else {
102 wp_register_script( $script['handle'], $script['src'], $script['deps'], $script['version'], array( 'in_footer' => WPBC_JS_IN_FOOTER ) );
103 }
104 }
105 }
106 }
107
108
109 // Load scripts or styles here
110 public function load(){
111
112 $is_load_scripts = true;
113
114 $is_load_scripts = apply_filters( 'wpbc_is_load_script_on_this_page', $is_load_scripts );
115
116 if ( ! $is_load_scripts ) return; // Exist, if on some page we do not need to load scripts
117
118
119 foreach( $this->objects as $num => $script ) {
120
121 if ( $this->isLoad( $script['where_to_load'] ) ) {
122
123 if ( $this->getType() == 'css' ) {
124
125 if ( $script['condition'] === false )
126
127 wp_enqueue_style( $script['handle'] );
128
129 else {
130
131 if (! function_exists('wp_style_add_data') ) { // This function is available only since WordPress 3.6.0 Update
132 wp_enqueue_style( $script['handle'] );
133 wp_style_add_data( $script['handle'], 'conditional', $script['condition'] );
134 } else { // Add additional "dynamic CSS" if the WP version older than 3.6.0 (its function suport since WP 3.3)
135 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
136 wp_enqueue_style( $this->objects[($num-1)]['handle'] );
137 // phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedStylesheet
138 wp_add_inline_style( $this->objects[ ( $num - 1 ) ]['handle'], sprintf( "<!--[if " . $script['condition'] . "]>\n" . "<link rel='stylesheet' id='" . $script['handle'] . "-css' href='" . $script['src'] . "?ver=" . $script['version'] . "' type='text/css' media='all' />\n" . "<![endif]-->\n" ) );
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 }