'sidebar_r',
'calibration_show_menu' => true,
'calibration_front_layout' => '',
'calibration_show_front_title' => true,
'calibration_apply_post_format' => true,
'calibration_show_post_as' => 'post_content',
'calibration_hide_default_category' => false,
'calibration_footer_title' => '' . get_bloginfo( 'name', 'display' ) . '',
'calibration_footer_entry' => sprintf(
/* translators: %1$s: linked name of the theme, %2$s: linked name of the theme author */
esc_html__( 'WordPress theme %1$s by %2$s', 'calibration' ), 'Calibration', 'mobileMarkup.com' ),
'calibration_show_privacy_policy' => true,
);
/**
* Filter theme default settings.
*
* @since 1.0.0
*
* @param array Theme default settings keys and values
*/
$defaults = apply_filters( 'calibration_theme_defaults', $defaults );
return $defaults;
}
endif;
if ( ! function_exists( 'calibration_get_theme_mods' ) ) :
/**
* Merge theme mods saved in database with theme defaults
*
* @since 1.0.0
*
* @return array Current theme modifications merged with default settings
*/
function calibration_get_theme_mods() {
return wp_parse_args( get_theme_mods(), calibration_get_theme_defaults() );
}
endif;
if ( ! function_exists( 'calibration_get_theme_mod' ) ) :
/**
* Get a specific theme mod value
*
* @since 1.0.0
*
* @param string $name Theme mod name
* @return mixed Theme mod value - stored in database or default or null
*/
function calibration_get_theme_mod( $name ) {
$defaults = calibration_get_theme_defaults();
if ( ! isset( $defaults[$name] ) ) :
return null;
endif;
$mod = get_theme_mod( $name, $defaults[$name] );
return $mod;
}
endif;
if ( ! function_exists( 'calibration_setup' ) ) :
add_action( 'after_setup_theme', 'calibration_setup' );
/**
* Set up theme defaults and registers support for various WordPress features.
*
* Action hook: 'after_setup_theme'
*
* @since 1.0.0
*/
function calibration_setup() {
/*
* Make theme available for translation.
*/
load_theme_textdomain( 'calibration', CALIB_LANG_DIR );
/*
* Add default posts and comments RSS feed links to head.
*/
add_theme_support( 'automatic-feed-links' );
/*
* Let WordPress manage the document title.
*/
add_theme_support( 'title-tag' );
/*
* Enable support for Post Thumbnails on posts and pages.
*/
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 300, 300 );
/*
* This theme uses wp_nav_menu() in one location.
*/
register_nav_menus( array(
'top' => __( 'Top Menu', 'calibration' )
) );
/*
* Switch default core markup for search form, comment form, and comments
* to output valid HTML5.
*/
add_theme_support( 'html5', array(
'comment-form',
'comment-list',
'gallery',
'caption',
) );
/*
* Enable support for Post Formats.
*/
add_theme_support( 'post-formats', array(
'gallery',
) );
/*
* Set up the WordPress core custom background feature.
*/
add_theme_support( 'custom-background', apply_filters( 'calibration_custom_background_args', array(
'default-color' => 'ffffff',
'default-image' => '',
'default-repeat' => 'no-repeat',
'default-position-x' => 'center',
'default-position-y' => 'center',
'default-size' => 'cover',
'default-attachment' => 'fixed',
'wp-head-callback' => '_custom_background_cb',
) ) );
/*
* Add theme support for selective refresh for widgets.
*/
add_theme_support( 'customize-selective-refresh-widgets' );
/*
* Add support for core custom logo.
*/
add_theme_support( 'custom-logo', apply_filters( 'calibration_custom_logo_args', array(
'height' => 125,
'width' => 250,
'flex-width' => true,
'flex-height' => true,
'header-text' => array( 'logo', 'tagline' ),
) ) );
}
endif;
// END of setup theme
add_action( 'after_setup_theme', 'calibration_content_width', 0 );
/**
* Set the content width in pixels, based on the theme's design and stylesheet.
*
* Action hook: 'after_setup_theme'
*
* @since 1.0.0
*
* @global int $content_width
*/
function calibration_content_width() {
$GLOBALS['content_width'] = apply_filters( 'calibration_content_width', 1920 );
}
add_action( 'widgets_init', 'calibration_widgets_init' );
/**
* Register widget areas.
*
* Action hook: 'widgets_init'
*
* @since 1.0.0
*/
function calibration_widgets_init() {
register_sidebar( array(
'name' => __( 'Sidebar', 'calibration' ),
'id' => 'sidebar-1',
'description' => __( 'Add widgets here to appear in your sidebar.', 'calibration' ),
'before_widget' => '',
'before_title' => '
',
) );
}
add_filter( 'language_attributes', 'calibration_document_attributes' );
/**
* Adds custom attributes to document root
*
* Filter hook: 'language_attributes'
*
* @since 1.0.0
*
* @param string $output Attributes applied to tag
*/
function calibration_document_attributes( $output ) {
return "$output itemscope itemtype=\"http://schema.org/WebPage\"";
}
add_filter( 'body_class', 'calibration_body_classes' );
/**
* Adds custom classes to the array of body classes.
*
* Filter hook: 'body_class'
*
* @since 1.0.0
*
* @param array $classes Classes for the body element.
*/
function calibration_body_classes( $classes ) {
if ( calibration_is_front() ) :
$classes[] = 'front';
endif;
if ( calibration_has_header_image() ) :
$classes[] = 'has-header-image';
endif;
if ( is_active_sidebar( 'sidebar-1' ) && ! is_page_template( 'templates/no-sidebar.php' ) && ! is_404() ) :
$classes[] = 'has-sidebar';
if ( calibration_is_empty_search() ) :
$classes[] = 'has-sidebar-below';
else :
$calibration_theme_mods = calibration_get_theme_mods();
$layout_type = ( calibration_is_front() && '' != $calibration_theme_mods['calibration_front_layout'] ? $calibration_theme_mods['calibration_front_layout'] : $calibration_theme_mods['calibration_site_layout'] );
switch ( $layout_type ) :
case 'sidebar_l':
$classes[] = 'has-sidebar-before';
break;
case 'sidebar_b':
$classes[] = 'has-sidebar-below';
break;
default:
$classes[] = 'has-sidebar-after';
break;
endswitch;
endif;
endif;
return $classes;
}
add_filter( 'wp_page_menu', 'calibration_standarize_menu', 10, 2 );
/**
* Remove div wrapper from page menu and assign the class to the list instead
*
* Filter hook: 'wp_page_menu'
*
* @since 1.0.0
*
* @param string $html Output of wp_page_menu()
*/
function calibration_standarize_menu( $html, $args ) {
if ( ! array_key_exists( 'theme_location', $args ) || 'top' != $args['theme_location'] ) :
return $html;
endif;
preg_match( '/^/i', $html, $matches );
$divclass = $matches[1];
$to_replace = array( '
', '
' );
$html = str_replace( $to_replace, '', $html );
$html = preg_replace( '/^
/i', '', $html );
return $html;
}
add_filter( 'show_recent_comments_widget_style', '__return_false' );
add_filter( 'prepend_attachment', 'calibration_prepend_attachment' );
/**
* Use large image size on attachment page
*
* Filter hook: 'prepend_attachment'
*
* @since 1.0.0
*
* @param string $p Attachment markup
*/
function calibration_prepend_attachment( $p ) {
if ( strpos( $p, '' ) === false ) :
return $p;
endif;
return "
\n" . wp_get_attachment_link( 0, 'large', false ) . "\n
";
}
add_filter( 'media_view_settings', 'calibration_gallery_defaults' );
/**
* Default settings for WP gallery
*
* Filter hook: 'media_view_settings'
*
* @since 1.0.0
*
* @param array $settings
*/
function calibration_gallery_defaults( $settings ) {
$settings['galleryDefaults']['columns'] = 5;
// Size is not fully supported, therefore we set more columns for thumbnails
// @link https://core.trac.wordpress.org/ticket/40692 and https://core.trac.wordpress.org/ticket/35654
// $settings['galleryDefaults']['size'] = 'medium';
$settings['galleryDefaults']['link'] = 'file';
return $settings;
}
add_filter( 'the_content', 'calibration_set_limit_on_gallery_shortcode', 9, 1 );
/**
* Inject calibration_lim attribute to the gallery shortcode within the content
*
* Filter hook: 'the_content'. It must run before parsing shortcodes.
*
* @since 1.0.0
*
* @param string $content The content
*/
function calibration_set_limit_on_gallery_shortcode( $content ) {
if ( is_single() ) :
return $content;
endif;
return str_replace( '[gallery', '[gallery calibration_lim=""', $content );
}
add_filter( 'shortcode_atts_gallery', 'calibration_shortcode_atts_gallery', 20, 3 );
/**
* Reads the number of columns and passes to the filter limiting attachments.
*
* Filter hook: 'shortcode_atts_gallery'
*
* @since 1.0.0
*
* @param array $result Parsed shortcode attributes
* @param array $defaults Default shortcode attributes
* @param array $atts Passed shortcode attributes
*/
function calibration_shortcode_atts_gallery( $result, $defaults, $atts ) {
// Set the limit based on columns number
if ( isset( $atts['calibration_lim'] ) ) :
$limit = ( ! empty( $atts['columns'] ) ? $atts['columns'] : $defaults['columns'] );
// Pass the limit to the filter fired on pre_get_posts
add_filter( 'calibration_gallery_attachments_query_limit', function() use ( &$limit ) { return $limit; } );
endif;
return $result;
}
add_action( 'pre_get_posts', 'calibration_limit_gallery_attachments_query' );
/**
* Limits attachments count if the number is provided through a filter hook.
*
* Action hook: 'pre_get_posts'
*
* @since 1.0.0
*
* @param object $query
*/
function calibration_limit_gallery_attachments_query( $q ) {
/**
* Filters the limit number for the query.
*
* @since 1.0.0
*
* @param int|null Limit number. null by default (means: do not apply).
*/
$limit = apply_filters( 'calibration_gallery_attachments_query_limit', null );
if ( null !== $limit ) :
$q->set( 'posts_per_page', intval( $limit ) );
endif;
}
add_filter( 'gallery_style', 'calibration_reset_gallery_attachments_query', 20, 1 );
/**
* Resets limit for attachments number in gallery shortcode.
*
* Filter hook: 'gallery_style'. Not modifies output but used as a good place to fire limit filter removal.
*
* @since 1.0.0
*
* @param string $data
*/
function calibration_reset_gallery_attachments_query( $data ) {
add_filter( 'calibration_gallery_attachments_query_limit', function() { return null; } );
return $data;
}
add_filter( 'the_password_form', 'calibration_the_password_form' );
/**
* Changes proctected post access form
*
* Filter hook: 'the_password_form'
*
* @since 1.0.0
*
* @param string $html The code of the form.
*/
function calibration_the_password_form( $html ) {
$source = array( '