<?php

require_once __DIR__ . '/includes/admin-customize.php';
require_once __DIR__ . '/includes/clean.php';

function theme_enqueue_styles()
{
    wp_enqueue_style('child-style', get_stylesheet_directory_uri() . '/style.css');
}

add_action('wp_enqueue_scripts', 'theme_enqueue_styles', 99);


/* ---------------------------------------------------------------------------
 * Enqueue Scripts
 * --------------------------------------------------------------------------- */
add_action('wp_enqueue_scripts', 'mfnch_enqueue_scripts', 101);
function mfnch_enqueue_scripts()
{
    wp_enqueue_script('custom-script', get_stylesheet_directory_uri() . '/dist/scripts/main.min.js', array('jquery'), '1.0', true);
}

// add_action('wp_head', 'add_ga4_placeholder');
function add_ga4_placeholder()
{
    ?>
    <!-- Google Analytics 4 managed by tarteaucitron -->
    <script type="text/plain" class="tarteaucitron-google-analytics">
        (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
        (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
        m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
        })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
    </script>
    <?php
}

// REMOVE ELEMENT FROM ADMIN MENU
function deuxtorrent_admin_page_removing()
{
    remove_menu_page('index.php');                  //Dashboard
//  remove_menu_page( 'edit.php?post_type=page' );    //Pages
    remove_menu_page('edit.php?post_type=themefusion_elastic');    //portfolio
    remove_menu_page('edit.php?post_type=avada_portfolio');    //portfolio
    remove_menu_page('edit.php?post_type=avada_faq');    //Pages
    remove_menu_page('edit.php');                   //Posts
    remove_menu_page('edit-comments.php');          //Comments
    remove_menu_page('options-discussion.php');          //setup Comments
}

add_action('admin_menu', 'deuxtorrent_admin_page_removing');

function avada_lang_setup()
{
    $lang = get_stylesheet_directory() . '/languages';
    load_child_theme_textdomain('Avada', $lang);
}

add_action('after_setup_theme', 'avada_lang_setup');


/* ---------------------------------------------------------------------------
 * ACF OPTIONS PAGE
 * --------------------------------------------------------------------------- */
/*if( function_exists('acf_add_options_page') ) {
  acf_add_options_page(array(
    'page_title' 	=> 'Paramètres du site',
    'menu_title' 	=> 'Paramètres du site',
    'menu_slug' 	=> 'deuxtorrents-general-settings',
    'capability' 	=> 'edit_posts',
    'redirect' 	=> false
  ));
}*/

if (function_exists('acf_add_options_page')) {
    acf_add_options_page(array(
        'page_title' => 'Documents téléchargeables',
        'menu_title' => 'Documents téléchargeables',
        'menu_slug'  => 'deuxtorrents-downloads',
        'capability' => 'edit_posts',
        'redirect'   => false
    ));
}


//add SVG to allowed file uploads
function add_file_types_to_uploads($file_types)
{

    $new_filetypes = array();
    $new_filetypes['svg'] = 'image/svg+xml';
    $file_types = array_merge($file_types, $new_filetypes);

    return $file_types;
}

add_action('upload_mimes', 'add_file_types_to_uploads');

//////////////////////////
///  RSS ZONE
////////////////////////////
function rss_widgets_init()
{
    register_sidebar(array(
        'name'        => 'RSS zone',
        'id'          => 'rss-widget-area',
        'description' => 'Récupération des flux d\'actualités de notaires.fr',
    ));
}

add_action('widgets_init', 'rss_widgets_init');
include_once __DIR__ . '/widget/class-rss-widget.php';


function footersecondaire_widgets_init()
{
    register_sidebar(array(
        'name'        => 'Footer secondaire',
        'id'          => 'footersecondaire-widget-area',
        'description' => 'Footer secondaire',
    ));
}

add_action('widgets_init', 'footersecondaire_widgets_init');

function footersecondaireUN_widgets_init()
{
    register_sidebar(array(
        'name'        => 'Footer secondaire 1',
        'id'          => 'footersecondaire-widget-area-1',
        'description' => 'Footer secondaire 1',
    ));
}

add_action('widgets_init', 'footersecondaireUN_widgets_init');

function footersecondaireDEUX_widgets_init()
{
    register_sidebar(array(
        'name'        => 'Footer secondaire 2',
        'id'          => 'footersecondaire-widget-area-2',
        'description' => 'Footer secondaire 2',
    ));
}

add_action('widgets_init', 'footersecondaireDEUX_widgets_init');

function footersecondaireTROIS_widgets_init()
{
    register_sidebar(array(
        'name'        => 'Footer secondaire 3',
        'id'          => 'footersecondaire-widget-area-3',
        'description' => 'Footer secondaire 3',
    ));
}

add_action('widgets_init', 'footersecondaireTROIS_widgets_init');

//function download_widgets_init() {
//  register_sidebar( array(
//    'name' => 'Download zone',
//    'id' => 'download-widget-area',
//    'description'   => 'Récupération des documents téléchargles de pied de page',
//  ) );
//}

//add_action( 'widgets_init', 'download_widgets_init' );

include_once __DIR__ . '/widget/class-download-widget.php';

require_once __DIR__ . '/includes/ctp.php';

show_admin_bar(false);




// Add "nocookie" To WordPress oEmbeded Youtube Videos
function wpex_youtube_nocookie_oembed( $return ) {
	$return = str_replace( 'youtube', 'youtube-nocookie', $return );
	return $return;
}
add_filter( 'oembed_dataparse', 'wpex_youtube_nocookie_oembed' );


