You've already forked wp-fedistream
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:
@@ -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' ) ) );
|
||||
|
||||
@@ -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 ) {
|
||||
|
||||
@@ -345,11 +345,18 @@ class Installer {
|
||||
*/
|
||||
private static function set_default_options(): void {
|
||||
$defaults = array(
|
||||
'wp_fedistream_enable_activitypub' => 1,
|
||||
'wp_fedistream_enable_woocommerce' => 0,
|
||||
'wp_fedistream_audio_formats' => array( 'mp3', 'wav', 'flac', 'ogg' ),
|
||||
'wp_fedistream_max_upload_size' => 50, // MB
|
||||
'wp_fedistream_default_license' => 'all-rights-reserved',
|
||||
'wp_fedistream_enable_activitypub' => 1,
|
||||
'wp_fedistream_enable_woocommerce' => 0,
|
||||
'wp_fedistream_audio_formats' => array( 'mp3', 'wav', 'flac', 'ogg' ),
|
||||
'wp_fedistream_max_upload_size' => 50, // MB
|
||||
'wp_fedistream_default_license' => 'all-rights-reserved',
|
||||
// License management options.
|
||||
'wp_fedistream_license_key' => '',
|
||||
'wp_fedistream_license_server_url' => '',
|
||||
'wp_fedistream_license_server_secret' => '',
|
||||
'wp_fedistream_license_status' => 'unchecked',
|
||||
'wp_fedistream_license_data' => array(),
|
||||
'wp_fedistream_license_last_check' => 0,
|
||||
);
|
||||
|
||||
foreach ( $defaults as $option => $value ) {
|
||||
|
||||
653
includes/License/Manager.php
Normal file
653
includes/License/Manager.php
Normal file
@@ -0,0 +1,653 @@
|
||||
<?php
|
||||
/**
|
||||
* License management class.
|
||||
*
|
||||
* Wraps the wc-licensed-product-client library for WordPress integration.
|
||||
*
|
||||
* @package WP_FediStream
|
||||
*/
|
||||
|
||||
namespace WP_FediStream\License;
|
||||
|
||||
use Magdev\WcLicensedProductClient\SecureLicenseClient;
|
||||
use Magdev\WcLicensedProductClient\Dto\LicenseInfo;
|
||||
use Magdev\WcLicensedProductClient\Dto\LicenseStatus;
|
||||
use Magdev\WcLicensedProductClient\Dto\LicenseState;
|
||||
use Magdev\WcLicensedProductClient\Dto\ActivationResult;
|
||||
use Magdev\WcLicensedProductClient\Exception\LicenseException;
|
||||
use Magdev\WcLicensedProductClient\Exception\LicenseNotFoundException;
|
||||
use Magdev\WcLicensedProductClient\Exception\LicenseExpiredException;
|
||||
use Magdev\WcLicensedProductClient\Exception\LicenseInvalidException;
|
||||
use Magdev\WcLicensedProductClient\Exception\LicenseRevokedException;
|
||||
use Magdev\WcLicensedProductClient\Exception\LicenseInactiveException;
|
||||
use Magdev\WcLicensedProductClient\Exception\DomainMismatchException;
|
||||
use Magdev\WcLicensedProductClient\Exception\MaxActivationsReachedException;
|
||||
use Magdev\WcLicensedProductClient\Exception\RateLimitExceededException;
|
||||
use Magdev\WcLicensedProductClient\Security\SignatureException;
|
||||
use Symfony\Component\HttpClient\HttpClient;
|
||||
|
||||
// Prevent direct file access.
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* License Manager class.
|
||||
*
|
||||
* Handles license validation, activation, and status checking.
|
||||
*/
|
||||
final class Manager {
|
||||
|
||||
/**
|
||||
* Option names for license settings.
|
||||
*/
|
||||
public const OPTION_LICENSE_KEY = 'wp_fedistream_license_key';
|
||||
public const OPTION_SERVER_URL = 'wp_fedistream_license_server_url';
|
||||
public const OPTION_SERVER_SECRET = 'wp_fedistream_license_server_secret';
|
||||
public const OPTION_LICENSE_STATUS = 'wp_fedistream_license_status';
|
||||
public const OPTION_LICENSE_DATA = 'wp_fedistream_license_data';
|
||||
public const OPTION_LAST_CHECK = 'wp_fedistream_license_last_check';
|
||||
|
||||
/**
|
||||
* Transient name for caching license validation.
|
||||
*/
|
||||
private const TRANSIENT_LICENSE_CHECK = 'wp_fedistream_license_check';
|
||||
|
||||
/**
|
||||
* Cache TTL in seconds (24 hours).
|
||||
*/
|
||||
private const CACHE_TTL = 86400;
|
||||
|
||||
/**
|
||||
* Singleton instance.
|
||||
*
|
||||
* @var Manager|null
|
||||
*/
|
||||
private static ?Manager $instance = null;
|
||||
|
||||
/**
|
||||
* License client instance.
|
||||
*
|
||||
* @var SecureLicenseClient|null
|
||||
*/
|
||||
private ?SecureLicenseClient $client = null;
|
||||
|
||||
/**
|
||||
* Get singleton instance.
|
||||
*
|
||||
* @return Manager
|
||||
*/
|
||||
public static function get_instance(): Manager {
|
||||
if ( null === self::$instance ) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Private constructor.
|
||||
*/
|
||||
private function __construct() {
|
||||
$this->init_hooks();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize WordPress hooks.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function init_hooks(): void {
|
||||
add_action( 'wp_ajax_fedistream_validate_license', array( $this, 'ajax_validate_license' ) );
|
||||
add_action( 'wp_ajax_fedistream_activate_license', array( $this, 'ajax_activate_license' ) );
|
||||
add_action( 'wp_ajax_fedistream_deactivate_license', array( $this, 'ajax_deactivate_license' ) );
|
||||
add_action( 'wp_ajax_fedistream_check_license_status', array( $this, 'ajax_check_status' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the license client.
|
||||
*
|
||||
* @return bool True if client was initialized successfully.
|
||||
*/
|
||||
private function init_client(): bool {
|
||||
if ( null !== $this->client ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$server_url = self::get_server_url();
|
||||
$server_secret = self::get_server_secret();
|
||||
|
||||
if ( empty( $server_url ) || empty( $server_secret ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
$this->client = new SecureLicenseClient(
|
||||
httpClient: HttpClient::create(),
|
||||
baseUrl: $server_url,
|
||||
serverSecret: $server_secret,
|
||||
);
|
||||
return true;
|
||||
} catch ( \Throwable $e ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate the current license.
|
||||
*
|
||||
* @return array{success: bool, message: string, data?: array}
|
||||
*/
|
||||
public function validate(): array {
|
||||
if ( ! $this->init_client() ) {
|
||||
return array(
|
||||
'success' => false,
|
||||
'message' => __( 'License server configuration is incomplete.', 'wp-fedistream' ),
|
||||
);
|
||||
}
|
||||
|
||||
$license_key = self::get_license_key();
|
||||
if ( empty( $license_key ) ) {
|
||||
return array(
|
||||
'success' => false,
|
||||
'message' => __( 'No license key provided.', 'wp-fedistream' ),
|
||||
);
|
||||
}
|
||||
|
||||
$domain = wp_parse_url( home_url(), PHP_URL_HOST );
|
||||
|
||||
try {
|
||||
$result = $this->client->validate( $license_key, $domain );
|
||||
|
||||
// Update cached status.
|
||||
$this->update_cached_status( 'valid', array(
|
||||
'product_id' => $result->productId,
|
||||
'expires_at' => $result->expiresAt?->format( 'c' ),
|
||||
'version_id' => $result->versionId,
|
||||
) );
|
||||
|
||||
return array(
|
||||
'success' => true,
|
||||
'message' => __( 'License validated successfully.', 'wp-fedistream' ),
|
||||
'data' => array(
|
||||
'status' => 'valid',
|
||||
'product_id' => $result->productId,
|
||||
'expires_at' => $result->expiresAt?->format( 'Y-m-d' ),
|
||||
'lifetime' => $result->isLifetime(),
|
||||
),
|
||||
);
|
||||
} catch ( LicenseNotFoundException $e ) {
|
||||
$this->update_cached_status( 'invalid' );
|
||||
return array(
|
||||
'success' => false,
|
||||
'message' => __( 'License key not found. Please check your license key.', 'wp-fedistream' ),
|
||||
);
|
||||
} catch ( LicenseExpiredException $e ) {
|
||||
$this->update_cached_status( 'expired' );
|
||||
return array(
|
||||
'success' => false,
|
||||
'message' => __( 'Your license has expired. Please renew to continue.', 'wp-fedistream' ),
|
||||
);
|
||||
} catch ( LicenseRevokedException $e ) {
|
||||
$this->update_cached_status( 'revoked' );
|
||||
return array(
|
||||
'success' => false,
|
||||
'message' => __( 'Your license has been revoked.', 'wp-fedistream' ),
|
||||
);
|
||||
} catch ( LicenseInactiveException $e ) {
|
||||
$this->update_cached_status( 'inactive' );
|
||||
return array(
|
||||
'success' => false,
|
||||
'message' => __( 'License is inactive. Please activate it first.', 'wp-fedistream' ),
|
||||
);
|
||||
} catch ( DomainMismatchException $e ) {
|
||||
$this->update_cached_status( 'invalid' );
|
||||
return array(
|
||||
'success' => false,
|
||||
'message' => __( 'This license is not activated for this domain.', 'wp-fedistream' ),
|
||||
);
|
||||
} catch ( SignatureException $e ) {
|
||||
return array(
|
||||
'success' => false,
|
||||
'message' => __( 'License verification failed. Please check your server secret.', 'wp-fedistream' ),
|
||||
);
|
||||
} catch ( RateLimitExceededException $e ) {
|
||||
return array(
|
||||
'success' => false,
|
||||
'message' => __( 'Too many requests. Please try again later.', 'wp-fedistream' ),
|
||||
);
|
||||
} catch ( LicenseException $e ) {
|
||||
return array(
|
||||
'success' => false,
|
||||
'message' => sprintf(
|
||||
/* translators: %s: Error message */
|
||||
__( 'License validation failed: %s', 'wp-fedistream' ),
|
||||
$e->getMessage()
|
||||
),
|
||||
);
|
||||
} catch ( \Throwable $e ) {
|
||||
return array(
|
||||
'success' => false,
|
||||
'message' => __( 'Unable to verify license. Please try again later.', 'wp-fedistream' ),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate the license for this domain.
|
||||
*
|
||||
* @return array{success: bool, message: string, data?: array}
|
||||
*/
|
||||
public function activate(): array {
|
||||
if ( ! $this->init_client() ) {
|
||||
return array(
|
||||
'success' => false,
|
||||
'message' => __( 'License server configuration is incomplete.', 'wp-fedistream' ),
|
||||
);
|
||||
}
|
||||
|
||||
$license_key = self::get_license_key();
|
||||
if ( empty( $license_key ) ) {
|
||||
return array(
|
||||
'success' => false,
|
||||
'message' => __( 'No license key provided.', 'wp-fedistream' ),
|
||||
);
|
||||
}
|
||||
|
||||
$domain = wp_parse_url( home_url(), PHP_URL_HOST );
|
||||
|
||||
try {
|
||||
$result = $this->client->activate( $license_key, $domain );
|
||||
|
||||
if ( $result->success ) {
|
||||
// Validate after activation to get full license info.
|
||||
return $this->validate();
|
||||
}
|
||||
|
||||
return array(
|
||||
'success' => false,
|
||||
'message' => $result->message,
|
||||
);
|
||||
} catch ( MaxActivationsReachedException $e ) {
|
||||
return array(
|
||||
'success' => false,
|
||||
'message' => __( 'Maximum number of activations reached. Please deactivate another site first.', 'wp-fedistream' ),
|
||||
);
|
||||
} catch ( LicenseNotFoundException $e ) {
|
||||
return array(
|
||||
'success' => false,
|
||||
'message' => __( 'License key not found. Please check your license key.', 'wp-fedistream' ),
|
||||
);
|
||||
} catch ( LicenseExpiredException $e ) {
|
||||
return array(
|
||||
'success' => false,
|
||||
'message' => __( 'Your license has expired. Please renew to continue.', 'wp-fedistream' ),
|
||||
);
|
||||
} catch ( SignatureException $e ) {
|
||||
return array(
|
||||
'success' => false,
|
||||
'message' => __( 'License verification failed. Please check your server secret.', 'wp-fedistream' ),
|
||||
);
|
||||
} catch ( LicenseException $e ) {
|
||||
return array(
|
||||
'success' => false,
|
||||
'message' => sprintf(
|
||||
/* translators: %s: Error message */
|
||||
__( 'License activation failed: %s', 'wp-fedistream' ),
|
||||
$e->getMessage()
|
||||
),
|
||||
);
|
||||
} catch ( \Throwable $e ) {
|
||||
return array(
|
||||
'success' => false,
|
||||
'message' => __( 'Unable to activate license. Please try again later.', 'wp-fedistream' ),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current license status.
|
||||
*
|
||||
* @param bool $force_refresh Force a fresh check from the server.
|
||||
* @return array{success: bool, message: string, data?: array}
|
||||
*/
|
||||
public function get_status( bool $force_refresh = false ): array {
|
||||
// Check cached status first.
|
||||
if ( ! $force_refresh ) {
|
||||
$cached = $this->get_cached_validation();
|
||||
if ( null !== $cached ) {
|
||||
return $cached;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! $this->init_client() ) {
|
||||
return array(
|
||||
'success' => false,
|
||||
'message' => __( 'License server configuration is incomplete.', 'wp-fedistream' ),
|
||||
'data' => array(
|
||||
'status' => 'unconfigured',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
$license_key = self::get_license_key();
|
||||
if ( empty( $license_key ) ) {
|
||||
return array(
|
||||
'success' => false,
|
||||
'message' => __( 'No license key configured.', 'wp-fedistream' ),
|
||||
'data' => array(
|
||||
'status' => 'unchecked',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
$result = $this->client->status( $license_key );
|
||||
|
||||
$status_map = array(
|
||||
LicenseState::Active->value => 'valid',
|
||||
LicenseState::Inactive->value => 'inactive',
|
||||
LicenseState::Expired->value => 'expired',
|
||||
LicenseState::Revoked->value => 'revoked',
|
||||
);
|
||||
|
||||
$status = $status_map[ $result->status->value ] ?? 'invalid';
|
||||
|
||||
$data = array(
|
||||
'status' => $status,
|
||||
'valid' => $result->valid,
|
||||
'domain' => $result->domain,
|
||||
'expires_at' => $result->expiresAt?->format( 'Y-m-d' ),
|
||||
'lifetime' => $result->isLifetime(),
|
||||
'activations_count' => $result->activationsCount,
|
||||
'max_activations' => $result->maxActivations,
|
||||
);
|
||||
|
||||
// Cache the result.
|
||||
$this->cache_validation( array(
|
||||
'success' => $result->valid,
|
||||
'message' => $result->valid
|
||||
? __( 'License is active.', 'wp-fedistream' )
|
||||
: __( 'License is not active.', 'wp-fedistream' ),
|
||||
'data' => $data,
|
||||
) );
|
||||
|
||||
$this->update_cached_status( $status, $data );
|
||||
|
||||
return array(
|
||||
'success' => $result->valid,
|
||||
'message' => $result->valid
|
||||
? __( 'License is active.', 'wp-fedistream' )
|
||||
: __( 'License is not active.', 'wp-fedistream' ),
|
||||
'data' => $data,
|
||||
);
|
||||
} catch ( LicenseNotFoundException $e ) {
|
||||
$this->update_cached_status( 'invalid' );
|
||||
return array(
|
||||
'success' => false,
|
||||
'message' => __( 'License key not found.', 'wp-fedistream' ),
|
||||
'data' => array(
|
||||
'status' => 'invalid',
|
||||
),
|
||||
);
|
||||
} catch ( SignatureException $e ) {
|
||||
return array(
|
||||
'success' => false,
|
||||
'message' => __( 'License verification failed. Please check your server secret.', 'wp-fedistream' ),
|
||||
'data' => array(
|
||||
'status' => 'error',
|
||||
),
|
||||
);
|
||||
} catch ( \Throwable $e ) {
|
||||
return array(
|
||||
'success' => false,
|
||||
'message' => __( 'Unable to check license status.', 'wp-fedistream' ),
|
||||
'data' => array(
|
||||
'status' => 'error',
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deactivate the license (clear local data).
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function deactivate(): bool {
|
||||
self::clear_license_data();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the license is currently valid.
|
||||
*
|
||||
* Uses cached status for performance.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function is_license_valid(): bool {
|
||||
$status = get_option( self::OPTION_LICENSE_STATUS, 'unchecked' );
|
||||
return 'valid' === $status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the license key.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_license_key(): string {
|
||||
return get_option( self::OPTION_LICENSE_KEY, '' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the license server URL.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_server_url(): string {
|
||||
return get_option( self::OPTION_SERVER_URL, '' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the server secret.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_server_secret(): string {
|
||||
return get_option( self::OPTION_SERVER_SECRET, '' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cached license status.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_cached_status(): string {
|
||||
return get_option( self::OPTION_LICENSE_STATUS, 'unchecked' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cached license data.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_cached_data(): array {
|
||||
return get_option( self::OPTION_LICENSE_DATA, array() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get last check timestamp.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public static function get_last_check(): int {
|
||||
return (int) get_option( self::OPTION_LAST_CHECK, 0 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Save license settings.
|
||||
*
|
||||
* @param array $data Settings data.
|
||||
* @return bool
|
||||
*/
|
||||
public static function save_settings( array $data ): bool {
|
||||
if ( isset( $data['license_key'] ) ) {
|
||||
update_option( self::OPTION_LICENSE_KEY, sanitize_text_field( $data['license_key'] ) );
|
||||
}
|
||||
|
||||
if ( isset( $data['server_url'] ) ) {
|
||||
update_option( self::OPTION_SERVER_URL, esc_url_raw( $data['server_url'] ) );
|
||||
}
|
||||
|
||||
if ( isset( $data['server_secret'] ) ) {
|
||||
// Only update if a new secret is provided.
|
||||
$secret = sanitize_text_field( $data['server_secret'] );
|
||||
if ( ! empty( $secret ) ) {
|
||||
update_option( self::OPTION_SERVER_SECRET, $secret );
|
||||
}
|
||||
}
|
||||
|
||||
// Reset status when settings change.
|
||||
update_option( self::OPTION_LICENSE_STATUS, 'unchecked' );
|
||||
delete_transient( self::TRANSIENT_LICENSE_CHECK );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all license data.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function clear_license_data(): void {
|
||||
update_option( self::OPTION_LICENSE_STATUS, 'unchecked' );
|
||||
update_option( self::OPTION_LICENSE_DATA, array() );
|
||||
update_option( self::OPTION_LAST_CHECK, 0 );
|
||||
delete_transient( self::TRANSIENT_LICENSE_CHECK );
|
||||
}
|
||||
|
||||
/**
|
||||
* Update cached license status.
|
||||
*
|
||||
* @param string $status Status value.
|
||||
* @param array $data Additional data.
|
||||
* @return void
|
||||
*/
|
||||
private function update_cached_status( string $status, array $data = array() ): void {
|
||||
update_option( self::OPTION_LICENSE_STATUS, $status );
|
||||
update_option( self::OPTION_LICENSE_DATA, $data );
|
||||
update_option( self::OPTION_LAST_CHECK, time() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Cache validation result.
|
||||
*
|
||||
* @param array $result Validation result.
|
||||
* @return void
|
||||
*/
|
||||
private function cache_validation( array $result ): void {
|
||||
set_transient( self::TRANSIENT_LICENSE_CHECK, $result, self::CACHE_TTL );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cached validation result.
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
private function get_cached_validation(): ?array {
|
||||
$cached = get_transient( self::TRANSIENT_LICENSE_CHECK );
|
||||
return false === $cached ? null : $cached;
|
||||
}
|
||||
|
||||
/**
|
||||
* AJAX handler: Validate license.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function ajax_validate_license(): void {
|
||||
check_ajax_referer( 'fedistream_license_action', 'nonce' );
|
||||
|
||||
if ( ! current_user_can( 'manage_fedistream_settings' ) ) {
|
||||
wp_send_json_error( array(
|
||||
'message' => __( 'You do not have permission to perform this action.', 'wp-fedistream' ),
|
||||
) );
|
||||
}
|
||||
|
||||
$result = $this->validate();
|
||||
|
||||
if ( $result['success'] ) {
|
||||
wp_send_json_success( $result );
|
||||
} else {
|
||||
wp_send_json_error( $result );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* AJAX handler: Activate license.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function ajax_activate_license(): void {
|
||||
check_ajax_referer( 'fedistream_license_action', 'nonce' );
|
||||
|
||||
if ( ! current_user_can( 'manage_fedistream_settings' ) ) {
|
||||
wp_send_json_error( array(
|
||||
'message' => __( 'You do not have permission to perform this action.', 'wp-fedistream' ),
|
||||
) );
|
||||
}
|
||||
|
||||
$result = $this->activate();
|
||||
|
||||
if ( $result['success'] ) {
|
||||
wp_send_json_success( $result );
|
||||
} else {
|
||||
wp_send_json_error( $result );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* AJAX handler: Deactivate license.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function ajax_deactivate_license(): void {
|
||||
check_ajax_referer( 'fedistream_license_action', 'nonce' );
|
||||
|
||||
if ( ! current_user_can( 'manage_fedistream_settings' ) ) {
|
||||
wp_send_json_error( array(
|
||||
'message' => __( 'You do not have permission to perform this action.', 'wp-fedistream' ),
|
||||
) );
|
||||
}
|
||||
|
||||
$this->deactivate();
|
||||
|
||||
wp_send_json_success( array(
|
||||
'success' => true,
|
||||
'message' => __( 'License deactivated.', 'wp-fedistream' ),
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* AJAX handler: Check license status.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function ajax_check_status(): void {
|
||||
check_ajax_referer( 'fedistream_license_action', 'nonce' );
|
||||
|
||||
if ( ! current_user_can( 'manage_fedistream_settings' ) ) {
|
||||
wp_send_json_error( array(
|
||||
'message' => __( 'You do not have permission to perform this action.', 'wp-fedistream' ),
|
||||
) );
|
||||
}
|
||||
|
||||
$force_refresh = isset( $_POST['force'] ) && 'true' === $_POST['force'];
|
||||
$result = $this->get_status( $force_refresh );
|
||||
|
||||
if ( $result['success'] ) {
|
||||
wp_send_json_success( $result );
|
||||
} else {
|
||||
wp_send_json_error( $result );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,7 @@ use WP_FediStream\Taxonomies\License;
|
||||
use WP_FediStream\User\Library as UserLibrary;
|
||||
use WP_FediStream\User\LibraryPage;
|
||||
use WP_FediStream\User\Notifications;
|
||||
use WP_FediStream\License\Manager as LicenseManager;
|
||||
|
||||
// Prevent direct file access.
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
@@ -155,10 +156,13 @@ final class Plugin {
|
||||
new ListColumns();
|
||||
}
|
||||
|
||||
// Initialize frontend components.
|
||||
if ( ! is_admin() ) {
|
||||
// Initialize frontend components (only if licensed).
|
||||
if ( ! is_admin() && LicenseManager::is_license_valid() ) {
|
||||
new TemplateLoader();
|
||||
new Shortcodes();
|
||||
} elseif ( ! is_admin() ) {
|
||||
// Register shortcodes that show license message.
|
||||
new Shortcodes( true ); // Unlicensed mode.
|
||||
}
|
||||
|
||||
// Initialize widgets (always needed for admin widget management).
|
||||
@@ -167,8 +171,8 @@ final class Plugin {
|
||||
// Initialize AJAX handlers.
|
||||
new Ajax();
|
||||
|
||||
// Initialize ActivityPub integration.
|
||||
if ( get_option( 'wp_fedistream_enable_activitypub', 1 ) ) {
|
||||
// Initialize ActivityPub integration (only if licensed and enabled).
|
||||
if ( get_option( 'wp_fedistream_enable_activitypub', 1 ) && LicenseManager::is_license_valid() ) {
|
||||
new ActivityPubIntegration();
|
||||
new ActivityPubRestApi();
|
||||
}
|
||||
@@ -184,6 +188,9 @@ final class Plugin {
|
||||
new UserLibrary();
|
||||
new LibraryPage();
|
||||
new Notifications();
|
||||
|
||||
// Initialize license manager.
|
||||
LicenseManager::get_instance();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -409,86 +416,334 @@ final class Plugin {
|
||||
return;
|
||||
}
|
||||
|
||||
// Save settings.
|
||||
if ( isset( $_POST['fedistream_settings_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['fedistream_settings_nonce'] ), 'fedistream_save_settings' ) ) {
|
||||
update_option( 'wp_fedistream_enable_activitypub', isset( $_POST['enable_activitypub'] ) ? 1 : 0 );
|
||||
update_option( 'wp_fedistream_enable_woocommerce', isset( $_POST['enable_woocommerce'] ) ? 1 : 0 );
|
||||
update_option( 'wp_fedistream_max_upload_size', absint( $_POST['max_upload_size'] ?? 50 ) );
|
||||
update_option( 'wp_fedistream_default_license', sanitize_text_field( wp_unslash( $_POST['default_license'] ?? 'all-rights-reserved' ) ) );
|
||||
// Get current tab.
|
||||
$current_tab = isset( $_GET['tab'] ) ? sanitize_key( $_GET['tab'] ) : 'license';
|
||||
|
||||
echo '<div class="notice notice-success is-dismissible"><p>' . esc_html__( 'Settings saved.', 'wp-fedistream' ) . '</p></div>';
|
||||
}
|
||||
// Handle form submissions.
|
||||
$this->handle_settings_save( $current_tab );
|
||||
|
||||
// Get current settings.
|
||||
$enable_activitypub = get_option( 'wp_fedistream_enable_activitypub', 1 );
|
||||
$enable_woocommerce = get_option( 'wp_fedistream_enable_woocommerce', 0 );
|
||||
$max_upload_size = get_option( 'wp_fedistream_max_upload_size', 50 );
|
||||
$default_license = get_option( 'wp_fedistream_default_license', 'all-rights-reserved' );
|
||||
|
||||
// License settings.
|
||||
$license_key = LicenseManager::get_license_key();
|
||||
$license_server_url = LicenseManager::get_server_url();
|
||||
$license_status = LicenseManager::get_cached_status();
|
||||
$license_data = LicenseManager::get_cached_data();
|
||||
$last_check = LicenseManager::get_last_check();
|
||||
|
||||
$tabs = array(
|
||||
'license' => __( 'License', 'wp-fedistream' ),
|
||||
'settings' => __( 'Default Settings', 'wp-fedistream' ),
|
||||
'integrations' => __( 'Integrations', 'wp-fedistream' ),
|
||||
);
|
||||
?>
|
||||
<div class="wrap">
|
||||
<h1><?php esc_html_e( 'FediStream Settings', 'wp-fedistream' ); ?></h1>
|
||||
|
||||
<form method="post" action="">
|
||||
<?php wp_nonce_field( 'fedistream_save_settings', 'fedistream_settings_nonce' ); ?>
|
||||
<nav class="nav-tab-wrapper wp-clearfix">
|
||||
<?php foreach ( $tabs as $tab_key => $tab_label ) : ?>
|
||||
<a href="<?php echo esc_url( admin_url( 'admin.php?page=fedistream-settings&tab=' . $tab_key ) ); ?>"
|
||||
class="nav-tab <?php echo $current_tab === $tab_key ? 'nav-tab-active' : ''; ?>">
|
||||
<?php echo esc_html( $tab_label ); ?>
|
||||
</a>
|
||||
<?php endforeach; ?>
|
||||
</nav>
|
||||
|
||||
<table class="form-table">
|
||||
<tr>
|
||||
<th scope="row"><?php esc_html_e( 'ActivityPub Integration', 'wp-fedistream' ); ?></th>
|
||||
<td>
|
||||
<label>
|
||||
<input type="checkbox" name="enable_activitypub" value="1" <?php checked( $enable_activitypub, 1 ); ?>>
|
||||
<?php esc_html_e( 'Enable ActivityPub features', 'wp-fedistream' ); ?>
|
||||
</label>
|
||||
<p class="description"><?php esc_html_e( 'Publish releases to the Fediverse and allow followers.', 'wp-fedistream' ); ?></p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row"><?php esc_html_e( 'WooCommerce Integration', 'wp-fedistream' ); ?></th>
|
||||
<td>
|
||||
<label>
|
||||
<input type="checkbox" name="enable_woocommerce" value="1" <?php checked( $enable_woocommerce, 1 ); ?> <?php disabled( ! $this->is_woocommerce_active() ); ?>>
|
||||
<?php esc_html_e( 'Enable WooCommerce features', 'wp-fedistream' ); ?>
|
||||
</label>
|
||||
<?php if ( ! $this->is_woocommerce_active() ) : ?>
|
||||
<p class="description" style="color: #d63638;"><?php esc_html_e( 'WooCommerce is not installed or active.', 'wp-fedistream' ); ?></p>
|
||||
<?php else : ?>
|
||||
<p class="description"><?php esc_html_e( 'Sell albums and tracks through WooCommerce.', 'wp-fedistream' ); ?></p>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">
|
||||
<label for="max_upload_size"><?php esc_html_e( 'Max Upload Size', 'wp-fedistream' ); ?></label>
|
||||
</th>
|
||||
<td>
|
||||
<input type="number" name="max_upload_size" id="max_upload_size" value="<?php echo esc_attr( $max_upload_size ); ?>" min="1" max="500" class="small-text"> MB
|
||||
<p class="description"><?php esc_html_e( 'Maximum file size for audio uploads.', 'wp-fedistream' ); ?></p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">
|
||||
<label for="default_license"><?php esc_html_e( 'Default License', 'wp-fedistream' ); ?></label>
|
||||
</th>
|
||||
<td>
|
||||
<select name="default_license" id="default_license">
|
||||
<option value="all-rights-reserved" <?php selected( $default_license, 'all-rights-reserved' ); ?>><?php esc_html_e( 'All Rights Reserved', 'wp-fedistream' ); ?></option>
|
||||
<option value="cc-by" <?php selected( $default_license, 'cc-by' ); ?>>CC BY</option>
|
||||
<option value="cc-by-sa" <?php selected( $default_license, 'cc-by-sa' ); ?>>CC BY-SA</option>
|
||||
<option value="cc-by-nc" <?php selected( $default_license, 'cc-by-nc' ); ?>>CC BY-NC</option>
|
||||
<option value="cc-by-nc-sa" <?php selected( $default_license, 'cc-by-nc-sa' ); ?>>CC BY-NC-SA</option>
|
||||
<option value="cc0" <?php selected( $default_license, 'cc0' ); ?>>CC0 (Public Domain)</option>
|
||||
</select>
|
||||
<p class="description"><?php esc_html_e( 'Default license for new uploads.', 'wp-fedistream' ); ?></p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<?php submit_button(); ?>
|
||||
</form>
|
||||
<div class="fedistream-settings-content">
|
||||
<?php
|
||||
switch ( $current_tab ) {
|
||||
case 'license':
|
||||
$this->render_license_tab( $license_key, $license_server_url, $license_status, $license_data, $last_check );
|
||||
break;
|
||||
case 'settings':
|
||||
$this->render_settings_tab( $max_upload_size, $default_license );
|
||||
break;
|
||||
case 'integrations':
|
||||
$this->render_integrations_tab( $enable_activitypub, $enable_woocommerce );
|
||||
break;
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle settings form submission.
|
||||
*
|
||||
* @param string $tab Current tab.
|
||||
* @return void
|
||||
*/
|
||||
private function handle_settings_save( string $tab ): void {
|
||||
if ( ! isset( $_POST['fedistream_settings_nonce'] ) || ! wp_verify_nonce( sanitize_key( $_POST['fedistream_settings_nonce'] ), 'fedistream_save_settings' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch ( $tab ) {
|
||||
case 'license':
|
||||
LicenseManager::save_settings( array(
|
||||
'license_key' => isset( $_POST['license_key'] ) ? sanitize_text_field( wp_unslash( $_POST['license_key'] ) ) : '',
|
||||
'server_url' => isset( $_POST['license_server_url'] ) ? esc_url_raw( wp_unslash( $_POST['license_server_url'] ) ) : '',
|
||||
'server_secret' => isset( $_POST['license_server_secret'] ) ? sanitize_text_field( wp_unslash( $_POST['license_server_secret'] ) ) : '',
|
||||
) );
|
||||
echo '<div class="notice notice-success is-dismissible"><p>' . esc_html__( 'License settings saved.', 'wp-fedistream' ) . '</p></div>';
|
||||
break;
|
||||
|
||||
case 'settings':
|
||||
update_option( 'wp_fedistream_max_upload_size', absint( $_POST['max_upload_size'] ?? 50 ) );
|
||||
update_option( 'wp_fedistream_default_license', sanitize_text_field( wp_unslash( $_POST['default_license'] ?? 'all-rights-reserved' ) ) );
|
||||
echo '<div class="notice notice-success is-dismissible"><p>' . esc_html__( 'Settings saved.', 'wp-fedistream' ) . '</p></div>';
|
||||
break;
|
||||
|
||||
case 'integrations':
|
||||
update_option( 'wp_fedistream_enable_activitypub', isset( $_POST['enable_activitypub'] ) ? 1 : 0 );
|
||||
update_option( 'wp_fedistream_enable_woocommerce', isset( $_POST['enable_woocommerce'] ) ? 1 : 0 );
|
||||
echo '<div class="notice notice-success is-dismissible"><p>' . esc_html__( 'Integration settings saved.', 'wp-fedistream' ) . '</p></div>';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the License tab.
|
||||
*
|
||||
* @param string $license_key License key.
|
||||
* @param string $server_url Server URL.
|
||||
* @param string $status License status.
|
||||
* @param array $license_data License data.
|
||||
* @param int $last_check Last check timestamp.
|
||||
* @return void
|
||||
*/
|
||||
private function render_license_tab( string $license_key, string $server_url, string $status, array $license_data, int $last_check ): void {
|
||||
$status_classes = array(
|
||||
'valid' => 'notice-success',
|
||||
'invalid' => 'notice-error',
|
||||
'expired' => 'notice-warning',
|
||||
'revoked' => 'notice-error',
|
||||
'inactive' => 'notice-warning',
|
||||
'unchecked' => 'notice-info',
|
||||
'unconfigured' => 'notice-info',
|
||||
);
|
||||
|
||||
$status_messages = array(
|
||||
'valid' => __( 'License is active and valid.', 'wp-fedistream' ),
|
||||
'invalid' => __( 'License is invalid.', 'wp-fedistream' ),
|
||||
'expired' => __( 'License has expired.', 'wp-fedistream' ),
|
||||
'revoked' => __( 'License has been revoked.', 'wp-fedistream' ),
|
||||
'inactive' => __( 'License is inactive. Please activate it.', 'wp-fedistream' ),
|
||||
'unchecked' => __( 'License has not been validated yet.', 'wp-fedistream' ),
|
||||
'unconfigured' => __( 'License server is not configured.', 'wp-fedistream' ),
|
||||
);
|
||||
|
||||
$status_icons = array(
|
||||
'valid' => 'dashicons-yes-alt',
|
||||
'invalid' => 'dashicons-dismiss',
|
||||
'expired' => 'dashicons-warning',
|
||||
'revoked' => 'dashicons-dismiss',
|
||||
'inactive' => 'dashicons-marker',
|
||||
'unchecked' => 'dashicons-info-outline',
|
||||
'unconfigured' => 'dashicons-admin-generic',
|
||||
);
|
||||
|
||||
$status_class = $status_classes[ $status ] ?? 'notice-info';
|
||||
$status_message = $status_messages[ $status ] ?? __( 'Unknown status.', 'wp-fedistream' );
|
||||
$status_icon = $status_icons[ $status ] ?? 'dashicons-info-outline';
|
||||
?>
|
||||
<div class="fedistream-license-status notice <?php echo esc_attr( $status_class ); ?>" style="padding: 12px; display: flex; align-items: center; gap: 10px;">
|
||||
<span class="dashicons <?php echo esc_attr( $status_icon ); ?>" style="font-size: 24px; width: 24px; height: 24px;"></span>
|
||||
<div>
|
||||
<strong><?php echo esc_html( $status_message ); ?></strong>
|
||||
<?php if ( 'valid' === $status && ! empty( $license_data['expires_at'] ) ) : ?>
|
||||
<br>
|
||||
<span class="description">
|
||||
<?php
|
||||
printf(
|
||||
/* translators: %s: Expiration date */
|
||||
esc_html__( 'Expires: %s', 'wp-fedistream' ),
|
||||
esc_html( $license_data['expires_at'] )
|
||||
);
|
||||
?>
|
||||
</span>
|
||||
<?php elseif ( 'valid' === $status && empty( $license_data['expires_at'] ) ) : ?>
|
||||
<br>
|
||||
<span class="description"><?php esc_html_e( 'Lifetime license', 'wp-fedistream' ); ?></span>
|
||||
<?php endif; ?>
|
||||
<?php if ( $last_check > 0 ) : ?>
|
||||
<br>
|
||||
<span class="description">
|
||||
<?php
|
||||
printf(
|
||||
/* translators: %s: Time ago */
|
||||
esc_html__( 'Last checked: %s', 'wp-fedistream' ),
|
||||
esc_html( human_time_diff( $last_check, time() ) . ' ' . __( 'ago', 'wp-fedistream' ) )
|
||||
);
|
||||
?>
|
||||
</span>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<form method="post" action="" id="fedistream-license-form">
|
||||
<?php wp_nonce_field( 'fedistream_save_settings', 'fedistream_settings_nonce' ); ?>
|
||||
|
||||
<table class="form-table">
|
||||
<tr>
|
||||
<th scope="row">
|
||||
<label for="license_server_url"><?php esc_html_e( 'License Server URL', 'wp-fedistream' ); ?></label>
|
||||
</th>
|
||||
<td>
|
||||
<input type="url" name="license_server_url" id="license_server_url"
|
||||
value="<?php echo esc_attr( $server_url ); ?>"
|
||||
class="regular-text" placeholder="https://example.com">
|
||||
<p class="description"><?php esc_html_e( 'The URL of your license server.', 'wp-fedistream' ); ?></p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">
|
||||
<label for="license_key"><?php esc_html_e( 'License Key', 'wp-fedistream' ); ?></label>
|
||||
</th>
|
||||
<td>
|
||||
<input type="text" name="license_key" id="license_key"
|
||||
value="<?php echo esc_attr( $license_key ); ?>"
|
||||
class="regular-text" placeholder="XXXX-XXXX-XXXX-XXXX">
|
||||
<p class="description"><?php esc_html_e( 'Your license key from your purchase.', 'wp-fedistream' ); ?></p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">
|
||||
<label for="license_server_secret"><?php esc_html_e( 'Server Secret', 'wp-fedistream' ); ?></label>
|
||||
</th>
|
||||
<td>
|
||||
<input type="password" name="license_server_secret" id="license_server_secret"
|
||||
value="" class="regular-text" placeholder="<?php echo esc_attr( ! empty( LicenseManager::get_server_secret() ) ? '••••••••••••••••' : '' ); ?>">
|
||||
<p class="description"><?php esc_html_e( '64-character verification secret from your license account. Leave empty to keep existing.', 'wp-fedistream' ); ?></p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<p class="submit">
|
||||
<?php submit_button( __( 'Save License Settings', 'wp-fedistream' ), 'primary', 'submit', false ); ?>
|
||||
<button type="button" id="fedistream-validate-license" class="button button-secondary" style="margin-left: 10px;">
|
||||
<span class="dashicons dashicons-yes" style="vertical-align: middle; margin-top: -2px;"></span>
|
||||
<?php esc_html_e( 'Validate License', 'wp-fedistream' ); ?>
|
||||
</button>
|
||||
<button type="button" id="fedistream-activate-license" class="button button-secondary" style="margin-left: 10px;">
|
||||
<span class="dashicons dashicons-admin-network" style="vertical-align: middle; margin-top: -2px;"></span>
|
||||
<?php esc_html_e( 'Activate License', 'wp-fedistream' ); ?>
|
||||
</button>
|
||||
<span id="fedistream-license-spinner" class="spinner" style="float: none; margin-top: 4px;"></span>
|
||||
</p>
|
||||
</form>
|
||||
|
||||
<div id="fedistream-license-message" style="display: none; margin-top: 10px;"></div>
|
||||
|
||||
<script type="text/javascript">
|
||||
var fedistreamLicenseNonce = '<?php echo esc_js( wp_create_nonce( 'fedistream_license_action' ) ); ?>';
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the Default Settings tab.
|
||||
*
|
||||
* @param int $max_upload_size Max upload size in MB.
|
||||
* @param string $default_license Default license.
|
||||
* @return void
|
||||
*/
|
||||
private function render_settings_tab( int $max_upload_size, string $default_license ): void {
|
||||
?>
|
||||
<form method="post" action="">
|
||||
<?php wp_nonce_field( 'fedistream_save_settings', 'fedistream_settings_nonce' ); ?>
|
||||
|
||||
<table class="form-table">
|
||||
<tr>
|
||||
<th scope="row">
|
||||
<label for="max_upload_size"><?php esc_html_e( 'Max Upload Size', 'wp-fedistream' ); ?></label>
|
||||
</th>
|
||||
<td>
|
||||
<input type="number" name="max_upload_size" id="max_upload_size" value="<?php echo esc_attr( $max_upload_size ); ?>" min="1" max="500" class="small-text"> MB
|
||||
<p class="description"><?php esc_html_e( 'Maximum file size for audio uploads.', 'wp-fedistream' ); ?></p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">
|
||||
<label for="default_license"><?php esc_html_e( 'Default License', 'wp-fedistream' ); ?></label>
|
||||
</th>
|
||||
<td>
|
||||
<select name="default_license" id="default_license">
|
||||
<option value="all-rights-reserved" <?php selected( $default_license, 'all-rights-reserved' ); ?>><?php esc_html_e( 'All Rights Reserved', 'wp-fedistream' ); ?></option>
|
||||
<option value="cc-by" <?php selected( $default_license, 'cc-by' ); ?>>CC BY</option>
|
||||
<option value="cc-by-sa" <?php selected( $default_license, 'cc-by-sa' ); ?>>CC BY-SA</option>
|
||||
<option value="cc-by-nc" <?php selected( $default_license, 'cc-by-nc' ); ?>>CC BY-NC</option>
|
||||
<option value="cc-by-nc-sa" <?php selected( $default_license, 'cc-by-nc-sa' ); ?>>CC BY-NC-SA</option>
|
||||
<option value="cc0" <?php selected( $default_license, 'cc0' ); ?>>CC0 (Public Domain)</option>
|
||||
</select>
|
||||
<p class="description"><?php esc_html_e( 'Default license for new uploads.', 'wp-fedistream' ); ?></p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<?php submit_button(); ?>
|
||||
</form>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the Integrations tab.
|
||||
*
|
||||
* @param int $enable_activitypub Whether ActivityPub is enabled.
|
||||
* @param int $enable_woocommerce Whether WooCommerce integration is enabled.
|
||||
* @return void
|
||||
*/
|
||||
private function render_integrations_tab( int $enable_activitypub, int $enable_woocommerce ): void {
|
||||
?>
|
||||
<form method="post" action="">
|
||||
<?php wp_nonce_field( 'fedistream_save_settings', 'fedistream_settings_nonce' ); ?>
|
||||
|
||||
<table class="form-table">
|
||||
<tr>
|
||||
<th scope="row"><?php esc_html_e( 'ActivityPub Integration', 'wp-fedistream' ); ?></th>
|
||||
<td>
|
||||
<label>
|
||||
<input type="checkbox" name="enable_activitypub" value="1" <?php checked( $enable_activitypub, 1 ); ?>>
|
||||
<?php esc_html_e( 'Enable ActivityPub features', 'wp-fedistream' ); ?>
|
||||
</label>
|
||||
<p class="description"><?php esc_html_e( 'Publish releases to the Fediverse and allow followers.', 'wp-fedistream' ); ?></p>
|
||||
<?php if ( ! $this->is_activitypub_active() ) : ?>
|
||||
<p class="description" style="color: #dba617;">
|
||||
<span class="dashicons dashicons-warning" style="font-size: 16px; width: 16px; height: 16px; vertical-align: text-bottom;"></span>
|
||||
<?php esc_html_e( 'The ActivityPub plugin is recommended for full Fediverse integration.', 'wp-fedistream' ); ?>
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row"><?php esc_html_e( 'WooCommerce Integration', 'wp-fedistream' ); ?></th>
|
||||
<td>
|
||||
<label>
|
||||
<input type="checkbox" name="enable_woocommerce" value="1" <?php checked( $enable_woocommerce, 1 ); ?> <?php disabled( ! $this->is_woocommerce_active() ); ?>>
|
||||
<?php esc_html_e( 'Enable WooCommerce features', 'wp-fedistream' ); ?>
|
||||
</label>
|
||||
<?php if ( ! $this->is_woocommerce_active() ) : ?>
|
||||
<p class="description" style="color: #d63638;">
|
||||
<span class="dashicons dashicons-dismiss" style="font-size: 16px; width: 16px; height: 16px; vertical-align: text-bottom;"></span>
|
||||
<?php esc_html_e( 'WooCommerce is not installed or active.', 'wp-fedistream' ); ?>
|
||||
</p>
|
||||
<?php else : ?>
|
||||
<p class="description"><?php esc_html_e( 'Sell albums and tracks through WooCommerce.', 'wp-fedistream' ); ?></p>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<?php submit_button(); ?>
|
||||
</form>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueue admin assets.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user