feat: Add license management and tabbed settings (v0.3.0)

- Implement license management using magdev/wc-licensed-product-client
- Reorganize settings page into License, Default Settings, Integrations tabs
- Add license validation and activation via AJAX
- Frontend features require valid license (admin works always)
- Update translations with German (de_CH) for license strings

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-29 12:03:05 +01:00
parent d62f01cf41
commit f3cd19efe0
15 changed files with 6539 additions and 99 deletions

View File

@@ -7,6 +7,8 @@
namespace WP_FediStream\Frontend;
use WP_FediStream\License\Manager as LicenseManager;
// Prevent direct file access.
if ( ! defined( 'ABSPATH' ) ) {
exit;
@@ -36,6 +38,11 @@ class Ajax {
* @return void
*/
public function get_track(): void {
// Check license.
if ( ! LicenseManager::is_license_valid() ) {
wp_send_json_error( array( 'message' => __( 'This feature requires a valid license.', 'wp-fedistream' ) ) );
}
// Verify nonce.
if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( sanitize_key( $_POST['nonce'] ), 'wp-fedistream-nonce' ) ) {
wp_send_json_error( array( 'message' => __( 'Invalid nonce.', 'wp-fedistream' ) ) );
@@ -125,6 +132,11 @@ class Ajax {
* @return void
*/
public function record_play(): void {
// Check license.
if ( ! LicenseManager::is_license_valid() ) {
wp_send_json_error( array( 'message' => __( 'This feature requires a valid license.', 'wp-fedistream' ) ) );
}
// Verify nonce.
if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( sanitize_key( $_POST['nonce'] ), 'wp-fedistream-nonce' ) ) {
wp_send_json_error( array( 'message' => __( 'Invalid nonce.', 'wp-fedistream' ) ) );

View File

@@ -27,13 +27,35 @@ class Shortcodes {
private Plugin $plugin;
/**
* Constructor.
* Whether running in unlicensed mode.
*
* @var bool
*/
public function __construct() {
$this->plugin = Plugin::get_instance();
private bool $unlicensed_mode = false;
/**
* Constructor.
*
* @param bool $unlicensed_mode Whether to run in unlicensed mode.
*/
public function __construct( bool $unlicensed_mode = false ) {
$this->plugin = Plugin::get_instance();
$this->unlicensed_mode = $unlicensed_mode;
$this->register_shortcodes();
}
/**
* Get the unlicensed message HTML.
*
* @return string
*/
private function get_unlicensed_message(): string {
return '<div class="fedistream-unlicensed-notice" style="padding: 20px; background: #f0f0f1; border-left: 4px solid #dba617; margin: 10px 0;">'
. '<p style="margin: 0; color: #50575e;">'
. esc_html__( 'This content requires a valid FediStream license.', 'wp-fedistream' )
. '</p></div>';
}
/**
* Register all shortcodes.
*
@@ -501,6 +523,11 @@ class Shortcodes {
* @return string
*/
private function render_template( string $template, array $context ): string {
// Check for unlicensed mode.
if ( $this->unlicensed_mode ) {
return $this->get_unlicensed_message();
}
try {
return $this->plugin->render( $template, $context );
} catch ( \Exception $e ) {