| @@ -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\WPCoder; | |
| 10 | +use WPCoder\WOW_Plugin; | |
| 11 | 11 | |
| 12 | 12 | class EnqueueScript { |
| 13 | 13 | |
| 14 | 14 | public static function init( $result ): void { |
| @@ -14,16 +14,18 @@ | ||
| 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 | - self::include_scripts( $result ); | |
| 18 | + if ( ! empty( $js ) && ! empty( $param['inline_js'] ) ) { | |
| 19 | + self::print_style( $js, $param, $result ); | |
| 20 | + } | |
| 19 | 21 | |
| 20 | 22 | if ( ! empty( $js ) && empty( $param['inline_js'] ) ) { |
| 21 | 23 | self::include_script( $result, $param ); |
| 22 | 24 | } |
| 23 | 25 | |
| 26 | + self::include_scripts( $result ); | |
| 24 | 27 | |
| 25 | - | |
| 26 | 28 | add_filter( 'script_loader_tag', [ __CLASS__, 'add_attribute' ], 20, 2 ); |
| 27 | 29 | } |
| 28 | 30 | |
| 29 | 31 | public static function add_attribute( $tag, $handle ) { |
| @@ -35,26 +37,13 @@ | ||
| 35 | 37 | |
| 36 | 38 | return $tag; |
| 37 | 39 | } |
| 38 | 40 | |
| 39 | - public static function inline( $result ): void { | |
| 40 | - | |
| 41 | + private static function print_style( $js, $param, $result ): void { | |
| 41 | 42 | if ( is_admin() ) { |
| 42 | 43 | return; |
| 43 | 44 | } |
| 44 | 45 | |
| 45 | - $param = maybe_unserialize( $result->param ); | |
| 46 | - $js = wp_specialchars_decode( $result->js_code, ENT_QUOTES ); | |
| 47 | - | |
| 48 | - if ( empty( $param['inline_js'] ) ) { | |
| 49 | - return; | |
| 50 | - } | |
| 51 | - | |
| 52 | - if ( empty( $js ) ) { | |
| 53 | - return; | |
| 54 | - } | |
| 55 | - | |
| 56 | - | |
| 57 | 46 | $minified = ! empty( $param['minified_js'] ) ? $param['minified_js'] : 'obfuscate'; |
| 58 | 47 | |
| 59 | 48 | if ( $minified === 'obfuscate' ) { |
| 60 | 49 | $packer = new Obfuscator( $js, 'Normal', true, false ); |
| @@ -64,9 +53,9 @@ | ||
| 64 | 53 | $packer = new Obfuscator( $js, 'None', true, false ); |
| 65 | 54 | $js = $packer->pack(); |
| 66 | 55 | } |
| 67 | 56 | |
| 68 | - $slug = WPCoder::SLUG . '-js-' . $result->id . '-inline'; | |
| 57 | + $slug = WOW_Plugin::SLUG . '-js-' . $result->id . '-inline'; | |
| 69 | 58 | echo '<script id="' . esc_attr( $slug ) . '">' . $js . '</script>'; |
| 70 | 59 | } |
| 71 | 60 | |
| 72 | 61 | private static function include_script( $result, $param ): void { |
| @@ -72,10 +61,10 @@ | ||
| 72 | 61 | private static function include_script( $result, $param ): void { |
| 73 | 62 | $url = FolderManager::get_js_url( $result ); |
| 74 | 63 | $time = ! empty( $param['time'] ) ? $param['time'] : time(); |
| 75 | 64 | $dependency = ! empty( $param['jquery_dependency'] ) ? [] : [ 'jquery' ]; |
| 76 | - wp_enqueue_script( WPCoder::SLUG . '-script-' . $result->id, $url, $dependency, | |
| 77 | - WPCoder::info('version') . '_' . $time, true ); | |
| 65 | + wp_enqueue_script( WOW_Plugin::SLUG . '-script-' . $result->id, $url, $dependency, | |
| 66 | + WOW_Plugin::VERSION . '_' . $time, true ); | |
| 78 | 67 | } |
| 79 | 68 | |
| 80 | 69 | private static function include_scripts( $result ): void { |
| 81 | 70 | $scripts = self::get_scripts( $result ); |
| @@ -103,10 +92,10 @@ | ||
| 103 | 92 | for ( $i = 0; $i < $count; $i ++ ) { |
| 104 | 93 | if ( $param['include'][ $i ] === 'js' && ! empty( $param['include_file'][ $i ] ) ) { |
| 105 | 94 | $scripts[] = [ |
| 106 | 95 | 'url' => $param['include_file'][ $i ], |
| 107 | - 'slug' => WPCoder::SLUG . '-' . $result->id . '-js-' . $i, | |
| 108 | - 'ver' => WPCoder::info('version') . '_' . $time, | |
| 96 | + 'slug' => WOW_Plugin::SLUG . '-' . $result->id . '-js-' . $i, | |
| 97 | + 'ver' => WOW_Plugin::VERSION . '_' . $time, | |
| 109 | 98 | ]; |
| 110 | 99 | } |
| 111 | 100 | } |
| 112 | 101 | |
| @@ -126,9 +115,9 @@ | ||
| 126 | 115 | $id = $result->id; |
| 127 | 116 | $param = maybe_unserialize( $result->param ); |
| 128 | 117 | |
| 129 | 118 | if ( ! empty( $param['js_attributes'] ) && ! empty( $result->js_code ) ) { |
| 130 | - $scripts[ WPCoder::SLUG . '-script-' . $id ] = $param['js_attributes']; | |
| 119 | + $scripts[ WOW_Plugin::SLUG . '-script-' . $id ] = $param['js_attributes']; | |
| 131 | 120 | } |
| 132 | 121 | |
| 133 | 122 | |
| 134 | 123 | $count = ! empty( $param['include'] ) ? count( $param['include'] ) : 0; |
| @@ -140,9 +129,9 @@ | ||
| 140 | 129 | for ( $i = 0; $i < $count; $i ++ ) { |
| 141 | 130 | if ( $param['include'][ $i ] === 'js' && ! empty( $param['include_file'][ $i ] ) ) { |
| 142 | 131 | $attr = ! empty( $param['file_js_att'][ $i ] ) ? $param['file_js_att'][ $i ] : ''; |
| 143 | 132 | |
| 144 | - $scripts[ WPCoder::SLUG . '-' . $id . '-js-' . $i ] = $attr; | |
| 133 | + $scripts[ WOW_Plugin::SLUG . '-' . $id . '-js-' . $i ] = $attr; | |
| 145 | 134 | } |
| 146 | 135 | } |
| 147 | 136 | } |
| 148 | 137 | |