Astra_Minify::render_js()

Renders and caches the JavaScript


Description


Return

(void|false) Checks early if cache directory was emptied before generating the new files


Source

File: classes/class-astra-minify.php

		public static function render_js() {

			self::load_filesystem();

			if ( ! defined( 'FS_CHMOD_FILE' ) ) {
				define( 'FS_CHMOD_FILE', ( fileperms( ABSPATH . 'index.php' ) & 0777 | 0644 ) );
			}

			if ( get_option( 'astra-addon-js-status' ) ) {
				$assets_status = self::clear_assets_cache();

				if ( false == $assets_status ) {
					return false;
				}
			}

			$cache_dir    = self::get_cache_dir();
			$new_js_key   = str_replace( '.', '-', uniqid( '', true ) );
			$js_slug      = self::_asset_slug();
			$js_files     = self::get_js_files();
			$dep_js_files = self::$dependent_js_files;
			$js           = '';
			$js_min       = '';
			$filepath     = $cache_dir['path'] . $js_slug . '-' . $new_js_key . '.js';

			if ( count( $js_files ) > 0 ) {

				foreach ( $js_files as $k => $file ) {

					if ( ! empty( $file ) && file_exists( $file ) ) {
						$js .= self::$astra_addon_filesystem->get_contents(
							$file,
							FS_CHMOD_FILE
						);
					}
				}
			}

			$js = apply_filters( 'astra_render_js', $js );

			$status = self::$astra_addon_filesystem->put_contents(
				$filepath,
				$js,
				FS_CHMOD_FILE
			);

			$status = ! $status;

			// Save the new css key.
			update_option( 'astra-addon-js-status', $status );
			update_option( self::$_js_key . '-dep-' . $js_slug, $dep_js_files );
			update_option( self::$_js_key . '-' . $js_slug, $new_js_key );

			do_action( 'astra_after_render_js' );
		}

Changelog

Changelog
Version Description
1.0 Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.