<?php

/* IOF GEREMIA FUNCTIONS */

/**
 * WP Bootstrap Starter functions and definitions
 *
 * @link https://developer.wordpress.org/themes/basics/theme-functions/
 *
 * @package WP_Bootstrap_Starter
 */

if ( ! function_exists( 'puraluce_setup' ) ) :
/**
 * Sets up theme defaults and registers support for various WordPress features.
 *
 * Note that this function is hooked into the after_setup_theme hook, which
 * runs before the init hook. The init hook is too late for some features, such
 * as indicating support for post thumbnails.
 */
function puraluce_setup() {
    /*
     * Make theme available for translation.
     * Translations can be filed in the /languages/ directory.
     * If you're building a theme based on WP Bootstrap Starter, use a find and replace
     * to change 'wp-bootstrap-starter' to the name of your theme in all the template files.
     */
    load_theme_textdomain( 'puraluce', get_template_directory() . '/languages' );

    // Add default posts and comments RSS feed links to head.
    add_theme_support( 'automatic-feed-links' );

    /*
     * Let WordPress manage the document title.
     * By adding theme support, we declare that this theme does not use a
     * hard-coded <title> tag in the document head, and expect WordPress to
     * provide it for us.
     */
    add_theme_support( 'title-tag' );

    /*
     * Enable support for Post Thumbnails on posts and pages.
     *
     * @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
     */
    add_theme_support( 'post-thumbnails' );



add_action( 'after_setup_theme', 'woocommerce_support' );

function woocommerce_support() {
add_theme_support( 'woocommerce' );
    add_theme_support( 'wc-product-gallery-zoom' );
    add_theme_support( 'wc-product-gallery-lightbox' );
    add_theme_support( 'wc-product-gallery-slider' );

}

/* =============================================================
IMAGES AND THUMBNAILS
================================================================ */

/**
 * Add automatic image sizes
 */
if ( function_exists( 'add_image_size' ) ) {
    add_image_size( 'anteprima_prodotto', 450, 450, true ); //(cropped)
}



    // This theme uses wp_nav_menu() in one location. MENU 1
    register_nav_menus( array(
        'navigazione' => esc_html__( 'navigazione', 'puraluce' ),
    ) );

    // This theme uses wp_nav_menu() in one location. MENU 2
    register_nav_menus( array(
        'secondary' => esc_html__( 'Secondary', 'puraluce' ),
    ) );

    // This theme uses wp_nav_menu() in one location. MENU 3
    register_nav_menus( array(
        'lingue' => esc_html__( 'lingue', 'puraluce' ),
    ) );

      // This theme uses wp_nav_menu() in one location. MENU 4
    register_nav_menus( array(
        'menu_footer' => esc_html__( 'Menu Footer', 'puraluce' ),
    ) );


    /*
     * Switch default core markup for search form, comment form, and comments
     * to output valid HTML5.
     */
    add_theme_support( 'html5', array(
        'comment-form',
        'comment-list',
        'caption',
    ) );

    // Add theme support for selective refresh for widgets.
    add_theme_support( 'customize-selective-refresh-widgets' );

    function puraluce_add_editor_styles() {
        add_editor_style( 'custom-editor-style.css' );
    }
    add_action( 'admin_init', 'puraluce_add_editor_styles' );

}
endif;
add_action( 'after_setup_theme', 'puraluce_setup' );



/**
 * Register widget area.
 *
 * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
 */
function puraluce_widgets_init() {
    register_sidebar( array(
        'name'          => esc_html__( 'Sidebar', 'puraluce' ),
        'id'            => 'sidebar-1',
        'description'   => esc_html__( 'Add widgets here.', 'puraluce' ),
        'before_widget' => '<section id="%1$s" class="widget %2$s">',
        'after_widget'  => '</section>',
        'before_title'  => '<h3 class="widget-title">',
        'after_title'   => '</h3>',
    ) );
    register_sidebar( array(
        'name'          => esc_html__( 'Footer 1', 'puraluce' ),
        'id'            => 'footer-1',
        'description'   => esc_html__( 'Add widgets here.', 'puraluce' ),
        'before_widget' => '<section id="%1$s" class="widget %2$s">',
        'after_widget'  => '</section>',
        'before_title'  => '<h3 class="widget-title">',
        'after_title'   => '</h3>',
    ) );
    register_sidebar( array(
        'name'          => esc_html__( 'Footer 2', 'puraluce' ),
        'id'            => 'footer-2',
        'description'   => esc_html__( 'Add widgets here.', 'puraluce' ),
        'before_widget' => '<section id="%1$s" class="widget %2$s">',
        'after_widget'  => '</section>',
        'before_title'  => '<h3 class="widget-title">',
        'after_title'   => '</h3>',
    ) );
    register_sidebar( array(
        'name'          => esc_html__( 'Footer 3', 'puraluce' ),
        'id'            => 'footer-3',
        'description'   => esc_html__( 'Add widgets here.', 'puraluce' ),
        'before_widget' => '<section id="%1$s" class="widget %2$s">',
        'after_widget'  => '</section>',
        'before_title'  => '<h3 class="widget-title">',
        'after_title'   => '</h3>',
    ) );
}
add_action( 'widgets_init', 'puraluce_widgets_init' );



/**
 * Enqueue scripts and styles.
 */

function puraluce_scripts() {

    // CSS ==============
    // load bootstrap css
    wp_register_style( 'bootstrap-css', 'https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css' );
    wp_enqueue_style( 'bootstrap-css');

    // load font awesome
    wp_register_style( 'fontawesome-cdn', 'https://use.fontawesome.com/releases/v5.1.0/css/all.css' );
    wp_enqueue_style( 'fontawesome-cdn');

     // load AOS css
  /*  wp_register_style( 'aos-css-cdn', 'https://unpkg.com/aos@2.3.1/dist/aos.css' );
    wp_enqueue_style( 'aos-css-cdn'); */

    // load CSS init theme
    wp_enqueue_style( 'starter-style', get_stylesheet_uri() );

          // load MAGNIFIC POPUP CSS
    wp_enqueue_style( 'magnific_popup-css', get_template_directory_uri() . '/css/magnific-popup.css' );

         // load SWIPER CSS
    wp_enqueue_style( 'swiper-css', get_template_directory_uri() . '/css/swiper.css' );

    // load Custom CSS
    wp_enqueue_style( 'custom-style-css', get_template_directory_uri() . '/css/style.css' );

    // JS ==============
    // load JQUERY
   wp_enqueue_script( 'jquery-js-cdn','https://code.jquery.com/jquery-3.3.1.min.js', array('jquery'));

    // load BOOTSTRAP
  wp_enqueue_script( 'bootstrap-js-cdn','https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js', array('jquery'));



     // load MAGNIFIC POPUP
    wp_enqueue_script( 'magnific_popup-js', get_template_directory_uri() . '/js/magnific-popup.js');

        // load ENLLAX JS
    wp_enqueue_script( 'enllax-js', get_template_directory_uri() . '/js/enllax.js');

       // load SWIPER JS
    wp_enqueue_script( 'swiper-js', get_template_directory_uri() . '/js/swiper.js');

     // load AOS JS
 /* wp_enqueue_script( 'aos-js-cdn','https://unpkg.com/aos@2.3.1/dist/aos.js', array('jquery')); */

    // load CUSTOM JS
    wp_enqueue_script( 'custom-js', get_template_directory_uri() . '/js/script.js');

}

add_action( 'wp_enqueue_scripts', 'puraluce_scripts' );




/**
 * Custom template tags for this theme.
 */
require get_template_directory() . '/inc/template-tags.php';


/**
 * Load plugin compatibility file.
 */
require get_template_directory() . '/inc/plugin-compatibility/plugin-compatibility.php';

/**
 * Load custom WordPress nav walker.
 */

    require_once(get_template_directory() . '/inc/assets/wp_bootstrap_navwalker.php');

/**
 * aggiungere funzione per aggiungere classe al link del menu in funzione active
 */


add_filter('nav_menu_css_class' , 'aggiungi_active_menu_cliccato' , 10 , 2);

function aggiungi_active_menu_cliccato ($classes, $item) {
if (in_array('current-menu-item', $classes) ){
$classes[] = 'attivato';
}
return $classes;
}



/**
 * dichiarare opzioni custom
 */


/**
 * dichiarare opzioni custom
 */


if( function_exists('acf_add_options_page') ) {

    acf_add_options_page(array(
        'page_title'     => 'Theme General Settings',
        'menu_title'    => 'Puraluce Option',
        'menu_slug'     => 'theme-general-settings',
        'capability'    => 'edit_posts',
        'redirect'        => false
    ));

    acf_add_options_sub_page(array(
        'page_title'     => 'Theme Footer Settings',
        'menu_title'    => 'Footer',
        'parent_slug'    => 'theme-general-settings',
    ));


    acf_add_options_sub_page(array(
        'page_title'     => 'Socials',
        'menu_title'    => 'Socials',
        'parent_slug'    => 'theme-general-settings',
    ));

}


/* ===================================================================
PAGINAZIONE ARCHIVIO E TASSONOMIE
====================================================================== */


// Numbered Pagination
function paginazione_post() {
    global $wp_query;
        $big = 999999999; // need an unlikely integer
            echo paginate_links( array(
            'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
            'format' => '?paged=%#%',
            'current' => max( 1, get_query_var('paged') ),
            'total' => $wp_query->max_num_pages
        ) );
}

/* FINE PHP */
?>
