<?php
/**
 * Plugin Name: Agency Pulse - Admin Customizer & Menu Organizer
 * Plugin URI: https://www.agencypulsewp.com/plugins/admin-menu-organizer
 * Description: A visual drag-and-drop admin menu builder and admin customizer for WordPress. Reorder, rename, hide, and group any admin menu item and brand and customize the admin interface without code.
 * Version: 1.1.0
 * Author: Agency Pulse
 * Author URI: https://www.agencypulsewp.com
 * License: GPL-2.0-or-later
 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
 * Text Domain: agency-pulse-admin-menu
 * Domain Path: /languages
 * Requires at least: 5.8
 * Requires PHP: 7.4
 * Tested up to: 6.7
 * Tags: admin menu, menu organizer, menu builder, admin ui, wordpress admin
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly.
}

/**
 * Define plugin constants
 */
if ( ! defined( 'AGENCY_PULSE_ADMIN_MENU_FILE' ) ) {
	define( 'AGENCY_PULSE_ADMIN_MENU_FILE', __FILE__ );
}

if ( ! defined( 'AGENCY_PULSE_ADMIN_MENU_DIR' ) ) {
	define( 'AGENCY_PULSE_ADMIN_MENU_DIR', plugin_dir_path( __FILE__ ) );
}

if ( ! defined( 'AGENCY_PULSE_ADMIN_MENU_URL' ) ) {
	define( 'AGENCY_PULSE_ADMIN_MENU_URL', plugin_dir_url( __FILE__ ) );
}

if ( ! defined( 'AGENCY_PULSE_ADMIN_MENU_VERSION' ) ) {
	define( 'AGENCY_PULSE_ADMIN_MENU_VERSION', '1.1.0' );
}

/**
 * Plugin activation.
 *
 * Grants the ap_menu_manager capability to the administrator role and records
 * the initial DB schema version. Uses literal strings intentionally — the
 * constants class is loaded during plugins_loaded, which has not yet fired
 * when an activation hook runs for a plugin being activated for the first time.
 *
 * @since 1.0.0
 */
function agency_pulse_admin_menu_activate() {
	$role = get_role( 'administrator' );
	if ( $role ) {
		$role->add_cap( 'ap_menu_manager' );
	}
	if ( ! get_option( 'aamo_db_version' ) ) {
		add_option( 'aamo_db_version', '1.0.0' );
	}
}
register_activation_hook( AGENCY_PULSE_ADMIN_MENU_FILE, 'agency_pulse_admin_menu_activate' );

/**
 * Main plugin initialization.
 *
 * Boots after all plugins are loaded so it can inspect and modify the full
 * admin menu regardless of what other plugins have registered.
 * The require list grows with each build phase as new classes are created.
 *
 * @since 1.0.0
 */
function agency_pulse_admin_menu_init() {
	load_plugin_textdomain(
		'agency-pulse-admin-menu',
		false,
		dirname( plugin_basename( AGENCY_PULSE_ADMIN_MENU_FILE ) ) . '/languages'
	);

	require_once AGENCY_PULSE_ADMIN_MENU_DIR . 'includes/class-constants.php';
	require_once AGENCY_PULSE_ADMIN_MENU_DIR . 'includes/class-pro-connector.php';
	require_once AGENCY_PULSE_ADMIN_MENU_DIR . 'includes/class-license-manager.php';
	require_once AGENCY_PULSE_ADMIN_MENU_DIR . 'includes/class-api-client.php';
	require_once AGENCY_PULSE_ADMIN_MENU_DIR . 'includes/class-settings-manager.php';
	require_once AGENCY_PULSE_ADMIN_MENU_DIR . 'includes/class-admin-notices.php';
	require_once AGENCY_PULSE_ADMIN_MENU_DIR . 'includes/admin/class-menu-builder.php';
	require_once AGENCY_PULSE_ADMIN_MENU_DIR . 'includes/admin/class-role-assignments.php';
	require_once AGENCY_PULSE_ADMIN_MENU_DIR . 'includes/admin/class-role-manager.php';
	require_once AGENCY_PULSE_ADMIN_MENU_DIR . 'includes/admin/class-settings-page.php';
	require_once AGENCY_PULSE_ADMIN_MENU_DIR . 'includes/admin/class-dashboard-widget.php';
	require_once AGENCY_PULSE_ADMIN_MENU_DIR . 'includes/admin/class-dashboard-webhook.php';
	require_once AGENCY_PULSE_ADMIN_MENU_DIR . 'includes/class-access-control.php';
	require_once AGENCY_PULSE_ADMIN_MENU_DIR . 'includes/class-plugin.php';

	Agency_Pulse_Admin_Menu::get_instance();
}
add_action( 'plugins_loaded', 'agency_pulse_admin_menu_init' );
