Skip to content

Instantly share code, notes, and snippets.

@Gkiokan
Created August 25, 2017 11:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gkiokan/026a68e6fbe42daffd6e8006d1892497 to your computer and use it in GitHub Desktop.
Save Gkiokan/026a68e6fbe42daffd6e8006d1892497 to your computer and use it in GitHub Desktop.
Custom File loader from Array of files with target Dir
<?php
/*
Project: Autoload function files
Author: Gkiokan Sali
Date: 25.08.2017
Comment: Allows you to include_once files from array only.
*/
// Declare the function itself when it is not defined anywhere else
if(!is_callable('autoload_function_files')):
function autoload_function_files($files=[], $folder=''){
$base_path = __DIR__ . '/' . $folder . '/%s.php';
if(is_array($files))
foreach($files as $file):
$path = sprintf($base_path, $file);
if(file_exists($path))
include_once $path;
endforeach;
}
endif;
$basic_files = [
'basics',
'remove-comments',
'theme-support',
'theme-setup',
'vc-container-extension',
'enqueue',
'navigation-extension',
'onepage-render',
'optimize',
];
$navigation_files = [
'Menus',
// 'ExtendsBodymovinIconFields',
// 'ExtendsBodymovinIconWalker',
// 'ExtendsInContactButtonWalker',
// 'SubMenuWalker',
];
$vc_addon_files = [
'buttons',
'extensions',
'footer_navigation',
];
// Load them all
autoload_function_files($basic_files, 'basic');
autoload_function_files($navigation_files, 'navigation');
autoload_function_files($vc_addon_files, 'vc_addition');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment