PluginProbe
WP Coder – Insert & Manage Code Snippets / 4.1
WP Coder – Insert & Manage Code Snippets v4.1
4.5.1 1.1 2.3.1 2.3.2 2.4.1 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 3.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.1 3.1.1 3.2 3.2.1 3.3 3.4 3.5 3.5.1 All 39 releases
← All changes | classes/Publisher/EnqueueScript.php +25 -13 3.04.1 View file →
@@ -6,9 +6,9 @@
6 6
7 7 use WPCoder\Dashboard\DBManager;
8 8 use WPCoder\Dashboard\FolderManager;
9 9 use WPCoder\Optimization\Obfuscator;
10 -use WPCoder\WOW_Plugin;
10 +use WPCoder\WPCoder;
11 11
12 12 class EnqueueScript {
13 13
14 14 public static function init( $result ): void {
@@ -14,17 +14,14 @@
14 14 public static function init( $result ): void {
15 15 $param = maybe_unserialize( $result->param );
16 16 $js = wp_specialchars_decode( $result->js_code, ENT_QUOTES );
17 17
18 - if ( ! empty( $js ) && ! empty( $param['inline_js'] ) ) {
19 - self::print_style( $js, $param, $result );
20 - }
18 + self::include_scripts( $result );
21 19
22 20 if ( ! empty( $js ) && empty( $param['inline_js'] ) ) {
23 21 self::include_script( $result, $param );
24 22 }
25 23
26 - self::include_scripts( $result );
27 24
28 25 add_filter( 'script_loader_tag', [ __CLASS__, 'add_attribute' ], 20, 2 );
29 26 }
30 27
@@ -37,13 +34,26 @@
37 34
38 35 return $tag;
39 36 }
40 37
41 - private static function print_style( $js, $param, $result ): void {
38 + public static function inline( $result ): void {
39 +
42 40 if ( is_admin() ) {
43 41 return;
44 42 }
45 43
44 + $param = maybe_unserialize( $result->param );
45 + $js = wp_specialchars_decode( $result->js_code, ENT_QUOTES );
46 +
47 + if ( empty( $param['inline_js'] ) ) {
48 + return;
49 + }
50 +
51 + if ( empty( $js ) ) {
52 + return;
53 + }
54 +
55 +
46 56 $minified = ! empty( $param['minified_js'] ) ? $param['minified_js'] : 'obfuscate';
47 57
48 58 if ( $minified === 'obfuscate' ) {
49 59 $packer = new Obfuscator( $js, 'Normal', true, false );
@@ -53,10 +63,12 @@
53 63 $packer = new Obfuscator( $js, 'None', true, false );
54 64 $js = $packer->pack();
55 65 }
56 66
57 - $slug = WOW_Plugin::SLUG . '-js-' . $result->id . '-inline';
67 + $slug = WPCoder::SLUG . '-js-' . $result->id . '-inline';
68 + // phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
58 69 echo '<script id="' . esc_attr( $slug ) . '">' . $js . '</script>';
70 + // phpcs:enable
59 71 }
60 72
61 73 private static function include_script( $result, $param ): void {
62 74 $url = FolderManager::get_js_url( $result );
@@ -61,10 +73,10 @@
61 73 private static function include_script( $result, $param ): void {
62 74 $url = FolderManager::get_js_url( $result );
63 75 $time = ! empty( $param['time'] ) ? $param['time'] : time();
64 76 $dependency = ! empty( $param['jquery_dependency'] ) ? [] : [ 'jquery' ];
65 - wp_enqueue_script( WOW_Plugin::SLUG . '-script-' . $result->id, $url, $dependency,
66 - WOW_Plugin::VERSION . '_' . $time, true );
77 + wp_enqueue_script( WPCoder::SLUG . '-script-' . $result->id, $url, $dependency,
78 + WPCoder::info( 'version' ) . '_' . $time, true );
67 79 }
68 80
69 81 private static function include_scripts( $result ): void {
70 82 $scripts = self::get_scripts( $result );
@@ -92,10 +104,10 @@
92 104 for ( $i = 0; $i < $count; $i ++ ) {
93 105 if ( $param['include'][ $i ] === 'js' && ! empty( $param['include_file'][ $i ] ) ) {
94 106 $scripts[] = [
95 107 'url' => $param['include_file'][ $i ],
96 - 'slug' => WOW_Plugin::SLUG . '-' . $result->id . '-js-' . $i,
97 - 'ver' => WOW_Plugin::VERSION . '_' . $time,
108 + 'slug' => WPCoder::SLUG . '-' . $result->id . '-js-' . $i,
109 + 'ver' => WPCoder::info( 'version' ) . '_' . $time,
98 110 ];
99 111 }
100 112 }
101 113
@@ -115,9 +127,9 @@
115 127 $id = $result->id;
116 128 $param = maybe_unserialize( $result->param );
117 129
118 130 if ( ! empty( $param['js_attributes'] ) && ! empty( $result->js_code ) ) {
119 - $scripts[ WOW_Plugin::SLUG . '-script-' . $id ] = $param['js_attributes'];
131 + $scripts[ WPCoder::SLUG . '-script-' . $id ] = $param['js_attributes'];
120 132 }
121 133
122 134
123 135 $count = ! empty( $param['include'] ) ? count( $param['include'] ) : 0;
@@ -129,9 +141,9 @@
129 141 for ( $i = 0; $i < $count; $i ++ ) {
130 142 if ( $param['include'][ $i ] === 'js' && ! empty( $param['include_file'][ $i ] ) ) {
131 143 $attr = ! empty( $param['file_js_att'][ $i ] ) ? $param['file_js_att'][ $i ] : '';
132 144
133 - $scripts[ WOW_Plugin::SLUG . '-' . $id . '-js-' . $i ] = $attr;
145 + $scripts[ WPCoder::SLUG . '-' . $id . '-js-' . $i ] = $attr;
134 146 }
135 147 }
136 148 }
137 149