PluginProbe
Comments Extra Fields For Post,Pages and CPT / 4.5
Comments Extra Fields For Post,Pages and CPT v4.5
trunk 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 2.2 2.3 4.0 4.1 4.2 4.3 4.4 4.5 4.6 4.7 4.8 5.0 5.1 5.2
wp-comment-fields / classes / scripts.class.php

scripts.class.php in Comments Extra Fields For Post,Pages and CPT 4.5, at classes/scripts.class.php

167 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * N-Media Scripts Framework
4 *
5 * It will register/enqueue all scripts & styles
6 */
7
8
9 if ( ! defined( 'ABSPATH' ) ) { exit; }
10
11
12 class WPCOMMENT_SCRIPTS {
13
14 private static $ins = null;
15
16 /**
17 * Return scripts URL.
18 *
19 * @var URL
20 *
21 */
22 public static $scripts_url = WPCOMMENT_URL;
23
24 /**
25 * Return current wpcomment version.
26 *
27 * @var string
28 *
29 */
30 public static $version = WPCOMMENT_VERSION;
31
32 /**
33 * Main Init
34 */
35 public static function init() {}
36
37
38 /**
39 * Register Script
40 *
41 */
42 private static function register_script( $handle, $path, $deps = array( 'jquery' ), $version = '', $in_footer = true ) {
43 wp_register_script( $handle, $path, $deps, $version, $in_footer );
44 }
45
46
47 /**
48 * Register and Enqueue Scripts.
49 *
50 */
51 public static function enqueue_script( $handle, $path = '', $deps = array( 'jquery' ), $version = '', $in_footer = true ) {
52 if (!wp_script_is( $handle, 'registered' ) && $path ) {
53 self::register_script( $handle, $path, $deps, $version, $in_footer );
54 }
55 wp_enqueue_script( $handle );
56 }
57
58
59 /**
60 * Register Styles.
61 *
62 */
63 private static function register_style( $handle, $path, $deps = array(), $version, $media = 'all' ) {
64 wp_register_style( $handle, $path, $deps, $version, $media );
65 }
66
67
68 /**
69 * Register and Enqueue Styles.
70 *
71 */
72 public static function enqueue_style( $handle, $path = '', $deps = array(), $version='', $media = 'all') {
73 if (!wp_script_is( $handle, 'registered' ) && $path ) {
74 self::register_style( $handle, $path, $deps, $version, $media, $has_rtl );
75 }
76 wp_enqueue_style( $handle );
77 }
78
79
80 /**
81 * Register all PPOM Scripts.
82 */
83 public static function register_scripts($register_scripts) {
84
85 foreach ( $register_scripts as $handle => $props ) {
86 $is_footer = isset($props['footer']) ? $props['footer'] : true ;
87 self::register_script( $handle, $props['src'], $props['deps'], $props['version'], $is_footer );
88 }
89 }
90
91
92 /**
93 * Register Styles
94 */
95 public static function register_styles($register_styles) {
96
97 foreach ( $register_styles as $handle => $props ) {
98 self::register_style( $handle, $props['src'], $props['deps'], $props['version'], 'all' );
99 }
100 }
101
102
103 /**
104 * Localize Scripts Data
105 *
106 */
107 public static function localize_script( $handle, $js_var_name, $js_var_data=array() ) {
108
109 if ( wp_script_is( $handle ) ) {
110
111 if ( empty($js_var_data) ) { return; }
112
113 wp_localize_script( $handle, $js_var_name, $js_var_data );
114 }
115 }
116
117
118 /**
119 * Add Inline CSS
120 *
121 */
122 public static function inline_style( $handle, $css ) {
123
124 if ( $css != '' ) {
125 wp_add_inline_style( $handle, $css );
126 }
127 }
128
129
130 /**
131 * Add Inline JS
132 *
133 */
134 public static function inline_script( $handle, $js ) {
135
136 if ( $js != '' ) {
137 wp_add_inline_script( $handle, $js );
138 }
139 }
140
141
142 /**
143 * get plugin url
144 *
145 */
146 public static function get_url() {
147
148 return self::$scripts_url;
149 }
150
151 /**
152 * get plugin version
153 *
154 */
155 public static function get_version() {
156
157 return self::$version;
158 }
159
160 public static function get_instance() {
161
162 // create a new object if it doesn't exist.
163 is_null(self::$ins) && self::$ins = new self;
164
165 return self::$ins;
166 }
167 }