<?php
/**
 * Order From DM — branding, defaults, and Reborn Labs service URLs.
 *
 * @package OrderFromDM
 * @see docs/repository-map.md
 */
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

define( 'DC_V2_PLUGIN_NAME', 'OrderFromDm' );
define( 'DC_V2_PLUGIN_SLUG', 'order-from-dm' );
define( 'DC_V2_TEXT_DOMAIN', 'order-from-dm' );
define( 'DC_V2_FEATURES_EMAIL', 'suggestions@rebornlabs.me' );
define( 'DC_V2_SUPPORT_EMAIL', 'support@rebornlabs.me' );

// --- Licensing / freemium (Reborn Labs usage API + Lemon Squeezy) ---
if ( ! defined( 'DC_V2_FREE_ORDER_LIMIT' ) ) {
	define( 'DC_V2_FREE_ORDER_LIMIT', 5 );
}
if ( ! defined( 'DC_V2_USAGE_API_URL' ) ) {
	define( 'DC_V2_USAGE_API_URL', 'https://rebornlabs.me/api/ofdm/usage.php' );
}
if ( ! defined( 'DC_V2_ENROLL_API_URL' ) ) {
	define( 'DC_V2_ENROLL_API_URL', 'https://rebornlabs.me/api/ofdm/enroll.php' );
}
if ( ! defined( 'DC_V2_AI_API_URL' ) ) {
	define( 'DC_V2_AI_API_URL', 'https://rebornlabs.me/api/ofdm/ai-complete.php' );
}
if ( ! defined( 'DC_V2_CHAT_RUNTIME_API_URL' ) ) {
	define( 'DC_V2_CHAT_RUNTIME_API_URL', 'https://rebornlabs.me/api/ofdm/chat-runtime.php' );
}
if ( ! defined( 'DC_V2_FIELDS_EDITOR_RUNTIME_API_URL' ) ) {
	define( 'DC_V2_FIELDS_EDITOR_RUNTIME_API_URL', 'https://rebornlabs.me/api/ofdm/fields-editor-runtime.php' );
}
if ( ! defined( 'DC_V2_ORDER_TICKET_API_URL' ) ) {
	define( 'DC_V2_ORDER_TICKET_API_URL', 'https://rebornlabs.me/api/ofdm/order-ticket.php' );
}
if ( ! defined( 'DC_V2_STORE_SNAPSHOT_API_URL' ) ) {
	define( 'DC_V2_STORE_SNAPSHOT_API_URL', 'https://rebornlabs.me/api/ofdm/store-snapshot.php' );
}
if ( ! defined( 'DC_V2_LS_API_URL' ) ) {
	define( 'DC_V2_LS_API_URL', 'https://api.lemonsqueezy.com/v1' );
}
// Lemon Squeezy hosted checkouts — Pro monthly (default) + yearly.
if ( ! defined( 'DC_V2_LS_CHECKOUT_URL' ) ) {
	define( 'DC_V2_LS_CHECKOUT_URL', '' );
}
// Per-locale monthly checkouts (secrets.php; legacy DC_V2_LS_CHECKOUT_URL = prod ES monthly).
if ( ! defined( 'DC_V2_LS_CHECKOUT_PROD_ES' ) ) {
	define( 'DC_V2_LS_CHECKOUT_PROD_ES', DC_V2_LS_CHECKOUT_URL );
}
if ( ! defined( 'DC_V2_LS_CHECKOUT_PROD_EN' ) ) {
	define( 'DC_V2_LS_CHECKOUT_PROD_EN', '' );
}
if ( ! defined( 'DC_V2_LS_CHECKOUT_TEST_ES' ) ) {
	define( 'DC_V2_LS_CHECKOUT_TEST_ES', '' );
}
if ( ! defined( 'DC_V2_LS_CHECKOUT_TEST_EN' ) ) {
	define( 'DC_V2_LS_CHECKOUT_TEST_EN', '' );
}
// Yearly checkouts (prod). Test domains fall back to monthly test URLs.
if ( ! defined( 'DC_V2_LS_CHECKOUT_PROD_YEARLY_ES' ) ) {
	define( 'DC_V2_LS_CHECKOUT_PROD_YEARLY_ES', '' );
}
if ( ! defined( 'DC_V2_LS_CHECKOUT_PROD_YEARLY_EN' ) ) {
	define( 'DC_V2_LS_CHECKOUT_PROD_YEARLY_EN', '' );
}
// Comma-separated hosts that always get TEST checkout (empty = all stores use live checkout).
if ( ! defined( 'DC_V2_LS_TEST_CHECKOUT_DOMAINS' ) ) {
	define( 'DC_V2_LS_TEST_CHECKOUT_DOMAINS', '' );
}
// Shared secret with the Reborn usage API. Define DC_V2_USAGE_SECRET in wp-config.php.
if ( ! defined( 'DC_V2_USAGE_SECRET' ) ) {
	define( 'DC_V2_USAGE_SECRET', '' );
}

function dc_v2_plugin_name() {
	return apply_filters( 'dc_v2_plugin_name', DC_V2_PLUGIN_NAME );
}

function dc_v2_plugin_title() {
	return apply_filters( 'dc_v2_plugin_title', 'Order From DM' );
}

function dc_v2_menu_icon() {
	$emoji = apply_filters( 'dc_v2_menu_icon_emoji', '💬' );
	$svg   = sprintf(
		'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><text x="12" y="18" font-size="15" text-anchor="middle">%s</text></svg>',
		$emoji
	);
	return 'data:image/svg+xml;base64,' . base64_encode( $svg );
}

function dc_v2_menu_position() {
	// Dashboard is 2 — 2.1 keeps Order From DM directly below Escritorio/Dashboard.
	return (float) apply_filters( 'dc_v2_menu_position', 2.1 );
}

function dc_v2_features_email() {
	return apply_filters( 'dc_v2_features_email', DC_V2_FEATURES_EMAIL );
}

function dc_v2_support_email() {
	return apply_filters( 'dc_v2_support_email', DC_V2_SUPPORT_EMAIL );
}

function dc_v2_free_order_limit() {
	return (int) apply_filters( 'dc_v2_free_order_limit', DC_V2_FREE_ORDER_LIMIT );
}

function dc_v2_usage_api_url() {
	return apply_filters( 'dc_v2_usage_api_url', DC_V2_USAGE_API_URL );
}

function dc_v2_enroll_api_url() {
	return apply_filters( 'dc_v2_enroll_api_url', DC_V2_ENROLL_API_URL );
}

function dc_v2_ai_api_url() {
	return apply_filters( 'dc_v2_ai_api_url', DC_V2_AI_API_URL );
}

function dc_v2_chat_runtime_api_url() {
	return apply_filters( 'dc_v2_chat_runtime_api_url', DC_V2_CHAT_RUNTIME_API_URL );
}

function dc_v2_fields_editor_runtime_api_url() {
	return apply_filters( 'dc_v2_fields_editor_runtime_api_url', DC_V2_FIELDS_EDITOR_RUNTIME_API_URL );
}

function dc_v2_order_ticket_api_url() {
	return apply_filters( 'dc_v2_order_ticket_api_url', DC_V2_ORDER_TICKET_API_URL );
}

function dc_v2_store_snapshot_api_url() {
	return apply_filters( 'dc_v2_store_snapshot_api_url', DC_V2_STORE_SNAPSHOT_API_URL );
}

/**
 * Whether the one-time store-snapshot collector should load at all.
 * After done/declined, the class (and its REST route) stay unloaded — no ongoing trail.
 */
function dc_v2_store_snapshot_should_load() {
	$payload_version = 2;
	$opt             = get_option( 'dc_v2_store_snapshot', null );
	if ( ! is_array( $opt ) ) {
		return true;
	}
	$status = (string) ( $opt['status'] ?? '' );
	$ver    = (int) ( $opt['payload_version'] ?? 0 );
	// After first successful batch: dead route (class not loaded).
	if ( 'done' === $status && $ver >= $payload_version ) {
		return false;
	}
	if ( ! empty( $opt['dismantled'] ) && $ver >= $payload_version ) {
		return false;
	}
	if ( 'failed' === $status && (int) ( $opt['attempts'] ?? 0 ) >= 3 ) {
		return false;
	}
	return true;
}

function dc_v2_ls_api_url() {
	return apply_filters( 'dc_v2_ls_api_url', DC_V2_LS_API_URL );
}

function dc_v2_ls_checkout_url() {
	$url = dc_v2_ls_checkout_url_resolved( 'monthly' );
	return apply_filters( 'dc_v2_ls_checkout_url', $url );
}

/**
 * Domains that always use Lemon Squeezy TEST checkout (not live payments).
 *
 * @return string[]
 */
function dc_v2_ls_test_checkout_domains() {
	$raw = DC_V2_LS_TEST_CHECKOUT_DOMAINS;
	if ( is_array( $raw ) ) {
		$list = $raw;
	} else {
		$list = array_filter( array_map( 'trim', explode( ',', (string) $raw ) ) );
	}
	$list = array_map(
		static function ( $host ) {
			$host = strtolower( (string) $host );
			return preg_replace( '/^www\./', '', $host );
		},
		$list
	);
	return apply_filters( 'dc_v2_ls_test_checkout_domains', array_values( array_filter( $list ) ) );
}

function dc_v2_ls_uses_test_checkout() {
	$domain = dc_v2_site_domain();
	return in_array( $domain, dc_v2_ls_test_checkout_domains(), true );
}

/**
 * @return 'es'|'en'
 */
function dc_v2_ls_checkout_lang() {
	$locale = strtolower( (string) dc_v2_plugin_locale() );
	return ( strpos( $locale, 'es' ) === 0 ) ? 'es' : 'en';
}

/**
 * Built-in fallbacks (public Lemon Squeezy checkout links).
 * Monthly = default Pro CTA; yearly = discounted annual plan.
 *
 * @return array{
 *   monthly: array{prod: array{es: string, en: string}, test: array{es: string, en: string}},
 *   yearly: array{prod: array{es: string, en: string}}
 * }
 */
function dc_v2_ls_checkout_catalog() {
	$defaults = array(
		'monthly' => array(
			'prod' => array(
				'es' => 'https://reborn.lemonsqueezy.com/checkout/buy/982844d1-8d1a-42e6-869c-2b42c59c351f',
				'en' => 'https://reborn.lemonsqueezy.com/checkout/buy/5197dc6f-e3a6-4cd6-991c-d54b4bb4e9e8',
			),
			'test' => array(
				'es' => 'https://reborn.lemonsqueezy.com/checkout/buy/ddde9269-519a-4a62-beae-a3d68f199f85',
				'en' => 'https://reborn.lemonsqueezy.com/checkout/buy/5a81e116-c2f0-4742-b7ae-dfe7832527ac',
			),
		),
		'yearly'  => array(
			'prod' => array(
				'es' => 'https://reborn.lemonsqueezy.com/checkout/buy/d7fc92de-fa00-4919-85e9-bdd6508e7418',
				'en' => 'https://reborn.lemonsqueezy.com/checkout/buy/172f4d59-5589-455a-a93d-eca14abee611',
			),
		),
	);

	$pick = static function ( $constant, $fallback ) {
		return ( defined( $constant ) && constant( $constant ) !== '' ) ? constant( $constant ) : $fallback;
	};

	return array(
		'monthly' => array(
			'prod' => array(
				'es' => $pick( 'DC_V2_LS_CHECKOUT_PROD_ES', $defaults['monthly']['prod']['es'] ),
				'en' => $pick( 'DC_V2_LS_CHECKOUT_PROD_EN', $defaults['monthly']['prod']['en'] ),
			),
			'test' => array(
				'es' => $pick( 'DC_V2_LS_CHECKOUT_TEST_ES', $defaults['monthly']['test']['es'] ),
				'en' => $pick( 'DC_V2_LS_CHECKOUT_TEST_EN', $defaults['monthly']['test']['en'] ),
			),
		),
		'yearly'  => array(
			'prod' => array(
				'es' => $pick( 'DC_V2_LS_CHECKOUT_PROD_YEARLY_ES', $defaults['yearly']['prod']['es'] ),
				'en' => $pick( 'DC_V2_LS_CHECKOUT_PROD_YEARLY_EN', $defaults['yearly']['prod']['en'] ),
			),
		),
	);
}

/**
 * @param 'monthly'|'yearly' $plan
 */
function dc_v2_ls_checkout_url_resolved( $plan = 'monthly' ) {
	$catalog = dc_v2_ls_checkout_catalog();
	$lang    = dc_v2_ls_checkout_lang();
	$plan    = ( $plan === 'yearly' ) ? 'yearly' : 'monthly';

	if ( $plan === 'yearly' ) {
		// No test yearly variants yet — always use prod yearly so the banner can show a distinct $79 CTA.
		$yearly = $catalog['yearly']['prod'][ $lang ] ?? $catalog['yearly']['prod']['es'] ?? '';
		if ( $yearly !== '' ) {
			return $yearly;
		}
		// Last resort on test domains: monthly test checkout.
		if ( dc_v2_ls_uses_test_checkout() ) {
			return $catalog['monthly']['test'][ $lang ] ?? $catalog['monthly']['test']['es'] ?? '';
		}
		return '';
	}

	$mode = dc_v2_ls_uses_test_checkout() ? 'test' : 'prod';
	return $catalog['monthly'][ $mode ][ $lang ] ?? $catalog['monthly'][ $mode ]['es'] ?? '';
}

function dc_v2_ls_checkout_url_yearly() {
	$url = dc_v2_ls_checkout_url_resolved( 'yearly' );
	return apply_filters( 'dc_v2_ls_checkout_url_yearly', $url );
}

function dc_v2_usage_secret() {
	return apply_filters( 'dc_v2_usage_secret', DC_V2_USAGE_SECRET );
}

/**
 * Normalize a host/URL the same way Reborn ofdm_normalize_domain does.
 */
function dc_v2_normalize_domain( $domain ) {
	$domain = strtolower( trim( (string) $domain ) );
	if ( $domain === '' ) {
		return '';
	}
	if ( strpos( $domain, '://' ) === false ) {
		$domain = 'https://' . $domain;
	}
	$host = wp_parse_url( $domain, PHP_URL_HOST );
	if ( ! is_string( $host ) || $host === '' ) {
		return '';
	}
	return preg_replace( '/^www\./', '', $host );
}

/**
 * Normalized site domain used as the per-site key for the usage counter.
 */
function dc_v2_site_domain() {
	$host = dc_v2_normalize_domain( home_url( '/' ) );
	return apply_filters( 'dc_v2_site_domain', $host );
}

/**
 * Site locale for plugin UI (admin + storefront). Falls back to English source strings.
 */
function dc_v2_plugin_locale() {
	return apply_filters( 'dc_v2_plugin_locale', get_locale() );
}

function dc_v2_load_textdomain( $force = false ) {
	static $loaded = false;
	if ( $loaded && ! $force ) {
		return;
	}
	if ( $force ) {
		unload_textdomain( 'order-from-dm' );
	}
	load_plugin_textdomain(
		'order-from-dm',
		false,
		dirname( plugin_basename( DC_V2_FILE ) ) . '/languages'
	);
	$loaded = true;
}

function dc_v2_badge_text() {
	return apply_filters( 'dc_v2_badge_text', __( 'We are here for you', 'order-from-dm' ) );
}

function dc_v2_powered_by_url() {
	return apply_filters( 'dc_v2_powered_by_url', 'https://rebornlabs.me' );
}

function dc_v2_powered_by_label() {
	return apply_filters( 'dc_v2_powered_by_label', __( '⚡️ Powered by Reborn Labs', 'order-from-dm' ) );
}

function dc_v2_docs_url() {
	return apply_filters( 'dc_v2_docs_url', 'https://rebornlabs.me' );
}

function dc_v2_lets_build_url() {
	return apply_filters( 'dc_v2_lets_build_url', 'https://rebornlabs.me/lets-build/' );
}

function dc_v2_admin_hero_image_url() {
	$relative = 'assets/admin/hero-illustration.png';
	$path     = DC_V2_PATH . $relative;
	if ( ! file_exists( $path ) ) {
		return '';
	}
	$ver = (string) filemtime( $path );
	return add_query_arg( 'ver', $ver, dc_v2_asset_url( $relative ) );
}

/**
 * Versioned URL for an admin hero asset, or empty string if missing.
 *
 * @param string $relative Path under plugin root.
 */
function dc_v2_admin_asset_url( $relative ) {
	$relative = ltrim( (string) $relative, '/' );
	$path     = DC_V2_PATH . $relative;
	if ( ! file_exists( $path ) ) {
		return '';
	}
	$ver = (string) filemtime( $path );
	return add_query_arg( 'ver', $ver, dc_v2_asset_url( $relative ) );
}

function dc_v2_admin_hero_main_desktop_url() {
	return dc_v2_admin_asset_url( 'assets/admin/hero-main-desktop.webp' );
}

function dc_v2_admin_hero_main_mobile_url() {
	return dc_v2_admin_asset_url( 'assets/admin/hero-main-mobile.webp' );
}

function dc_v2_admin_hero_fields_desktop_url() {
	return dc_v2_admin_asset_url( 'assets/admin/hero-fields-desktop.webp' );
}

function dc_v2_admin_hero_fields_mobile_url() {
	return dc_v2_admin_asset_url( 'assets/admin/hero-fields-mobile.webp' );
}

function dc_v2_plugin_brand_mark_url() {
	// Landing OrderFromDM mark (logo.png / logo-64.png), not the old favicon.svg.
	$candidates = array( 'assets/brand-mark-64.png', 'assets/brand-mark.png' );
	foreach ( $candidates as $relative ) {
		$path = DC_V2_PATH . $relative;
		if ( ! file_exists( $path ) ) {
			continue;
		}
		$ver = (string) filemtime( $path );
		return add_query_arg( 'ver', $ver, dc_v2_asset_url( $relative ) );
	}
	return '';
}

/**
 * WooCommerce store currency formatting for the chat UI.
 *
 * @return array{code:string,symbol:string,position:string,decimals:int,decimalSep:string,thousandSep:string}
 */
function dc_v2_store_currency() {
	$code     = function_exists( 'get_woocommerce_currency' ) ? get_woocommerce_currency() : 'USD';
	$symbol   = function_exists( 'get_woocommerce_currency_symbol' )
		? html_entity_decode( get_woocommerce_currency_symbol( $code ), ENT_QUOTES, 'UTF-8' )
		: '$';
	$position = (string) get_option( 'woocommerce_currency_pos', 'left' );
	$decimals = function_exists( 'wc_get_price_decimals' ) ? (int) wc_get_price_decimals() : 2;
	$dec_sep  = function_exists( 'wc_get_price_decimal_separator' ) ? wc_get_price_decimal_separator() : '.';
	$thou_sep = function_exists( 'wc_get_price_thousand_separator' ) ? wc_get_price_thousand_separator() : ',';

	return array(
		'code'        => $code,
		'symbol'      => $symbol,
		'position'    => $position,
		'decimals'    => $decimals,
		'decimalSep'  => $dec_sep,
		'thousandSep' => $thou_sep,
	);
}

/**
 * Real WordPress site icon only — never invents /favicon.ico (often 404 → broken img).
 */
function dc_v2_site_favicon_url( $size = 96 ) {
	$url = get_site_icon_url( (int) $size );
	return apply_filters( 'dc_v2_site_favicon_url', $url ? $url : '', $size );
}

/**
 * Header brand: custom logo → site icon → bundled Order From DM mark.
 *
 * @param string $logo_url Appearance logo_url.
 * @return array{src:string,mode:string} mode: logo|favicon|plugin|none
 */
function dc_v2_resolve_header_brand( $logo_url = '' ) {
	$logo_url = is_string( $logo_url ) ? trim( $logo_url ) : '';
	if ( '' !== $logo_url ) {
		return array(
			'src'  => $logo_url,
			'mode' => 'logo',
		);
	}
	$favicon = dc_v2_site_favicon_url( 96 );
	if ( '' !== $favicon ) {
		return array(
			'src'  => $favicon,
			'mode' => 'favicon',
		);
	}
	$plugin = dc_v2_plugin_brand_mark_url();
	if ( '' !== $plugin ) {
		return array(
			'src'  => $plugin,
			'mode' => 'plugin',
		);
	}
	return array(
		'src'  => '',
		'mode' => 'none',
	);
}

function dc_v2_light_appearance_tokens() {
	return array(
		'primary_foreground' => '#fafafa',
		'card'               => '#ffffff',
		'card_foreground'    => '#09090b',
		'muted'              => '#f4f4f5',
		'muted_foreground'   => '#71717a',
		'border'             => '#e4e4e7',
		'input'              => '#ffffff',
		'footer'             => 'rgba(255,255,255,0.95)',
		'header'             => 'rgba(255,255,255,0.72)',
		'shadow'             => '0 2px 12px rgba(9, 9, 11, 0.08)',
	);
}

function dc_v2_dark_appearance_tokens() {
	return array(
		'primary_foreground' => '#09090b',
		'card'               => '#18181b',
		'card_foreground'    => '#fafafa',
		'muted'              => '#27272a',
		'muted_foreground'   => '#a1a1aa',
		'border'             => '#3f3f46',
		'input'              => '#18181b',
		'footer'             => 'rgba(9,9,11,0.95)',
		'header'             => 'rgba(9,9,11,0.72)',
		'shadow'             => '0 2px 16px rgba(0, 0, 0, 0.35)',
	);
}

function dc_v2_orderfromdm_appearance_tokens() {
	return array(
		'primary_foreground' => '#ffffff',
		'card'               => '#262626',
		'card_foreground'    => '#ffffff',
		'muted'              => '#363636',
		'muted_foreground'   => '#a8a8a8',
		'border'             => '#363636',
		'input'              => '#262626',
		'footer'             => '#000000',
		'header'             => '#000000',
		'shadow'             => 'none',
	);
}

function dc_v2_default_appearance() {
	return array_merge( array(
		'preset'       => 'orderfromdm',
		'primary'      => '#3797f0',
		'secondary'    => '#a8a8a8',
		'background'   => '#000000',
		'foreground'   => '#f5f5f5',
		'badge_text'   => dc_v2_badge_text(),
		'logo_url'     => '',
		'typing_speed' => '45',
	), dc_v2_orderfromdm_appearance_tokens() );
}

function dc_v2_default_share_preview() {
	dc_v2_load_textdomain();
	return __( 'Finish your order', 'order-from-dm' );
}

/**
 * Share / Open Graph preview line for a document copy payload.
 *
 * @param array|mixed $copy Document copy meta.
 */
function dc_v2_share_preview_text( $copy ) {
	$copy = is_array( $copy ) ? $copy : array();
	$text = trim( (string) ( $copy['share_preview'] ?? '' ) );
	if ( '' === $text ) {
		return dc_v2_default_share_preview();
	}
	return $text;
}

function dc_v2_default_copy() {
	dc_v2_load_textdomain();
	return array(
		'welcome'        => __( 'Hi! Your order is almost ready — we just need a few details to complete it.', 'order-from-dm' ),
		'products_intro' => '',
		'payment_intro'  => __( 'Select your payment method', 'order-from-dm' ),
		'shipping_intro' => __( 'Great! Please tell us where to ship your order.', 'order-from-dm' ),
		'success_note'   => __( 'Complete the bank transfer using your order number and send us the payment proof. We will start preparing your order once confirmed.', 'order-from-dm' ),
		'success_close'  => __( 'You can close this window 🛍️', 'order-from-dm' ),
		'share_preview'  => dc_v2_default_share_preview(),
		'cta_continue'   => __( 'Continue', 'order-from-dm' ),
		'cta_products_incomplete' => __( 'Complete product details', 'order-from-dm' ),
		'cta_payment'    => __( 'Continue', 'order-from-dm' ),
		'cta_payment_incomplete' => __( 'Select a payment method', 'order-from-dm' ),
		'cta_shipping'   => __( 'Confirm order', 'order-from-dm' ),
		'cta_shipping_incomplete' => __( 'Complete shipping details', 'order-from-dm' ),
	);
}

/**
 * Plugin asset URL — always HTTPS when the site uses SSL (avoids mixed-content blank admin).
 */
function dc_v2_asset_url( $relative ) {
	$relative = ltrim( (string) $relative, '/' );
	$url      = plugins_url( $relative, DC_V2_FILE );
	$home     = home_url( '/' );
	if ( is_ssl() || 0 === strpos( $home, 'https://' ) ) {
		$url = set_url_scheme( $url, 'https' );
	}
	return $url;
}

/**
 * Known bootstrap paths for duplicate-install detection (dev + customer folders).
 *
 * @return string[]
 */
function dc_v2_duplicate_install_paths() {
	$bootstraps = array(
		'order-from-dm/amispet-direct-checkout-v2.php',
		'amispet-direct-checkout-v2/amispet-direct-checkout-v2.php',
	);
	$found      = array();
	foreach ( $bootstraps as $path ) {
		if ( is_readable( WP_PLUGIN_DIR . '/' . $path ) ) {
			$found[] = $path;
		}
	}
	return $found;
}
