| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin entry file. |
| 4 |
* |
| 5 |
* Defines the path / file constants, loads the Composer autoloader, |
| 6 |
* loads the text domain, and hands off to {@see Core::instance()} to |
| 7 |
* boot every module in phased order. |
| 8 |
* |
| 9 |
* This file is intentionally minimal — the rule of thumb is "no |
| 10 |
* runtime logic in the bootstrap." Each subsystem (settings storage, |
| 11 |
* session guard, admin UI, REST API, Freemius) lives behind its own |
| 12 |
* class under `includes/` and registers its own hooks from there. |
| 13 |
* |
| 14 |
* @package FoxeLabs\Loggedin |
| 15 |
* @author Joel James |
| 16 |
* @copyright 2025 Joel James |
| 17 |
* @license GPL-2.0+ |
| 18 |
* |
| 19 |
* @wordpress-plugin |
| 20 |
* Plugin Name: Loggedin - Session Manager, Limit Concurrent Logins & Force Logout |
| 21 |
* Plugin URI: https://foxelabs.com/software/plugins/loggedin |
| 22 |
* Description: Limit an account to a specific number of simultaneous logins across all devices. |
| 23 |
* Version: 3.2.0 |
| 24 |
* Author: Joel James |
| 25 |
* Author URI: https://foxelabs.com/ |
| 26 |
* Donate link: https://paypal.me/JoelCJ |
| 27 |
* License: GPL-2.0+ |
| 28 |
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt |
| 29 |
* Text Domain: loggedin |
| 30 |
* Domain Path: /languages |
| 31 |
* Requires PHP: 7.4 |
| 32 |
* Requires at least: 6.0 |
| 33 |
*/ |
| 34 |
|
| 35 |
namespace FoxeLabs\Loggedin; |
| 36 |
|
| 37 |
defined( 'WPINC' ) || die; |
| 38 |
|
| 39 |
/** |
| 40 |
* Absolute filesystem path to the plugin directory, with trailing slash. |
| 41 |
* |
| 42 |
* Used everywhere we need to include or read a file shipped inside |
| 43 |
* the plugin (the autoloader, the React bundle in `build/`, the |
| 44 |
* language files, etc.). Defined here once so individual classes |
| 45 |
* can read it via `Plugin::dir()` without ever recomputing it. |
| 46 |
*/ |
| 47 |
define( 'LOGGEDIN_DIR', plugin_dir_path( __FILE__ ) ); |
| 48 |
|
| 49 |
/** |
| 50 |
* Absolute filesystem path to *this file*. |
| 51 |
* |
| 52 |
* Freemius needs the main plugin file path during instance creation |
| 53 |
* (it derives the plugin basename from it). Captured here so we don't |
| 54 |
* have to thread it through every constructor. |
| 55 |
*/ |
| 56 |
define( 'LOGGEDIN_FILE', __FILE__ ); |
| 57 |
|
| 58 |
if ( ! function_exists( __NAMESPACE__ . '\\init' ) ) { |
| 59 |
/** |
| 60 |
* Boot the plugin once core has finished loading. |
| 61 |
* |
| 62 |
* Wrapped in a `function_exists` guard so a second copy of the |
| 63 |
* plugin loaded from a different directory (a stray symlink, a |
| 64 |
* dev clone) can't redefine the function and silently shadow the |
| 65 |
* first init call. The function: |
| 66 |
* |
| 67 |
* 1. Pulls in the Composer autoloader. |
| 68 |
* 2. Hands off to {@see Core::instance()}, which is responsible |
| 69 |
* for wiring every module in order. |
| 70 |
* |
| 71 |
* The text domain is not loaded here: since WordPress 4.6 core |
| 72 |
* loads translations for a wordpress.org-hosted plugin on first |
| 73 |
* use, keyed on the `Text Domain` header. |
| 74 |
* |
| 75 |
* @since 2.0.0 |
| 76 |
* |
| 77 |
* @return void |
| 78 |
*/ |
| 79 |
function init(): void { |
| 80 |
require __DIR__ . '/vendor/autoload.php'; |
| 81 |
|
| 82 |
alias_legacy_classes(); |
| 83 |
|
| 84 |
Core::instance(); |
| 85 |
} |
| 86 |
} |
| 87 |
|
| 88 |
if ( ! function_exists( __NAMESPACE__ . '\\alias_legacy_classes' ) ) { |
| 89 |
/** |
| 90 |
* Keep the pre-3.2.0 `DuckDev\Loggedin` class names resolvable. |
| 91 |
* |
| 92 |
* The namespace moved to `FoxeLabs\Loggedin` with the Duck Dev to |
| 93 |
* Foxe Labs rebrand. Add-ons are separate plugins that WordPress |
| 94 |
* updates independently, so a site can — and often will — run the |
| 95 |
* new parent alongside an add-on built against the old names. |
| 96 |
* |
| 97 |
* `Plugin` is the only parent class add-ons reference across the |
| 98 |
* boundary: each one guards its boot with |
| 99 |
* `class_exists( '\DuckDev\Loggedin\Plugin' )`, and Active Sessions |
| 100 |
* also imports it. Without the alias that guard reports false and |
| 101 |
* every add-on silently disables itself. Everything else crossing |
| 102 |
* the boundary is a `loggedin_`-prefixed hook, and those names did |
| 103 |
* not change. |
| 104 |
* |
| 105 |
* Safe to drop once all four add-ons have shipped a release built |
| 106 |
* against `FoxeLabs\Loggedin` and had time to roll out. |
| 107 |
* |
| 108 |
* @since 3.2.0 |
| 109 |
* |
| 110 |
* @return void |
| 111 |
*/ |
| 112 |
function alias_legacy_classes(): void { |
| 113 |
if ( ! class_exists( '\\DuckDev\\Loggedin\\Plugin', false ) ) { |
| 114 |
class_alias( Plugin::class, '\\DuckDev\\Loggedin\\Plugin' ); |
| 115 |
} |
| 116 |
} |
| 117 |
} |
| 118 |
|
| 119 |
add_action( 'plugins_loaded', __NAMESPACE__ . '\\init' ); |
| 120 |
|