mirror of
https://git.sindominio.net/estibadores/wordpress.git
synced 2024-11-23 02:51:06 +01:00
320 lines
8.9 KiB
PHP
320 lines
8.9 KiB
PHP
<?php
|
|
|
|
/**
|
|
* $content_width support
|
|
*
|
|
* We are setting this to 1170, Bootstrap's container maximum width, and allow
|
|
* filtering by whoever wants to manage this variable. We are adding this as a
|
|
* requirement: https://themes.trac.wordpress.org/ticket/38066#comment:5
|
|
*
|
|
* @link https://wycks.wordpress.com/2013/02/14/why-the-content_width-wordpress-global-kinda-sucks/
|
|
*/
|
|
function ltk_content_width() {
|
|
$GLOBALS['content_width'] = apply_filters('ltk_content_width', 1170);
|
|
}
|
|
add_action('after_setup_theme', 'ltk_content_width', 0);
|
|
|
|
/**
|
|
* Check for the presence of child theme namespaces
|
|
*
|
|
* Child themes can hook in namespaces and directories by specifying them in a
|
|
* $namespaces var, in the form of $namespaces['My\\Namespace'] = 'directory' so
|
|
* our autoloader can and will handle them without requiring child themes to add
|
|
* more autoloaders.
|
|
*/
|
|
if (! isset($namespaces)) {
|
|
$namespaces = [];
|
|
}
|
|
|
|
$namespaces['LTK\\Foundation\\'] =
|
|
__DIR__ . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR;
|
|
|
|
/**
|
|
* Class autoloader
|
|
*
|
|
* @param string $class Namespace + class name of the class to load
|
|
*/
|
|
function ltk_autoloader($class) {
|
|
global $namespaces;
|
|
|
|
foreach ($namespaces as $namespace => $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 '<div class="update-nag">';
|
|
printf(__('This theme requires PHP version 5.4.0. You are currently using %s.', 'ltk-foundation'), PHP_VERSION);
|
|
echo '</div>';
|
|
});
|
|
|
|
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 <head>
|
|
*
|
|
* @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' => '<div class="widget %1$s %2$s">',
|
|
'after_widget' => '</div>',
|
|
'before_title' => '<div class="widget-heading">',
|
|
'after_title' => '</div>'
|
|
];
|
|
|
|
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' => '<div class="col-xs-12 col-sm-6 col-md-4 col-lg-3"><div class="widget %1$s %2$s">',
|
|
'after_widget' => '</div></div>',
|
|
'before_title' => '<div class="widget-heading">',
|
|
'after_title' => '</div>'
|
|
]);
|
|
|
|
}
|
|
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');
|