<?php
/**
 * Adds custom classes to the array of body classes.
 *
 * @param array $classes Classes for the body element.
 * @return array
 */
function finbiz_body_classes( $classes ) {
  // Adds a class of hfeed to non-singular pages.
  if ( ! is_singular() ) {
    $classes[] = 'hfeed';
  }

  if ( is_front_page() ) {
    $classes[] = 'default_header';
  }

  return $classes;
}
add_filter( 'body_class', 'finbiz_body_classes' );

/**
 * Return the most-used custom header on inner pages.
 */
function finbiz_get_inner_page_header_id() {
  global $wpdb;

  $exclude_id = get_queried_object_id();

  $header_id = $wpdb->get_var(
    $wpdb->prepare(
      "SELECT pm.meta_value
      FROM {$wpdb->postmeta} pm
      INNER JOIN {$wpdb->posts} p ON p.ID = pm.post_id
      WHERE pm.meta_key = 'header_select'
      AND pm.meta_value != ''
      AND p.post_type = 'page'
      AND p.post_status = 'publish'
      AND p.ID != %d
      GROUP BY pm.meta_value
      ORDER BY COUNT(*) DESC
      LIMIT 1",
      $exclude_id
    )
  );

  return $header_id ? absint( $header_id ) : 0;
}

/**
 * Add a pingback url auto-discovery header for singularly identifiable articles.
 */
function finbiz_pingback_header() {
  if ( is_singular() && pings_open() ) {
    echo '<link rel="pingback" href="', esc_url( get_bloginfo( 'pingback_url' ) ), '">';
  }
}

add_action( 'wp_head', 'finbiz_pingback_header' );
/**  kses_allowed_html */
function finbiz_prefix_kses_allowed_html($tags, $context) {
  switch($context) {
    case 'finbiz': 
      $tags = array( 
        'a' => array('href' => array()),
        'b' => array()
      );
      return $tags;
    default: 
      return $tags;
  }
}
add_filter( 'wp_kses_allowed_html', 'finbiz_prefix_kses_allowed_html', 10, 2);

/*
Register Fonts theme google font
*/
function finbiz_is_arabic_locale() {
    return 0 === strpos( get_locale(), 'ar' );
}

/**
 * Current front-end language (WPML-aware).
 *
 * @return string
 */
function finbiz_get_current_language() {
	if ( defined( 'ICL_LANGUAGE_CODE' ) ) {
		$lang = strtolower( (string) ICL_LANGUAGE_CODE );
	} else {
		$lang = apply_filters( 'wpml_current_language', null );
		$lang = $lang ? strtolower( (string) $lang ) : '';
	}

	if ( in_array( $lang, array( 'en', 'ar' ), true ) ) {
		return $lang;
	}

	return finbiz_is_arabic_locale() ? 'ar' : 'en';
}

/**
 * Raw site name from WordPress settings (bypasses language filter).
 *
 * @return string
 */
function finbiz_get_raw_site_name() {
	static $raw_name = null;

	if ( null !== $raw_name ) {
		return $raw_name;
	}

	remove_filter( 'option_blogname', 'finbiz_filter_blogname_for_language', 10 );
	$raw_name = (string) get_option( 'blogname' );
	add_filter( 'option_blogname', 'finbiz_filter_blogname_for_language', 10 );

	return $raw_name;
}

/**
 * Site name shown in breadcrumbs, header, and similar UI per language.
 *
 * Customize Arabic/English names via the finbiz_localized_site_names filter.
 *
 * @param string $lang Optional language code.
 * @return string
 */
function finbiz_get_localized_site_name( $lang = '' ) {
	if ( ! $lang ) {
		$lang = finbiz_get_current_language();
	}

	$names = apply_filters(
		'finbiz_localized_site_names',
		array(
			'en' => finbiz_get_raw_site_name(),
			'ar' => 'الريان',
		)
	);

	$name = ! empty( $names[ $lang ] ) ? $names[ $lang ] : $names['en'];

	return $name;
}

/**
 * Show localized site title on the front end (no WPML String Translation).
 *
 * @param string $blogname Site name from wp_options.
 * @return string
 */
function finbiz_filter_blogname_for_language( $blogname ) {
	if ( is_admin() && ! wp_doing_ajax() ) {
		return $blogname;
	}

	return finbiz_get_localized_site_name();
}
add_filter( 'option_blogname', 'finbiz_filter_blogname_for_language', 10 );

/**
 * Use localized site name for the home crumb in Breadcrumb NavXT.
 *
 * @param string $title Breadcrumb title.
 * @param array  $type  Breadcrumb type.
 * @param int    $id    Object ID.
 * @return string
 */
function finbiz_bcn_home_breadcrumb_title( $title, $type, $id ) {
	if ( in_array( 'home', (array) $type, true ) ) {
		return finbiz_get_localized_site_name();
	}

	return $title;
}
add_filter( 'bcn_breadcrumb_title', 'finbiz_bcn_home_breadcrumb_title', 10, 3 );

function finbiz_studio_fonts_url() {
    $font_url = '';
    
    /*
    Translators: If there are characters in your language that are not supported
    by chosen font(s), translate this to 'off'. Do not translate into your own language.
     */
    if ( 'off' !== _x( 'on', 'Google font: on or off', 'finbiz' ) ) {
        $font_url = add_query_arg( 'family', urlencode( 'DM Sans: 400,500,600,700|Red Hat Display:500,600,700' ), "//fonts.googleapis.com/css" );
    }
    return $font_url;
}

function finbiz_almarai_fonts_url() {
    return add_query_arg(
        array(
            'family'  => 'Almarai:wght@300;400;700;800',
            'display' => 'swap',
        ),
        'https://fonts.googleapis.com/css2'
    );
}

function finbiz_almarai_font_css() {
    $font = "'Almarai', sans-serif";

    return "
    html[lang^='ar'] body,
    html[lang^='ar'] :where(
        h1, h2, h3, h4, h5, h6,
        p, a, span, div, li, ul, ol,
        td, th, label, legend, figcaption,
        input, textarea, select, option, button,
        .menu-area, .navbar, .nav-menu,
        .elementor-widget-container,
        .elementor-heading-title,
        .elementor-button,
        .elementor-icon-list-text,
        .rts-btn, .react-button a,
        .page-title, .sub-title,
        .breadcrumbs-title, .site-title,
        .blog-title, .widget-title,
        .wp-block-heading, .wp-block-paragraph
    ) {
        font-family: {$font} !important;
    }

    html[lang^='ar'] .fa,
    html[lang^='ar'] .fas,
    html[lang^='ar'] .far,
    html[lang^='ar'] .fab,
    html[lang^='ar'] .fal,
    html[lang^='ar'] [class*='fa-']::before,
    html[lang^='ar'] .dashicons,
    html[lang^='ar'] .dashicons::before,
    html[lang^='ar'] .eicon,
    html[lang^='ar'] [class*=' eicon-'],
    html[lang^='ar'] i[class*='icon']::before {
        font-family: 'Font Awesome 6 Free', 'Font Awesome 5 Free', dashicons, eicons, inherit !important;
    }

    html[lang^='ar'] .fab,
    html[lang^='ar'] .fab::before {
        font-family: 'Font Awesome 6 Brands', 'Font Awesome 5 Brands' !important;
    }

    html[lang^='ar'] .reactheme-breadcrumbs .breadcrumbs-title {
        float: right !important;
        direction: rtl;
        flex-direction: row !important;
        justify-content: flex-start;
        white-space: nowrap;
    }

    html[lang^='ar'] .reactheme-breadcrumbs .breadcrumbs-title > span {
        display: inline-flex;
        flex-direction: row;
        align-items: center;
        gap: 14px;
    }

    html[lang^='ar'] .reactheme-breadcrumbs .breadcrumbs-title span a.home span {
        margin: 0 !important;
        padding: 0 0 0 18px !important;
    }

    html[lang^='ar'] .reactheme-breadcrumbs .breadcrumbs-title span.current-item {
        margin: 0 !important;
        padding: 0 !important;
        line-height: 1.2;
    }

    html[lang^='ar'] .reactheme-breadcrumbs .breadcrumbs-title span a:before {
        right: auto !important;
          left: 6px !important;
    top: 71%;
        transform: translateY(-50%) rotate(180deg);
    }
    ";
}

function finbiz_enqueue_arabic_almarai_font() {
    if ( ! finbiz_is_arabic_locale() ) {
        return;
    }

    wp_enqueue_style(
        'finbiz-almarai-font',
        finbiz_almarai_fonts_url(),
        array(),
        '1.0.0'
    );

    wp_add_inline_style( 'finbiz-almarai-font', finbiz_almarai_font_css() );
}
add_action( 'wp_enqueue_scripts', 'finbiz_enqueue_arabic_almarai_font', 20 );

function finbiz_enqueue_arabic_almarai_font_admin() {
    if ( ! finbiz_is_arabic_locale() || ! is_admin() ) {
        return;
    }

    wp_enqueue_style(
        'finbiz-almarai-font-admin',
        finbiz_almarai_fonts_url(),
        array(),
        '1.0.0'
    );

    wp_add_inline_style( 'finbiz-almarai-font-admin', finbiz_almarai_font_css() );
}
add_action( 'admin_enqueue_scripts', 'finbiz_enqueue_arabic_almarai_font_admin' );


function finbiz_studio_scripts() {
    if ( finbiz_is_arabic_locale() ) {
        return;
    }

    wp_enqueue_style( 'studio-fonts', finbiz_studio_fonts_url(), array(), '1.0.0' );
}
add_action( 'wp_enqueue_scripts', 'finbiz_studio_scripts' );

//Favicon Icon
function finbiz_site_icon() {
 if ( ! ( function_exists( 'has_site_icon' ) && has_site_icon() ) ) {     
    global $finbiz_option;
     
    if(!empty($finbiz_option['rs_favicon']['url']))
    {?>
    <link rel="shortcut icon" type="image/x-icon" href="<?php echo esc_url(($finbiz_option['rs_favicon']['url'])); ?>"> 
  <?php 
    }
  }
}
add_filter('wp_head', 'finbiz_site_icon');


//excerpt for specific section
function finbiz_wpex_get_excerpt( $args = array() ) {
  // Defaults
  $defaults = array(
    'post'            => '',
    'length'          => 48,
    'readmore'        => false,
    'readmore_text'   => esc_html__( 'read more', 'finbiz' ),
    'readmore_after'  => '',
    'custom_excerpts' => true,
    'disable_more'    => false,
  );
  // Apply filters
  $defaults = apply_filters( 'finbiz_wpex_get_excerpt_defaults', $defaults );
  // Parse args
  $args = wp_parse_args( $args, $defaults );
  // Apply filters to args
  $args = apply_filters( 'finbiz_wpex_get_excerpt_args', $defaults );
  // Extract
  extract( $args );
  // Get global post data
  if ( ! $post ) {
    global $post;
  }

  $post_id = $post->ID;
  if ( $custom_excerpts && has_excerpt( $post_id ) ) {
    $output = $post->post_excerpt;
  } 
  else { 
    $readmore_link = '<a href="' . get_permalink( $post_id ) . '" class="readmore">' . $readmore_text . $readmore_after . '</a>';    
    if ( ! $disable_more && strpos( $post->post_content, '<!--more-->' ) ) {
      $output = apply_filters( 'the_content', get_the_content( $readmore_text . $readmore_after ) );
    }    
    else {     
      $output = wp_trim_words( strip_shortcodes( $post->post_content ), $length );      
      if ( $readmore ) {
        $output .= apply_filters( 'finbiz_wpex_readmore_link', $readmore_link );
      }
    }
  }
  // Apply filters and echo
  return apply_filters( 'finbiz_wpex_get_excerpt', $output );
}

//Demo content file include here

function finbiz_import_files() {
  return array(

    //demo 1
    array(
    	'import_file_name'           => 'Default Demo',
    	'categories'                 => array( 'Business' ),
    	'import_file_url'            => 'https://reactheme.com/products/demo-data/finbiz/main/finbiz-content.xml',
             
			'import_redux'               => array(
				array(
				'file_url'    => 'https://reactheme.com/products/demo-data/finbiz/main/finbiz-options.json',
				'option_name' => 'finbiz_option',
				),
			),

      	'import_preview_image_url'   => 'https://reactheme.com/products/landing/wp/finbiz/assets/images/demos/01.webp',
     	'import_notice'              => esc_html__( 'Caution: For importing demo data please click on "Import Demo Data" button. During demo data installation please do not refresh the page.', 'finbiz' ),
      	'preview_url'                => 'https://reactheme.com/products/wordpress/finbiz-main',     
      
    ),
	
    
    // constulting
    array(
    	'import_file_name'           => 'Consulting Demo',
    	'categories'                 => array( 'Constulting' ),
    	'import_file_url'            => 'https://reactheme.com/products/demo-data/finbiz/consulting/finbiz-content.xml',
             
			'import_redux'               => array(
				array(
				'file_url'    => 'https://reactheme.com/products/demo-data/finbiz/consulting/finbiz-options.json',
				'option_name' => 'finbiz_option',
				),
			),

      	'import_preview_image_url'   => 'https://reactheme.com/products/landing/wp/finbiz/assets/images/demos/02.webp',
     	'import_notice'              => esc_html__( 'Caution: For importing demo data please click on "Import Demo Data" button. During demo data installation please do not refresh the page.', 'finbiz' ),
      	'preview_url'                => 'https://reactheme.com/products/wordpress/finbiz-consulting',     
      
    ),


	// Corporate Demo
    array(
    	'import_file_name'           => 'Corporate Demo',
    	'categories'                 => array( 'Corporate' ),
    	'import_file_url'            => 'https://reactheme.com/products/demo-data/finbiz/corporate/finbiz-content.xml',
             
			'import_redux'               => array(
				array(
				'file_url'    => 'https://reactheme.com/products/demo-data/finbiz/corporate/finbiz-options.json',
				'option_name' => 'finbiz_option',
				),
			),

      	'import_preview_image_url'   => 'https://reactheme.com/products/landing/wp/finbiz/assets/images/demos/03.webp',
     	'import_notice'              => esc_html__( 'Caution: For importing demo data please click on "Import Demo Data" button. During demo data installation please do not refresh the page.', 'finbiz' ),
      	'preview_url'                => 'https://reactheme.com/products/wordpress/finbiz-corporate',     
      
    ),

    // Agency Demo
    array(
    	'import_file_name'           => 'Modern Agency',
    	'categories'                 => array( 'Agency' ),
    	'import_file_url'            => 'https://reactheme.com/products/demo-data/finbiz/agency/finbiz-content.xml',
             
			'import_redux'               => array(
				array(
				'file_url'    => 'https://reactheme.com/products/demo-data/finbiz/agency/finbiz-options.json',
				'option_name' => 'finbiz_option',
				),
			),

      	'import_preview_image_url'   => 'https://reactheme.com/products/landing/wp/finbiz/assets/images/demos/09.webp',
     	'import_notice'              => esc_html__( 'Caution: For importing demo data please click on "Import Demo Data" button. During demo data installation please do not refresh the page.', 'finbiz' ),
      	'preview_url'                => 'https://reactheme.com/products/wordpress/finbiz-agency',     
      
    ),


	// Insurance Demo
    array(
    	'import_file_name'           => 'Insurance Demo',
    	'categories'                 => array( 'Insurance' ),
    	'import_file_url'            => 'https://reactheme.com/products/demo-data/finbiz/insurance/finbiz-content.xml',
             
			'import_redux'               => array(
				array(
				'file_url'    => 'https://reactheme.com/products/demo-data/finbiz/insurance/finbiz-options.json',
				'option_name' => 'finbiz_option',
				),
			),

      	'import_preview_image_url'   => 'https://reactheme.com/products/landing/wp/finbiz/assets/images/demos/04.webp',
     	'import_notice'              => esc_html__( 'Caution: For importing demo data please click on "Import Demo Data" button. During demo data installation please do not refresh the page.', 'finbiz' ),
      	'preview_url'                => 'https://reactheme.com/products/wordpress/finbiz-insurance',     
      
    ),


	// Marketing Demo
	array(
    	'import_file_name'           => 'Marketing Demo',
    	'categories'                 => array( 'Marketing' ),
    	'import_file_url'            => 'https://reactheme.com/products/demo-data/finbiz/marketing/finbiz-content.xml',
             
			'import_redux'               => array(
				array(
				'file_url'    => 'https://reactheme.com/products/demo-data/finbiz/marketing/finbiz-options.json',
				'option_name' => 'finbiz_option',
				),
			),

      	'import_preview_image_url'   => 'https://reactheme.com/products/landing/wp/finbiz/assets/images/demos/05.webp',
     	'import_notice'              => esc_html__( 'Caution: For importing demo data please click on "Import Demo Data" button. During demo data installation please do not refresh the page.', 'finbiz' ),
      	'preview_url'                => 'https://reactheme.com/products/wordpress/finbiz-marketing',     
      
    ),


	// Finance Demo
	array(
    	'import_file_name'           => 'Finace Demo',
    	'categories'                 => array( 'Finance' ),
    	'import_file_url'            => 'https://reactheme.com/products/demo-data/finbiz/finance/finbiz-content.xml',
             
		'import_redux'               => array(
			array(
			'file_url'    => 'https://reactheme.com/products/demo-data/finbiz/finance/finbiz-options.json',
			'option_name' => 'finbiz_option',
			),
		),

      	'import_preview_image_url'   => 'https://reactheme.com/products/landing/wp/finbiz/assets/images/demos/06.webp',
     	'import_notice'              => esc_html__( 'Caution: For importing demo data please click on "Import Demo Data" button. During demo data installation please do not refresh the page.', 'finbiz' ),
      	'preview_url'                => 'https://reactheme.com/products/wordpress/finbiz-finance',     
      
    ),

	// Human Resource Demo
	array(
    	'import_file_name'           => 'HR Demo',
    	'categories'                 => array( 'HR' ),
    	'import_file_url'            => 'https://reactheme.com/products/demo-data/finbiz/hr/finbiz-content.xml',
             
		'import_redux'               => array(
			array(
			'file_url'    => 'https://reactheme.com/products/demo-data/finbiz/hr/finbiz-options.json',
			'option_name' => 'finbiz_option',
			),
		),

      	'import_preview_image_url'   => 'https://reactheme.com/products/landing/wp/finbiz/assets/images/demos/07.webp',
     	'import_notice'              => esc_html__( 'Caution: For importing demo data please click on "Import Demo Data" button. During demo data installation please do not refresh the page.', 'finbiz' ),
      	'preview_url'                => 'https://reactheme.com/products/wordpress/finbiz-hr',     
      
    ),

	// IT Solution Demo
	array(
    	'import_file_name'           => 'IT Demo',
    	'categories'                 => array( 'IT Solutions' ),
    	'import_file_url'            => 'https://reactheme.com/products/demo-data/finbiz/it/finbiz-content.xml',
             
		'import_redux'               => array(
			array(
			'file_url'    => 'https://reactheme.com/products/demo-data/finbiz/it/finbiz-options.json',
			'option_name' => 'finbiz_option',
			),
		),

      	'import_preview_image_url'   => 'https://reactheme.com/products/landing/wp/finbiz/assets/images/demos/08.webp',
     	'import_notice'              => esc_html__( 'Caution: For importing demo data please click on "Import Demo Data" button. During demo data installation please do not refresh the page.', 'finbiz' ),
      	'preview_url'                => 'https://reactheme.com/products/wordpress/finbiz-it/',     
      
    ),

	// Startup Agency
	array(
    	'import_file_name'           => 'Startup Agency',
    	'categories'                 => array( 'Startup' ),
    	'import_file_url'            => 'https://reactheme.com/products/demo-data/finbiz/startup/finbiz-content.xml',
             
		'import_redux'               => array(
			array(
			'file_url'    => 'https://reactheme.com/products/demo-data/finbiz/startup/finbiz-options.json',
			'option_name' => 'finbiz_option',
			),
		),

      	'import_preview_image_url'   => 'https://reactheme.com/products/landing/wp/finbiz/assets/images/demos/09.webp',
     	'import_notice'              => esc_html__( 'Caution: For importing demo data please click on "Import Demo Data" button. During demo data installation please do not refresh the page.', 'finbiz' ),
      	'preview_url'                => 'https://reactheme.com/products/wordpress/finbiz-startup/',     
      
    ),

	// Branding Agency
	array(
    	'import_file_name'           => 'Branding Agency',
    	'categories'                 => array( 'Branding Agency' ),
    	'import_file_url'            => 'https://reactheme.com/products/demo-data/finbiz/branding/finbiz-content.xml',
             
		'import_redux'               => array(
			array(
			'file_url'    => 'https://reactheme.com/products/demo-data/finbiz/branding/finbiz-options.json',
			'option_name' => 'finbiz_option',
			),
		),

      	'import_preview_image_url'   => 'https://reactheme.com/products/landing/wp/finbiz/assets/images/demos/11.webp',
     	'import_notice'              => esc_html__( 'Caution: For importing demo data please click on "Import Demo Data" button. During demo data installation please do not refresh the page.', 'finbiz' ),
      	'preview_url'                => 'https://reactheme.com/products/wordpress/finbiz-branding/',     
      
    ),

	// Business Agency
	array(
    	'import_file_name'           => 'Business Agency',
    	'categories'                 => array( 'Business Agency' ),
    	'import_file_url'            => 'https://reactheme.com/products/demo-data/finbiz/business-agency/finbiz-content.xml',
             
		'import_redux'               => array(
			array(
			'file_url'    => 'https://reactheme.com/products/demo-data/finbiz/business-agency/finbiz-options.json',
			'option_name' => 'finbiz_option',
			),
		),

      	'import_preview_image_url'   => 'https://reactheme.com/products/landing/wp/finbiz/assets/images/demos/24.webp',
     	'import_notice'              => esc_html__( 'Caution: For importing demo data please click on "Import Demo Data" button. During demo data installation please do not refresh the page.', 'finbiz' ),
      	'preview_url'                => 'https://themewant.com/products/wordpress/finbiz-business-agency/',     
      
    ),

	// Finbiz Business
	array(
    	'import_file_name'           => 'Business',
    	'categories'                 => array( 'Business' ),
    	'import_file_url'            => 'https://reactheme.com/products/demo-data/finbiz/finbiz-business/finbiz-content.xml',
		'import_redux'               => array(
			array(
			'file_url'    => 'https://reactheme.com/products/demo-data/finbiz/finbiz-business/finbiz-options.json',
			'option_name' => 'finbiz_option',
			),
		),
      	'import_preview_image_url'   => 'https://reactheme.com/products/landing/wp/finbiz/assets/images/demos/12.webp',
     	'import_notice'              => esc_html__( 'Caution: For importing demo data please click on "Import Demo Data" button. During demo data installation please do not refresh the page.', 'finbiz' ),
      	'preview_url'                => 'https://reactheme.com/products/wordpress/finbiz-business/',     
      
    ),


	//Onepage demo import config
	//demo 1
    array(
    	'import_file_name'           => 'Default Onepage',
    	'categories'                 => array( 'Business' ),
    	'import_file_url'            => 'https://reactheme.com/products/demo-data/finbiz/main/finbiz-content-onepage.xml',
             
			'import_redux'               => array(
				array(
				'file_url'    => 'https://reactheme.com/products/demo-data/finbiz/main/finbiz-options.json',
				'option_name' => 'finbiz_option',
				),
			),

      	'import_preview_image_url'   => 'https://reactheme.com/products/landing/wp/finbiz/assets/images/demos/01.webp',
     	'import_notice'              => esc_html__( 'Caution: For importing demo data please click on "Import Demo Data" button. During demo data installation please do not refresh the page.', 'finbiz' ),
      	'preview_url'                => 'https://reactheme.com/products/wordpress/finbiz-main/main-home-one-page/',     
      
    ),
	
    
    // constulting
    array(
    	'import_file_name'           => 'Consulting Onepage',
    	'categories'                 => array( 'Constulting' ),
    	'import_file_url'            => 'https://reactheme.com/products/demo-data/finbiz/consulting/finbiz-content-onepage.xml',
             
			'import_redux'               => array(
				array(
				'file_url'    => 'https://reactheme.com/products/demo-data/finbiz/consulting/finbiz-options.json',
				'option_name' => 'finbiz_option',
				),
			),

      	'import_preview_image_url'   => 'https://reactheme.com/products/landing/wp/finbiz/assets/images/demos/02.webp',
     	'import_notice'              => esc_html__( 'Caution: For importing demo data please click on "Import Demo Data" button. During demo data installation please do not refresh the page.', 'finbiz' ),
      	'preview_url'                => 'https://reactheme.com/products/wordpress/finbiz-consulting/consulting-one-page/',     
      
    ),


     // constulting
    array(
    	'import_file_name'           => 'Business Agency Onepage',
    	'categories'                 => array( 'Business Agency' ),
    	'import_file_url'            => 'https://reactheme.com/products/demo-data/finbiz/business-agency/finbiz-content-onepage.xml',
             
			'import_redux'               => array(
				array(
				'file_url'    => 'https://reactheme.com/products/demo-data/finbiz/business-agency/finbiz-options.json',
				'option_name' => 'finbiz_option',
				),
			),

      	'import_preview_image_url'   => 'https://reactheme.com/products/landing/wp/finbiz/assets/images/demos/02.webp',
     	'import_notice'              => esc_html__( 'Caution: For importing demo data please click on "Import Demo Data" button. During demo data installation please do not refresh the page.', 'finbiz' ),
      	'preview_url'                => 'https://reactheme.com/products/wordpress/finbiz-business-agency/business-agency-onepage/',     
      
    ),


	// Corporate Demo
    array(
    	'import_file_name'           => 'Corporate Onepage',
    	'categories'                 => array( 'Corporate' ),
    	'import_file_url'            => 'https://reactheme.com/products/demo-data/finbiz/corporate/finbiz-content-onepage.xml',
             
			'import_redux'               => array(
				array(
				'file_url'    => 'https://reactheme.com/products/demo-data/finbiz/corporate/finbiz-options.json',
				'option_name' => 'finbiz_option',
				),
			),

      	'import_preview_image_url'   => 'https://reactheme.com/products/landing/wp/finbiz/assets/images/demos/03.webp',
     	'import_notice'              => esc_html__( 'Caution: For importing demo data please click on "Import Demo Data" button. During demo data installation please do not refresh the page.', 'finbiz' ),
      	'preview_url'                => 'https://reactheme.com/products/wordpress/finbiz-corporate/corporate-one-page/',     
      
    ),

    // Agency Demo
    array(
    	'import_file_name'           => 'Agency Onepage',
    	'categories'                 => array( 'Agency' ),
    	'import_file_url'            => 'https://reactheme.com/products/demo-data/finbiz/agency/finbiz-content-onepage.xml',
             
			'import_redux'               => array(
				array(
				'file_url'    => 'https://reactheme.com/products/demo-data/finbiz/agency/finbiz-options.json',
				'option_name' => 'finbiz_option',
				),
			),

      	'import_preview_image_url'   => 'https://reactheme.com/products/landing/wp/finbiz/assets/images/demos/03.webp',
     	'import_notice'              => esc_html__( 'Caution: For importing demo data please click on "Import Demo Data" button. During demo data installation please do not refresh the page.', 'finbiz' ),
      	'preview_url'                => 'https://reactheme.com/products/wordpress/finbiz-agency/main-home-one-page/',     
      
    ),


	// Insurance Demo
    array(
    	'import_file_name'           => 'Insurance Onepage',
    	'categories'                 => array( 'Insurance' ),
    	'import_file_url'            => 'https://reactheme.com/products/demo-data/finbiz/insurance/finbiz-content-onepage.xml',
             
		'import_redux'               => array(
			array(
			'file_url'    => 'https://reactheme.com/products/demo-data/finbiz/insurance/finbiz-options.json',
			'option_name' => 'finbiz_option',
			),
		),

      	'import_preview_image_url'   => 'https://reactheme.com/products/landing/wp/finbiz/assets/images/demos/04.webp',
     	'import_notice'              => esc_html__( 'Caution: For importing demo data please click on "Import Demo Data" button. During demo data installation please do not refresh the page.', 'finbiz' ),
      	'preview_url'                => 'https://reactheme.com/products/wordpress/finbiz-insurance/insurance-one-page/',     
      
    ),


	// Marketing Demo
	array(
    	'import_file_name'           => 'Marketing OnePage',
    	'categories'                 => array( 'Marketing' ),
    	'import_file_url'            => 'https://reactheme.com/products/demo-data/finbiz/marketing/finbiz-content-onepage.xml',
             
		'import_redux'               => array(
			array(
			'file_url'    => 'https://reactheme.com/products/demo-data/finbiz/marketing/finbiz-options.json',
			'option_name' => 'finbiz_option',
			),
		),

      	'import_preview_image_url'   => 'https://reactheme.com/products/landing/wp/finbiz/assets/images/demos/05.webp',
     	'import_notice'              => esc_html__( 'Caution: For importing demo data please click on "Import Demo Data" button. During demo data installation please do not refresh the page.', 'finbiz' ),
      	'preview_url'                => 'https://reactheme.com/products/wordpress/finbiz-marketing/marketing-home-2/',     
      
    ),


	// Finance Demo
	array(
    	'import_file_name'           => 'Finace Onepage',
    	'categories'                 => array( 'Finance' ),
    	'import_file_url'            => 'https://reactheme.com/products/demo-data/finbiz/finance/finbiz-content-onepage.xml',
             
		'import_redux'               => array(
			array(
			'file_url'    => 'https://reactheme.com/products/demo-data/finbiz/finance/finbiz-options.json',
			'option_name' => 'finbiz_option',
			),
		),

      	'import_preview_image_url'   => 'https://reactheme.com/products/landing/wp/finbiz/assets/images/demos/06.webp',
     	'import_notice'              => esc_html__( 'Caution: For importing demo data please click on "Import Demo Data" button. During demo data installation please do not refresh the page.', 'finbiz' ),
      	'preview_url'                => 'https://reactheme.com/products/wordpress/finbiz-finance/finance-home-onepage/',     
      
    ),

	// Human Resource Demo
	array(
    	'import_file_name'           => 'HR Onepage',
    	'categories'                 => array( 'HR' ),
    	'import_file_url'            => 'https://reactheme.com/products/demo-data/finbiz/hr/finbiz-content-onepage.xml',
             
		'import_redux'               => array(
			array(
			'file_url'    => 'https://reactheme.com/products/demo-data/finbiz/hr/finbiz-options.json',
			'option_name' => 'finbiz_option',
			),
		),

      	'import_preview_image_url'   => 'https://reactheme.com/products/landing/wp/finbiz/assets/images/demos/07.webp',
     	'import_notice'              => esc_html__( 'Caution: For importing demo data please click on "Import Demo Data" button. During demo data installation please do not refresh the page.', 'finbiz' ),
      	'preview_url'                => 'https://reactheme.com/products/wordpress/finbiz-hr/hr-one-page/',     
      
    ),

	// IT Demo
	array(
    	'import_file_name'           => 'IT Onepage',
    	'categories'                 => array( 'IT Solutions' ),
    	'import_file_url'            => 'https://reactheme.com/products/demo-data/finbiz/it/finbiz-content-onepage.xml',
             
		'import_redux'               => array(
			array(
			'file_url'    => 'https://reactheme.com/products/demo-data/finbiz/it/finbiz-options.json',
			'option_name' => 'finbiz_option',
			),
		),

      	'import_preview_image_url'   => 'https://reactheme.com/products/landing/wp/finbiz/assets/images/demos/08.webp',
     	'import_notice'              => esc_html__( 'Caution: For importing demo data please click on "Import Demo Data" button. During demo data installation please do not refresh the page.', 'finbiz' ),
      	'preview_url'                => 'https://reactheme.com/products/wordpress/finbiz-it/it-solutions-onepage/',     
      
    ),
	//startup
	array(
    	'import_file_name'           => 'Startup Onepage',
    	'categories'                 => array( 'Startup' ),
    	'import_file_url'            => 'https://reactheme.com/products/demo-data/finbiz/startup/finbiz-content-onepage.xml',
             
		'import_redux'               => array(
			array(
			'file_url'    => 'https://reactheme.com/products/demo-data/finbiz/startup/finbiz-options.json',
			'option_name' => 'finbiz_option',
			),
		),

      	'import_preview_image_url'   => 'https://reactheme.com/products/landing/wp/finbiz/assets/images/demos/09.webp',
     	'import_notice'              => esc_html__( 'Caution: For importing demo data please click on "Import Demo Data" button. During demo data installation please do not refresh the page.', 'finbiz' ),
      	'preview_url'                => 'https://reactheme.com/products/wordpress/finbiz-startup/stratup-agency-one/',     
      
    ),

	// Branding Agency
	array(
    	'import_file_name'           => 'Branding Onepage',
    	'categories'                 => array( 'Branding Agency' ),
    	'import_file_url'            => 'https://reactheme.com/products/demo-data/finbiz/branding/finbiz-content-onepage.xml',
             
		'import_redux'               => array(
			array(
			'file_url'    => 'https://reactheme.com/products/demo-data/finbiz/branding/finbiz-options.json',
			'option_name' => 'finbiz_option',
			),
		),

      	'import_preview_image_url'   => 'https://reactheme.com/products/landing/wp/finbiz/assets/images/demos/11.webp',
     	'import_notice'              => esc_html__( 'Caution: For importing demo data please click on "Import Demo Data" button. During demo data installation please do not refresh the page.', 'finbiz' ),
      	'preview_url'                => 'https://reactheme.com/products/wordpress/finbiz-branding/branding-agency-one/',     
      
    ),
	// Finbiz Business OnePage
	array(
    	'import_file_name'           => 'Business OnePage',
    	'categories'                 => array( 'Business OnePage' ),
    	'import_file_url'            => 'https://reactheme.com/products/demo-data/finbiz/finbiz-business/finbiz-content.xml',
		'import_redux'               => array(
			array(
			'file_url'    => 'https://reactheme.com/products/demo-data/finbiz/finbiz-business/finbiz-options.json',
			'option_name' => 'finbiz_option',
			),
		),
      	'import_preview_image_url'   => 'https://reactheme.com/products/landing/wp/finbiz/assets/images/demos/12.webp',
     	'import_notice'              => esc_html__( 'Caution: For importing demo data please click on "Import Demo Data" button. During demo data installation please do not refresh the page.', 'finbiz' ),
      	'preview_url'                => 'https://reactheme.com/products/wordpress/finbiz-business/main-home-one-page/',
    ),

	//RTL Demo
    array(
      'import_file_name'           => 'Finbiz RTL Demo',
      'categories'                 => array( 'Business(RTL)' ),
      'import_file_url'            => 'https://reactheme.com/products/demo-data/finbiz/rtl/finbiz-content.xml',
             
      'import_redux'               => array(
        array(
          'file_url'    => 'https://reactheme.com/products/demo-data/finbiz/rtl/rtl/finbiz-option.json',
          'option_name' => 'finbiz_option',
        ),
      ),

      'import_preview_image_url'   => 'https://reactheme.com/products/banner/finbiz/wp/rtl.png',
     'import_notice'              => esc_html__( 'Caution: For importing demo data please click on "Import Demo Data" button. During demo data installation please do not refresh the page.', 'finbiz' ),
      'preview_url'                => 'https://reactheme.com/products/wordpress/finbiz-rtl',     
      
    ), 
    
  );
}

add_filter( 'pt-ocdi/import_files', 'finbiz_import_files' );
function finbiz_after_import_setup() {
  // Assign menus to their locations.
	$main_menu     = get_term_by( 'name', 'Primary Menu', 'nav_menu' );
  $menu_single     = get_term_by( 'name', 'Single Menu', 'nav_menu' );
	set_theme_mod( 'nav_menu_locations', array(
      'menu-1' => $main_menu->term_id, 
      'menu-2' => $menu_single->term_id,      
    )
  );

 // Assign front page and posts page (blog page).
    if( 'Default Demo' == $selected_import['import_file_name'] ) {
		$front_page_id = get_page_by_title( 'Main Home' );
	}
  
	if( 'Consulting Demo' == $selected_import['import_file_name'] ) {
		$front_page_id = get_page_by_title( 'Consulting Home' );
	}

	if( 'Corporate Demo' == $selected_import['import_file_name'] ) {
		$front_page_id = get_page_by_title( 'Corporate Home' );
	}

	if( 'Business Agency' == $selected_import['import_file_name'] ) {
		$front_page_id = get_page_by_title( 'Business agency' );
	}

	if( 'Insurance Demo' == $selected_import['import_file_name'] ) {
		$front_page_id = get_page_by_title( 'Insurance Home' );
	}
	if( 'Marketing Demo' == $selected_import['import_file_name'] ) {
		$front_page_id = get_page_by_title( 'Marketing Home' );
	}
	if( 'Finace Demo' == $selected_import['import_file_name'] ) {
		$front_page_id = get_page_by_title( 'Finance Home' );
	}
	if( 'HR Demo' == $selected_import['import_file_name'] ) {
		$front_page_id = get_page_by_title( 'Human Resource' );
	}
	if( 'IT Demo' == $selected_import['import_file_name'] ) {
		$front_page_id = get_page_by_title( 'IT Solutions' );
	}
	if( 'Modern Agency' == $selected_import['import_file_name'] ) {
		$front_page_id = get_page_by_title( 'Modern Agency' );
	}
	if( 'Startup Agency' == $selected_import['import_file_name'] ) {
		$front_page_id = get_page_by_title( 'Startup Agency' );
	}
	if( 'Branding Agency' == $selected_import['import_file_name'] ) {
		$front_page_id = get_page_by_title( 'Branding Agency' );
	}
	if( 'Branding Agency' == $selected_import['import_file_name'] ) {
		$front_page_id = get_page_by_title( 'Branding Agency' );
	}
	if( 'Business' == $selected_import['import_file_name'] ) {
		$front_page_id = get_page_by_title( 'Business' );
	}

	//onepage demo home
	if( 'Default Onepage' == $selected_import['import_file_name'] ) {
		$front_page_id = get_page_by_title( 'Main Home One Page' );
	}

	if( 'Consulting Onepage' == $selected_import['import_file_name'] ) {
		$front_page_id = get_page_by_title( 'Consulting One Page' );
	}

	if( 'Business Agency Onepage' == $selected_import['import_file_name'] ) {
		$front_page_id = get_page_by_title( 'Business agency Onepage' );
	}

	if( 'Corporate Onepage' == $selected_import['import_file_name'] ) {
		$front_page_id = get_page_by_title( 'Corporate One Page' );
	}

	if( 'Insurance Onepage' == $selected_import['import_file_name'] ) {
		$front_page_id = get_page_by_title( 'Insurance One Page' );
	}

	if( 'Marketing OnePage' == $selected_import['import_file_name'] ) {
		$front_page_id = get_page_by_title( 'Marketing One Page' );
	}

	if( 'Finace Onepage' == $selected_import['import_file_name'] ) {
		$front_page_id = get_page_by_title( 'Finance One Page' );
	}

	if( 'HR Onepage' == $selected_import['import_file_name'] ) {
		$front_page_id = get_page_by_title( 'HR One Page' );
	}

	if( 'IT Onepage' == $selected_import['import_file_name'] ) {
		$front_page_id = get_page_by_title( 'IT Solutions OnePage' );
	}

	if( 'Agecny Onepage' == $selected_import['import_file_name'] ) {
		$front_page_id = get_page_by_title( 'Agency One Page' );
	}

	if( 'Startup Onepage' == $selected_import['import_file_name'] ) {
		$front_page_id = get_page_by_title( 'Startup One Page' );
	}

	if( 'Branding Onepage' == $selected_import['import_file_name'] ) {
		$front_page_id = get_page_by_title( 'Branding Agency One' );
	}

	if( 'Business OnePage' == $selected_import['import_file_name'] ) {
		$front_page_id = get_page_by_title( 'Business OnePage' );
	}

	if( 'Finbiz RTL Demo' == $selected_import['import_file_name'] ) {
		$front_page_id = get_page_by_title( 'Main Home' );
	}
 
  $blog_page_id  = get_page_by_title( 'Blog List' );
  update_option( 'show_on_front', 'page' );
  update_option( 'page_on_front', $front_page_id->ID );
  update_option( 'page_for_posts', $blog_page_id->ID ); 

  //Import Revolution Slider
  if ( class_exists( 'RevSlider' ) ) {
    $slider_array = array(
      get_template_directory()."/inc/demo-data/sliders/home1-slider.zip",                            
      get_template_directory()."/inc/demo-data/sliders/home-2-slider.zip",                            
      get_template_directory()."/inc/demo-data/sliders/home-3-slider.zip",                            
      get_template_directory()."/inc/demo-data/sliders/home-4-slider.zip",                            
      get_template_directory()."/inc/demo-data/sliders/home-3-slider-1.zip",                            
      get_template_directory()."/inc/demo-data/sliders/it-solutions.zip",                            
      get_template_directory()."/inc/demo-data/sliders/business-agency.zip",                            
    );
    $slider = new RevSlider();
    foreach($slider_array as $filepath){
      $slider->importSliderFromPost(true,true,$filepath);  
    }
  }
}
add_action( 'pt-ocdi/after_import', 'finbiz_after_import_setup' );
add_filter( 'use_widgets_block_editor', '__return_false' );

function finbiz_mime_types($mimes) {
  $mimes['svg'] = 'image/svg+xml';
  return $mimes;
}
add_filter('upload_mimes', 'finbiz_mime_types');
//disable elementor default styles
update_option('elementor_disable_color_schemes', 'yes');
update_option('elementor_disable_typography_schemes', 'yes');

//added elementor support for custom post type
function finbiz_enable_elementor_for_custom_post_type() {
  add_post_type_support( 'rt-portfolios', 'elementor' );
  add_post_type_support( 'teams', 'elementor' );
  add_post_type_support( 'rts-canvans', 'elementor' );
  add_post_type_support( 'rtelements_pro', 'elementor' );
  add_post_type_support( 'rts-header', 'elementor' );
  add_post_type_support( 'rts-footer', 'elementor' );
}
add_action( 'init', 'finbiz_enable_elementor_for_custom_post_type' );


add_filter( 'finbiz_localized_site_names', function ( $names ) {
    $names['ar'] = 'الريان'; // شركة خليفة والريان   
    return $names;
} );








// الرابط الجديد
define('CUSTOM_LOGIN_SLUG', 'es-dash');

// إنشاء Rewrite Rule
add_action('init', function () {
    add_rewrite_rule(
        '^' . CUSTOM_LOGIN_SLUG . '/?$',
        'wp-login.php',
        'top'
    );
});

// منع wp-admin و wp-login.php
add_action('init', function () {

    $uri = $_SERVER['REQUEST_URI'];

    if (
        !is_user_logged_in() &&
        (
            strpos($uri, '/wp-admin') !== false ||
            strpos($uri, 'wp-login.php') !== false
        ) &&
        strpos($uri, '/' . CUSTOM_LOGIN_SLUG) === false
    ) {

        global $wp_query;
        $wp_query->set_404();
        status_header(404);
        nocache_headers();

        if (get_404_template()) {
            include get_404_template();
        } else {
            wp_die('404 Not Found');
        }

        exit;
    }
}, 999);