for posts and comments
add_theme_support( 'automatic-feed-links' );
//theme is not defining titles on its own
add_theme_support( 'title-tag' );
// this theme uses wp_nav_menu() in one location
register_nav_menu( 'primary', __( 'Primary Menu', 'fourseasons' ) );
//editor-style.css
add_editor_style();
//remove gallery inline style
add_filter( 'use_default_gallery_style', '__return_false' );
//gallery images always link to file
function fourseasons_gal_link($out){
$out['link'] = 'file';
return $out;
}
add_filter( 'shortcode_atts_gallery','fourseasons_gal_link');
//change default gravatar
add_filter( 'avatar_defaults', 'fourseasons_newgravatar' );
function fourseasons_newgravatar ($avatar_defaults) {
$myavatar = get_template_directory_uri() . '/images/avatar.jpg';
$avatar_defaults[$myavatar] = "fourseasons user";
return $avatar_defaults;
}
// this theme uses a custom image size for featured images, displayed on "standard" posts
add_theme_support( 'post-thumbnails' );
// set thumbnail sizes
set_post_thumbnail_size( 225, 200, true ); // width, height, crop = true
//limit excerpt
function fourseasons_excerpt_length($length) {
return 30;
}
add_filter('excerpt_length', 'fourseasons_excerpt_length');
}
add_action( 'after_setup_theme', 'fourseasons_fw_setup' );
//frontend scipts and styles
function fourseasons_frontend_load(){
//css
wp_enqueue_style('font-awesome', get_template_directory_uri().'/css/font-awesome.css',array(),null,'all');
wp_enqueue_style('dp-default', get_stylesheet_uri(),array(),null,'all');
wp_enqueue_style('dp-responsive-style', get_template_directory_uri().'/style-responsive.css',array(),null,'all');
//ie-only style sheets
global $wp_styles;
wp_register_style('dp-ltie9-def', get_template_directory_uri(). '/style.css',array(),null);
$wp_styles->add_data('dp-ltie9-def', 'conditional', 'lt IE 9');
wp_enqueue_style('dp-ltie9-def');
wp_register_style('dp-ltie8', get_template_directory_uri(). '/css/stop_ie.css',array(),null);
$wp_styles->add_data('dp-ltie8', 'conditional', 'lt IE 8');
wp_enqueue_style('dp-ltie8');
//js
wp_enqueue_script('jquery');
wp_enqueue_script('retina_js', get_template_directory_uri() . '/js/retina.min.js', '', '', true );
wp_enqueue_script('smoothscroll', get_template_directory_uri() . '/js/smoothscroll.js', '', '', true );
wp_enqueue_script('startup', get_template_directory_uri().'/js/startup.js', array('jquery'));
wp_enqueue_script('dp-imageviewer', get_template_directory_uri().'/js/dp.imageviewer.js', array('jquery'));
if( is_single() && comments_open() && get_option( 'thread_comments' )){
wp_enqueue_script( 'comment-reply' );
}
}
add_action( 'wp_enqueue_scripts', 'fourseasons_frontend_load' );
// enqueues scripts and styles for backend
function dp_admin_load(){
wp_enqueue_style('dp-admin', get_template_directory_uri().'/css/admin.css',array(),null,'all');
wp_enqueue_script('dp-admin', get_template_directory_uri().'/js/admin_scripts.js', array('jquery'));
}
add_action('admin_enqueue_scripts', 'dp_admin_load');
// register widgetized areas, and load custom ones also!
function fourseasons_fw_widgets_init() {
register_sidebar( array(
'name' => __( 'Archives Sidebar', 'fourseasons' ),
'id' => 'posts-widget-area',
'description' => __( 'Sidebar for all Archives, Categories, Tags pages.', 'fourseasons' ),
'before_widget' => '',
'before_title' => '
',
) );
register_sidebar( array(
'name' => __( 'Search & 404 Sidebar', 'fourseasons' ),
'id' => 'search-widget-area',
'description' => __( 'Sidebar for Search & 404 pages', 'fourseasons' ),
'before_widget' => '',
'before_title' => '',
) );
register_sidebar( array(
'name' => __( 'Widget Area #1', 'fourseasons' ),
'id' => 'widget-area-one',
'description' => __( 'Widget area for sidebar or footer', 'fourseasons' ),
'before_widget' => '',
'before_title' => '',
) );
register_sidebar( array(
'name' => __( 'Widget Area #2', 'fourseasons' ),
'id' => 'widget-area-two',
'description' => __( 'Widget area for sidebar or footer', 'fourseasons' ),
'before_widget' => '',
'before_title' => '',
) );
register_sidebar( array(
'name' => __( 'Widget Area #3', 'fourseasons' ),
'id' => 'widget-area-three',
'description' => __( 'Widget area for sidebar or footer', 'fourseasons' ),
'before_widget' => '',
'before_title' => '',
) );
register_sidebar( array(
'name' => __( 'Widget Area #4', 'fourseasons' ),
'id' => 'widget-area-four',
'description' => __( 'Widget area for sidebar or footer', 'fourseasons' ),
'before_widget' => '',
'before_title' => '',
) );
register_sidebar( array(
'name' => __( 'Widget Area #5', 'fourseasons' ),
'id' => 'widget-area-five',
'description' => __( 'Widget area for sidebar or footer', 'fourseasons' ),
'before_widget' => '',
'before_title' => '',
) );
register_sidebar( array(
'name' => __( 'Widget Area #6', 'fourseasons' ),
'id' => 'widget-area-six',
'description' => __( 'Widget area for sidebar or footer', 'fourseasons' ),
'before_widget' => '',
'before_title' => '',
) );
register_sidebar( array(
'name' => __( 'Widget Area #7', 'fourseasons' ),
'id' => 'widget-area-seven',
'description' => __( 'Widget area for sidebar or footer', 'fourseasons' ),
'before_widget' => '',
'before_title' => '',
) );
register_sidebar( array(
'name' => __( 'Widget Area #8', 'fourseasons' ),
'id' => 'widget-area-eight',
'description' => __( 'Widget area for sidebar or footer', 'fourseasons' ),
'before_widget' => '',
'before_title' => '',
) );
register_sidebar( array(
'name' => __( 'Widget Area #9', 'fourseasons' ),
'id' => 'widget-area-nine',
'description' => __( 'Widget area for sidebar or footer', 'fourseasons' ),
'before_widget' => '',
'before_title' => '',
) );
register_sidebar( array(
'name' => __( 'Widget Area #10', 'fourseasons' ),
'id' => 'widget-area-ten',
'description' => __( 'Widget area for sidebar or footer', 'fourseasons' ),
'before_widget' => '',
'before_title' => '',
) );
}
add_action( 'widgets_init', 'fourseasons_fw_widgets_init' );
// removes the default styles that are packaged with the recent comments widget
function fourseasons_fw_remove_recent_comments_style() {
global $wp_widget_factory;
remove_action( 'wp_head', array( $wp_widget_factory->widgets['WP_Widget_Recent_Comments'], 'recent_comments_style' ) );
}
add_action( 'widgets_init', 'fourseasons_fw_remove_recent_comments_style' );
// comment functions
function fourseasons_validate_gravatar($email) {
// Craft a potential url and test its headers
$hash = md5(strtolower(trim($email)));
$uri = 'http://www.gravatar.com/avatar/' . $hash . '?d=404';
$headers = @get_headers($uri);
if (!preg_match("|200|", $headers[0])) {
$has_valid_avatar = FALSE;
} else {
$has_valid_avatar = TRUE;
}
return $has_valid_avatar;
}
function fourseasons_comments( $comment, $args, $depth ){
print '
';
if(!fourseasons_validate_gravatar(get_comment_author_email())){
//replace to theme avatar
print '';
}else{
//default
print get_avatar($comment,'60');
}
print '
';
}
// retina image generator
function fourseasons_retina_support_create_images( $file, $width, $height, $crop = false ) {
if ( $width || $height ) {
$resized_file = wp_get_image_editor( $file );
if ( ! is_wp_error( $resized_file ) ) {
$filename = $resized_file->generate_filename( $width . 'x' . $height . '@2x' );
$resized_file->resize( $width * 2, $height * 2, $crop );
$resized_file->save( $filename );
$info = $resized_file->get_size();
return array(
'file' => wp_basename( $filename ),
'width' => $info['width'],
'height' => $info['height'],
);
}
}
return false;
}
function fourseasons_delete_retina_support_images( $attachment_id ) {
$meta = wp_get_attachment_metadata( $attachment_id );
$upload_dir = wp_upload_dir();
if(isset( $meta['file'] )){
$path = pathinfo( $meta['file'] );
}
if(is_array($meta) && isset($path)){
foreach ( $meta as $key => $value ) {
if ( 'sizes' === $key ) {
foreach ( $value as $sizes => $size ) {
$original_filename = $upload_dir['basedir'] . '/' . $path['dirname'] . '/' . $size['file'];
$retina_filename = substr_replace( $original_filename, '@2x.', strrpos( $original_filename, '.' ), strlen( '.' ) );
if ( file_exists( $retina_filename ) )
unlink( $retina_filename );
}
}
}
}
}
function fourseasons_retina_support_attachment_meta( $metadata, $attachment_id ) {
foreach ( $metadata as $key => $value ) {
if ( is_array( $value ) ) {
foreach ( $value as $image => $attr ) {
if ( is_array( $attr ) && !empty($attr['width']) && !empty($attr['height']) )
fourseasons_retina_support_create_images( get_attached_file( $attachment_id ), $attr['width'], $attr['height'], true );
}
}
}
return $metadata;
}
add_filter( 'delete_attachment', 'fourseasons_delete_retina_support_images' );
add_filter( 'wp_generate_attachment_metadata', 'fourseasons_retina_support_attachment_meta', 10, 2 );
// put theme options in customizer
function fourseasons_theme_customizer( $wp_customize ) {
//logo
$wp_customize->add_setting( 'fourseasons_logo', array(
'sanitize_callback' => 'esc_url_raw',
'default' => get_template_directory_uri() .'/images/logo.png'
) );
$wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'fourseasons_logo', array(
'label' => __( 'Logo', 'fourseasons' ),
'section' => 'title_tagline',
'settings' => 'fourseasons_logo',
) ) );
//season
$wp_customize->add_section( 'fourseasons_season_section' , array(
'title' => __( 'Season Layouts', 'fourseasons' ),
'priority' => 30,
'description' => __( 'Select a layout for your website!', 'fourseasons' )
) );
$wp_customize->add_setting( 'fourseasons_season', array( 'sanitize_callback' => 'fourseasons_sanitize_season' ) );
$wp_customize->add_control( 'fourseasons_season', array(
'section' => 'fourseasons_season_section',
'type' => 'radio',
'choices' => array(
'spring' => 'Spring',
'summer' => 'Summer',
'fall' => 'Fall',
'winter' => 'Winter'
),
) );
function fourseasons_sanitize_season($input){
$seasons = array('spring','summer','fall','winter');
if(in_array($input,$seasons)){
return $input;
}
}
//post sharing
$wp_customize->add_section( 'fourseasons_post_sharing_section' , array(
'title' => __( 'Post Sharing', 'fourseasons' ),
'priority' => 100,
'description' => __( 'Select which sharing icons should appear below posts!', 'fourseasons' )
) );
$wp_customize->add_setting( 'fourseasons_post_sharing_facebook', array( 'sanitize_callback' => 'fourseasons_sanitize_footer_icons' ) );
$wp_customize->add_control( 'fourseasons_post_sharing_facebook', array(
'label' => __( 'Facebook', 'fourseasons' ),
'section' => 'fourseasons_post_sharing_section',
'type' => 'checkbox'
) );
$wp_customize->add_setting( 'fourseasons_post_sharing_twitter', array( 'sanitize_callback' => 'fourseasons_sanitize_footer_icons' ) );
$wp_customize->add_control( 'fourseasons_post_sharing_twitter', array(
'label' => __( 'Twitter', 'fourseasons' ),
'section' => 'fourseasons_post_sharing_section',
'type' => 'checkbox'
) );
$wp_customize->add_setting( 'fourseasons_post_sharing_gplus', array( 'sanitize_callback' => 'fourseasons_sanitize_footer_icons' ) );
$wp_customize->add_control( 'fourseasons_post_sharing_gplus', array(
'label' => __( 'Google+', 'fourseasons' ),
'section' => 'fourseasons_post_sharing_section',
'type' => 'checkbox'
) );
$wp_customize->add_setting( 'fourseasons_post_sharing_linkedin', array( 'sanitize_callback' => 'fourseasons_sanitize_footer_icons' ) );
$wp_customize->add_control( 'fourseasons_post_sharing_linkedin', array(
'label' => __( 'LinkedIN', 'fourseasons' ),
'section' => 'fourseasons_post_sharing_section',
'type' => 'checkbox'
) );
$wp_customize->add_setting( 'fourseasons_post_sharing_pinterest', array( 'sanitize_callback' => 'fourseasons_sanitize_footer_icons' ) );
$wp_customize->add_control( 'fourseasons_post_sharing_pinterest', array(
'label' => __( 'Pinterest', 'fourseasons' ),
'section' => 'fourseasons_post_sharing_section',
'type' => 'checkbox'
) );
$wp_customize->add_setting( 'fourseasons_post_sharing_reddit', array( 'sanitize_callback' => 'fourseasons_sanitize_footer_icons' ) );
$wp_customize->add_control( 'fourseasons_post_sharing_reddit', array(
'label' => __( 'Reddit', 'fourseasons' ),
'section' => 'fourseasons_post_sharing_section',
'type' => 'checkbox'
) );
$wp_customize->add_setting( 'fourseasons_post_sharing_digg', array( 'sanitize_callback' => 'fourseasons_sanitize_footer_icons' ) );
$wp_customize->add_control( 'fourseasons_post_sharing_digg', array(
'label' => __( 'Digg', 'fourseasons' ),
'section' => 'fourseasons_post_sharing_section',
'type' => 'checkbox'
) );
$wp_customize->add_setting( 'fourseasons_post_sharing_delicious', array( 'sanitize_callback' => 'fourseasons_sanitize_footer_icons' ) );
$wp_customize->add_control( 'fourseasons_post_sharing_delicious', array(
'label' => __( 'Delicous', 'fourseasons' ),
'section' => 'fourseasons_post_sharing_section',
'type' => 'checkbox'
) );
$wp_customize->add_setting( 'fourseasons_post_sharing_stumble', array( 'sanitize_callback' => 'fourseasons_sanitize_footer_icons' ) );
$wp_customize->add_control( 'fourseasons_post_sharing_stumble', array(
'label' => __( 'StumbleUpon', 'fourseasons' ),
'section' => 'fourseasons_post_sharing_section',
'type' => 'checkbox'
) );
$wp_customize->add_setting( 'fourseasons_post_sharing_tumblr', array( 'sanitize_callback' => 'fourseasons_sanitize_footer_icons' ) );
$wp_customize->add_control( 'fourseasons_post_sharing_tumblr', array(
'label' => __( 'Tumblr', 'fourseasons' ),
'section' => 'fourseasons_post_sharing_section',
'type' => 'checkbox'
) );
$wp_customize->add_setting( 'fourseasons_post_sharing_email', array( 'sanitize_callback' => 'fourseasons_sanitize_footer_icons' ) );
$wp_customize->add_control( 'fourseasons_post_sharing_email', array(
'label' => __( 'Email', 'fourseasons' ),
'section' => 'fourseasons_post_sharing_section',
'type' => 'checkbox'
) );
//sidebar & footer
$wp_customize->add_section( 'fourseasons_sidebar_footer_section' , array(
'title' => __( 'Sidebar & Footer', 'fourseasons' ),
'priority' => 100
) );
//sidebar position
$wp_customize->add_setting( 'fourseasons_default_sidebar_position', array(
'sanitize_callback' => 'fourseasons_sanitize_sb_position'
) );
$wp_customize->add_control( 'fourseasons_default_sidebar_position', array(
'label' => __( 'Default sidebar position', 'fourseasons' ),
'section' => 'fourseasons_sidebar_footer_section',
'type' => 'select',
'choices' => array(
'' => __('Right','fourseasons'),
'left' => __('Left','fourseasons')
)
) );
function fourseasons_sanitize_sb_position( $input ) {
if($input == 'left'){
return $input;
}else{
return '';
}
}
//footer social icons
$wp_customize->add_setting( 'fourseasons_footer_icons_behance', array( 'sanitize_callback' => 'fourseasons_sanitize_footer_icons' ) );
$wp_customize->add_control( 'fourseasons_footer_icons_behance', array(
'label' => __( 'Footer icons - Behance', 'fourseasons' ),
'section' => 'fourseasons_sidebar_footer_section',
'type' => 'text'
) );
$wp_customize->add_setting( 'fourseasons_footer_icons_dribbble', array( 'sanitize_callback' => 'fourseasons_sanitize_footer_icons' ) );
$wp_customize->add_control( 'fourseasons_footer_icons_dribbble', array(
'label' => __( 'Footer icons - Dribbble', 'fourseasons' ),
'section' => 'fourseasons_sidebar_footer_section',
'type' => 'text'
) );
$wp_customize->add_setting( 'fourseasons_footer_icons_facebook', array( 'sanitize_callback' => 'fourseasons_sanitize_footer_icons' ) );
$wp_customize->add_control( 'fourseasons_footer_icons_facebook', array(
'label' => __( 'Footer icons - Facebook', 'fourseasons' ),
'section' => 'fourseasons_sidebar_footer_section',
'type' => 'text'
) );
$wp_customize->add_setting( 'fourseasons_footer_icons_gplus', array( 'sanitize_callback' => 'fourseasons_sanitize_footer_icons' ) );
$wp_customize->add_control( 'fourseasons_footer_icons_gplus', array(
'label' => __( 'Footer icons - Google+', 'fourseasons' ),
'section' => 'fourseasons_sidebar_footer_section',
'type' => 'text'
) );
$wp_customize->add_setting( 'fourseasons_footer_icons_instagram', array( 'sanitize_callback' => 'fourseasons_sanitize_footer_icons' ) );
$wp_customize->add_control( 'fourseasons_footer_icons_instagram', array(
'label' => __( 'Footer icons - Instagram', 'fourseasons' ),
'section' => 'fourseasons_sidebar_footer_section',
'type' => 'text'
) );
$wp_customize->add_setting( 'fourseasons_footer_icons_linkedin', array( 'sanitize_callback' => 'fourseasons_sanitize_footer_icons' ) );
$wp_customize->add_control( 'fourseasons_footer_icons_linkedin', array(
'label' => __( 'Footer icons - LinkedIN', 'fourseasons' ),
'section' => 'fourseasons_sidebar_footer_section',
'type' => 'text'
) );
$wp_customize->add_setting( 'fourseasons_footer_icons_pinterest', array( 'sanitize_callback' => 'fourseasons_sanitize_footer_icons' ) );
$wp_customize->add_control( 'fourseasons_footer_icons_pinterest', array(
'label' => __( 'Footer icons - Pinterest', 'fourseasons' ),
'section' => 'fourseasons_sidebar_footer_section',
'type' => 'text'
) );
$wp_customize->add_setting( 'fourseasons_footer_icons_rss', array( 'sanitize_callback' => 'fourseasons_sanitize_footer_icons' ) );
$wp_customize->add_control( 'fourseasons_footer_icons_rss', array(
'label' => __( 'Footer icons - RSS', 'fourseasons' ),
'section' => 'fourseasons_sidebar_footer_section',
'type' => 'text'
) );
$wp_customize->add_setting( 'fourseasons_footer_icons_twitter', array( 'sanitize_callback' => 'fourseasons_sanitize_footer_icons' ) );
$wp_customize->add_control( 'fourseasons_footer_icons_twitter', array(
'label' => __( 'Footer icons - Twitter', 'fourseasons' ),
'section' => 'fourseasons_sidebar_footer_section',
'type' => 'text'
) );
function fourseasons_sanitize_footer_icons( $input ) {
return esc_url( $input );
}
}
add_action( 'customize_register', 'fourseasons_theme_customizer' );
// user can decide which post categories to load on a blog or portfolio page template
if ( is_admin() ) {
$dp_new_meta_boxes_blogcats = array(
"sc_gen" => array(
"name" => "dp_blog_cats",
"std" => "",
"title" => "Post Categories"
)
);
function dp_category_selector() {
global $post;
$dp_blog_cats = get_post_meta($post->ID, 'dp_blog_cats', true);
$tax_terms = get_terms('category');
echo''.__('Here you can select which post categories you\'d like to display on this page.','fourseasons').'
';
}
function dp_create_meta_box_blogcats() {
global $theme_name;
if ( function_exists('add_meta_box') ) {
add_meta_box( 'dp-category-selector', 'Post Categories', 'dp_category_selector', 'page', 'side' );
}
}
add_action('admin_menu', 'dp_create_meta_box_blogcats');
//save meta box values
function dp_save_postdata_blogcats(){
global $post, $dp_blog_cats;
//save fields
if(!empty($_POST['dp_blog_cats'])){
update_post_meta($post->ID,'dp_blog_cats',$_POST['dp_blog_cats']);
}
}
add_action('save_post', 'dp_save_postdata_blogcats');
}
// user can decide which widget area should appear on a page template
if(is_admin()){
$dp_new_meta_boxes_widget_areas = array(
"sc_gen" => array(
"name" => "dp_widget_areas",
"std" => "",
"title" => "Widget Areas"
)
);
function dp_widget_areas() {
global $post;
$dp_widget_areas_sidebar = get_post_meta($post->ID, 'dp-widget-areas-sidebar', true);
$dp_widget_areas_first_footer = get_post_meta($post->ID, 'dp-widget-areas-first-footer', true);
$dp_widget_areas_second_footer = get_post_meta($post->ID, 'dp-widget-areas-second-footer', true);
$dp_widget_areas_third_footer = get_post_meta($post->ID, 'dp-widget-areas-third-footer', true);
$dp_widget_areas_fourth_footer = get_post_meta($post->ID, 'dp-widget-areas-fourth-footer', true);
echo''.__('Here you can select widget areas that should appear on this page.','fourseasons').'
';
//list widget areas
echo ''.__('Sidebar','fourseasons').'
';
echo '';
echo '
';
echo ''.__('Footer','fourseasons').'
';
echo '';
echo '';
echo '';
echo '';
echo '
';
}
function dp_create_meta_box_widget_areas() {
global $theme_name;
if ( function_exists('add_meta_box') ) {
add_meta_box( 'dp-widget-areas', 'Widget Areas', 'dp_widget_areas', 'page', 'side' );
add_meta_box( 'dp-widget-areas', 'Widget Areas', 'dp_widget_areas', 'post', 'side' );
}
}
add_action('admin_menu', 'dp_create_meta_box_widget_areas');
//save meta box values
function dp_save_postdata_widget_areas(){
global $post, $dp_widget_areas;
//save fields
if(!empty($_POST['dp-widget-areas-sidebar'])){
update_post_meta($post->ID,'dp-widget-areas-sidebar',$_POST['dp-widget-areas-sidebar']);
}elseif(!empty($post->ID)){
delete_post_meta($post->ID,'dp-widget-areas-sidebar');
}
if(!empty($_POST['dp-widget-areas-first-footer'])){
update_post_meta($post->ID,'dp-widget-areas-first-footer',$_POST['dp-widget-areas-first-footer']);
}elseif(!empty($post->ID)){
delete_post_meta($post->ID,'dp-widget-areas-first-footer');
}
if(!empty($_POST['dp-widget-areas-second-footer'])){
update_post_meta($post->ID,'dp-widget-areas-second-footer',$_POST['dp-widget-areas-second-footer']);
}elseif(!empty($post->ID)){
delete_post_meta($post->ID,'dp-widget-areas-second-footer');
}
if(!empty($_POST['dp-widget-areas-third-footer'])){
update_post_meta($post->ID,'dp-widget-areas-third-footer',$_POST['dp-widget-areas-third-footer']);
}elseif(!empty($post->ID)){
delete_post_meta($post->ID,'dp-widget-areas-third-footer');
}
if(!empty($_POST['dp-widget-areas-fourth-footer'])){
update_post_meta($post->ID,'dp-widget-areas-fourth-footer',$_POST['dp-widget-areas-fourth-footer']);
}elseif(!empty($post->ID)){
delete_post_meta($post->ID,'dp-widget-areas-fourth-footer');
}
}
add_action('save_post', 'dp_save_postdata_widget_areas');
}
?>