<?php
/**
 * Menu_Order Class
 *
 * @package dvcrs-core
 */

namespace DVCRS\Core;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Menu_Order Class
 */
class Menu_Order {

	/**
	 * Menu_Order constructor
	 */
	public function __construct() {

		\add_action( 'admin_menu', [ $this, 'set_admin_menu_separator' ] );
		\add_filter( 'custom_menu_order', [ $this, 'custom_menu_order' ] );
		\add_filter( 'menu_order', [ $this, 'custom_menu_order' ] );

	}

	/**
	 * Add WordPress admin menu separators
	 */
	public function set_admin_menu_separator() {

		global $menu;

		$menu[79] = array(
			0 => '',
			1 => 'read',
			2 => 'separator79',
			3 => '',
			4 => 'wp-menu-separator',
		);

		$menu[89] = array(
			0 => '',
			1 => 'read',
			2 => 'separator89',
			3 => '',
			4 => 'wp-menu-separator',
		);
	}

	/**
	 * Customize WordPress admin menu order
	 *
	 * @param array $menu Array of WordPress admin menu items.
	 *
	 * @return array
	 */
	public function custom_menu_order( $menu ) {

		if ( ! $menu ) {
			return true;
		}

		$custom_menu = [
			'index.php',
			'separator1',
			'edit.php?post_type=page',
			'nestedpages',
			'edit.php',
			'edit.php?post_type=person',
			'edit.php?post_type=resort',
			'edit.php?post_type=review',
			'separator2',
			'upload.php',
			'edit-comments.php',
			'separator79',
			'users.php',
			'themes.php',
			'plugins.php',
			'tools.php',
			'options-general.php',
			'separator-last',
			'wpseo_dashboard',
			'separator89',
		];

		$diff_menu = array_diff( $menu, $custom_menu );

		return array_merge( $custom_menu, $diff_menu );
	}

}

new Menu_Order();
