From 9dacaa8cf54fa67d39dc758cce45ad779161cf68 Mon Sep 17 00:00:00 2001 From: Gary Kealy Date: Wed, 12 Sep 2018 12:27:29 +0100 Subject: [PATCH] Refactor functions.php --- functions.php | 91 +++++++++++++-------------------------------------- 1 file changed, 23 insertions(+), 68 deletions(-) diff --git a/functions.php b/functions.php index a86173d..e30c279 100644 --- a/functions.php +++ b/functions.php @@ -9,72 +9,27 @@ if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } -/** - * Initialize theme default settings - */ -require get_template_directory() . '/inc/theme-settings.php'; +$understrap_includes = array( + '/theme-settings.php', // Initialize theme default settings. + '/setup.php', // Theme setup and custom theme supports. + '/widgets.php', // Register widget area. + '/enqueue.php', // Enqueue scripts and styles. + '/template-tags.php', // Custom template tags for this theme. + '/pagination.php', // Custom pagination for this theme. + '/hooks.php', // Custom hooks. + '/extras.php', // Custom functions that act independently of the theme templates. + '/customizer.php', // Customizer additions. + '/custom-comments.php', // Custom Comments file. + '/jetpack.php', // Load Jetpack compatibility file. + '/class-wp-bootstrap-navwalker.php', // Load custom WordPress nav walker. + '/woocommerce.php', // Load WooCommerce functions. + '/editor.php', // Load Editor functions. +); -/** - * Theme setup and custom theme supports. - */ -require get_template_directory() . '/inc/setup.php'; - -/** - * Register widget area. - */ -require get_template_directory() . '/inc/widgets.php'; - -/** - * Enqueue scripts and styles. - */ -require get_template_directory() . '/inc/enqueue.php'; - -/** - * Custom template tags for this theme. - */ -require get_template_directory() . '/inc/template-tags.php'; - -/** - * Custom pagination for this theme. - */ -require get_template_directory() . '/inc/pagination.php'; - -/** - * Custom hooks. - */ -require get_template_directory() . '/inc/hooks.php'; - -/** - * Custom functions that act independently of the theme templates. - */ -require get_template_directory() . '/inc/extras.php'; - -/** - * Customizer additions. - */ -require get_template_directory() . '/inc/customizer.php'; - -/** - * Custom Comments file. - */ -require get_template_directory() . '/inc/custom-comments.php'; - -/** - * Load Jetpack compatibility file. - */ -require get_template_directory() . '/inc/jetpack.php'; - -/** - * Load custom WordPress nav walker. - */ -require get_template_directory() . '/inc/class-wp-bootstrap-navwalker.php'; - -/** - * Load WooCommerce functions. - */ -require get_template_directory() . '/inc/woocommerce.php'; - -/** - * Load Editor functions. - */ -require get_template_directory() . '/inc/editor.php'; +foreach ( $understrap_includes as $file ) { + $filepath = locate_template( '/inc' . $file ); + if ( ! $filepath ) { + trigger_error( sprintf( 'Error locating /inc%s for inclusion', $file ), E_USER_ERROR ); + } + require_once $filepath; +}