Skip to content

Commit

Permalink
fix: has_access var and scripts enqueue
Browse files Browse the repository at this point in the history
  • Loading branch information
pranvinit committed Nov 22, 2024
1 parent 4e03d60 commit f4fa7f8
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
6 changes: 5 additions & 1 deletion admin/partials/rt-transcoder-admin-display.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@

// Check if the user has access to the transcoding service.
$usage_details = get_site_option( 'rt-transcoding-usage' );
$has_access = isset( $usage_details[ $this->api_key ]->sub_status ) && $usage_details[ $this->api_key ]->sub_status;
$usage = $usage_details[ $this->api_key ] ?? null;
$has_access = ! empty( $this->api_key ) &&
is_object( $usage ) &&
! empty( $usage->status ) &&
( ! isset( $usage->remaining ) || $usage->remaining > 0 );
// Temporarily allow access to all users.
$has_access = true;
?>
Expand Down
5 changes: 2 additions & 3 deletions admin/rt-retranscode-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public function __construct() {
$this->stored_api_key = get_site_option( 'rt-transcoding-api-key-stored' );

$this->usage_info = get_site_option( 'rt-transcoding-usage' );
// Load Rest Endpoints.
$this->load_rest_endpoints();

// Do not activate re-transcoding without valid license key
// Or usage are fully utilized.
Expand Down Expand Up @@ -80,9 +82,6 @@ public function __construct() {

// Allow people to change what capability is required to use this feature.
$this->capability = apply_filters( 'retranscode_media_cap', 'manage_options' );

// Load Rest Endpoints.
$this->load_rest_endpoints();
}

/**
Expand Down
16 changes: 13 additions & 3 deletions admin/rt-transcoder-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,13 @@ public function register_transcoder_settings() {

// Check if the user has an active paid subscription.
$usage_details = get_site_option( 'rt-transcoding-usage' );
$has_access = isset( $usage_details[ $this->api_key ]->sub_status ) && $usage_details[ $this->api_key ]->sub_status;
$usage = $usage_details[ $this->api_key ] ?? null;
$has_access = ! empty( $this->api_key ) &&
is_object( $usage ) &&
! empty( $usage->status ) &&
( ! isset( $usage->remaining ) || $usage->remaining > 0 );
// Temporarily allow access to all users.
$has_access = true;

// Register adaptive bitrate streaming setting with conditional default.
register_setting(
Expand Down Expand Up @@ -189,7 +195,11 @@ public function register_transcoder_settings() {
*/
public function sanitize_adaptive_bitrate( $value ) {
$usage_details = get_site_option( 'rt-transcoding-usage' );
$has_access = isset( $usage_details[ $this->api_key ]->sub_status ) && $usage_details[ $this->api_key ]->sub_status;
$usage = $usage_details[ $this->api_key ] ?? null;
$has_access = ! empty( $this->api_key ) &&
is_object( $usage ) &&
! empty( $usage->status ) &&
( ! isset( $usage->remaining ) || $usage->remaining > 0 );
// Temporarily allow access to all users.
$has_access = true;

Expand Down Expand Up @@ -249,7 +259,7 @@ public function enqueue_scripts_styles() {

$page = transcoder_filter_input( INPUT_GET, 'page', FILTER_SANITIZE_FULL_SPECIAL_CHARS );

if ( 'admin.php' !== $pagenow || 'rt-transcoder' !== $page ) {
if ( 'upload.php' !== $pagenow && ( 'admin.php' !== $pagenow && 'rt-transcoder' !== $page ) ) {
return;
}
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
Expand Down
4 changes: 4 additions & 0 deletions admin/rt-transcoder-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ public function __construct( $no_init = false ) {
$this->api_key = get_site_option( 'rt-transcoding-api-key' );
$this->stored_api_key = get_site_option( 'rt-transcoding-api-key-stored' );

// Temporarily inclduing rt-retranscode-admin.php file here.
include_once RT_TRANSCODER_PATH . 'admin/rt-retranscode-admin.php'; // phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.UsingCustomConstant

/**
* Allow other plugin and wp-config to overwrite API URL.
*/
Expand All @@ -136,6 +139,7 @@ public function __construct( $no_init = false ) {
}

add_action( 'admin_init', array( $this, 'save_api_key' ), 10, 1 );

// phpcs:disable
if ( $this->api_key ) {
// Store api key as different db key if user disable transcoding service.
Expand Down

0 comments on commit f4fa7f8

Please sign in to comment.