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

Commit

Permalink
Merge pull request #1126 from JPOak/combine-path-function
Browse files Browse the repository at this point in the history
Combine asset path function. Much prettier.
  • Loading branch information
olefredrik authored Oct 12, 2017
2 parents 27e18c3 + 73e5679 commit b421d00
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 37 deletions.
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

0 comments on commit b421d00

Please sign in to comment.