<?php
// ---------------
// ADVANDED CUSTOM FIELDS
// ---------------

//Google maps api key
add_filter('acf/settings/google_api_key', function () {
  return 'AIzaSyDi4wYgHpk9b_bG1raFgKe5qyRlet9C7Ng';
});

// Nascondo ACF field group dal menu principale
// add_filter('acf/settings/show_admin', '__return_false');


// Cambio la cartella di destinazione dei Json
function my_acf_json_save_point( $path ) {
  // update path
  $path = get_stylesheet_directory() . '/functions/init/custom-fields/acf-json';
  // return
  return $path;
}
add_filter('acf/settings/save_json', 'my_acf_json_save_point');


// Dico ad ACF di prendere gli acf da una cartella in formato Json
function my_acf_json_load_point( $paths ) {
  // remove original path (optional)
  unset($paths[0]);
  // append path
  $paths[] = get_stylesheet_directory() . '/functions/init/custom-fields/acf-json';
  // return
  return $paths;
}
add_filter('acf/settings/load_json', 'my_acf_json_load_point');


// ---------------
// ADMIN PAGES
// ------------------------------------------------------

if( function_exists('acf_add_options_page') ) {
  if (!function_exists('dueper_add_options_pages')) {
    add_action( 'init', 'dueper_add_options_pages' );
    function dueper_add_options_pages(){
      $general_conf = acf_add_options_page(array(
        'page_title' 	=> 'Configurazioni generali',
        'menu_title' 	=> 'Configurazioni',
        'menu_slug' 	=> 'theme-general-conf',
        'capability' 	=> 'edit_others_pages',//Editor
        'redirect'    => true,
        'icon_url'    => 'dashicons-welcome-view-site'
      ));

      acf_add_options_sub_page(array(
        'page_title' 	=> 'Opzioni generali',
        'menu_title' 	=> 'Generali',
        'parent_slug' 	=> $general_conf['menu_slug'],
      ));
      acf_add_options_sub_page(array(
        'page_title' 	=> 'Opzioni avanzate',
        'capability'  => 'update_core',
        'menu_title' 	=> 'Avanzate',
        'parent_slug' 	=> $general_conf['menu_slug'],
      ));

      $social_page = acf_add_options_page(array(
        'page_title' 	=> 'Account social',
        'menu_title' 	=> 'Social',
        'menu_slug' 	=> 'theme-social-account',
        'capability' 	=> 'edit_others_pages',//Editor
        'redirect'    => true,
        'icon_url'    => 'dashicons-share'
      ));
    }
  }
}
