$directory) {
// Test if class name belongs to this namespace
$lenght = strlen($namespace);
if (strncmp($namespace, $class, $lenght) !== 0) {
continue;
}
// Find class file
$relative_class = substr($class, $lenght);
$file = $directory . str_replace('\\', DIRECTORY_SEPARATOR, $relative_class) . '.php';
// Require and get out of here
if (file_exists($file)) {
require $file;
return;
}
}
}
spl_autoload_register('ltk_autoloader');
/**
* Check that we can use PHP 5.4 and fail if not
*/
function ltk_version_check($old_name, $old_theme) {
if (version_compare(phpversion(), '5.4.0', '<')) {
add_action('admin_notices', function() {
echo '
';
printf(__('This theme requires PHP version 5.4.0. You are currently using %s.', 'ltk-foundation'), PHP_VERSION);
echo '
';
});
switch_theme($old_theme->stylesheet);
return false;
}
}
add_action('after_switch_theme', 'ltk_version_check', 10, 2);
/**
* Theme setup
*
* Child themes can modify the outcome of this code by adding their own action
* with add_action() on the default priority, since this is executed at 9 (being
* 10 the default).
*
* We are not recommending to do that, though, since this code is enabling
* features supported by the vanilla LTK Foundation. Child themes just don't
* need to do anything, they ARE already supporting these.
*/
function ltk_setup() {
/**
* Enable translations
*/
load_theme_textdomain('ltk-foundation', get_template_directory() . '/languages');
/**
* Title tag management
*
* @link http://codex.wordpress.org/Function_Reference/add_theme_support#Title_Tag
*/
add_theme_support('title-tag');
/**
* Enable post thumbnails
*
* We are configuring them in the ltk_images() function, not here
*
* @link http://codex.wordpress.org/Post_Thumbnails
* @link http://codex.wordpress.org/Function_Reference/set_post_thumbnail_size
* @link http://codex.wordpress.org/Function_Reference/add_image_size
*/
add_theme_support('post-thumbnails');
/**
* Enable post formats
*
* @link http://codex.wordpress.org/Post_Formats
* @todo Create templates for each format
*/
add_theme_support('post-formats', [
'aside',
'gallery',
'link',
'image',
'quote',
'status',
'video',
'audio',
'chat'
]);
/**
* Enable HTML5 markup
*
* @link http://codex.wordpress.org/Function_Reference/add_theme_support#HTML5
*/
add_theme_support('html5', [
'caption',
'comment-form',
'comment-list',
'gallery',
'search-form'
]);
/**
* RSS links to
*
* @link https://codex.wordpress.org/Automatic_Feed_Links
*/
add_theme_support('automatic-feed-links');
/**
* Enable custom backgrounds
*
* @link https://codex.wordpress.org/Custom_Backgrounds
*/
add_theme_support('custom-background');
/**
* Enable custom header
*
* @link https://codex.wordpress.org/Custom_Headers
*/
add_theme_support('custom-header');
/**
* Enable custom logo
*
* @link https://codex.wordpress.org/Theme_Logo
*/
add_theme_support('custom-logo', [
'height' => 100,
'width' => 400,
'flex-height' => true,
'flex-width' => true
]);
/**
* Add site menus
*
* @link http://codex.wordpress.org/Function_Reference/register_nav_menus
*/
register_nav_menus([
'primary' => __('Primary Navigation', 'ltk-foundation'),
'fixed-top' => __('Top Navigation', 'ltk-foundation'),
'footer' => __('Footer Links', 'ltk-foundation')
]);
}
add_action('after_setup_theme', 'ltk_setup', 9);
/**
* Theme assets
*
* Child themes can modify the outcome of this code by adding their own action
* with add_action() on the default priority, since this is executed at 9 (being
* 10 the default).
*
* @link https://developer.wordpress.org/reference/functions/wp_enqueue_style/
* @link https://developer.wordpress.org/reference/functions/wp_enqueue_script/
* @todo Implement https://modernizr.com/docs and FontAwesome
*/
function ltk_assets() {
if (is_admin()) {
return;
}
// Built in scripts
if (is_singular()) {
wp_enqueue_script('comment-reply');
}
// HTML5 Shiv and Respond.js
wp_enqueue_script('html5shiv', get_template_directory_uri() . '/assets/js/html5shiv.min.js');
wp_style_add_data('html5shiv', 'conditional', 'lt IE 9');
wp_enqueue_script('respond', get_template_directory_uri() . '/assets/js/respond.min.js');
wp_style_add_data('respond', 'conditional', 'lt IE 9');
// Custom assets
wp_enqueue_style('ltk-foundation-main', get_template_directory_uri() . '/assets/css/main.min.css', false, null);
wp_enqueue_script('ltk-foundation-main', get_template_directory_uri() . '/assets/js/main.min.js', ['jquery'], null, true);
}
add_action('wp_enqueue_scripts', 'ltk_assets', 9);
/**
* Theme sidebars
*/
function ltk_sidebars() {
$config = [
'before_widget' => '',
'after_widget' => '
',
'before_title' => '',
'after_title' => '
'
];
register_sidebar([
'id' => 'column-right',
'name' => __('Right column', 'ltk-foundation'),
'description' => __('Column on the right that will appear if it has widgets.', 'ltk-foundation'),
] + $config);
register_sidebar([
'id' => 'column-left',
'name' => __('Left column', 'ltk-foundation'),
'description' => __('Column on the left that will appear if it has widgets.', 'ltk-foundation'),
] + $config);
register_sidebar([
'id' => 'footer',
'name' => __('Footer', 'ltk-foundation'),
'description' => __('Widget zone in the page footer.', 'ltk-foundation'),
'before_widget' => '',
'before_title' => '',
'after_title' => '
'
]);
}
add_action('widgets_init', 'ltk_sidebars', 9);
/**
* Theme image sizes and configuration
*
* Child themes can modify the outcome of this code by adding their own action
* with add_action() on the default priority, since this is executed at 9 (being
* 10 the default).
*/
function ltk_images() {
set_post_thumbnail_size(848, 476, true);
$sizes = [
'ltk-full-width' => [__('100% width', 'ltk-foundation'), 848, 9999, false],
'ltk-half-width' => [__('50% width', 'ltk-foundation'), 422, 9999, false],
'ltk-third-width-square' => [__('33% width (1:1)', 'ltk-foundation'), 282, 282, true],
'ltk-quarter-width' => [__('25% width', 'ltk-foundation'), 210, 9999, false],
'ltk-quarter-width-square' => [__('25% width (1:1)', 'ltk-foundation'), 210, 210, true],
'ltk-lists-medium' => [__('Medium image for lists (4:3)', 'ltk-foundation'), 398, 299, true],
'ltk-lists-small' => [__('Small image for lists (4:3)', 'ltk-foundation'), 200, 150, true],
'ltk-lists-small-square' => [__('Square image for lists (1:1)', 'ltk-foundation'), 120, 120, true],
];
foreach ($sizes as $slug => $settings) {
add_image_size($slug, $settings[1], $settings[2], $settings[3]);
}
}
add_action('after_setup_theme', 'ltk_images', 9);
/* Cleaning body class */
add_filter('body_class', 'LTK\Foundation\ViewHelper::layoutBodyClasses');
/* WordPress built-in customizer support */
add_action('customize_register', 'LTK\Foundation\Customize\Customizer::register');
add_action('customize_preview_init', 'LTK\Foundation\Customize\Customizer::registerPreview');
add_action('wp_head', 'LTK\Foundation\Customize\Customizer::defaultSettings');
/* Post pagination */
add_filter('wp_link_pages_args', 'LTK\Foundation\View\Post::paginationArguments');
add_filter('wp_link_pages', 'LTK\Foundation\View\Post::paginationFilterPages');
add_filter('wp_link_pages_link', 'LTK\Foundation\View\Post::paginationFilterPagesLink');
/* Protected posts lock icon */
add_filter('protected_title_format', 'LTK\Foundation\View\Post::passwordProtectedPostIcon');
add_filter('private_title_format', 'LTK\Foundation\View\Post::passwordProtectedPostIcon');