%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /var/www/sms.eco-n-tech.co.uk/wp-content/themes/hittasmslanwebvatra/
Upload File :
Create Path :
Current File : /var/www/sms.eco-n-tech.co.uk/wp-content/themes/hittasmslanwebvatra/functions.php

<?php

require_once("assets/inc/scripts-and-styles.php");
require_once("assets/inc/img-sizes.php");

function theme_setup(){
	add_theme_support( 'title-tag' );
	add_theme_support( 'post-thumbnails' ); 
	register_nav_menus(
		array(
			'main_menu' => __( 'Menu', 'hittasmslan' ),
			'foot_menu' => __( 'Footer menu', 'hittasmslan' )
	));   
}
add_action('after_setup_theme', 'theme_setup');

function hittasmslan_acf_op_init() {
	if( function_exists('acf_add_options_page') ) {        
		$option_page = acf_add_options_page(array(
			'page_title'    => __('General Settings', 'hittasmslan'),
			'menu_title'    => __('General Settings', 'hittasmslan'),
			'menu_slug'     => 'general-theme-settings',
			'capability'    => 'edit_posts',
			'redirect'      => false,          
		));
	}
}
add_action('acf/init', 'hittasmslan_acf_op_init');

function svg_upload_allow( $mimes ) {
	$mimes['svg']  = 'image/svg+xml';
	return $mimes;
}
add_filter( 'upload_mimes', 'svg_upload_allow' );

function fix_svg_mime_type( $data, $file, $filename, $mimes, $real_mime = '' ){
  if( version_compare( $GLOBALS['wp_version'], '5.1.0', '>=' ) )
	$dosvg = in_array( $real_mime, [ 'image/svg', 'image/svg+xml' ] );
  else
	$dosvg = ( '.svg' === strtolower( substr($filename, -4) ) );
  if( $dosvg ){
	if( current_user_can('manage_options') ){
	  $data['ext']  = 'svg';
	  $data['type'] = 'image/svg+xml';
	}
	else {
	  $data['ext'] = $type_and_ext['type'] = false;
	}
  }
  return $data;
}
add_filter( 'wp_check_filetype_and_ext', 'fix_svg_mime_type', 10, 5 );

function show_svg_in_media_library( $response ) {
	if ( $response['mime'] === 'image/svg+xml' ) {
		$response['sizes'] = [
			'medium' => [
				'url' => $response['url'],
			],
		];
	}
	return $response;
}
add_filter( 'wp_prepare_attachment_for_js', 'show_svg_in_media_library' );

function custom_menu_classes($classes, $item, $args) {
  if($args->theme_location == 'main_menu') {
	$classes[] = 'tab-container';
  }
  return $classes;
}
add_filter('nav_menu_css_class', 'custom_menu_classes', 1, 3);

function custom_specific_menu_location_atts( $atts, $item, $args ) {
	if( $args->theme_location == 'main_menu' ) {
	  $atts['class'] = 'tab';
	}
	return $atts;
}
add_filter( 'nav_menu_link_attributes', 'custom_specific_menu_location_atts', 10, 3 );

function custom_nav_menu_submenu_css_class( $classes ) {
	$classes[] = 'dropdown';
	return $classes;
}
add_filter( 'nav_menu_submenu_css_class', 'custom_nav_menu_submenu_css_class' );

/* custom Walker */
class Walker_Page_Custom extends Walker_Nav_Menu {
	/**
	 * @see Walker::start_lvl()
	 * @since 2.1.0
	 *
	 * @param string $output Passed by reference. Used to append additional content.
	 * @param int $depth Depth of page. Used for padding.
	 */
	function start_lvl(&$output, $depth) {
		$indent = str_repeat("\t", $depth);
		$output .= "\n$indent<button class='expand-dropdown'><i class='fas fa-angle-down'></i></button><ul class='sub-menu dropdown'>\n";
	}

	/**
	 * @see Walker::end_lvl()
	 * @since 2.1.0
	 *
	 * @param string $output Passed by reference. Used to append additional content.
	 * @param int $depth Depth of page. Used for padding.
	 */
	function end_lvl(&$output, $depth) {
		$indent = str_repeat("\t", $depth);
		$output .= "$indent</ul>\n";
	}
}

/* custom blog excerpt */
function get_sentence_tally_excerpt( $content = '', $tally = 2, $stitches = '' ) {

	$buffer = array_slice( explode( '.', sanitize_text_field( $content ) ), 0, $tally );

	$filter = array_filter( array_map( 'trim', $buffer ), 'strlen' );

	$excerpt = join( '. ', $filter ) . '.';

	return esc_attr( $excerpt . $stitches );

};

/* load scripts async or defer */
if(!is_admin()) {
	function add_asyncdefer_attribute($tag, $handle) {
		if (strpos($handle, 'async') !== false) {
			return str_replace( '<script ', '<script async ', $tag );
		}
		else if (strpos($handle, 'defer') !== false) {
			return str_replace( '<script ', '<script defer ', $tag );
		}
		else {
			return $tag;
		}
	}
	add_filter('script_loader_tag', 'add_asyncdefer_attribute', 10, 2);
}

/* remove slugs from lana and lana_utan posts */
function custom_remove_slug( $post_link, $post, $leavename ) {
	if('lana' == $post->post_type && 'publish' == $post->post_status) {
		$post_link = str_replace( '/' . $post->post_type . '/', '/', $post_link);
		return $post_link;
	}elseif('lana_utan' == $post->post_type && 'publish' == $post->post_status) {
		$post_type_data = get_post_type_object( $post->post_type );
		$post_type_slug = $post_type_data->rewrite['slug'];
		$post_link = str_replace( '/' . $post_type_slug . '/', '/', $post_link);
		return $post_link;
	}else{
		return $post_link;
	}
   return $post_link;
}
add_filter( 'post_type_link', 'custom_remove_slug', 10, 3 );

function custom_parse_request( $query ) {
	if ( ! $query->is_main_query() || 2 != count( $query->query ) || ! isset( $query->query['page'] ) ) {
		return;
	}
	if ( ! empty( $query->query['name'] ) ) {
		$query->set( 'post_type', array( 'post', 'lana', 'lana_utan', 'page' ) );
	}
}
add_action( 'pre_get_posts', 'custom_parse_request' );

/* change slug for standard post */
function standard_post_type_args( $args, $post_type ) {
	if ($post_type !== 'post') {
		return $args;
	}
	$args['rewrite'] = [
		'slug' => 'blogg',
		'with_front' => true,
	];
	return $args;
}
add_filter( 'register_post_type_args', 'standard_post_type_args', 10, 2 );

function standard_post_type_slug ($permalink, $post) {
	if ($post->post_type !== 'post') {
		return $permalink;
	}
	return '/blogg/%postname%/';
}
add_filter( 'pre_post_link', 'standard_post_type_slug', 10, 2 );

Zerion Mini Shell 1.0