<?php

if ( function_exists('register_sidebar') )
register_sidebar(array(
'name' => 'Телефон 1',
'id' => 'telefon1',
'before_widget' => '',
'after_widget' => '',
'before_title' => '',
'after_title' => '',
));

if ( function_exists('register_sidebar') )
register_sidebar(array(
'name' => 'Телефон 2',
'id' => 'telefon2',
'before_widget' => '',
'after_widget' => '',
'before_title' => '',
'after_title' => '',
));

if ( function_exists('register_sidebar') )
register_sidebar(array(
'name' => 'Адрес внизу',
'id' => 'adres-v-nizu',
'before_widget' => '',
'after_widget' => '',
'before_title' => '',
'after_title' => '',
));

if ( function_exists('register_sidebar') )
register_sidebar(array(
'name' => 'Копирайт',
'id' => 'kopirait',
'before_widget' => '',
'after_widget' => '',
'before_title' => '',
'after_title' => '',
));

function my_breadcrumb() {
echo ' <ul class="B_crumbBox">
<li class="B_firstCrumb" itemscope="itemscope" ><a href="/" class="B_homeCrumb" itemprop="url" rel="Home"><span itemprop="title">Главная</span></a>&nbsp; /&nbsp;</li>';
$categories = get_the_category();
if($categories[0]){
  echo '<a href="' . get_category_link($categories[0]->term_id ) . '">
  '. $categories[0]->name . '';
  echo '</ul>';
}
echo ' <li itemscope="itemscope" class="B_currentCrumb" itemtype="http://data-vocabulary.org/Breadcrumb">';
      echo the_title(); 
      echo '</li></ul>';
}

//Remove WPAUTOP from ACF TinyMCE Editor
function acf_wysiwyg_remove_wpautop() {
    remove_filter('acf_the_content', 'wpautop' );
}
add_action('acf/init', 'acf_wysiwyg_remove_wpautop');

//добавление nofollow для ссылок на рубрики start
function wph_nofollow_cats($text) { 
    $text = stripslashes($text);
    $text = preg_replace_callback('|<a (.+?)>|i', 
          'wp_rel_nofollow_callback', $text);
    return $text; }
function wph_nofollow_cat($text) {
    $text = str_replace('rel="category tag"', "", $text);
    $text = wph_nofollow_cats($text);
    return $text; } 
add_filter('wp_list_categories', 'wph_nofollow_cats');
add_filter('the_category', 'wph_nofollow_cat');
//добавление nofollow для ссылок на рубрики end








add_theme_support( 'post-thumbnails' ); // для всех типов постов

$default_attr = array(
  'src' => $src,
  'class' => "attachment-$size",
  'alt' => trim(strip_tags( $wp_postmeta->_wp_attachment_image_alt )),
);

 function content($limit) {
  $content = explode(' ', get_the_content(), $limit);
  if (count($content)>=$limit) {
    array_pop($content);
    $content = implode(" ",$content).'...';
  } else {
    $content = implode(" ",$content);
  }
  $content = preg_replace('`[[^]]*]`','',$content);
  return $content;
}


// WOOOCOMERCE


// woocommerce_currencies
add_filter( 'woocommerce_currencies', 'add_inr_currency' );
add_filter( 'woocommerce_currency_symbol', 'add_inr_currency_symbol'
);
function add_inr_currency( $currencies ) {
$currencies['RUB'] = 'Российский рубль';
return $currencies;
}
function add_inr_currency_symbol( $symbol ) {
$currency = get_option( 'woocommerce_currency' );
switch( $currency ) {
case 'RUB': $symbol = ''; break;
}
return $symbol;
}


// woocommerce_currencies

// html код в описаниях категорий


remove_filter('term-description', 'wp_filter_kses');
remove_filter('term-description', 'wp_kses_data');
remove_filter('pre_term_description', 'wp_filter_kses');
remove_filter('pre_term_description', 'wp_kses_data');



//скрытие аксессуаров со странице магазина
function woo_custom_pre_get_posts_query( $q ) {
    if ( ! $q->is_main_query() ) return;
    if ( ! $q->is_post_type_archive() ) return;
 
    if ( ! is_admin() && is_shop() ) {
        $q->set( 'tax_query', array(array(
            'taxonomy' => 'product_cat',
            'field' => 'slug',
            'terms' => array( 'suveniry-i-podarki','podstavki-pod-cvetov','stulya-i-stoly','urny','navesy','mangaly','lezhanki-dlya-koshek-i-sobak','lavochkiskamejki','krovatibanketki','ograzhdeniya','zerkala' ), // Don't display products in the shoes category on the shop page
            'operator' => 'NOT IN'
        )));
 
    }
    remove_action( 'pre_get_posts', 'custom_pre_get_posts_query' );
}
add_action( 'pre_get_posts', 'woo_custom_pre_get_posts_query' );







add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
  function custom_override_checkout_fields( $fields ) { /*Убрали ненужные поля*/
//  unset($fields['billing']['billing_company']);
//   unset($fields['billing']['billing_last_name']);


 // unset($fields['billing']['billing_address_1']);


 // unset($fields['billing']['billing_address_2']);
//   unset($fields['billing']['billing_email']);
//  unset($fields['billing']['billing_state']);


//    unset($fields['billing']['billing_city']);


//    unset($fields['billing']['billing_postcode']);
     unset($fields['billing']['billing_country']);


 return $fields;
}
 add_filter('woocommerce_billing_fields', 'custom_woocommerce_billing_fields');
 function custom_woocommerce_billing_fields( $fields ) {
 $fields['billing_address_1']['class'] = array( 'form-row-wide' ); /*Поле адреса шире*/
 return $fields;
 }


// убрать подытог
 add_filter( 'woocommerce_get_order_item_totals', 'adjust_woocommerce_get_order_item_totals' );

function adjust_woocommerce_get_order_item_totals( $totals ) {
unset($totals['cart_subtotal'] );
return $totals;
}

// убрать обзоры
add_filter( 'woocommerce_product_tabs', 'sb_woo_remove_reviews_tab', 98);
function sb_woo_remove_reviews_tab($tabs) {

unset($tabs['reviews']);

return $tabs;
}


//отключаем стандартные стили woocommerce
add_filter( 'woocommerce_enqueue_styles', '__return_false' );



// Удаляем и добавляем Хуки
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_title', 5);
remove_action('woocommerce_before_shop_loop', 'woocommerce_result_count', 20);
// remove_action('woocommerce_before_single_product_summary', 'woocommerce_show_product_sale_flash', 10);

// add_action('woocommerce_before_shop_loop', 'woof_products_top_panel', 100);
add_action('woocommerce_after_shop_loop_item_baton', 'woocommerce_template_single_add_to_cart', 100);
add_action('woocommerce_after_shop_loop_item_govno', 'woocommerce_template_single_excerpt', 100);



function change_rub_symbol() {
// Just returns rubles :)
return ' руб';
}
add_filter( 'woocommerce_currency_symbol', 'change_rub_symbol', 50 );



// Сортировка woocommerce по артикулу

add_filter('woocommerce_get_catalog_ordering_args', 'am_woocommerce_catalog_orderby');
function am_woocommerce_catalog_orderby( $args ) {
    $args['meta_key'] = '_sku';
    $args['orderby'] = 'meta_value';
    $args['order'] = 'asc';
    return $args;
}


// Удалить лишние классы у меню 
// add_filter('nav_menu_item_id', 'remove_nav_menu_item_id'); function remove_nav_menu_item_id($id) { return ""; }
// add_filter('nav_menu_css_class','remove_nav_menu_classes'); function remove_nav_menu_classes($classes) { if ( in_array("current-menu-item", $classes ) ) { unset( $classes ); $classes[0]= 'current'; } else { $classes = array(); $classes[0]= 'class tipo'; } return $classes; }



// 404 ошибка фифа

if (is_page (array('https://myfifasalon1.ru/?id=117',''))) {
    status_header( 404 );
    nocache_headers();
    include( get_query_template( '404' ) );
    die();
}






// Убрать творчество вордпресс

function wph_admin_footer_text () {
}
add_filter('admin_footer_text', 'wph_admin_footer_text');



// отключаем пункты в верхнем меню в админке
function wph_new_toolbar() {
    global $wp_admin_bar;
    $wp_admin_bar->remove_menu('comments');    //меню комментарии
    $wp_admin_bar->remove_menu('new-content'); //меню "добавить"
    $wp_admin_bar->remove_menu('wp-logo');     //меню "о wordpress"
    $wp_admin_bar->remove_menu('all-in-one-seo-pack');     //меню "о wordpress"
}
add_action('wp_before_admin_bar_render', 'wph_new_toolbar');
//-----------------------------------



// Удаляем виджеты
function remove_dashboard_meta() {
        remove_meta_box( 'dashboard_incoming_links', 'dashboard', 'normal' );
        remove_meta_box( 'dashboard_plugins', 'dashboard', 'normal' );
        remove_meta_box( 'dashboard_primary', 'dashboard', 'normal' );
        remove_meta_box( 'dashboard_secondary', 'dashboard', 'normal' );
        remove_meta_box( 'dashboard_incoming_links', 'dashboard', 'normal' );
        remove_meta_box( 'dashboard_quick_press', 'dashboard', 'side' );
        remove_meta_box( 'dashboard_recent_drafts', 'dashboard', 'side' );
        remove_meta_box( 'dashboard_recent_comments', 'dashboard', 'normal' );
        remove_meta_box( 'dashboard_right_now', 'dashboard', 'normal' );
        remove_meta_box( 'dashboard_activity', 'dashboard', 'normal');//since 3.8
}
add_action( 'admin_init', 'remove_dashboard_meta' );

// Вставляем в шапку стили

function devise_separators() {
echo '<style type="text/css">


#toplevel_page_asp_settings, #menu-posts-foogallery li:nth-child(4), #menu-posts-foogallery li:nth-child(5)
, #menu-posts-foogallery li:nth-child(6), #menu-posts-foogallery li:nth-child(7), #toplevel_page_woocommerce li:nth-child(4)
, #toplevel_page_woocommerce li:nth-child(5), #toplevel_page_woocommerce li:nth-child(8), #toplevel_page_woocommerce li:nth-child(9)
, #toplevel_page_woocommerce li:nth-child(10)
.notice-error, div.error , #toplevel_page_all-in-one-seo-pack-aioseop_class
{
  display: none !important;
}


</style>';
}
add_action( 'admin_head', 'devise_separators' );


// Удаляем эллементы меню
function remove_menus(){
  remove_menu_page( 'index.php' );                  //Консоль
  remove_menu_page( 'edit.php' );                 //Записи
  // remove_menu_page( 'upload.php' );               //Медиафайлы
  // remove_menu_page( 'edit.php?post_type=page' );  //Страницы
  remove_menu_page( 'edit-comments.php' );          //Комментарии
  remove_menu_page( 'themes.php' );               //Внешний вид
  remove_submenu_page( 'themes.php', 'widgets.php' ); // Субменю
  remove_menu_page( 'plugins.php' );              //Плагины
  remove_menu_page( 'users.php' );                //Пользователи
  remove_menu_page( 'tools.php' );                  //Инструменты
  remove_menu_page( 'options-general.php' );      //Параметры
  remove_menu_page( 'options-general.php' ); 
  remove_menu_page( 'foobox-image-lightbox' );
  remove_menu_page( 'wpcf7' );
};




/* редирект с login на /wp-login.php  и с admin на /wp-admin */
add_action('template_redirect', 'kama_login_redirect');
function kama_login_redirect(){
  if( strpos($_SERVER['REQUEST_URI'], 'login')!==false )
    $loc = '/wp-login.php';
  elseif( strpos($_SERVER['REQUEST_URI'], 'admin')!==false )
    $loc = '/wp-admin/';
  if( $loc ){
    header( 'Location: '.get_option('site_url').$loc, true, 303 );
    exit;
  }
}




if ( !function_exists('hide_admin_bar_search') ) {
  function hide_admin_bar_search () { ?>
    <style type="text/css">
    #wpadminbar #adminbarsearch, #wp-admin-bar-comments, #wp-admin-bar-wp-logo, #wp-admin-bar-dashboard {
      display: none;
    }
    </style>
    <?php
  };
};
function my_login_logo(){
   echo '
   <style type="text/css">
#login h1 a {
height: 50px;
background-size: 100%!important;
}
    </style>';
};
add_action('login_head', 'my_login_logo');
add_action( 'admin_menu', 'remove_menus' );
add_action('admin_head', 'hide_admin_bar_search');
add_action('wp_head', 'hide_admin_bar_search');
remove_action( 'load-plugins.php', 'wp_update_plugins' );
remove_action( 'load-update.php', 'wp_update_plugins' );
remove_action( 'admin_init', '_maybe_update_plugins' );
remove_action( 'wp_update_plugins', 'wp_update_plugins' );
add_filter( 'pre_transient_update_plugins', create_function( '$a',
"return null;" ) );
remove_action( 'wp_version_check', 'wp_version_check' );
remove_action( 'admin_init', '_maybe_update_core' );
add_filter( 'pre_transient_update_core', create_function( '$a',
"return null;" ) );
define( 'WP_AUTO_UPDATE_CORE', 'minor' );




// Чистый вордпресс

remove_action('wp_head','feed_links_extra', 3);
remove_action( 'wp_head', 'wp_resource_hints', 2 );
remove_action('wp_head','feed_links', 2);
remove_action('wp_head','rsd_link');
remove_action('wp_head','wlwmanifest_link');
remove_action('wp_head','wp_generator');
remove_action('wp_head','start_post_rel_link',10,0);
remove_action('wp_head','index_rel_link');
remove_action('wp_head','adjacent_posts_rel_link_wp_head', 10, 0 );
remove_action('wp_head','wp_shortlink_wp_head', 10, 0 );
 function ny_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', 'ny_remove_recent_comments_style' );
remove_action('wp_head', 'print_emoji_detection_script', 7);
remove_action('wp_print_styles', 'print_emoji_styles');
add_action( 'wp_print_styles', 'aa_deregister_styles', 100 );
function aa_deregister_styles() {
    if ( ! is_page( get_theme_mod( "header_contacts") ) ) {
        wp_deregister_style( 'contact-form-7' );
    }
}
add_action( 'wp_print_scripts', 'aa_deregister_javascript', 100 );
function aa_deregister_javascript() {
    if ( ! is_page( get_theme_mod( "header_contacts") ) ) {
        wp_deregister_script( 'contact-form-7' );
    }
}
remove_action('wp_print_styles', 'pagenavi_stylesheets');
remove_action( 'template_redirect', 'wp_shortlink_header', 11 );
function ny_remove_x_pingback( $headers ) {
    unset( $headers['X-Pingback'] );
    return $headers;
}
add_filter( 'wp_headers', 'ny_remove_x_pingback' );
header_remove( 'x-powered-by' );

add_theme_support('admin-bar', array( 'callback' => '__return_false'));
add_filter('show_admin_bar', '__return_false');

remove_action( 'wp_head', 'wp_oembed_add_discovery_links' );
remove_action( 'wp_head', 'rest_output_link_wp_head' );
remove_action( 'template_redirect', 'rest_output_link_header', 11, 0 );
add_filter('rest_enabled', '__return_false');
remove_action( 'xmlrpc_rsd_apis',            'rest_output_rsd' );
remove_action( 'wp_head',                    'rest_output_link_wp_head', 10, 0 );
remove_action( 'template_redirect',          'rest_output_link_header', 11, 0 );
remove_action( 'auth_cookie_malformed',      'rest_cookie_collect_status' );
remove_action( 'auth_cookie_expired',        'rest_cookie_collect_status' );
remove_action( 'auth_cookie_bad_username',   'rest_cookie_collect_status' );
remove_action( 'auth_cookie_bad_hash',       'rest_cookie_collect_status' );
remove_action( 'auth_cookie_valid',          'rest_cookie_collect_status' );
remove_filter( 'rest_authentication_errors', 'rest_cookie_check_errors', 100 );
remove_action( 'init',          'rest_api_init' );
remove_action( 'rest_api_init', 'rest_api_default_filters', 10, 1 );
remove_action( 'parse_request', 'rest_api_loaded' );
remove_action( 'rest_api_init',          'wp_oembed_register_route'              );
remove_filter( 'rest_pre_serve_request', '_oembed_rest_pre_serve_request', 10, 4 );
remove_action( 'wp_head', 'wp_oembed_add_discovery_links' );
/*
 *  Удаляем остальные ненужные meta из head
 *
 */
remove_action( 'wp_head', 'wp_generator' );
remove_action( 'wp_head', 'rel_canonical' );
remove_action( 'wp_head', 'wp_shortlink_wp_head' ); 
remove_action( 'wp_head', 'rsd_link' ); 
remove_action( 'wp_head', 'wlwmanifest_link' );
remove_action( 'wp_head', 'index_rel_link' ); 
remove_action( 'wp_head', 'start_post_rel_link', 10 );  
remove_action( 'wp_head', 'parent_post_rel_link', 10 ); 
remove_action( 'wp_head', 'adjacent_posts_rel_link', 10 );
remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10 ); 
remove_action( 'wp_head', 'feed_links', 2 );
remove_action( 'wp_head', 'pagenavi_css' ); 

?>