*/ public static function catalog(): array { $items = array( array( 'id' => 'upload', 'category' => 'library', 'aiPowered' => false, 'default' => true, 'locked' => false, 'tier' => self::TIER_FREE, 'label' => __( 'Upload', 'foldrocket' ), 'description' => __( 'Upload new media from the library top bar.', 'foldrocket' ), ), array( 'id' => 'folders', 'category' => 'library', 'aiPowered' => false, 'default' => true, 'locked' => false, 'tier' => self::TIER_FREE, 'label' => __( 'Virtual folders', 'foldrocket' ), 'description' => __( 'Organize media into virtual folders without moving files on disk.', 'foldrocket' ), ), array( 'id' => 'folder_import', 'category' => 'library', 'aiPowered' => false, 'default' => true, 'locked' => false, 'tier' => self::TIER_FREE, 'label' => __( 'Import folders', 'foldrocket' ), 'description' => __( 'Copy HappyFiles, FileBird, Real Media Library, and WP Media Folder folders into virtual folders without moving files.', 'foldrocket' ), ), array( 'id' => 'advanced_filters', 'category' => 'library', 'aiPowered' => false, 'default' => true, 'locked' => false, 'tier' => self::TIER_FREE, 'label' => __( 'Advanced filters', 'foldrocket' ), 'description' => __( 'Filter by MIME type, AI status, unused, missing ALT, large files, orientation, date, and author. Order by date, title, size, or usage.', 'foldrocket' ), ), array( 'id' => 'smart_views', 'category' => 'library', 'aiPowered' => false, 'default' => true, 'locked' => false, 'tier' => self::TIER_FREE, 'label' => __( 'Smart views', 'foldrocket' ), 'description' => __( 'Save, rename, update, and delete reusable library filter shortcuts.', 'foldrocket' ), ), array( 'id' => 'folder_colors', 'category' => 'library', 'aiPowered' => false, 'default' => true, 'locked' => false, 'tier' => self::TIER_FREE, 'label' => __( 'Folder colors', 'foldrocket' ), 'description' => __( 'Give a folder a color so its name stands out in the sidebar.', 'foldrocket' ), ), array( 'id' => 'download_zip', 'category' => 'library', 'aiPowered' => false, 'default' => true, 'locked' => false, 'tier' => self::TIER_FREE, 'label' => __( 'Download zip', 'foldrocket' ), 'description' => __( 'Download the files in the current folder or smart view as a zip. The archive is deleted after the download.', 'foldrocket' ), ), array( 'id' => 'bulk_actions', 'category' => 'library', 'aiPowered' => false, 'default' => true, 'locked' => false, 'tier' => self::TIER_FREE, 'label' => __( 'Bulk actions', 'foldrocket' ), 'description' => __( 'Select multiple items to assign to a folder or delete.', 'foldrocket' ), ), array( 'id' => 'bricks_media_browser', 'category' => 'integrations', 'aiPowered' => false, 'default' => true, 'locked' => false, 'tier' => self::TIER_FREE, 'label' => __( 'Bricks media browser', 'foldrocket' ), 'description' => __( 'Show virtual folders in the Bricks media browser. Files stay in uploads.', 'foldrocket' ), ), array( 'id' => 'media_modal_search', 'category' => 'integrations', 'aiPowered' => false, 'default' => true, 'locked' => false, 'tier' => self::TIER_FREE, 'label' => __( 'Media modal picker', 'foldrocket' ), 'description' => __( 'Folders and search in the WordPress media modal.', 'foldrocket' ), ), ); $modal = array_pop( $items ); $items = array_merge( $items, ProFeatureManifest::entries() ); if ( is_array( $modal ) ) { $items[] = $modal; } return $items; } /** @return array */ public static function defaults(): array { $out = array(); foreach ( self::catalog() as $feature ) { $out[ $feature['id'] ] = (bool) $feature['default']; } return $out; } /** @return array */ public static function stored(): array { $stored = get_option( self::OPTION, array() ); return is_array( $stored ) ? $stored : array(); } /** * Resolved enabled map (defaults + stored + locked rules). * Admin preference only — does not apply commercial entitlement. * * @return array */ public static function enabled_map(): array { $defaults = self::defaults(); $stored = self::stored(); $out = $defaults; foreach ( $defaults as $id => $_default ) { if ( array_key_exists( $id, $stored ) ) { $out[ $id ] = (bool) $stored[ $id ]; } } foreach ( self::catalog() as $feature ) { $id = $feature['id']; if ( ! empty( $feature['locked'] ) ) { $out[ $id ] = (bool) $feature['default']; } } return $out; } /** * Commercial tier for a feature id (`free` or `pro`). * Unknown ids default to free so core paths stay open. */ public static function tier_for( string $id ): string { if ( 'library' === $id ) { return self::TIER_FREE; } if ( 'semantic_vector_search' === $id ) { return self::TIER_PRO; } foreach ( self::catalog() as $feature ) { if ( $feature['id'] === $id ) { $tier = (string) ( $feature['tier'] ?? self::TIER_PRO ); return self::TIER_FREE === $tier ? self::TIER_FREE : self::TIER_PRO; } } return self::TIER_PRO; } public static function is_pro_tier( string $id ): bool { return self::TIER_PRO === self::tier_for( $id ); } /** Whether the current site is entitled to use this feature's tier. */ public static function is_entitled( string $id ): bool { if ( 'semantic_vector_search' === $id ) { return false; } if ( self::TIER_FREE === self::tier_for( $id ) ) { return true; } return self::license_is_active(); } /** * Admin preference only (Features page toggle), ignoring license. */ public static function is_enabled( string $id ): bool { // Always-on core — not listed on the Features page. if ( 'library' === $id ) { return true; } // Hard product lock — never enable, never surface in Features UI. if ( 'semantic_vector_search' === $id ) { return false; } $map = self::enabled_map(); if ( ! array_key_exists( $id, $map ) ) { return true; // Unknown IDs fail open for forward compatibility of core paths. } return (bool) $map[ $id ]; } /** * True when the feature may run (admin enabled + commercially entitled). * Prefer this over is_enabled() for UI gates and REST. */ public static function is_available( string $id ): bool { if ( 'library' === $id ) { return true; } if ( 'semantic_vector_search' === $id ) { return false; } return self::is_enabled( $id ) && self::is_entitled( $id ); } /** * Map of feature id → currently available (for FRKT_BOOT.features). * * @return array */ public static function available_map(): array { $out = array(); foreach ( self::enabled_map() as $id => $_enabled ) { $out[ $id ] = self::is_available( $id ); } return $out; } /** `free` or `pro` edition for the current site. */ public static function edition(): string { return self::license_is_active() ? self::TIER_PRO : self::TIER_FREE; } /** * Persist toggles. Locked features and non-entitled Pro features keep their value. * * @param array $incoming * @return array */ public static function update( array $incoming ): array { $current = self::enabled_map(); $locked = array(); foreach ( self::catalog() as $feature ) { if ( ! empty( $feature['locked'] ) ) { $locked[ $feature['id'] ] = true; } } foreach ( $incoming as $id => $value ) { $id = sanitize_key( (string) $id ); if ( $id === '' || ! array_key_exists( $id, $current ) ) { continue; } if ( isset( $locked[ $id ] ) ) { continue; } // Pro features cannot be toggled without an active license. if ( self::is_pro_tier( $id ) && ! self::license_is_active() ) { continue; } $current[ $id ] = (bool) $value; } unset( $current['semantic_vector_search'], $current['library'] ); update_option( self::OPTION, $current, false ); return self::enabled_map(); } /** * Catalog rows enriched with current state for the Features UI. * * @return list> */ public static function catalog_with_state(): array { $enabled = self::enabled_map(); $out = array(); foreach ( self::catalog() as $feature ) { $id = $feature['id']; $entitled = self::is_entitled( $id ); $catalog_locked = ! empty( $feature['locked'] ); $feature['enabled'] = (bool) ( $enabled[ $id ] ?? $feature['default'] ); $feature['entitled'] = $entitled; $feature['available'] = self::is_available( $id ); $feature['requiresPro'] = self::is_pro_tier( $id ); // UI lock: catalog-locked or Pro without entitlement. $feature['locked'] = $catalog_locked || ( self::is_pro_tier( $id ) && ! $entitled ); $out[] = $feature; } return $out; } /** Ensure option exists with known keys (idempotent). */ public static function ensure_option(): void { $defaults = self::defaults(); $stored = self::stored(); $merged = array_merge( $defaults, array_intersect_key( $stored, $defaults ) ); // Never persist always-on / product-disabled keys. unset( $merged['semantic_vector_search'], $merged['library'] ); if ( $merged !== $stored ) { update_option( self::OPTION, $merged, false ); } } private static function license_is_active(): bool { if ( ! class_exists( \FoldRocket\Commercial\LicenseBridge::class ) ) { return false; } return \FoldRocket\Commercial\LicenseBridge::is_active(); } }