<?php
/**
 * PublisherKits Core Library (PK Core) - bundle entry point.
 *
 * The core is an embedded, versioned PHP library bundled inside adopting
 * PublisherKits plugins (the Freemius SDK / Action Scheduler pattern). It is
 * NOT a plugin. At runtime the newest bundled version across all active
 * plugins wins and boots once; it owns the site profile, the single
 * site-level topic pack, the deterministic classification engine and the
 * shared read contract. See PK-CORE-SPEC-00-DESIGN-LOCK.txt.
 *
 * Each bundling plugin does exactly one thing with the core: require this
 * file. To activate only one module, set $pkcore_modules first:
 *
 *     $pkcore_modules = array( 'classify' );          // or array( 'profile' )
 *     require_once __DIR__ . '/pkcore/pkcore.php';
 *
 * Omitting $pkcore_modules (or passing an empty array) requests BOTH modules.
 * The payload always contains both; module flags control activation only.
 * The plugin's activation hook must also call PKCORE_Loader::boot() (the
 * activation hook can fire without a fresh plugins_loaded for the activating
 * plugin).
 *
 * @package PublisherKits\Core
 * @since   0.1.0
 */

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

/**
 * Version of the PK Core bundled in THIS plugin.
 *
 * Bump on any core schema or API change. The loader compares this across all
 * bundling plugins with version_compare(); the highest wins. A variable, not
 * a constant: constants collide across bundles, variables do not.
 */
$pkcore_this_version = '0.9.16';

// The loader is a tiny, FROZEN registry shared by all bundles. The first
// bundle to load defines it; later bundles reuse it (class_exists guard
// inside). Versioned behaviour lives in the payload it loads, never here.
require_once __DIR__ . '/includes/class-pkcore-loader.php';

// Which modules this bundle's host plugin wants: 'profile', 'classify'.
$pkcore_modules_requested = ( isset( $pkcore_modules ) && is_array( $pkcore_modules ) )
	? $pkcore_modules
	: array();

// Register this bundle: version => this bundle's core root + module request.
PKCORE_Loader::register( $pkcore_this_version, __DIR__, $pkcore_modules_requested );

// Don't leak the request into the next bundle's require of this file.
unset( $pkcore_modules, $pkcore_modules_requested );

// Boot the winning version once every active plugin has registered its
// bundle. All active plugin main files are included before plugins_loaded
// fires, so by then every bundle is registered and "newest wins" is
// decidable. Activation runs its own explicit PKCORE_Loader::boot().
if ( function_exists( 'add_action' ) ) {
	add_action( 'plugins_loaded', array( 'PKCORE_Loader', 'boot' ), 1 );
}
