<?php
/**
 * Plugin Name: WPEstate Translate
 * Description: Translation management plugin tailored for the WPResidence and WPRentals themes.
 * Version: 0.1.0
 * Author: WPEstate
 * Text Domain: wpr-translate
 * Domain Path: /languages
 */

/**
 * Plugin bootstrap file.
 *
 * Loads core dependencies, defines shared constants, and boots the plugin
 * only after required files are present.
 */

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

// Capture the absolute filesystem and URL roots for the plugin once to avoid recalculating them.
$wpr_translate_plugin_root = plugin_dir_path( __FILE__ );
$wpr_translate_plugin_url  = plugin_dir_url( __FILE__ );

if ( ! defined( 'WPR_TRANSLATE_PLUGIN_ROOT' ) ) {
    // Ensure the root path always ends with a trailing slash for consistent concatenation later.
    $root_path = function_exists( 'trailingslashit' ) ? trailingslashit( $wpr_translate_plugin_root ) : rtrim( $wpr_translate_plugin_root, '/\\' ) . '/';
    define( 'WPR_TRANSLATE_PLUGIN_ROOT', $root_path );
}

if ( ! defined( 'WPR_TRANSLATE_PLUGIN_URL' ) ) {
    // Guarantee the plugin URL mirrors the filesystem root formatting.
    $root_url = function_exists( 'trailingslashit' ) ? trailingslashit( $wpr_translate_plugin_url ) : rtrim( $wpr_translate_plugin_url, '/\\' ) . '/';
    define( 'WPR_TRANSLATE_PLUGIN_URL', $root_url );
}

if ( ! defined( 'WPR_TRANSLATE_PATH' ) ) {
    define( 'WPR_TRANSLATE_PATH', WPR_TRANSLATE_PLUGIN_ROOT );
}

if ( ! defined( 'WPR_TRANSLATE_URL' ) ) {
    define( 'WPR_TRANSLATE_URL', WPR_TRANSLATE_PLUGIN_URL );
}

if ( ! defined( 'WPR_TRANSLATE_VERSION' ) ) {
    define( 'WPR_TRANSLATE_VERSION', '0.1.0' );
}

if ( ! defined( 'WPR_TRANSLATE_BASENAME' ) ) {
    define( 'WPR_TRANSLATE_BASENAME', plugin_basename( __FILE__ ) );
}

// List all core files that must be loaded for the plugin to operate.
$wpr_translate_includes = array(
    'includes/activator.php',
    'includes/translation-directories.php',
    'includes/translation-files.php',
    'includes/translation-runtime.php',
    'includes/date-localization.php',
    'includes/custom-field-rules.php',
    'includes/translation-hooks.php',
    'includes/language-manager.php',
    'includes/main-lang-functions.php',
    'includes/language-permalinks.php',
    'includes/language-router.php',
    'includes/functions-language.php',
    'includes/functions-permalinks.php',
    'includes/body-language-attribute.php',
    'includes/meta-sync.php',
    'includes/custom-fields-sync.php',
    'includes/theme-widget-strings.php',
    'includes/admin/theme-widget-strings.php',
    'includes/plugin-bootstrap.php',
);

foreach ( $wpr_translate_includes as $include ) {
    // Resolve the absolute path to the include file relative to the plugin root.
    $file = WPR_TRANSLATE_PLUGIN_ROOT . $include;

    if ( file_exists( $file ) ) {
        // Only load the file when it exists to avoid fatal errors on missing includes.
        require_once $file;
    }
}

if ( function_exists( 'register_activation_hook' ) ) {
    // Hook into the activation lifecycle to provision plugin requirements.
    register_activation_hook( __FILE__, 'wpr_translate_activate_plugin' );
}

if ( function_exists( 'register_uninstall_hook' ) ) {
    // Register uninstall cleanup to remove plugin data when requested.
    register_uninstall_hook( __FILE__, 'wpr_translate_uninstall_plugin' );
}

if ( function_exists( 'wpr_translate_bootstrap_plugin' ) ) {
    // Start the plugin only when the bootstrap function is available from the includes above.
    wpr_translate_bootstrap_plugin();
}



