$filetype['ext'],
      'type'            => $filetype['type'],
      'proper_filename' => $data['proper_filename']
  ];
}, 10, 4 );
function cc_mime_types( $mimes ){
  $mimes['svg'] = 'image/svg+xml';
  return $mimes;
}
add_filter( 'upload_mimes', 'cc_mime_types' );
function fix_svg() {
  echo '';
}
add_action( 'admin_head', 'fix_svg' );
add_theme_support( 'post-thumbnails' );
function get_ajax_blog_posts()
{
  global $post;
  $blog_posts_offset = ($_POST['offset']) ? $_POST['offset'] : 0;
  $numberposts = ($_POST['numberposts']) ? $_POST['numberposts'] : 11;
  $banner_display = ($_POST['banner']) ? $_POST['banner'] : false;
  $args = array(
    'category_name' => 'Blog Post',
    'numberposts' => $numberposts,
    'offset' => $blog_posts_offset,
  );
  if(($_POST['tag'])&&($_POST['tag']!='all')){
    $args['tag'] = $_POST['tag'];
  }
  
  $blog_posts = get_posts($args);
  $response = '';
  if ($blog_posts) {
    $posts_counter = 0;
    foreach ($blog_posts as $blog_post) {
      $post = $blog_post;
      setup_postdata($post);
      if($posts_counter==3){
        $response .= get_template_part('blog-posts/blog-post-small');
        if($blog_posts_offset==0){
          $response .= get_template_part('blog-posts/blog-banner');
        }
      }else if($posts_counter==6){
        $response .= get_template_part('blog-posts/blog-post-large');
      }else{
        $response .= get_template_part('blog-posts/blog-post-small');
      }
      wp_reset_postdata();
      $posts_counter++;
    }
  }
  echo $response;
  die;
}
add_action('wp_ajax_get_ajax_blog_posts', 'get_ajax_blog_posts');
add_action('wp_ajax_nopriv_get_ajax_blog_posts', 'get_ajax_blog_posts');
function get_pages_count($tag = false)
{
  $args = array(
    'category_name' => 'Blog Post',
    'numberposts' => -1,
  );
  if(($tag)&&($tag!='all')){  $args['tag'] = $tag; }
  $posts = new WP_Query( $args );
  $total = ceil ($posts->found_posts / 11);
  return $total; 
}
function get_ajax_blog_posts_new()
{
  ob_start(); 
  global $post;
  $blog_posts_offset = ($_POST['offset']) ? $_POST['offset'] : 0;
  $numberposts = ($_POST['numberposts']) ? $_POST['numberposts'] : 11;
  $banner_display = ($_POST['banner']) ? $_POST['banner'] : false;
  $author = ($_POST['author']) ? $_POST['author'] : -1;
  $args = array(
    'category_name' => 'Blog Post',
    'numberposts' => $numberposts,
    'offset' => $blog_posts_offset,
    'author' => $author,
  );
  if(($_POST['tag'])&&($_POST['tag']!='all')){
    $args['tag'] = $_POST['tag'];
  }
  $blog_posts = get_posts($args);
  $response = '';
  if ($blog_posts) {
    $posts_counter = 0;
    foreach ($blog_posts as $blog_post) {
      $post = $blog_post;
      setup_postdata($post);
      if($posts_counter==3){
        $response .= get_template_part('blog-posts/blog-post-small');
        if($blog_posts_offset==0){
          $response .= get_template_part('blog-posts/blog-banner');
        }
      }else if($posts_counter==6){
        $response .= get_template_part('blog-posts/blog-post-large');
      }else{
        $response .= get_template_part('blog-posts/blog-post-small');
      }
      wp_reset_postdata();
      $posts_counter++;
    }
  }
  $response = ob_get_clean(); 
  if (0 == strlen($response))
  {
  $data['results'] = false; 
  }
  else
  {
  $data['results'] = true; 
  }
  $data['response'] = $response;
  echo json_encode ($data); 
  die;
}
add_action('wp_ajax_get_ajax_blog_posts_new', 'get_ajax_blog_posts_new');
add_action('wp_ajax_nopriv_get_ajax_blog_posts_new', 'get_ajax_blog_posts_new');
add_action( 'wp_enqueue_scripts', 'myajax_data', 99 );
function myajax_data(){
	wp_localize_script( 'main-script', 'myajax',
		array(
			'url' => admin_url('admin-ajax.php')
		)
	);
}
function enqueue_my_scripts($hook) {
    if ( 'post.php' != $hook ) {
        return;
    }
    wp_enqueue_style( 'post-css', get_template_directory_uri() . '/css/post-style.css' );
}
add_action('admin_enqueue_scripts', 'enqueue_my_scripts');
function load_template_part($template_name, $part_name=null) {
    ob_start();
    get_template_part($template_name, $part_name);
    $var = ob_get_contents();
    ob_end_clean();
    return $var;
}
function add_blocks_before_h2($content) {
    $exploded = explode("
slug;
                }
            }
            $args = array(
                'numberposts' => 1,
                'exclude' => get_the_ID(),
                'offset' => 0,
                'tag' => $tagsSlug
            );
            $preview_posts = get_posts($args);
            global $post;
            $post = $preview_posts[0];
            setup_postdata( $post );
            $post_title = get_the_title();
            $post_link = get_permalink();
            wp_reset_postdata();
        $exploded[2] =  $exploded[2] . "";
    }
    if ($exploded[4]) {
        $exploded[3] =  $exploded[3] . load_template_part('blog-posts/blog-register');
    }
    $result = implode(" 1)))
    {
      $content .= ". Страница " . $PAGEN;
    }
    return $content; 
}
function update_facebook_description($content) {
  global $PAGEN; 
  if (($PAGEN) && (($PAGEN > 1)))
  {
    $content .= ". Страница " . $PAGEN;
  }
  return $content; 
}
add_filter( 'wpseo_next_rel_link', 'custom_change_wpseo_next' );
function custom_change_wpseo_next( $link ) {
          $link = ""; 
          return $link;
}
if (!function_exists('str_contains')) {
  function str_contains($haystack, $needle) {
      return $needle !== '' && mb_strpos($haystack, $needle) !== false;
  }
}
function get_ajax_blog_single_post()
{
  global $post;
  $blog_posts_offset  = ($_POST['offset']) ? $_POST['offset'] : 0;
  $blog_posts_exclude = ($_POST['sameid']);
  $args = array(
    'category_name' => 'Blog Post',
    'numberposts' => 1,
    'exclude' => $blog_posts_exclude,    
    'offset' => $blog_posts_offset,
    'meta_query' => array(
      'relation' => 'AND',
      'post_count_all_rule' => array(
          'key'     => 'post_count_all',
          'compare' => 'EXISTS',
      ),
    ),
    'orderby' => array(
      'date' => 'DESC',
      'post_count_all_rule' => 'DESC',
    ),
  );
  if(($_POST['tag'])&&($_POST['tag']!='all')){
    $args['tag'] = $_POST['tag'];
  }
  
  $blog_posts = get_posts($args);
  $response = '';
  if ($blog_posts) {
    ob_start(); 
    foreach ($blog_posts as $blog_post) {
      
      $post = $blog_post;
      // var_dump($post); 
      $ID = $post->ID; 
      setup_postdata($post);
      $title = get_the_title($ID); 
      $url = get_the_permalink($ID); 
      $response .= get_template_part('template-parts/ajax_post');
      $description = get_post_meta($ID, '_yoast_wpseo_metadesc', true); 
      wp_reset_postdata();
    }
    $response = ob_get_clean(); 
  }
  
  if ($response)
  {
    $results['results'] = true;
    $results['content'] = $response;
    $results['title'] = $title;
    $results['url'] = trim($url);
    $results['ID'] = $ID;
    $results['description'] = $description; 
  } else {
    $results['results'] = false;
  }
  
  echo json_encode($results, JSON_UNESCAPED_UNICODE);
  die;
}
add_action('wp_ajax_get_ajax_blog_single_post', 'get_ajax_blog_single_post');
add_action('wp_ajax_nopriv_get_ajax_blog_single_post', 'get_ajax_blog_single_post');
add_action( 'save_post', 'update_blog_meta' );
function update_blog_meta( $post_id ) {
	
  $slug = 'post';
	if ( $slug != $_POST['post_type'] ) return;
    
  $rate = get_post_meta ( $post_id, 'post_count_' . $post_id, true); 
  update_post_meta(  $post_id, 'post_count_all', $rate); 
}
function allstylesBVN() {
	wp_enqueue_style( 'allstyles', get_template_directory_uri() . '/css/allstyles.css', array(), '1.0.1' );
	wp_enqueue_style( 'slider-style', get_template_directory_uri() . '/css/lightslider.min.css', array(), 1 );
}
add_action( 'wp_enqueue_scripts', 'allstylesBVN', 200 );
function newstylesBVN() {
	wp_enqueue_style( 'newstyles', get_template_directory_uri() . '/css/newstyles.css', array(), rand(0,9999) );
}
add_action( 'wp_enqueue_scripts', 'newstylesBVN', 200 );
function sliderscript() {
	wp_enqueue_script( 'slider-script', get_template_directory_uri() . '/js/lightslider.min.js', array(), 1, true );
}
// add_action( 'wp_enqueue_scripts', 'sliderscript', 50 );
function mainScript() {
	wp_enqueue_script( 'main-script', get_template_directory_uri() . '/js/main.js', array(), 1, true );
}
// add_action( 'wp_enqueue_scripts', 'mainScript', 100 );
  wp_localize_script('main-script', 'siteVars', array(
    // 'query' => array(
    //   'raw_vars' => $wp_query->query_vars,
    //   'vars' => json_encode($wp_query->query_vars), // everything about your loop is here
    //   'current_page' => get_query_var('paged') ? get_query_var('paged') : 1,
    //   'max_page' => $wp_query->max_num_pages,
    // ),
    'site' => array(
      'url' => site_url(),
      'ajax' => admin_url('admin-ajax.php'),
    ),
    // 'translate' => array(
    //   'wl_add_text' => __("Added to the wish list", gV('slug')),
    //   'wl_remove_text' => __("Removed from the wish list", gV('slug')),
    // ),
  ));
remove_filter('pre_user_description', 'wp_filter_kses');  
add_filter( 'pre_user_description', 'wp_filter_post_kses' ); 
function change_contact_info($contactmethods) {
	unset($contactmethods['pinterest']);
	unset($contactmethods['soundcloud']);
	$contactmethods['tumblr'] = 'Telegram';
    $contactmethods['twitter'] = 'Twitter';
    $contactmethods['facebook'] = 'Facebook';
    $contactmethods['linkedin'] = 'Вконтакте';
    $contactmethods['myspace'] = 'Одноклассники';
    return $contactmethods;
}
add_filter('user_contactmethods','change_contact_info',10,1);
// Добавляем attached iamge url в REST API endpointЫ с ключом images
function ws_register_images_field() {
  register_rest_field( 
      'post',
      'images',
      array(
          'get_callback'    => 'ws_get_images_urls',
          'update_callback' => null,
          'schema'          => null,
      )
  );
}
add_action( 'rest_api_init', 'ws_register_images_field' );
function ws_get_images_urls( $object, $field_name, $request ) {
  $medium = wp_get_attachment_image_src( get_post_thumbnail_id( $object->id ), 'medium' );
  $medium_url = $medium['0'];
  $large = wp_get_attachment_image_src( get_post_thumbnail_id( $object->id ), 'large' );
  $large_url = $large['0'];
  return array(
      'medium' => $medium_url,
      'large'  => $large_url,
  );
}
add_filter( 'cancel_comment_reply_link', '__return_false' );
// Добавляем имя автора в REST API endpointЫ с ключом author_name
if(!function_exists('add_post_autor_field')){
  function add_post_autor_field($response, $post) {
      $response->data['author_name'] = get_the_author_meta( 'display_name' , $post->author );
      return $response;
  }
}
add_filter('rest_prepare_post', 'add_post_autor_field', 10, 3);
// Добавляем галочки к субменю в меню с id=2
add_filter( 'walker_nav_menu_start_el', 'parent_menu_dropdown', 10, 4 );
function parent_menu_dropdown( $item_output, $item, $depth, $args ) {
    if ( is_nav_menu( 2 ) && ! empty( $item->classes ) && in_array( 'menu-item-has-children', $item->classes ) ) {
        return $item_output . '';
    }
    return $item_output;
}
//Remove Gutenberg Block Library CSS from loading on the frontend
function smartwp_remove_wp_block_library_css(){
 wp_dequeue_style( 'wp-block-library' );
 wp_dequeue_style( 'wp-block-library-theme' );
 wp_dequeue_style( 'wc-blocks-style' ); // Remove WooCommerce block CSS
} 
add_action( 'wp_enqueue_scripts', 'smartwp_remove_wp_block_library_css', 100 );
add_action( 'wp_enqueue_scripts', 'my_dequeue_style', 99 );
function my_dequeue_style(){
	wp_dequeue_style( 'pld-frontend' );
}
function set_pagination_base () {
    global $wp_rewrite;
    $wp_rewrite->pagination_base = '%3F' . 'page=';
}
// add_action( 'init', 'set_pagination_base' );
// add_filter( 'paginate_links', function($link){
// if(is_paged()){$link= str_replace('page/1/', '', $link);}
// return $link;
// } );
// add_filter( 'redirect_canonical', function ( $redirect_url ) {
// if ( is_paged() ) {
//     return false;
// }
// return $redirect_url;
// }, 10, 1 );
// 
// add_action( 'init', function() {
//     $GLOBALS['wp_rewrite']->pagination_base = '?PAGEN=';
// });
// Removes the canonical redirection
remove_filter( 'template_redirect', 'redirect_canonical' );
// Add custom rewrite rules
// add_action( 'init', 'my_add_custom_rewrite_rules' );
// function my_add_custom_rewrite_rules() {
//     // Slug of the target page
//     $page_slug = 'page';
//     // Page number to replace
//     $page_num = 2;
//     // Title you wish to replace the page number with
//     $title = 'custom-string';
//     // Add the custom rewrite rule
//     add_rewrite_rule(
//         '^' . $page_slug . '/' . $title . '/?$',
//         'index.php?pagename=' . $page_slug . '&page=' . $page_num, 'top'
//     );
// }
// add_action("init","remove_m_parameter");
// function remove_m_parameter()
// {
//   if(isset($_GET['tags']))
//   {
//   unset($_GET['tags']);
//   }
// }
// 
// вставляем изображение записи под первым параграфом
add_filter( 'the_content', 'insert_featured_image', 20 );
function insert_featured_image( $content ) {
	if( !$id ) {
        global $post;
        $id = get_the_id();
    }
	$content = preg_replace( "/<\/p>/", "" . get_the_post_thumbnail($id), $content, 1 );
// 	$content = preg_replace( "/<\/p>/", "" . "", $content, 1 );
	$content .= '123';
	return $content;
	wp_reset_postdata();
}
/**
 *  Create a custom excerpt string from the first paragraph of the content.
 *
 *  @param   integer  $id       The id of the post
 *  @return  string   $excerpt  The excerpt string
 */
function wp_first_paragraph_excerpt( $id=null ) {
    // Set $id to the current post by default
    if( !$id ) {
        global $post;
        $id = get_the_id();
    }
    // Get the post content
    $content = get_post_field( 'post_content', $id );
    $content = apply_filters( 'the_content', strip_shortcodes( $content ) );
    // Remove all tags, except paragraphs
    $excerpt = strip_tags( $content, '
' );
    // Remove empty paragraph tags
    $excerpt = force_balance_tags( $excerpt );
    $excerpt = preg_replace( '#\s*+(
)?\s*
#i', '', $excerpt );
    $excerpt = preg_replace( '~\s?(\s| )+
\s?~', '', $excerpt );
    // Get the first paragraph
    $excerpt = substr( $excerpt, 0, strpos( $excerpt, '' ) + 4 );
    // Remove remaining paragraph tags
    $excerpt = strip_tags( $excerpt );
    return $excerpt;
}
// //меняем надпись кнопки в форме комментов
// function change_comment_form_submit_label($arg) {
//   $arg['label_submit'] = 'Оставить комментарий';
//   return $arg;
// }
// add_filter('comment_form_defaults', 'change_comment_form_submit_label', 11);
// add_filter( 'comment_form_default_fields', 'wpse_62742_comment_placeholders' );
/**
 * Comment Form Placeholder Comment Field
 */
 function placeholder_comment_form_field($fields) {
    $replace_comment = __('Комментарий', 'yourdomain');
     
    $fields['comment_field'] = '';
    
    return $fields;
 }
add_filter( 'comment_form_defaults', 'placeholder_comment_form_field' );
add_filter( 'comment_form_default_fields', 'wpse_62742_comment_placeholders' );
/**
 * Change default fields, add placeholder and change type attributes.
 *
 * @param  array $fields
 * @return array
 */
function wpse_62742_comment_placeholders( $fields )
{
    $fields['author'] = str_replace(
        'ID, 'post-single');
//     if ( is_single() && ! is_admin() ) {
//         return prefix_insert_after_paragraph( '' . $feat_img . '
', 1, $content );
//     }
//     return $content;
// }
// Parent Function that makes the magic happen
function prefix_insert_after_paragraph( $insertion, $paragraph_id, $content ) {
    $closing_p = '';
    $paragraphs = explode( $closing_p, $content );
    foreach ($paragraphs as $index => $paragraph) {
        if ( trim( $paragraph ) ) {
            $paragraphs[$index] .= $closing_p;
        }
        if ( $paragraph_id == $index + 1 ) {
            $paragraphs[$index] .= $insertion;
        }
    }
    return implode( '', $paragraphs );
}