Skip to content
This repository has been archived by the owner on Sep 16, 2019. It is now read-only.

Combine asset path function. Much prettier. #1126

Merged
merged 1 commit into from
Oct 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
60 changes: 24 additions & 36 deletions library/enqueue-scripts.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,45 +10,33 @@
*/


if ( ! function_exists( 'foundationpress_scripts' ) ) :
function foundationpress_scripts() {

// Check to see if rev-manifest exists for CSS and JS static asset revisioning
//https://github.com/sindresorhus/gulp-rev/blob/master/integration.md
function css_asset_path($filename) {
$manifest_path = dirname(dirname(__FILE__)) . '/dist/assets/css/rev-manifest.json';

if (file_exists($manifest_path)) {
$manifest = json_decode(file_get_contents($manifest_path), TRUE);
} else {
$manifest = [];
}

if (array_key_exists($filename, $manifest)) {
return $manifest[$filename];
}

return $filename;
}

function js_asset_path($filename) {
$manifest_path = dirname(dirname(__FILE__)) . '/dist/assets/js/rev-manifest.json';

if (file_exists($manifest_path)) {
$manifest = json_decode(file_get_contents($manifest_path), TRUE);
} else {
$manifest = [];
}
// Check to see if rev-manifest exists for CSS and JS static asset revisioning
//https://github.com/sindresorhus/gulp-rev/blob/master/integration.md

if ( ! function_exists( 'foundationpress_asset_path' ) ) :
function foundationpress_asset_path( $filename ) {
$dir = end( explode ( '.' , $filename) );
$manifest_path = dirname( dirname(__FILE__) ) . '/dist/assets/' . $dir . '/rev-manifest.json';

if ( file_exists($manifest_path ) ) {
$manifest = json_decode( file_get_contents( $manifest_path ), TRUE);
} else {
$manifest = [];
}

if ( array_key_exists( $filename, $manifest) ) {
return $manifest[$filename];
}
return $filename;
}
endif;

if (array_key_exists($filename, $manifest)) {
return $manifest[$filename];
}

return $filename;
}
if ( ! function_exists( 'foundationpress_scripts' ) ) :
function foundationpress_scripts() {

// Enqueue the main Stylesheet.
wp_enqueue_style( 'main-stylesheet', get_template_directory_uri() . '/dist/assets/css/' . css_asset_path('app.css'), array(), '2.10.4', 'all' );
wp_enqueue_style( 'main-stylesheet', get_template_directory_uri() . '/dist/assets/css/' . foundationpress_asset_path('app.css'), array(), '2.10.4', 'all' );

// Deregister the jquery version bundled with WordPress.
wp_deregister_script( 'jquery' );
Expand All @@ -57,7 +45,7 @@ function js_asset_path($filename) {
wp_enqueue_script( 'jquery', 'https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array(), '3.2.1', false );

// Enqueue Founation scripts
wp_enqueue_script( 'foundation', get_template_directory_uri() . '/dist/assets/js/' . js_asset_path('app.js'), array( 'jquery' ), '2.10.4', true );
wp_enqueue_script( 'foundation', get_template_directory_uri() . '/dist/assets/js/' . foundationpress_asset_path('app.js'), array( 'jquery' ), '2.10.4', true );

// Enqueue FontAwesome from CDN. Uncomment the line below if you don't need FontAwesome.
//wp_enqueue_script( 'fontawesome', 'https://use.fontawesome.com/5016a31c8c.js', array(), '4.7.0', true );
Expand Down
2 changes: 1 addition & 1 deletion library/theme-support.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function foundationpress_theme_support() {
add_theme_support( 'wc-product-gallery-slider' );

// Add foundation.css as editor style https://codex.wordpress.org/Editor_Style
add_editor_style( 'dist/assets/css/app.css' );
add_editor_style( 'dist/assets/css/' . foundationpress_asset_path('app.css'));
}

add_action( 'after_setup_theme', 'foundationpress_theme_support' );
Expand Down