Created
February 28, 2017 15:05
-
-
Save ineersa/66ea65b068550fec583d3e28672e7ff3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Twenty Fifteen functions and definitions | |
* | |
* Set up the theme and provides some helper functions, which are used in the | |
* theme as custom template tags. Others are attached to action and filter | |
* hooks in WordPress to change core functionality. | |
* | |
* When using a child theme you can override certain functions (those wrapped | |
* in a function_exists() call) by defining them first in your child theme's | |
* functions.php file. The child theme's functions.php file is included before | |
* the parent theme's file, so the child theme functions would be used. | |
* | |
* @link https://codex.wordpress.org/Theme_Development | |
* @link https://codex.wordpress.org/Child_Themes | |
* | |
* Functions that are not pluggable (not wrapped in function_exists()) are | |
* instead attached to a filter or action hook. | |
* | |
* For more information on hooks, actions, and filters, | |
* {@link https://codex.wordpress.org/Plugin_API} | |
* | |
* @package WordPress | |
* @subpackage Twenty_Fifteen | |
* @since Twenty Fifteen 1.0 | |
*/ | |
/** | |
* Set the content width based on the theme's design and stylesheet. | |
* | |
* @since Twenty Fifteen 1.0 | |
*/ | |
if ( ! isset( $content_width ) ) { | |
$content_width = 660; | |
} | |
/** | |
* Twenty Fifteen only works in WordPress 4.1 or later. | |
*/ | |
if ( version_compare( $GLOBALS['wp_version'], '4.1-alpha', '<' ) ) { | |
require get_template_directory() . '/inc/back-compat.php'; | |
} | |
if ( ! function_exists( 'ifly_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 for post thumbnails. | |
* | |
* @since Twenty Fifteen 1.0 | |
*/ | |
function ifly_setup() { | |
/* | |
* Make theme available for translation. | |
* Translations can be filed in the /languages/ directory. | |
* If you're building a theme based on ifly, use a find and replace | |
* to change 'ifly' to the name of your theme in all the template files | |
*/ | |
load_theme_textdomain( 'ifly', get_template_directory() . '/languages' ); | |
// Add default posts and comments RSS feed links to head. | |
add_theme_support( 'automatic-feed-links' ); | |
/* | |
* Let WordPress manage the document title. | |
* By adding theme support, we declare that this theme does not use a | |
* hard-coded <title> tag in the document head, and expect WordPress to | |
* provide it for us. | |
*/ | |
add_theme_support( 'title-tag' ); | |
/* | |
* Enable support for Post Thumbnails on posts and pages. | |
* | |
* See: https://codex.wordpress.org/Function_Reference/add_theme_support#Post_Thumbnails | |
*/ | |
add_theme_support( 'post-thumbnails' ); | |
set_post_thumbnail_size( 825, 510, true ); | |
// This theme uses wp_nav_menu() in two locations. | |
register_nav_menus( array( | |
'primary' => __( 'Primary Menu', 'ifly' ), | |
'social' => __( 'Social Links Menu', 'ifly' ), | |
) ); | |
/* | |
* Switch default core markup for search form, comment form, and comments | |
* to output valid HTML5. | |
*/ | |
add_theme_support( 'html5', array( | |
'search-form', 'comment-form', 'comment-list', 'gallery', 'caption' | |
) ); | |
/* | |
* Enable support for Post Formats. | |
* | |
* See: https://codex.wordpress.org/Post_Formats | |
*/ | |
add_theme_support( 'post-formats', array( | |
'aside', 'image', 'video', 'quote', 'link', 'gallery', 'status', 'audio', 'chat' | |
) ); | |
$color_scheme = ifly_get_color_scheme(); | |
$default_color = trim( $color_scheme[0], '#' ); | |
// Setup the WordPress core custom background feature. | |
add_theme_support( 'custom-background', apply_filters( 'ifly_custom_background_args', array( | |
'default-color' => $default_color, | |
'default-attachment' => 'fixed', | |
) ) ); | |
/* | |
* This theme styles the visual editor to resemble the theme style, | |
* specifically font, colors, icons, and column width. | |
*/ | |
add_editor_style( array( 'css/editor-style.css', 'genericons/genericons.css', ifly_fonts_url() ) ); | |
} | |
endif; // ifly_setup | |
add_action( 'after_setup_theme', 'ifly_setup' ); | |
/** | |
* Register widget area. | |
* | |
* @since Twenty Fifteen 1.0 | |
* | |
* @link https://codex.wordpress.org/Function_Reference/register_sidebar | |
*/ | |
function ifly_widgets_init() { | |
register_sidebar( array( | |
'name' => __( 'Widget Area', 'ifly' ), | |
'id' => 'sidebar-1', | |
'description' => __( 'Add widgets here to appear in your sidebar.', 'ifly' ), | |
'before_widget' => '<aside id="%1$s" class="widget %2$s">', | |
'after_widget' => '</aside>', | |
'before_title' => '<h2 class="widget-title">', | |
'after_title' => '</h2>', | |
) ); | |
} | |
add_action( 'widgets_init', 'ifly_widgets_init' ); | |
if ( ! function_exists( 'ifly_fonts_url' ) ) : | |
/** | |
* Register Google fonts for Twenty Fifteen. | |
* | |
* @since Twenty Fifteen 1.0 | |
* | |
* @return string Google fonts URL for the theme. | |
*/ | |
function ifly_fonts_url() { | |
$fonts_url = ''; | |
$fonts = array(); | |
$subsets = 'latin,latin-ext'; | |
/* | |
* Translators: If there are characters in your language that are not supported | |
* by Noto Sans, translate this to 'off'. Do not translate into your own language. | |
*/ | |
if ( 'off' !== _x( 'on', 'Noto Sans font: on or off', 'ifly' ) ) { | |
$fonts[] = 'Noto Sans:400italic,700italic,400,700'; | |
} | |
/* | |
* Translators: If there are characters in your language that are not supported | |
* by Noto Serif, translate this to 'off'. Do not translate into your own language. | |
*/ | |
if ( 'off' !== _x( 'on', 'Noto Serif font: on or off', 'ifly' ) ) { | |
$fonts[] = 'Noto Serif:400italic,700italic,400,700'; | |
} | |
/* | |
* Translators: If there are characters in your language that are not supported | |
* by Inconsolata, translate this to 'off'. Do not translate into your own language. | |
*/ | |
if ( 'off' !== _x( 'on', 'Inconsolata font: on or off', 'ifly' ) ) { | |
$fonts[] = 'Inconsolata:400,700'; | |
} | |
/* | |
* Translators: To add an additional character subset specific to your language, | |
* translate this to 'greek', 'cyrillic', 'devanagari' or 'vietnamese'. Do not translate into your own language. | |
*/ | |
$subset = _x( 'no-subset', 'Add new subset (greek, cyrillic, devanagari, vietnamese)', 'ifly' ); | |
if ( 'cyrillic' == $subset ) { | |
$subsets .= ',cyrillic,cyrillic-ext'; | |
} elseif ( 'greek' == $subset ) { | |
$subsets .= ',greek,greek-ext'; | |
} elseif ( 'devanagari' == $subset ) { | |
$subsets .= ',devanagari'; | |
} elseif ( 'vietnamese' == $subset ) { | |
$subsets .= ',vietnamese'; | |
} | |
if ( $fonts ) { | |
$fonts_url = add_query_arg( array( | |
'family' => urlencode( implode( '|', $fonts ) ), | |
'subset' => urlencode( $subsets ), | |
), '//fonts.googleapis.com/css' ); | |
} | |
return $fonts_url; | |
} | |
endif; | |
/** | |
* JavaScript Detection. | |
* | |
* Adds a `js` class to the root `<html>` element when JavaScript is detected. | |
* | |
* @since Twenty Fifteen 1.1 | |
*/ | |
function ifly_javascript_detection() { | |
echo "<script>(function(html){html.className = html.className.replace(/\bno-js\b/,'js')})(document.documentElement);</script>\n"; | |
} | |
add_action( 'wp_head', 'ifly_javascript_detection', 0 ); | |
/** | |
* Enqueue scripts and styles. | |
* | |
* @since Twenty Fifteen 1.0 | |
*/ | |
function ifly_scripts() { | |
// Add custom fonts, used in the main stylesheet. | |
//wp_enqueue_style( 'ifly-fonts', ifly_fonts_url(), array(), null ); | |
wp_enqueue_style( 'ifly-main', get_template_directory_uri() . '/css/style.css', array(), null ); | |
//wp_enqueue_style( 'googleFonts', 'http://fonts.googleapis.com/css?family=Lato:100,300,400,700,900', array(), null ); | |
wp_enqueue_style( 'bootstrap', get_template_directory_uri() . '/css/bootstrap.min.css', array(), null ); | |
wp_enqueue_style( 'bootstrap-theme', get_template_directory_uri() . '/css/bootstrap-theme.min.css', array(), null ); | |
wp_enqueue_style( 'jquery-ui-css', 'http://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css', array(), null ); | |
wp_enqueue_style( 'fancybox-css', get_template_directory_uri() . '/js/fancybox/jquery.fancybox.css', array(), null ); | |
//wp_enqueue_style( 'slick', get_template_directory_uri() . '/slick/slick.css', array(), null ); | |
//wp_enqueue_style( 'slick-theme', get_template_directory_uri() . '/slick/slick-theme.css', array(), null ); | |
//wp_enqueue_script( 'jquery-js', 'https://code.jquery.com/jquery-1.11.3.min.js' ); | |
wp_enqueue_script( 'jquery-ui-js', 'https://code.jquery.com/ui/1.11.4/jquery-ui.js' ); | |
//wp_enqueue_script( 'slick-main', get_template_directory_uri() . '/slick/slick.min.js' ); | |
wp_enqueue_script( 'bootstrap-main', get_template_directory_uri() . '/js/bootstrap.min.js' ); | |
wp_enqueue_script( 'owl', get_template_directory_uri() . '/js/owl.carousel.min.js' ); | |
wp_enqueue_script( 'fancybox-js', get_template_directory_uri() . '/js/fancybox/jquery.fancybox.js' ); | |
wp_enqueue_script( 'theme-main-js', get_template_directory_uri() . '/js/script.js' ); | |
/*// Add Genericons, used in the main stylesheet. | |
wp_enqueue_style( 'genericons', get_template_directory_uri() . '/genericons/genericons.css', array(), '3.2' ); | |
// Load our main stylesheet. | |
wp_enqueue_style( 'ifly-style', get_stylesheet_uri() ); | |
// Load the Internet Explorer specific stylesheet. | |
wp_enqueue_style( 'ifly-ie', get_template_directory_uri() . '/css/ie.css', array( 'ifly-style' ), '20141010' ); | |
wp_style_add_data( 'ifly-ie', 'conditional', 'lt IE 9' ); | |
// Load the Internet Explorer 7 specific stylesheet. | |
wp_enqueue_style( 'ifly-ie7', get_template_directory_uri() . '/css/ie7.css', array( 'ifly-style' ), '20141010' ); | |
wp_style_add_data( 'ifly-ie7', 'conditional', 'lt IE 8' ); | |
wp_enqueue_script( 'ifly-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20141010', true ); | |
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) { | |
wp_enqueue_script( 'comment-reply' ); | |
} | |
if ( is_singular() && wp_attachment_is_image() ) { | |
wp_enqueue_script( 'ifly-keyboard-image-navigation', get_template_directory_uri() . '/js/keyboard-image-navigation.js', array( 'jquery' ), '20141010' ); | |
} | |
wp_enqueue_script( 'ifly-script', get_template_directory_uri() . '/js/functions.js', array( 'jquery' ), '20150330', true ); | |
wp_localize_script( 'ifly-script', 'screenReaderText', array( | |
'expand' => '<span class="screen-reader-text">' . __( 'expand child menu', 'ifly' ) . '</span>', | |
'collapse' => '<span class="screen-reader-text">' . __( 'collapse child menu', 'ifly' ) . '</span>', | |
) );*/ | |
} | |
add_action( 'wp_enqueue_scripts', 'ifly_scripts' ); | |
add_post_type_support( 'special', 'post-formats' ); | |
add_action('init', 'am_create_special'); | |
function am_create_special() { | |
$labels = array( | |
'name' => _x('Special propositions', 'am'), | |
'singular_name' => _x('Specials', 'am'), | |
'add_new' => _x('Add Special', 'am'), | |
'add_new_item' => __('Add Special', 'am'), | |
'edit_item' => __('Edit Specials', 'am'), | |
'new_item' => __('New Special', 'am'), | |
'view_item' => __('View Special', 'am'), | |
'search_items' => __('Search Specials', 'am'), | |
'not_found' => __('No Specials found', 'am'), | |
'not_found_in_trash' => __('No Specials found in Trash', 'am'), | |
'parent_item_colon' => '' | |
); | |
$args = array( | |
'labels' => $labels, | |
'public' => true, | |
'publicly_queryable' => true, | |
'exclude_from_search' => false, | |
'show_ui' => true, | |
'query_var' => true, | |
'capability_type' => 'post', | |
'hierarchical' => false, | |
'menu_position' => null, | |
'supports' => array('title','thumbnail','editor','excerpt','custom-fields','revisions', 'page-attributes'), | |
'rewrite' => array( | |
'slug' => 'special' | |
) | |
); | |
register_post_type('special',$args); | |
$labels = array( | |
'name' => _x('Aircraft', 'am'), | |
'singular_name' => _x('Aircraft', 'am'), | |
'add_new' => _x('Add Aircraft', 'am'), | |
'add_new_item' => __('Add Aircraft', 'am'), | |
'edit_item' => __('Edit Aircraft', 'am'), | |
'new_item' => __('New Aircraft', 'am'), | |
'view_item' => __('View Aircraft', 'am'), | |
'search_items' => __('Search Aircrafts', 'am'), | |
'not_found' => __('No Aircrafts found', 'am'), | |
'not_found_in_trash' => __('No Aircrafts found in Trash', 'am'), | |
'parent_item_colon' => '' | |
); | |
$args = array( | |
'labels' => $labels, | |
'public' => true, | |
'publicly_queryable' => true, | |
'exclude_from_search' => false, | |
'show_ui' => true, | |
'query_var' => true, | |
'capability_type' => 'post', | |
'hierarchical' => false, | |
'menu_position' => null, | |
'menu_icon' => 'dashicons-admin-tools', | |
'supports' => array('title','thumbnail','editor','excerpt','custom-fields','revisions', 'page-attributes'), | |
'rewrite' => array( | |
'slug' => 'aircraft-fleet' | |
) | |
); | |
register_post_type('aircraft-fleet',$args); | |
} | |
/** | |
* Add featured image as background image to post navigation elements. | |
* | |
* @since Twenty Fifteen 1.0 | |
* | |
* @see wp_add_inline_style() | |
*/ | |
function ifly_post_nav_background() { | |
if ( ! is_single() ) { | |
return; | |
} | |
$previous = ( is_attachment() ) ? get_post( get_post()->post_parent ) : get_adjacent_post( false, '', true ); | |
$next = get_adjacent_post( false, '', false ); | |
$css = ''; | |
if ( is_attachment() && 'attachment' == $previous->post_type ) { | |
return; | |
} | |
if ( $previous && has_post_thumbnail( $previous->ID ) ) { | |
$prevthumb = wp_get_attachment_image_src( get_post_thumbnail_id( $previous->ID ), 'post-thumbnail' ); | |
$css .= ' | |
.post-navigation .nav-previous { background-image: url(' . esc_url( $prevthumb[0] ) . '); } | |
.post-navigation .nav-previous .post-title, .post-navigation .nav-previous a:hover .post-title, .post-navigation .nav-previous .meta-nav { color: #fff; } | |
.post-navigation .nav-previous a:before { background-color: rgba(0, 0, 0, 0.4); } | |
'; | |
} | |
if ( $next && has_post_thumbnail( $next->ID ) ) { | |
$nextthumb = wp_get_attachment_image_src( get_post_thumbnail_id( $next->ID ), 'post-thumbnail' ); | |
$css .= ' | |
.post-navigation .nav-next { background-image: url(' . esc_url( $nextthumb[0] ) . '); border-top: 0; } | |
.post-navigation .nav-next .post-title, .post-navigation .nav-next a:hover .post-title, .post-navigation .nav-next .meta-nav { color: #fff; } | |
.post-navigation .nav-next a:before { background-color: rgba(0, 0, 0, 0.4); } | |
'; | |
} | |
wp_add_inline_style( 'ifly-style', $css ); | |
} | |
add_action( 'wp_enqueue_scripts', 'ifly_post_nav_background' ); | |
/** | |
* Display descriptions in main navigation. | |
* | |
* @since Twenty Fifteen 1.0 | |
* | |
* @param string $item_output The menu item output. | |
* @param WP_Post $item Menu item object. | |
* @param int $depth Depth of the menu. | |
* @param array $args wp_nav_menu() arguments. | |
* @return string Menu item with possible description. | |
*/ | |
function ifly_nav_description( $item_output, $item, $depth, $args ) { | |
if ( 'primary' == $args->theme_location && $item->description ) { | |
$item_output = str_replace( $args->link_after . '</a>', '<div class="menu-item-description">' . $item->description . '</div>' . $args->link_after . '</a>', $item_output ); | |
} | |
return $item_output; | |
} | |
add_filter( 'walker_nav_menu_start_el', 'ifly_nav_description', 10, 4 ); | |
/** | |
* Add a `screen-reader-text` class to the search form's submit button. | |
* | |
* @since Twenty Fifteen 1.0 | |
* | |
* @param string $html Search form HTML. | |
* @return string Modified search form HTML. | |
*/ | |
function ifly_search_form_modify( $html ) { | |
return str_replace( 'class="search-submit"', 'class="search-submit screen-reader-text"', $html ); | |
} | |
add_filter( 'get_search_form', 'ifly_search_form_modify' ); | |
/** | |
* Implement the Custom Header feature. | |
* | |
* @since Twenty Fifteen 1.0 | |
*/ | |
require get_template_directory() . '/inc/custom-header.php'; | |
/** | |
* Flightsparser. | |
* | |
* @since Twenty Fifteen 1.0 | |
*/ | |
require get_template_directory() . '/inc/flights-parser.php'; | |
/** | |
* Scheduleparser. | |
* | |
* @since Twenty Fifteen 1.0 | |
*/ | |
require get_template_directory() . '/inc/schedule-parser.php'; | |
/** | |
* Custom template tags for this theme. | |
* | |
* @since Twenty Fifteen 1.0 | |
*/ | |
require get_template_directory() . '/inc/template-tags.php'; | |
/** | |
* Customizer additions. | |
* | |
* @since Twenty Fifteen 1.0 | |
*/ | |
require get_template_directory() . '/inc/customizer.php'; | |
add_action( 'init', 'add_excerpts_to_pages' ); | |
function add_excerpts_to_pages() { | |
add_post_type_support( 'page', 'excerpt' ); | |
} | |
add_action( 'pre_get_posts', 'remove_faq_posts_from_news' ); | |
function remove_faq_posts_from_news( $query ) { | |
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1; | |
if( $query->is_main_query() && $query->is_home() ) { | |
$query->set( 'meta_key', 'faq' ); | |
$query->set( 'meta_value', 0 ); | |
$query->set( 'paged', $paged ); | |
} | |
} | |
function getBreadcrumbsItems($id, &$array=null, &$counter=0){ | |
if(!is_array($array)){ | |
$array = array(); | |
} | |
$parent = wp_get_post_parent_id( $id ); | |
if($parent){ | |
$array[$counter]['id'] = $parent; | |
$array[$counter]['title'] = get_the_title($parent); | |
$array[$counter]['url'] = get_the_permalink($parent); | |
if($parent==16){ | |
unset($array[$counter]); //ID 16-главная страница. Если родитель указан как главная страница удаляем его из массива. | |
} | |
$counter++; | |
getBreadcrumbsItems($parent, $array, $counter); | |
} | |
return array_reverse($array); | |
} | |
function jquery_tubular_to_wp_head() { | |
wp_enqueue_script( 'wp_head_jquery_tubular', get_stylesheet_directory_uri() . '/js/jquery.tubular/js/jquery.tubular.1.0.js', array(), null ); | |
} | |
add_action( 'wp_enqueue_scripts', 'jquery_tubular_to_wp_head'); | |
function redirect_to_thank_you_page(){ | |
wp_redirect('/page-thanks'); | |
} | |
add_action("wp_ajax_nopriv_search_flights", "search_flights_callback"); | |
add_action("wp_ajax_search_flights", "search_flights_callback"); | |
function search_flights_callback() { | |
$flights = new ScheduleParser(); | |
echo json_encode($flights->searchFlights($_POST)); | |
wp_die(); | |
} | |
add_filter('comment_post_redirect', 'redirect_to_thank_you_page'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment