'FFFFFF'
) );
// Set content-width
global $content_width;
if ( ! isset( $content_width ) ) {
$content_width = 580;
}
// Post thumbnails
add_theme_support( 'post-thumbnails' );
// Set post thumbnail size
$low_res_images = get_theme_mod( 'chaplin_activate_low_resolution_images', false );
if ( $low_res_images ) {
set_post_thumbnail_size( 1120, 9999 );
} else {
set_post_thumbnail_size( 2240, 9999 );
}
// Add image sizes
add_image_size( 'chaplin_preview_image_low_resolution', 540, 9999 );
add_image_size( 'chaplin_preview_image_high_resolution', 1080, 9999 );
add_image_size( 'chaplin_fullscreen', 1980, 9999 );
// Custom logo
add_theme_support( 'custom-logo', array(
'height' => 240,
'width' => 320,
'flex-height' => true,
'flex-width' => true,
'header-text' => array( 'site-title', 'site-description' ),
) );
// Title tag
add_theme_support( 'title-tag' );
// HTML5 semantic markup
add_theme_support( 'html5', array( 'search-form', 'comment-form', 'comment-list', 'gallery', 'caption' ) );
// Make the theme translation ready
load_theme_textdomain( 'chaplin', get_template_directory() . '/languages' );
// Alignwide and alignfull classes in the block editor
add_theme_support( 'align-wide' );
}
add_action( 'after_setup_theme', 'chaplin_theme_support' );
endif;
/* -----------------------------------------------------------------------------------------------
REQUIRED FILES
Include required files
--------------------------------------------------------------------------------------------------- */
// Handle Google Fonts
require get_template_directory() . '/parts/classes/class-google-fonts.php';
// Handle SVG icons
require get_template_directory() . '/parts/classes/class-svg-icons.php';
// Handle Customizer settings
require get_template_directory() . '/parts/classes/class-theme-customizer.php';
// Custom comment walker
require get_template_directory() . '/parts/classes/class-comment-walker.php';
/* -----------------------------------------------------------------------------------------------
REGISTER STYLES
Register and enqueue CSS
--------------------------------------------------------------------------------------------------- */
if ( ! function_exists( 'chaplin_register_styles' ) ) :
function chaplin_register_styles() {
$theme_version = wp_get_theme()->get( 'Version' );
$css_dependencies = array();
// Retrieve and enqueue the URL for Google Fonts
$google_fonts_url = Chaplin_Google_Fonts::get_google_fonts_url();
if ( $google_fonts_url ) {
wp_register_style( 'chaplin-google-fonts', $google_fonts_url, false, 1.0, 'all' );
$css_dependencies[] = 'chaplin-google-fonts';
}
// By default, only load the Font Awesome fonts if the social menu is in use
$load_font_awesome = apply_filters( 'chaplin_load_font_awesome', has_nav_menu( 'social-menu' ) );
if ( $load_font_awesome ) {
wp_register_style( 'chaplin-font-awesome', get_template_directory_uri() . '/assets/css/font-awesome.css', false, 1.0, 'all' );
$css_dependencies[] = 'chaplin-font-awesome';
}
wp_enqueue_style( 'chaplin-style', get_template_directory_uri() . '/style.css', $css_dependencies, $theme_version );
// Add output of Customizer settings as inline style
wp_add_inline_style( 'chaplin-style', chaplin_get_customizer_css( 'front-end' ) );
}
add_action( 'wp_enqueue_scripts', 'chaplin_register_styles' );
endif;
/* -----------------------------------------------------------------------------------------------
DEQUEUE STYLES
Dequeue the block library styles, as we provide our own
--------------------------------------------------------------------------------------------------- */
if ( ! function_exists( 'chaplin_deregister_styles' ) ) :
function chaplin_deregister_styles() {
wp_dequeue_style( 'wp-block-library' );
}
add_action( 'wp_print_styles', 'chaplin_deregister_styles', 100 );
endif;
/* -----------------------------------------------------------------------------------------------
REGISTER SCRIPTS
Register and enqueue JavaScript
--------------------------------------------------------------------------------------------------- */
if ( ! function_exists( 'chaplin_register_scripts' ) ) :
function chaplin_register_scripts() {
$theme_version = wp_get_theme()->get( 'Version' );
if ( ( ! is_admin() ) && is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
$js_dependencies = array( 'jquery', 'imagesloaded' );
wp_enqueue_script( 'chaplin-construct', get_template_directory_uri() . '/assets/js/construct.js', $js_dependencies, $theme_version );
// Setup AJAX
$ajax_url = admin_url( 'admin-ajax.php' );
// AJAX Load More
wp_localize_script( 'chaplin-construct', 'chaplin_ajax_load_more', array(
'ajaxurl' => esc_url( $ajax_url ),
) );
}
add_action( 'wp_enqueue_scripts', 'chaplin_register_scripts' );
endif;
/* -----------------------------------------------------------------------------------------------
MENUS
Register navigational menus (wp_nav_menu)
--------------------------------------------------------------------------------------------------- */
if ( ! function_exists( 'chaplin_menus' ) ) :
function chaplin_menus() {
// Register menus
$locations = array(
'main-menu' => __( 'Main menu', 'chaplin' ),
'footer-menu' => __( 'Footer Menu', 'chaplin' ),
'social-menu' => __( 'Social Menu', 'chaplin' ),
);
register_nav_menus( $locations );
}
add_action( 'init', 'chaplin_menus' );
endif;
/* -----------------------------------------------------------------------------------------------
BODY CLASSES
Conditional addition of classes to the body element
--------------------------------------------------------------------------------------------------- */
if ( ! function_exists( 'chaplin_body_classes' ) ) :
function chaplin_body_classes( $classes ) {
global $post;
$post_type = isset( $post ) ? $post->post_type : false;
// Determine type of infinite scroll
$pagination_type = get_theme_mod( 'chaplin_pagination_type', 'button' );
switch ( $pagination_type ) {
case 'button' :
$classes[] = 'pagination-type-button';
break;
case 'scroll' :
$classes[] = 'pagination-type-scroll';
break;
case 'links' :
$classes[] = 'pagination-type-links';
break;
}
// Check whether the current page should have an overlay header
if ( is_page_template( array( 'template-cover.php', 'template-full-width-cover.php' ) ) ) {
$classes[] = 'overlay-header';
// Check if we're fading
if ( get_theme_mod( 'chaplin_cover_template_fade_text', true ) ) {
$classes[] = 'overlay-header-fade-text';
}
// Check if it has a custom text color
if ( get_theme_mod( 'chaplin_cover_template_overlay_text_color' ) ) {
$classes[] = 'overlay-header-has-text-color';
}
}
// Check whether the current page should have an overlay header
if ( is_page_template( array( 'template-full-width-only-content.php', 'template-only-content.php' ) ) ) {
$classes[] = 'has-only-content';
}
// Check whether the current page should have an overlay header
if ( is_page_template( array( 'template-full-width-only-content.php', 'template-full-width.php', 'template-full-width-cover.php' ) ) ) {
$classes[] = 'has-full-width-content';
}
// Check for sticky header
if ( get_theme_mod( 'chaplin_sticky_header' ) ) {
$classes[] = 'has-sticky-header';
}
// Check for disabled search
if ( get_theme_mod( 'chaplin_disable_header_search', false ) ) {
$classes[] = 'disable-search-modal';
}
// Check for disabled menu modal on desktop
if ( get_theme_mod( 'chaplin_disable_menu_modal_on_desktop', false ) ) {
$classes[] = 'disable-menu-modal-on-desktop';
}
// Check for post thumbnail
if ( is_singular() && has_post_thumbnail() ) {
$classes[] = 'has-post-thumbnail';
} elseif ( is_singular() ) {
$classes[] = 'missing-post-thumbnail';
}
// Check whether we're in the customizer preview
if ( is_customize_preview() ) {
$classes[] = 'customizer-preview';
}
// Check if posts have single pagination
if ( is_single() && ( get_next_post() || get_previous_post() ) ) {
$classes[] = 'has-single-pagination';
} else {
$classes[] = 'has-no-pagination';
}
// Check if we're showing comments
if ( $post && ( ( $post_type == 'post' || comments_open() || get_comments_number() ) && ! post_password_required() ) ) {
$classes[] = 'showing-comments';
} else {
$classes[] = 'not-showing-comments';
}
// Slim page template class names (class = name - file suffix)
if ( is_page_template() ) {
$classes[] = basename( get_page_template_slug(), '.php' );
}
return $classes;
}
add_action( 'body_class', 'chaplin_body_classes' );
endif;
/* -----------------------------------------------------------------------------------------------
NO-JS CLASS
If we're missing JavaScript support, the HTML element will have a no-js class
--------------------------------------------------------------------------------------------------- */
if ( ! function_exists( 'chaplin_no_js_class' ) ) :
function chaplin_no_js_class() {
?>
'
',
'after_title' => '
',
'before_widget' => '
',
'after_widget' => '
',
);
// Footer #1
register_sidebar( array_merge( $shared_args, array(
'name' => __( 'Footer #1', 'chaplin' ),
'id' => 'footer-one',
'description' => __( 'Widgets in this area will be displayed in the first column in the footer.', 'chaplin' ),
) ) );
// Footer #2
register_sidebar( array_merge( $shared_args, array(
'name' => __( 'Footer #2', 'chaplin' ),
'id' => 'footer-two',
'description' => __( 'Widgets in this area will be displayed in the second column in the footer.', 'chaplin' ),
) ) );
}
add_action( 'widgets_init', 'chaplin_sidebar_registration' );
endif;
/* ---------------------------------------------------------------------------------------------
INCLUDE THEME WIDGETS
--------------------------------------------------------------------------------------------- */
require_once( get_template_directory() . '/parts/widgets/recent-comments.php' );
require_once( get_template_directory() . '/parts/widgets/recent-posts.php' );
/* ---------------------------------------------------------------------------------------------
REGISTER THEME WIDGETS
--------------------------------------------------------------------------------------------- */
if ( ! function_exists( 'chaplin_register_widgets' ) ) :
function chaplin_register_widgets() {
register_widget( 'Chaplin_Recent_Comments' );
register_widget( 'Chaplin_Recent_Posts' );
}
add_action( 'widgets_init', 'chaplin_register_widgets' );
endif;
/* ---------------------------------------------------------------------------------------------
DELIST DEFAULT WIDGETS REPLACE BY THEME ONES
--------------------------------------------------------------------------------------------- */
if ( ! function_exists( 'chaplin_unregister_default_widgets' ) ) {
function chaplin_unregister_default_widgets() {
unregister_widget( 'WP_Widget_Recent_Comments' );
unregister_widget( 'WP_Widget_Recent_Posts' );
}
add_action( 'widgets_init', 'chaplin_unregister_default_widgets', 11 );
}
/* -----------------------------------------------------------------------------------------------
GET PAGE ID FROM TEMPLATE
Get the ID of the first occurance of a page using the specified page template
@param $template_name string Page template file name for which to retrieve the post ID
--------------------------------------------------------------------------------------------------- */
if ( ! function_exists( 'chaplin_get_id_from_template' ) ) :
function chaplin_get_id_from_template( $template_name ) {
// Query all pages with the specified page template
$pages = get_posts( array(
'meta_key' => '_wp_page_template',
'meta_value' => $template_name,
'post_status' => 'publish',
'post_type' => 'page'
) );
// Get the ID of the first occurance of that page
if ( isset( $pages[0] ) ) {
$id = $pages[0]->ID;
return $id;
}
return false;
}
endif;
/* -----------------------------------------------------------------------------------------------
ADD EXCERPT SUPPORT TO PAGES
--------------------------------------------------------------------------------------------------- */
if ( ! function_exists( 'chaplin_add_excerpt_support_to_pages' ) ) :
function chaplin_add_excerpt_support_to_pages() {
add_post_type_support( 'page', 'excerpt' );
}
add_action( 'init', 'chaplin_add_excerpt_support_to_pages' );
endif;
/* -----------------------------------------------------------------------------------------------
FILTER ARCHIVE TITLE
@param $title string The initial title
--------------------------------------------------------------------------------------------------- */
if ( ! function_exists( 'chaplin_filter_archive_title' ) ) :
function chaplin_filter_archive_title( $title ) {
// Use the blog page title on home
$blog_page_id = get_option( 'page_for_posts' );
if ( is_home() && $blog_page_id && get_the_title( $blog_page_id ) ) {
$title = get_the_title( $blog_page_id );
}
return $title;
}
add_filter( 'get_the_archive_title', 'chaplin_filter_archive_title' );
endif;
/* -----------------------------------------------------------------------------------------------
FILTER ARCHIVE DESCRIPTION
@param $description string The initial description
--------------------------------------------------------------------------------------------------- */
if ( ! function_exists( 'chaplin_filter_archive_description' ) ) :
function chaplin_filter_archive_description( $description ) {
// Use the blog page manual excerpt on home
$blog_page_id = get_option( 'page_for_posts' );
if ( is_home() && $blog_page_id && has_excerpt( $blog_page_id ) ) {
$description = get_the_excerpt( $blog_page_id );
}
return $description;
}
add_filter( 'get_the_archive_description', 'chaplin_filter_archive_description' );
endif;
/* ---------------------------------------------------------------------------------------------
GET FALLBACK IMAGE
--------------------------------------------------------------------------------------------- */
if ( ! function_exists( 'chaplin_get_fallback_image_url' ) ) :
function chaplin_get_fallback_image_url() {
$disable_fallback_image = get_theme_mod( 'chaplin_disable_fallback_image', false );
if ( $disable_fallback_image ) {
return '';
}
$fallback_image_id = get_theme_mod( 'chaplin_fallback_image' );
if ( $fallback_image_id ) {
$fallback_image = wp_get_attachment_image_src( $fallback_image_id, 'full' );
}
$fallback_image_url = isset( $fallback_image ) ? esc_url( $fallback_image[0] ) : get_template_directory_uri() . '/assets/images/default-fallback-image.png';
return $fallback_image_url;
}
endif;
/* ---------------------------------------------------------------------------------------------
OUTPUT FALLBACK IMAGE
--------------------------------------------------------------------------------------------- */
if ( ! function_exists( 'chaplin_the_fallback_image' ) ) :
function chaplin_the_fallback_image() {
$fallback_image_url = chaplin_get_fallback_image_url();
if ( ! $fallback_image_url ) {
return;
}
echo '';
}
endif;
/* ---------------------------------------------------------------------------------------------
GET THE IMAGE SIZE OF PREVIEWS
--------------------------------------------------------------------------------------------- */
if ( ! function_exists( 'chaplin_get_preview_image_size' ) ) :
function chaplin_get_preview_image_size() {
// Check if low-resolution images are activated in the customizer
$low_res_images = get_theme_mod( 'chaplin_activate_low_resolution_images', false );
// If they are, we're using the low resolution image size
if ( $low_res_images ) {
return 'chaplin_preview_image_low_resolution';
// If not, we're using the high resolution image size
} else {
return 'chaplin_preview_image_high_resolution';
}
}
endif;
/* -----------------------------------------------------------------------------------------------
OUTPUT AND GET THEME SVG
Output and get the SVG markup for a icon in the Chaplin_SVG_Icons class
--------------------------------------------------------------------------------------------------- */
if ( ! function_exists( 'chaplin_the_theme_svg' ) ) :
function chaplin_the_theme_svg( $svg_name, $color = '' ) {
// Escaped in chaplin_get_theme_svg();
echo chaplin_get_theme_svg( $svg_name, $color );
}
endif;
if ( ! function_exists( 'chaplin_get_theme_svg' ) ) :
function chaplin_get_theme_svg( $svg_name, $color = '' ) {
// Make sure that only our allowed tags and attributes are included
$svg = wp_kses( Chaplin_SVG_Icons::get_svg( $svg_name, $color ), array(
'svg' => array(
'class' => true,
'xmlns' => true,
'width' => true,
'height' => true,
'viewbox' => true,
'aria-hidden' => true,
'role' => true,
'focusable' => true,
'tabindex' => true,
),
'path' => array(
'fill' => true,
'fill-rule' => true,
'd' => true,
'transform' => true,
),
'polygon' => array(
'fill' => true,
'fill-rule' => true,
'points' => true,
'transform' => true,
'focusable' => true,
'tabindex' => true,
),
) );
if ( ! $svg ) {
return false;
}
return $svg;
}
endif;
/* -----------------------------------------------------------------------------------------------
IS COMMENT BY POST AUTHOR?
Check if the specified comment is written by the author of the post commented on.
--------------------------------------------------------------------------------------------------- */
if ( ! function_exists( 'chaplin_is_comment_by_post_author' ) ) :
function chaplin_is_comment_by_post_author( $comment = null ) {
if ( is_object( $comment ) && $comment->user_id > 0 ) {
$user = get_userdata( $comment->user_id );
$post = get_post( $comment->comment_post_ID );
if ( ! empty( $user ) && ! empty( $post ) ) {
return $comment->user_id === $post->post_author;
}
}
return false;
}
endif;
/* -----------------------------------------------------------------------------------------------
FILTER COMMENT REPLY LINK TO NOT JS SCROLL
Filter the comment reply link to add a class indicating it should not use JS slow-scroll, as it
makes it scroll to the wrong position on the page
--------------------------------------------------------------------------------------------------- */
if ( ! function_exists( 'chaplin_filter_comment_reply_link' ) ) :
function chaplin_filter_comment_reply_link( $link ) {
$link = str_replace( 'class=\'', 'class=\'do-not-scroll ', $link );
return $link;
}
add_filter( 'comment_reply_link', 'chaplin_filter_comment_reply_link' );
endif;
/* -----------------------------------------------------------------------------------------------
FILTER CLASSES OF WP_LIST_PAGES ITEMS TO MATCH MENU ITEMS
Filter the class applied to wp_list_pages() items with children to match the menu class, to simplify
styling of sub levels in the fallback. Only applied if the match_menu_classes argument is set.
--------------------------------------------------------------------------------------------------- */
if ( ! function_exists( 'chaplin_filter_wp_list_pages_item_classes' ) ) :
function chaplin_filter_wp_list_pages_item_classes( $css_class, $item, $depth, $args, $current_page ) {
// Only apply to wp_list_pages() calls with match_menu_classes set to true
$match_menu_classes = isset( $args['match_menu_classes'] );
if ( ! $match_menu_classes ) {
return $css_class;
}
// Add current menu item class
if ( in_array( 'current_page_item', $css_class ) ) {
$css_class[] = 'current-menu-item';
}
// Add menu item has children class
if ( in_array( 'page_item_has_children', $css_class ) ) {
$css_class[] = 'menu-item-has-children';
}
return $css_class;
}
add_filter( 'page_css_class', 'chaplin_filter_wp_list_pages_item_classes', 10, 5 );
endif;
/* ------------------------------------------------------------------------------------------------
OUTPUT & GET POST META
If it's a single post, output the post meta values specified in the Customizer settings.
@param $post_id int The ID of the post for which the post meta should be output
@param $location string Which post meta location to output – single or preview
--------------------------------------------------------------------------------------------- */
if ( ! function_exists( 'chaplin_the_post_meta' ) ) :
function chaplin_the_post_meta( $post_id = null, $location = 'single-top' ) {
// Escaped in chaplin_get_post_meta()
echo chaplin_get_post_meta( $post_id, $location );
}
endif;
if ( ! function_exists( 'chaplin_get_post_meta' ) ) :
function chaplin_get_post_meta( $post_id = null, $location = 'single-top' ) {
// Require post ID
if ( ! $post_id ) {
return;
}
$page_template = get_page_template_slug( $post_id );
// Check that the post type should be able to output post meta
$allowed_post_types = apply_filters( 'chaplin_allowed_post_types_for_meta_output', array( 'post', 'jetpack-portfolio' ) );
if ( ! in_array( get_post_type( $post_id ), $allowed_post_types ) ) {
return;
}
$post_meta_wrapper_classes = '';
$post_meta_classes = '';
// Get the post meta settings for the location specified
if ( 'single-top' === $location ) {
$post_meta = get_theme_mod( 'chaplin_post_meta_single_top' );
$post_meta_wrapper_classes = ' post-meta-single post-meta-single-top';
// Empty = use a fallback
if ( ! $post_meta ) {
$post_meta = array(
'post-date',
'categories',
);
}
} elseif ( 'single-bottom' === $location ) {
$post_meta = get_theme_mod( 'chaplin_post_meta_single_bottom' );
$post_meta_wrapper_classes = ' post-meta-single post-meta-single-bottom';
// Empty = use a fallback
if ( ! $post_meta ) {
$post_meta = array(
'tags',
);
}
} elseif ( 'archive' === $location ) {
$post_meta = get_theme_mod( 'chaplin_post_meta_archive' );
$post_meta_wrapper_classes = ' post-meta-archive';
// Empty = use a fallback
if ( ! $post_meta ) {
$post_meta = array(
'post-date',
);
}
}
// If the post meta setting has the value 'empty', it's explicitly empty and the default post meta shouldn't be output
if ( $post_meta && ! in_array( 'empty', $post_meta ) ) :
// Make sure the right color is used for the post meta
if ( in_array( $page_template, array( 'template-cover.php', 'template-full-width-cover.php' ) ) && $location == 'single-top' ) {
$post_meta_classes .= ' color-inherit';
} else {
$post_meta_classes .= ' color-accent';
}
// Make sure we don't output an empty container
$has_meta = false;
global $post;
$post = get_post( $post_id );
setup_postdata( $post );
ob_start();
?>
theme_location == 'main-menu' && isset( $args->show_toggles ) ) {
// Wrap the menu item link contents in a div, used for positioning
$args->before = '
';
$args->after = '';
// Add a toggle to items with children
if ( in_array( 'menu-item-has-children', $item->classes ) ) {
$toggle_target_string = '.menu-modal .menu-item-' . $item->ID . ' > .sub-menu';
// Add the sub menu toggle
$args->after .= '';
}
// Close the wrapper
$args->after .= '
';
// Add sub menu icons to the main menu without toggles (the fallback menu)
} elseif ( $args->theme_location == 'main-menu' ) {
if ( in_array( 'menu-item-has-children', $item->classes ) ) {
$args->before = '