<?php
/**
* Visual functions and definitions
*
* @package Visual
* @since Visual 0.1
*/
/**
* Set the content width based on the theme's design and stylesheet.
*
* @since Visual 0.1
*/
if ( ! isset( $content_width ) )
$content_width = 670; /* pixels */
function visual_content_width() {
global $content_width;
if ( is_home() || is_search() || is_archive() )
$content_width = 326;
if ( is_page_template( 'page-fullwidth.php' ) )
$content_width = 990;
}
add_action( 'template_redirect', 'visual_content_width' );
/**
* Loads Options Framework for theme options
* See: https://github.com/devinsays/options-framework-theme
*
* @since Visual 0.4
*/
function visual_optionsframework_setup() {
define( 'OPTIONS_FRAMEWORK_DIRECTORY', get_template_directory_uri() . '/inc/options-framework/' );
require_once dirname( __FILE__ ) . '/inc/options-framework/options-framework.php';
}
add_action( 'after_setup_theme', 'visual_optionsframework_setup' );
/*
* Load Jetpack compatibility file.
*/
require( get_template_directory() . '/inc/jetpack.php' );
if ( ! function_exists( 'visual_setup' ) ) :
/**
* Sets up theme defaults and registers support for various WordPress features.
*
* Note that this function is hooked into the after_setup_theme hook, which runs
* before the init hook. The init hook is too late for some features, such as indicating
* support post thumbnails.
*
* @since Visual 0.1
*/
function visual_setup() {
/* Custom template tags for this theme */
require( get_template_directory() . '/inc/template-tags.php' );
/* Custom functions that act independently of the theme templates */
require( get_template_directory() . '/inc/extras.php' );
/* Loads options for theme customizer */
require_once( get_template_directory() . '/inc/options.php' );
/* Functions to enable the options */
require( get_template_directory() . '/inc/options-functions.php' );
/* Customizer additions */
require( get_template_directory() . '/inc/customizer.php' );
/* Theme updater functions */
require( get_template_directory() . '/inc/theme-updater.php' );
/**
* Make theme available for translation
* Translations can be filed in the /languages/ directory
* If you're building a theme based on Visual, use a find and replace
* to change 'visual' to the name of your theme in all the template files
*/
load_theme_textdomain( 'visual', get_template_directory() . '/languages' );
/* Add default posts and comments RSS feed links to head */
add_theme_support( 'automatic-feed-links' );
/* Enable support for Post Thumbnails */
add_theme_support( 'post-thumbnails' );
add_image_size( 'visual-thumbnail', 326, 999 );
add_image_size( 'visual-post', 700, 9999 );
/* This theme uses wp_nav_menu() in one location. */
register_nav_menus( array(
'primary' => __( 'Primary Menu', 'visual' ),
) );
/* Enable support for Post Formats */
add_theme_support( 'post-formats', array( 'image', 'gallery' ) );
}
endif; // visual_setup
add_action( 'after_setup_theme', 'visual_setup' );
/**
* Register widgetized area and update sidebar with default widgets
*
* @since Visual 0.1
*/
function visual_widgets_init() {
register_sidebar( array(
'name' => __( 'Sidebar', 'visual' ),
'id' => 'sidebar-1',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h1 class="widget-title"><span>',
'after_title' => '</span></h1>',
) );
}
add_action( 'widgets_init', 'visual_widgets_init' );
/**
* Enqueue scripts and styles
*
* @since Visual 0.1
*/
function visual_scripts() {
wp_enqueue_style( 'style', get_stylesheet_uri() );
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
if ( is_singular() && wp_attachment_is_image() ) {
wp_enqueue_script( 'keyboard-image-navigation', get_template_directory_uri() . '/js/keyboard-image-navigation.js', array( 'jquery' ), '20130601' );
}
if ( !is_singular() && !is_404() && !is_author() ) {
wp_enqueue_script( 'visual-masonry', get_template_directory_uri() . '/js/jquery.masonry.min.js', array( 'jquery' ), '20130601', true );
}
wp_enqueue_script( 'visual-scripts', get_template_directory_uri() . '/js/visual-scripts.js', array( 'jquery' ), '20130601', true );
}
add_action( 'wp_enqueue_scripts', 'visual_scripts' );
/**
* Custom background support
*
* @since Visual 0.9
*/
function visual_background_setup() {
$light = get_template_directory_uri() . '/css/light.css';
$bgdefaults = array(
'default-color' => '212121'
);
if ( of_get_option( 'visual_style' ) ) {
if ( of_get_option( 'visual_style' ) == $light ) {
$bgdefaults['default-color'] = 'f5f5f5';
$bgdefaults['default-image'] = get_template_directory_uri() . '/img/light-noise.png';
}
if ( of_get_option( 'visual_style' ) == 'minimal' ) {
$bgdefaults['default-color'] = 'f5f5f5';
}
}
add_theme_support( 'custom-background', $bgdefaults );
}
add_action( 'after_setup_theme', 'visual_background_setup' );
function visual_background_image_mod() {
return null;
}
/**
* Adds a body class for masonry layouts
*
* @since Visual 0.1
*/
function visual_body_class( $classes ) {
if ( !is_singular() && !is_404() && !is_author() )
$classes[] = 'masonry';
return $classes;
}
add_filter('body_class','visual_body_class');
/**
* Loads options.php from "inc" directory
*
* @since Visual 0.3
*/
function visual_options_location() {
return array('/inc/options.php');
}
add_filter ( 'options_framework_location', 'visual_options_location' );
/**
* Loads Google Fonts if necessary
*
* @since Visual 0.3
*/
function visual_google_fonts() {
$default_font = 'Raleway:400,700';
$google_fonts = visual_google_font_options();
$selected_font = of_get_option( 'primary_font', $default_font );
if ( array_key_exists( $selected_font, $google_fonts ) ) {
add_action( 'wp_enqueue_scripts', 'visual_fonts' );
}
}
add_action( 'after_setup_theme', 'visual_google_fonts' );