Skip to content

Add global functions for capability checks - #187

Open
pramodjodhani wants to merge 4 commits into
mainfrom
SMTNC-1895
Open

Add global functions for capability checks#187
pramodjodhani wants to merge 4 commits into
mainfrom
SMTNC-1895

Conversation

@pramodjodhani

@pramodjodhani pramodjodhani commented Jul 29, 2026

Copy link
Copy Markdown
Member

Summary

Adds two global Harbor functions so consuming plugins can check capability licensing against the cached unified license catalog, without reimplementing License_Repository logic locally.

  • lw_harbor_is_capability_license_available( $capability_slug ) — returns true when the unified key includes the capability, regardless of whether the product is activated on the current domain (e.g. not_activated entries still count).
  • lw_harbor_is_capability_license_active( $capability_slug ) — returns true when the capability is on a product that is valid and activated on the current domain.

Repository support is added via License_Repository::has_capability() and License_Repository::is_capability_active(). has_capability() uses a private is_capability_covered_by_license() helper to distinguish "on the license but not activated here" from statuses where the license genuinely doesn't cover the product (expired, no entitlement, etc.).

Both functions follow the existing global function pattern: version-leader registry, no remote API calls, local cache only.

Motivation

the-events-calendar/tribe-common#2960 (comment)

Usage

// Capability is on the license, even if not activated on this domain
if ( lw_harbor_is_capability_license_available( 'learndash-integrity' ) ) {
    // ...
}

// Capability is valid and activated on this domain
if ( lw_harbor_is_capability_license_active( 'learndash-integrity' ) ) {
    // ...
}

Test plan

  • Verify lw_harbor_is_capability_license_available() returns true for a not_activated product with the capability
  • Verify lw_harbor_is_capability_license_active() returns false for the same not_activated product
  • Verify lw_harbor_is_capability_license_available() returns false for expired products

Expose lw_harbor_get_licensed_products(), lw_harbor_is_capability_licensed(),
and lw_harbor_is_capability_license_active() so consuming plugins can query
the cached license catalog without reimplementing License_Repository logic.
…lity_licensed to lw_harbor_is_capability_license_active
@linear

linear Bot commented Jul 29, 2026

Copy link
Copy Markdown

SMTNC-1895


foreach ( $products as $entry ) {
if (
$this->is_capability_covered_by_license( $entry->get_validation_status() )

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we used is_valid() here, we'd get false for entries like:

  • not_activated
  • activation_required
  • out_of_activations
  • tier_selection_required

Those are not valid, but they are covered by the license. That's why I had to create is_capability_covered_by_license function.

@pramodjodhani
pramodjodhani requested a review from d4mation July 29, 2026 06:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant