Changeset 2658195
- Timestamp:
- 01/15/2022 09:19:07 PM (4 years ago)
- Location:
- torque/trunk
- Files:
-
- 3 edited
-
assets.php (modified) (3 diffs)
-
readme.txt (modified) (1 diff)
-
torque.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
torque/trunk/assets.php
r2615365 r2658195 234 234 $css = ''; 235 235 foreach ($files AS $item) { 236 if ( ($file = \file_get_contents($item)) !== false) {236 if (\file_exists($item) && ($file = \file_get_contents($item)) !== false) { 237 237 $css .= \preg_replace_callback('/url\\([\'"]?+([^\\)"\':]++)[\'"]?\\)/i', function (array $match) use ($item) { 238 238 \chdir(\dirname($item)); … … 282 282 // minify each file 283 283 foreach ($files AS $item) { 284 if ( ($file = \file_get_contents($item)) !== false) {284 if (\file_exists($item) && ($file = \file_get_contents($item)) !== false) { 285 285 $js .= ($js ? "\n\n" : '').$file; 286 286 } … … 312 312 return false; 313 313 } 314 315 /** 316 * Rebuilds the configured combined assets 317 * 318 * @return bool Whether the assets were regenerated 319 */ 320 public static function rebuildAssets() : bool { 321 if (($options = \get_option(packages::SLUG)) !== false) { 322 $success = true; 323 $dir = \dirname(\dirname(\dirname(__DIR__))).'/'; // can't use get_home_path() here 324 325 // rebuild CSS 326 if (!empty($options['combinestyle']) && \is_array($options['combinestyle'])) { 327 $files = []; 328 foreach ($options['combinestyle'] AS $item) { 329 $files[] = $dir.$item; 330 } 331 $target = __DIR__.'/build/'.\md5(\implode(',', $options['combinestyle'])).'.css'; 332 if (!self::buildCss($files, $target, $options['minifystyle'] ? ($options['style'] ?? []) : null)) { 333 $success = false; 334 } 335 } 336 337 // rebuild javascript 338 if (!empty($options['combinescript']) && \is_array($options['combinescript'])) { 339 $files = []; 340 foreach ($options['combinescript'] AS $item) { 341 $files[] = $dir.$item; 342 } 343 $target = __DIR__.'/build/'.\md5(\implode(',', $options['combinescript'])).'.js'; 344 if (!self::buildJavascript($files, $target, $options['minifyscript'] ? ($options['script'] ?? []) : null)) { 345 $success = false; 346 } 347 } 348 return $success; 349 } 350 return false; 351 } 314 352 } -
torque/trunk/readme.txt
r2639345 r2658195 137 137 == Changelog == 138 138 139 = Version 0.5.8 = 140 141 * Added hook to rebuild the assets when a plugin is updated 142 * Added CLI command "torque rebuild" 143 139 144 = Version 0.5.7 = 140 145 -
torque/trunk/torque.php
r2639355 r2658195 49 49 // uninstall 50 50 \register_uninstall_hook(__FILE__, '\\hexydec\\torque\\install::uninstall'); 51 52 // rebuild files when a plugin is updated 53 \add_action('upgrader_process_complete', function () { 54 \hexydec\torque\assets::rebuildAssets(); 55 }); 56 57 // add rebuild command 58 if (\class_exists('WP_CLI')) { 59 \WP_CLI::add_command('torque rebuild', '\\hexydec\\torque\\packages::rebuildAssets', [ 60 'shortdesc' => 'Rebuild the configured combined CSS and Javascript files' 61 ]); 62 }
Note: See TracChangeset
for help on using the changeset viewer.