for posts and comments add_theme_support( 'automatic-feed-links' ); //theme is not defining titles on its own add_theme_support( 'title-tag' ); //logo changing supported add_theme_support( 'custom-logo' ); } add_action( 'after_setup_theme', 'fourseasons_fw_setup' ); //frontend scipts and styles function fourseasons_frontend_load(){ //css wp_enqueue_style('fourseasons-reset', get_template_directory_uri().'/css/reset.css',array(),null,'all'); wp_enqueue_style('fourseasons-font', 'https://fonts.googleapis.com/css?family=Lato:400,300,700',array(),null,'all'); wp_enqueue_style('font-awesome', get_template_directory_uri().'/css/font-awesome.css',array(),null,'all'); wp_enqueue_style('fourseasons-default', get_stylesheet_uri(),array(),null,'all'); wp_enqueue_style('fourseasons-responsive-style', get_template_directory_uri().'/style-responsive.css',array(),null,'all'); //ie-only style sheets global $wp_styles; wp_enqueue_style('fourseasons-ltie9-def', get_template_directory_uri(). '/style.css',array(),null); $wp_styles->add_data('fourseasons-ltie9-def', 'conditional', 'lt IE 9'); wp_enqueue_style('fourseasons-ltie8', get_template_directory_uri(). '/css/stop_ie.css',array(),null); $wp_styles->add_data('fourseasons-ltie8', 'conditional', 'lt IE 8'); //js 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('fourseasons-startup', get_template_directory_uri().'/js/startup.js', array('jquery')); wp_enqueue_script('fourseasons-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' ); } //custom colors $fourseasons_header_textcolor = get_theme_mod('header_textcolor'); $fourseasons_main_text_color = get_theme_mod('fourseasons_main_text_color'); $fourseasons_link_color = get_theme_mod('fourseasons_link_color'); $fourseasons_link_hover_color = get_theme_mod('fourseasons_link_hover_color'); if(!empty($fourseasons_header_textcolor) || !empty($fourseasons_main_text_color) || !empty($fourseasons_link_color) || !empty($fourseasons_link_hover_color)){ $custom_css = ''; if(!empty($fourseasons_header_textcolor)){ $custom_css .= ' .site-title, .site-title a{ color: #'.wp_filter_nohtml_kses($fourseasons_header_textcolor).'; } '; } if(!empty($fourseasons_main_text_color) && $fourseasons_main_text_color != '#666666'){ $custom_css .= ' body{ color: '.wp_filter_nohtml_kses($fourseasons_main_text_color).'; } '; } if(!empty($fourseasons_link_color) && $fourseasons_link_color != '#d27506'){ $custom_css .= ' a, #page a{ color: '.wp_filter_nohtml_kses($fourseasons_link_color).'; } '; } if(!empty($fourseasons_link_hover_color) && $fourseasons_link_hover_color != '#333333'){ $custom_css .= ' a:hover, #page a:hover{ color: '.wp_filter_nohtml_kses($fourseasons_link_hover_color).'; } '; } wp_add_inline_style( 'fourseasons-default', $custom_css ); } } add_action( 'wp_enqueue_scripts', 'fourseasons_frontend_load' ); // enqueues scripts and styles for backend function fourseasons_admin_load(){ $screen = get_current_screen(); if ( $screen->post_type == 'page' ){ wp_enqueue_style('fourseasons-admin', get_template_directory_uri().'/css/admin.css',array(),null,'all'); wp_enqueue_script('fourseasons-admin', get_template_directory_uri().'/js/admin_scripts.js', array('jquery')); } } add_action('admin_enqueue_scripts', 'fourseasons_admin_load'); //change seasons function fourseasons_body_classes( $classes ) { $fourseasons_season = get_theme_mod('fourseasons_season'); if(!empty($_GET['season'])){ if($_GET['season'] == 'spring'){ $classes[] = 'season-spring'; } if($_GET['season'] == 'summer'){ $classes[] = 'season-summer'; } if($_GET['season'] == 'winter'){ $classes[] = 'season-winter'; } }elseif(!empty($fourseasons_season)){ $classes[] = 'season-'.$fourseasons_season; } return $classes; } add_filter( 'body_class', 'fourseasons_body_classes' ); // register widgetized areas, and load custom ones also! function fourseasons_fw_widgets_init() { register_sidebar( array( 'name' => __( 'Archives Sidebar', 'four-seasons' ), 'id' => 'posts-widget-area', 'description' => __( 'Sidebar for all Archives, Categories, Tags pages.', 'four-seasons' ), 'before_widget' => '', 'before_title' => '

', 'after_title' => '

', ) ); register_sidebar( array( 'name' => __( 'Search & 404 Sidebar', 'four-seasons' ), 'id' => 'search-widget-area', 'description' => __( 'Sidebar for Search & 404 pages', 'four-seasons' ), 'before_widget' => '', 'before_title' => '

', 'after_title' => '

', ) ); register_sidebar( array( 'name' => __( 'Widget Area #1', 'four-seasons' ), 'id' => 'widget-area-one', 'description' => __( 'Widget area for sidebar or footer', 'four-seasons' ), 'before_widget' => '', 'before_title' => '

', 'after_title' => '

', ) ); register_sidebar( array( 'name' => __( 'Widget Area #2', 'four-seasons' ), 'id' => 'widget-area-two', 'description' => __( 'Widget area for sidebar or footer', 'four-seasons' ), 'before_widget' => '', 'before_title' => '

', 'after_title' => '

', ) ); register_sidebar( array( 'name' => __( 'Widget Area #3', 'four-seasons' ), 'id' => 'widget-area-three', 'description' => __( 'Widget area for sidebar or footer', 'four-seasons' ), 'before_widget' => '', 'before_title' => '
', 'after_title' => '
', ) ); register_sidebar( array( 'name' => __( 'Widget Area #4', 'four-seasons' ), 'id' => 'widget-area-four', 'description' => __( 'Widget area for sidebar or footer', 'four-seasons' ), 'before_widget' => '', 'before_title' => '
', 'after_title' => '
', ) ); register_sidebar( array( 'name' => __( 'Widget Area #5', 'four-seasons' ), 'id' => 'widget-area-five', 'description' => __( 'Widget area for sidebar or footer', 'four-seasons' ), 'before_widget' => '', 'before_title' => '
', 'after_title' => '
', ) ); register_sidebar( array( 'name' => __( 'Widget Area #6', 'four-seasons' ), 'id' => 'widget-area-six', 'description' => __( 'Widget area for sidebar or footer', 'four-seasons' ), 'before_widget' => '', 'before_title' => '
', 'after_title' => '
', ) ); register_sidebar( array( 'name' => __( 'Widget Area #7', 'four-seasons' ), 'id' => 'widget-area-seven', 'description' => __( 'Widget area for sidebar or footer', 'four-seasons' ), 'before_widget' => '', 'before_title' => '
', 'after_title' => '
', ) ); register_sidebar( array( 'name' => __( 'Widget Area #8', 'four-seasons' ), 'id' => 'widget-area-eight', 'description' => __( 'Widget area for sidebar or footer', 'four-seasons' ), 'before_widget' => '', 'before_title' => '
', 'after_title' => '
', ) ); register_sidebar( array( 'name' => __( 'Widget Area #9', 'four-seasons' ), 'id' => 'widget-area-nine', 'description' => __( 'Widget area for sidebar or footer', 'four-seasons' ), 'before_widget' => '', 'before_title' => '
', 'after_title' => '
', ) ); register_sidebar( array( 'name' => __( 'Widget Area #10', 'four-seasons' ), 'id' => 'widget-area-ten', 'description' => __( 'Widget area for sidebar or footer', 'four-seasons' ), 'before_widget' => '', 'before_title' => '
', 'after_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 '

    '.get_comment_author().'   /   '; printf( __( '%1$s., %2$s','four-seasons'), get_comment_date(), get_comment_time() ); edit_comment_link( __( '(Edit)' ,'four-seasons'), ' ' ); comment_reply_link( array_merge( $args, array( 'depth' => $depth, 'max_depth' => $args['max_depth'], 'reply_text' => __('Reply','four-seasons') ) ) ); print '

    '.get_comment_text().'

    '; } // 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 ) { //season $wp_customize->add_section( 'fourseasons_season_section' , array( 'title' => __( 'Season Layouts', 'four-seasons' ), 'priority' => 30, 'description' => __( 'Select a layout for your website!', 'four-seasons' ) ) ); $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; } } //colors //add link color setting and control $wp_customize->add_setting( 'fourseasons_link_color', array( 'default' => '#d27506', 'sanitize_callback' => 'sanitize_hex_color', 'transport' => 'postMessage', ) ); $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'fourseasons_link_color', array( 'label' => __( 'Link Color', 'four-seasons' ), 'section' => 'colors', ) ) ); $wp_customize->add_setting( 'fourseasons_link_hover_color', array( 'default' => '#333333', 'sanitize_callback' => 'sanitize_hex_color', 'transport' => 'postMessage', ) ); $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'fourseasons_link_hover_color', array( 'label' => __( 'Link Hover Color', 'four-seasons' ), 'section' => 'colors', ) ) ); //add main text color setting and control $wp_customize->add_setting( 'fourseasons_main_text_color', array( 'default' => '#666666', 'sanitize_callback' => 'sanitize_hex_color', 'transport' => 'postMessage', ) ); $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'fourseasons_main_text_color', array( 'label' => __( 'Main Text Color', 'four-seasons' ), 'section' => 'colors', ) ) ); //sidebar & footer $wp_customize->add_section( 'fourseasons_sidebar_footer_section' , array( 'title' => __( 'Sidebar & Footer', 'four-seasons' ), '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', 'four-seasons' ), 'section' => 'fourseasons_sidebar_footer_section', 'type' => 'select', 'choices' => array( '' => __('Right','four-seasons'), 'left' => __('Left','four-seasons') ) ) ); 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' => 'esc_url_raw' ) ); $wp_customize->add_control( 'fourseasons_footer_icons_behance', array( 'label' => __( 'Footer icons - Behance', 'four-seasons' ), 'section' => 'fourseasons_sidebar_footer_section', 'type' => 'text' ) ); $wp_customize->add_setting( 'fourseasons_footer_icons_dribbble', array( 'sanitize_callback' => 'esc_url_raw' ) ); $wp_customize->add_control( 'fourseasons_footer_icons_dribbble', array( 'label' => __( 'Footer icons - Dribbble', 'four-seasons' ), 'section' => 'fourseasons_sidebar_footer_section', 'type' => 'text' ) ); $wp_customize->add_setting( 'fourseasons_footer_icons_facebook', array( 'sanitize_callback' => 'esc_url_raw' ) ); $wp_customize->add_control( 'fourseasons_footer_icons_facebook', array( 'label' => __( 'Footer icons - Facebook', 'four-seasons' ), 'section' => 'fourseasons_sidebar_footer_section', 'type' => 'text' ) ); $wp_customize->add_setting( 'fourseasons_footer_icons_gplus', array( 'sanitize_callback' => 'esc_url_raw' ) ); $wp_customize->add_control( 'fourseasons_footer_icons_gplus', array( 'label' => __( 'Footer icons - Google+', 'four-seasons' ), 'section' => 'fourseasons_sidebar_footer_section', 'type' => 'text' ) ); $wp_customize->add_setting( 'fourseasons_footer_icons_instagram', array( 'sanitize_callback' => 'esc_url_raw' ) ); $wp_customize->add_control( 'fourseasons_footer_icons_instagram', array( 'label' => __( 'Footer icons - Instagram', 'four-seasons' ), 'section' => 'fourseasons_sidebar_footer_section', 'type' => 'text' ) ); $wp_customize->add_setting( 'fourseasons_footer_icons_linkedin', array( 'sanitize_callback' => 'esc_url_raw' ) ); $wp_customize->add_control( 'fourseasons_footer_icons_linkedin', array( 'label' => __( 'Footer icons - LinkedIN', 'four-seasons' ), 'section' => 'fourseasons_sidebar_footer_section', 'type' => 'text' ) ); $wp_customize->add_setting( 'fourseasons_footer_icons_pinterest', array( 'sanitize_callback' => 'esc_url_raw' ) ); $wp_customize->add_control( 'fourseasons_footer_icons_pinterest', array( 'label' => __( 'Footer icons - Pinterest', 'four-seasons' ), 'section' => 'fourseasons_sidebar_footer_section', 'type' => 'text' ) ); $wp_customize->add_setting( 'fourseasons_footer_icons_rss', array( 'sanitize_callback' => 'esc_url_raw' ) ); $wp_customize->add_control( 'fourseasons_footer_icons_rss', array( 'label' => __( 'Footer icons - RSS', 'four-seasons' ), 'section' => 'fourseasons_sidebar_footer_section', 'type' => 'text' ) ); $wp_customize->add_setting( 'fourseasons_footer_icons_twitter', array( 'sanitize_callback' => 'esc_url_raw' ) ); $wp_customize->add_control( 'fourseasons_footer_icons_twitter', array( 'label' => __( 'Footer icons - Twitter', 'four-seasons' ), 'section' => 'fourseasons_sidebar_footer_section', 'type' => 'text' ) ); } 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() ) { $fourseasons_new_meta_boxes_blogcats = array( "sc_gen" => array( "name" => "fourseasons_blog_cats", "std" => "", "title" => "Post Categories" ) ); function fourseasons_category_selector() { global $post; $fourseasons_blog_cats = get_post_meta($post->ID, 'fourseasons_blog_cats', true); $tax_terms = get_terms('category'); echo'

    '.__('Here you can select which post categories you\'d like to display on this page.','four-seasons').'

    '; wp_nonce_field('fourseasons_update_blog_cats','fourseasons_update_blog_cats_nonce'); echo '

     

    '; } function fourseasons_create_meta_box_blogcats() { global $theme_name; if ( function_exists('add_meta_box') ) { add_meta_box( 'fourseasons-category-selector', 'Post Categories', 'fourseasons_category_selector', 'page', 'side' ); } } add_action('admin_menu', 'fourseasons_create_meta_box_blogcats'); //save meta box values function fourseasons_save_postdata_blogcats(){ global $post, $fourseasons_blog_cats; //save fields if(!empty($post->ID) && current_user_can('edit_page',$post->ID) && isset($_POST['fourseasons_update_blog_cats_nonce']) && wp_verify_nonce($_POST['fourseasons_update_blog_cats_nonce'],'fourseasons_update_blog_cats')){ if(!empty($_POST['fourseasons_blog_cats']) && is_array($_POST['fourseasons_blog_cats'])){ $_POST['fourseasons_blog_cats'] = array_map( 'esc_sql', $_POST['fourseasons_blog_cats'] ); update_post_meta($post->ID,'fourseasons_blog_cats',$_POST['fourseasons_blog_cats']); } } } add_action('save_post', 'fourseasons_save_postdata_blogcats'); } // user can decide which widget area should appear on a page template if(is_admin()){ $fourseasons_new_meta_boxes_widget_areas = array( "sc_gen" => array( "name" => "fourseasons_widget_areas", "std" => "", "title" => "Widget Areas" ) ); function fourseasons_widget_areas() { global $post; $fourseasons_widget_areas_sidebar = get_post_meta($post->ID, 'fourseasons-widget-areas-sidebar', true); $fourseasons_widget_areas_first_footer = get_post_meta($post->ID, 'fourseasons-widget-areas-first-footer', true); $fourseasons_widget_areas_second_footer = get_post_meta($post->ID, 'fourseasons-widget-areas-second-footer', true); $fourseasons_widget_areas_third_footer = get_post_meta($post->ID, 'fourseasons-widget-areas-third-footer', true); $fourseasons_widget_areas_fourth_footer = get_post_meta($post->ID, 'fourseasons-widget-areas-fourth-footer', true); echo'

    '.__('Here you can select widget areas that should appear on this page.','four-seasons').'

    '; wp_nonce_field('fourseasons_widget_areas','fourseasons_widget_areas_nonce'); //list widget areas echo '

    '.__('Sidebar','four-seasons').'

    '; echo '

    '; echo '

     

    '; echo '

    '.__('Footer','four-seasons').'

    '; echo '

    '; echo '

    '; echo '

    '; echo '

    '; echo '

     

    '; } function fourseasons_create_meta_box_widget_areas() { global $theme_name; if ( function_exists('add_meta_box') ) { add_meta_box( 'fourseasons-widget-areas', 'Widget Areas', 'fourseasons_widget_areas', 'page', 'side' ); add_meta_box( 'fourseasons-widget-areas', 'Widget Areas', 'fourseasons_widget_areas', 'post', 'side' ); } } add_action('admin_menu', 'fourseasons_create_meta_box_widget_areas'); //save meta box values function fourseasons_save_postdata_widget_areas(){ global $post, $fourseasons_widget_areas; //save fields if(!empty($post->ID) && current_user_can('edit_page', $post->ID) && current_user_can('edit_post') && isset($_POST['fourseasons_widget_areas_nonce']) && wp_verify_nonce($_POST['fourseasons_widget_areas_nonce'],'fourseasons_widget_areas')){ if(!empty($_POST['fourseasons-widget-areas-sidebar'])){ $_POST['fourseasons-widget-areas-sidebar'] = sanitize_text_field($_POST['fourseasons-widget-areas-sidebar']); update_post_meta($post->ID,'fourseasons-widget-areas-sidebar',$_POST['fourseasons-widget-areas-sidebar']); }elseif(!empty($post->ID)){ delete_post_meta($post->ID,'fourseasons-widget-areas-sidebar'); } if(!empty($_POST['fourseasons-widget-areas-first-footer'])){ $_POST['fourseasons-widget-areas-first-footer'] = sanitize_text_field($_POST['fourseasons-widget-areas-first-footer']); update_post_meta($post->ID,'fourseasons-widget-areas-first-footer',$_POST['fourseasons-widget-areas-first-footer']); }elseif(!empty($post->ID)){ delete_post_meta($post->ID,'fourseasons-widget-areas-first-footer'); } if(!empty($_POST['fourseasons-widget-areas-second-footer'])){ $_POST['fourseasons-widget-areas-second-footer'] = sanitize_text_field($_POST['fourseasons-widget-areas-second-footer']); update_post_meta($post->ID,'fourseasons-widget-areas-second-footer',$_POST['fourseasons-widget-areas-second-footer']); }elseif(!empty($post->ID)){ delete_post_meta($post->ID,'fourseasons-widget-areas-second-footer'); } if(!empty($_POST['fourseasons-widget-areas-third-footer'])){ $_POST['fourseasons-widget-areas-third-footer'] = sanitize_text_field($_POST['fourseasons-widget-areas-third-footer']); update_post_meta($post->ID,'fourseasons-widget-areas-third-footer',$_POST['fourseasons-widget-areas-third-footer']); }elseif(!empty($post->ID)){ delete_post_meta($post->ID,'fourseasons-widget-areas-third-footer'); } if(!empty($_POST['fourseasons-widget-areas-fourth-footer'])){ $_POST['fourseasons-widget-areas-fourth-footer'] = sanitize_text_field($_POST['fourseasons-widget-areas-fourth-footer']); update_post_meta($post->ID,'fourseasons-widget-areas-fourth-footer',$_POST['fourseasons-widget-areas-fourth-footer']); }elseif(!empty($post->ID)){ delete_post_meta($post->ID,'fourseasons-widget-areas-fourth-footer'); } } } add_action('save_post', 'fourseasons_save_postdata_widget_areas'); }