<?php






/**
 * Enqueue a script in the WordPress admin on edit.php.
 *
 * @param int $hook Hook suffix for the current admin page.
 */
function wpdocs_selectively_enqueue_admin_script( $hook ) {
    if ( 'post.php' != $hook ) {
        return;
    }
    wp_enqueue_script( 'my_custom_script', get_stylesheet_directory_uri() . '/js/scripts-admin.js', array(), '1.0' );
  }
  add_action( 'admin_enqueue_scripts', 'wpdocs_selectively_enqueue_admin_script', PHP_INT_MAX );




  // pour pouvoir styliser admin (et masquer éléments)
  // custom admin style sheet
  function my_admin_head() {
    echo '<link href="'.get_stylesheet_directory_uri().'/css/wp-admin.css" rel="stylesheet" type="text/css">';
  }
  add_action('admin_head', 'my_admin_head');










/************************************************************************** */


// add pages to admin menu
//https://stackoverflow.com/questions/39978561/how-to-add-custom-link-on-wordpress-admin-sidebar
add_action( 'admin_menu', 'linked_url' );
function linked_url() {
// add_menu_page( 'linked_url', 'FAQ', 'read', '/post.php?post=29&action=edit', '', 'dashicons-text', 50 );
// add_menu_page( 'linked_url', 'Liens utiles', 'read', '/post.php?post=49&action=edit', '', 'dashicons-admin-links', 55 );
// on va ajouter le lien vers la page d'accueil uniquement pour éditeur plus bas
}




// si lien externe dans admin menu
// add_action( 'admin_menu' , 'linkedurl_function' );
// function linkedurl_function() {
// global $menu;
// $menu[1][2] = "http://www.example.com";
// }


/************************************************************************** */


add_action( 'admin_menu', 'add_admin_menu_separator' );
function add_admin_menu_separator()
{
    add_menu_page( '', '', 'read', 'wp-menu-separator', '', '', '21' );
    add_menu_page( '', '', 'read', 'wp-menu-separator', '', '', '56' );
    // add_submenu_page( 'edit.php?post_type=page', 'wp-menu-separator', '', 'read', '11', '' );
}






// add_action('admin_init','dump_admin_menu');
// function dump_admin_menu() {
//   if (is_admin()) {
//     header('Content-Type:text/plain');
//     var_dump($GLOBALS['menu']);
//     exit;
//   }
// }




/* COMMENTS // https://www.powderkegwebdesign.com/quickly-easily-remove-comments-backend-wordpress/
* Remove comments in its entirety
*/


// Removes from admin menu
add_action( 'admin_menu', 'pk_remove_admin_menus' );
function pk_remove_admin_menus() {
    remove_menu_page( 'edit-comments.php' );
}


// Removes from post and pages
add_action('init', 'pk_remove_comment_support', 100);
  function pk_remove_comment_support() {
   remove_post_type_support( 'post', 'comments' );
   remove_post_type_support( 'page', 'comments' );
}


// Removes from admin bar
add_action( 'wp_before_admin_bar_render', 'pk_remove_comments_admin_bar' );
function pk_remove_comments_admin_bar() {
    global $wp_admin_bar;
    $wp_admin_bar->remove_menu('comments');
  }








/************************************************************************** */


// remove elements from editor menu


function remove_menus(){
  // get current login user's role
  $roles = wp_get_current_user()->roles;


  // test role
  if( !in_array('editor',$roles)){
  return;
  }


  //remove menu from site backend.
//   remove_menu_page( 'index.php' ); //Dashboard
  remove_menu_page( 'edit.php' ); //Posts
  remove_menu_page( 'upload.php' ); //Media
  remove_menu_page( 'edit-comments.php' ); //Comments
  remove_menu_page( 'themes.php' ); //Appearance
  remove_menu_page( 'plugins.php' ); //Plugins


  // remove_menu_page( 'profile.php' ); //profile
  remove_menu_page( 'users.php' ); //Users
  remove_menu_page( 'tools.php' ); //Tools
  remove_menu_page( 'options-general.php' ); //Settings
  remove_menu_page( 'edit.php?post_type=page' ); //Pages
  // remove_menu_page('edit.php?post_type=testimonial'); // Custom post type 1
  // remove_menu_page('edit.php?post_type=homeslider'); // Custom post type 2


  // remove_menu_page( 'WPML' );
  // remove_menu_page( 'Traductions' );
  // remove_menu_page( 'wpml_manage_languages' );
  // remove_menu_page( 'sitepress-multilingual-cms/menu/languages.php' );
  // remove_menu_page( 'admin.php?page=wpml-translation-management/menu/translations-queue.php' );
  // remove_menu_page( 'admin.php' );
  // remove_menu_page( '#toplevel_page_wpml-translation-management-menu-translations-queue' );
  remove_menu_page( 'edit.php?post_type=elementor_library' );




  // ajout lien vers page d'accueil
  add_menu_page( 'linked_url', 'Page d\'accueil', 'read', '/post.php?post=147&action=elementor', '', 'dashicons-admin-home', 10 );
  add_menu_page( 'linked_url', 'Menu', 'read', '/post.php?post=22&action=edit', '', 'dashicons-food', 11 );




  }
  add_action( 'admin_menu', 'remove_menus' , 100 );