atarim-wpal-integration-guide.txt
4 days ago
class-avcf-wpal-abilities.php
4 days ago
class-avcf-wpal-detector.php
4 days ago
class-avcf-wpal-rest.php
4 days ago
class-avcf-wpal-stats.php
4 days ago
class-avcf-wpal-detector.php
62 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Detects the WP Activity Log plugin and its edition. |
| 4 | * |
| 5 | * This is the single point of contact for checking whether WPAL is installed, |
| 6 | * which edition is active, and which features are available. If Melapress |
| 7 | * renames or moves classes in a future WPAL version, this file is the only |
| 8 | * place that needs to change. |
| 9 | * |
| 10 | * @package atarim-visual-collaboration |
| 11 | */ |
| 12 | |
| 13 | if ( ! defined('ABSPATH') ) { |
| 14 | exit; // Exit if accessed directly |
| 15 | } |
| 16 | |
| 17 | class AVCF_WPAL_Detector { |
| 18 | |
| 19 | /** |
| 20 | * Fully-qualified WPAL class used to retrieve activity log data. |
| 21 | */ |
| 22 | const WPAL_OCCURRENCES_CLASS = '\WSAL\Entities\Occurrences_Entity'; |
| 23 | |
| 24 | /** |
| 25 | * Method only present in the Premium edition. |
| 26 | * Used as the sentinel for edition detection. |
| 27 | */ |
| 28 | const WPAL_PREMIUM_METHOD = 'get_last24_links'; |
| 29 | |
| 30 | public function __construct() {} |
| 31 | |
| 32 | /** |
| 33 | * Whether WP Activity Log is installed and bootstrapped on this site. |
| 34 | */ |
| 35 | public function avcf_wpal_is_available() { |
| 36 | return class_exists( self::WPAL_OCCURRENCES_CLASS ); |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Whether the Premium edition is active. |
| 41 | * Premium ships an additional method on Occurrences_Entity that the free |
| 42 | * edition does not, so method_exists is a reliable detection signal. |
| 43 | */ |
| 44 | public function avcf_wpal_is_premium() { |
| 45 | if ( ! $this->avcf_wpal_is_available() ) { |
| 46 | return false; |
| 47 | } |
| 48 | return method_exists( self::WPAL_OCCURRENCES_CLASS, self::WPAL_PREMIUM_METHOD ); |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Edition label suitable for display or API output. |
| 53 | * Returns 'premium', 'free', or 'none'. |
| 54 | */ |
| 55 | public function avcf_wpal_edition() { |
| 56 | if ( ! $this->avcf_wpal_is_available() ) { |
| 57 | return 'none'; |
| 58 | } |
| 59 | return $this->avcf_wpal_is_premium() ? 'premium' : 'free'; |
| 60 | } |
| 61 | } |
| 62 |