Skip to content

Commit 75596c0

Browse files
Merge pull request #161 from rtMediaWP/vip-compatible
Use the proper function to get site options.
2 parents d4ab907 + 1332abf commit 75596c0

File tree

4 files changed

+54
-32
lines changed

4 files changed

+54
-32
lines changed

admin/partials/rt-transcoder-admin-display.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ class="screen-reader-text"><?php echo esc_attr__( 'Dismiss this notice', 'transc
213213
<td>
214214
<?php
215215

216-
$number_of_thumbnails = get_site_option( 'number_of_thumbs', 5 );
216+
$number_of_thumbnails = get_option( 'number_of_thumbs', 5 );
217217
if ( empty( $number_of_thumbnails ) ) {
218218
$number_of_thumbnails = 5;
219219
}
@@ -237,7 +237,7 @@ class="screen-reader-text"><?php echo esc_attr__( 'Dismiss this notice', 'transc
237237
<td>
238238
<?php
239239

240-
$rtt_override_thumbnail = get_site_option( 'rtt_override_thumbnail', false );
240+
$rtt_override_thumbnail = get_option( 'rtt_override_thumbnail', false );
241241
?>
242242
<input type="checkbox" name="rtt_override_thumbnail" value="1" <?php checked( $rtt_override_thumbnail, 1 ); ?> />
243243
<span class="rtm-tooltip">
@@ -258,7 +258,7 @@ class="screen-reader-text"><?php echo esc_attr__( 'Dismiss this notice', 'transc
258258
<td>
259259
<?php
260260

261-
$rtt_check_status_btn = get_site_option( 'rtt_client_check_status_button', false );
261+
$rtt_check_status_btn = get_option( 'rtt_client_check_status_button', false );
262262
?>
263263
<input type="checkbox" name="rtt_client_check_status_button" value="1" <?php checked( $rtt_check_status_btn, 1 ); ?> />
264264
<span class="rtm-tooltip">

admin/rt-transcoder-admin.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ class RT_Transcoder_Admin {
5656
*/
5757
public function __construct() {
5858

59-
$this->api_key = get_option( 'rt-transcoding-api-key' );
60-
$this->stored_api_key = get_option( 'rt-transcoding-api-key-stored' );
59+
$this->api_key = get_site_option( 'rt-transcoding-api-key' );
60+
$this->stored_api_key = get_site_option( 'rt-transcoding-api-key-stored' );
6161

6262
$this->load_translation();
6363

@@ -80,9 +80,9 @@ public function __construct() {
8080
add_action( 'admin_menu', array( $this, 'menu' ) );
8181
add_action( 'admin_init', array( $this, 'register_transcoder_settings' ) );
8282
if ( class_exists( 'RTMediaEncoding' ) ) {
83-
$old_rtmedia_encoding_key = get_option( 'rtmedia-encoding-api-key' );
83+
$old_rtmedia_encoding_key = get_site_option( 'rtmedia-encoding-api-key' );
8484
if ( ! empty( $old_rtmedia_encoding_key ) ) {
85-
update_option( 'rtmedia-encoding-api-key', '' );
85+
update_site_option( 'rtmedia-encoding-api-key', '' );
8686
}
8787
add_action( 'init', array( $this, 'disable_encoding' ) );
8888
}
@@ -223,7 +223,7 @@ public function transcoding_subscription_button( $name = 'No Name', $price = '0'
223223
$this->transcoder_handler->update_usage( $this->api_key );
224224
}
225225

226-
$usage_details = get_option( 'rt-transcoding-usage' );
226+
$usage_details = get_site_option( 'rt-transcoding-usage' );
227227

228228
if ( isset( $usage_details[ $this->api_key ]->plan->name ) && ( strtolower( $usage_details[ $this->api_key ]->plan->name ) === strtolower( $name ) ) && $usage_details[ $this->api_key ]->sub_status && ! $force ) {
229229
$form = '<button disabled="disabled" type="submit" class="button button-primary bpm-unsubscribe">' . esc_html__( 'Current Plan', 'transcoder' ) . '</button>';
@@ -412,7 +412,7 @@ public function save_video_thumbnail( $post ) {
412412
* @since 1.0.0
413413
*/
414414
public function transcoder_admin_notice() {
415-
$show_notice = get_option( 'transcoder_admin_notice', 1 );
415+
$show_notice = get_site_option( 'transcoder_admin_notice', 1 );
416416

417417
if ( '1' === $show_notice || 1 === $show_notice ) :
418418
?>
@@ -465,7 +465,7 @@ public function subscribe_transcoder_admin_notice() {
465465
*/
466466
public function transcoder_hide_admin_notice() {
467467
if ( check_ajax_referer( '_transcoder_hide_notice_', 'transcoder_notice_nonce' ) ) {
468-
update_option( 'transcoder_admin_notice', '0' );
468+
update_site_option( 'transcoder_admin_notice', '0' );
469469
}
470470
die();
471471
}

admin/rt-transcoder-functions.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ function rtt_bp_get_activity_content( $content, $activity ) {
455455
}
456456
// If media is sent to the transcoder then show the message.
457457
if ( is_file_being_transcoded( $media->media_id ) ) {
458-
if ( current_user_can( 'administrator' ) && '1' === get_site_option( 'rtt_client_check_status_button', false ) ) {
458+
if ( current_user_can( 'administrator' ) && '1' === get_option( 'rtt_client_check_status_button', false ) ) {
459459

460460
$check_button_text = __( 'Check Status', 'transcoder' );
461461

@@ -655,7 +655,7 @@ function rtt_get_upload_dir() {
655655
*/
656656
function rtt_is_override_thumbnail( $attachment_id = '' ) {
657657

658-
$rtt_override_thumbnail = get_option( 'rtt_override_thumbnail' );
658+
$rtt_override_thumbnail = get_option( 'rtt_override_thumbnail', false );
659659

660660
/**
661661
* Allow user to override the setting.
@@ -790,7 +790,7 @@ function rtt_enqueue_scripts() {
790790
}
791791
}
792792

793-
if ( '1' === get_site_option( 'rtt_client_check_status_button', false ) ) {
793+
if ( '1' === get_option( 'rtt_client_check_status_button', false ) ) {
794794
add_action( 'wp_enqueue_scripts', 'rtt_enqueue_scripts' );
795795
}
796796
add_action( 'admin_enqueue_scripts', 'rtt_enqueue_scripts' );
@@ -893,7 +893,7 @@ function rtt_add_transcoding_process_status_button_single_media_page( $rtmedia_i
893893

894894
if ( is_file_being_transcoded( $post_id ) ) {
895895

896-
if ( current_user_can( 'administrator' ) && '1' === get_site_option( 'rtt_client_check_status_button', false ) ) {
896+
if ( current_user_can( 'administrator' ) && '1' === get_option( 'rtt_client_check_status_button', false ) ) {
897897
$message = sprintf(
898898
'<div class="transcoding-in-progress"><button id="btn_check_status%1$s" class="btn_check_transcode_status" name="check_status_btn" data-value="%1$s">%2$s</button> <div class="transcode_status_box" id="span_status%1$s">%3$s</div></div>',
899899
esc_attr( $post_id ),

admin/rt-transcoder-handler.php

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public function __construct( $no_init = false ) {
141141
// Store api key as different db key if user disable transcoding service.
142142
if ( ! $this->stored_api_key ) {
143143
$this->stored_api_key = $this->api_key;
144-
update_option( 'rt-transcoding-api-key-stored', $this->stored_api_key );
144+
update_site_option( 'rt-transcoding-api-key-stored', $this->stored_api_key );
145145
}
146146
add_filter( 'rtmedia_allowed_types', array( $this, 'allowed_types_admin_settings' ), 10, 1 );
147147
$usage_info = get_site_option( 'rt-transcoding-usage' );
@@ -160,7 +160,7 @@ public function __construct( $no_init = false ) {
160160
if ( $usage_info[ $this->api_key ]->remaining < 524288000 && ! get_site_option( 'rt-transcoding-usage-limit-mail' ) ) {
161161
$this->nearing_usage_limit( $usage_info );
162162
} elseif ( $usage_info[ $this->api_key ]->remaining > 524288000 && get_site_option( 'rt-transcoding-usage-limit-mail' ) ) {
163-
update_option( 'rt-transcoding-usage-limit-mail', 0 );
163+
update_site_option( 'rt-transcoding-usage-limit-mail', 0 );
164164
}
165165
if ( strtotime( $usage_info[ $this->api_key ]->plan->expires ) > time() ) {
166166
add_filter( 'wp_generate_attachment_metadata', array( $this, 'wp_media_transcoding' ), 21, 2 );
@@ -393,7 +393,7 @@ public function update_usage( $key ) {
393393
$usage_info = null;
394394
}
395395

396-
update_option( 'rt-transcoding-usage', array( $key => $usage_info ) );
396+
update_site_option( 'rt-transcoding-usage', array( $key => $usage_info ) );
397397

398398
return $usage_info;
399399
}
@@ -406,12 +406,15 @@ public function update_usage( $key ) {
406406
* @param array $usage_details Usage informataion.
407407
*/
408408
public function nearing_usage_limit( $usage_details ) {
409+
409410
if ( defined( 'RT_TRANSCODER_NO_MAIL' ) ) {
410411
return;
411412
}
413+
412414
$subject = esc_html__( 'Transcoding: Nearing quota limit.', 'transcoder' );
413415
$message = '<p>' . esc_html__( 'You are nearing the quota limit for your transcoding service.', 'transcoder' ) . '</p><p>' . esc_html__( 'Following are the details:', 'transcoder' ) . '</p><p><strong>Used:</strong> %s</p><p><strong>' . esc_html__( 'Remaining', 'transcoder' ) . '</strong>: %s</p><p><strong>' . esc_html__( 'Total:', 'transcoder' ) . '</strong> %s</p>';
414416
$users = get_users( array( 'role' => 'administrator' ) );
417+
415418
if ( $users ) {
416419
$admin_email_ids = array();
417420
foreach ( $users as $user ) {
@@ -421,7 +424,8 @@ public function nearing_usage_limit( $usage_details ) {
421424
wp_mail( $admin_email_ids, $subject, sprintf( $message, size_format( $usage_details[ $this->api_key ]->used, 2 ), size_format( $usage_details[ $this->api_key ]->remaining, 2 ), size_format( $usage_details[ $this->api_key ]->total, 2 ) ) ); // phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.wp_mail_wp_mail
422425
remove_filter( 'wp_mail_content_type', array( $this, 'wp_mail_content_type' ) );
423426
}
424-
update_option( 'rt-transcoding-usage-limit-mail', 1 );
427+
428+
update_site_option( 'rt-transcoding-usage-limit-mail', 1 );
425429
}
426430

427431
/**
@@ -430,10 +434,13 @@ public function nearing_usage_limit( $usage_details ) {
430434
* @since 1.0.0
431435
*/
432436
public function usage_quota_over() {
437+
433438
if ( defined( 'RT_TRANSCODER_NO_MAIL' ) ) {
434439
return;
435440
}
441+
436442
$usage_details = get_site_option( 'rt-transcoding-usage' );
443+
437444
if ( ! $usage_details[ $this->api_key ]->remaining ) {
438445
$subject = esc_html__( 'Transcoding: Usage quota over.', 'transcoder' );
439446
$message = '<p>' . esc_html__( 'Your usage quota is over. Upgrade your plan', 'transcoder' ) . '</p><p>' . esc_html__( 'Following are the details:', 'transcoder' ) . '</p><p><strong>' . esc_html__( 'Used:', 'transcoder' ) . '</strong> %s</p><p><strong>' . esc_html__( 'Remaining', 'transcoder' ) . '</strong>: %s</p><p><strong>' . esc_html__( 'Total:', 'transcoder' ) . '</strong> %s</p>';
@@ -447,7 +454,8 @@ public function usage_quota_over() {
447454
wp_mail( $admin_email_ids, $subject, sprintf( $message, size_format( $usage_details[ $this->api_key ]->used, 2 ), 0, size_format( $usage_details[ $this->api_key ]->total, 2 ) ) ); // phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.wp_mail_wp_mail
448455
remove_filter( 'wp_mail_content_type', array( $this, 'wp_mail_content_type' ) );
449456
}
450-
update_option( 'rt-transcoding-usage-limit-mail', 1 );
457+
458+
update_site_option( 'rt-transcoding-usage-limit-mail', 1 );
451459
}
452460
}
453461

@@ -500,8 +508,8 @@ public function save_api_key() {
500508
die();
501509
}
502510
if ( $this->is_valid_key( $apikey ) ) {
503-
update_option( 'rt-transcoding-api-key', $apikey );
504-
update_option( 'rt-transcoding-api-key-stored', $apikey );
511+
update_site_option( 'rt-transcoding-api-key', $apikey );
512+
update_site_option( 'rt-transcoding-api-key-stored', $apikey );
505513

506514
$usage_info = $this->update_usage( $apikey );
507515
$return_page = add_query_arg(
@@ -1205,8 +1213,8 @@ public function handle_callback() {
12051213
* @since 1.0.0
12061214
*/
12071215
public function hide_transcoding_notice() {
1208-
update_option( 'rt-transcoding-service-notice', true );
1209-
update_option( 'rt-transcoding-expansion-notice', true );
1216+
update_site_option( 'rt-transcoding-service-notice', true );
1217+
update_site_option( 'rt-transcoding-expansion-notice', true );
12101218
echo true;
12111219
die();
12121220
}
@@ -1232,7 +1240,7 @@ public function enter_api_key() {
12321240
* @since 1.0.0
12331241
*/
12341242
public function disable_transcoding() {
1235-
update_option( 'rt-transcoding-api-key', '' );
1243+
update_site_option( 'rt-transcoding-api-key', '' );
12361244
esc_html_e( 'Transcoding disabled successfully.', 'transcoder' );
12371245
die();
12381246
}
@@ -1243,7 +1251,7 @@ public function disable_transcoding() {
12431251
* @since 1.0.0
12441252
*/
12451253
public function enable_transcoding() {
1246-
update_option( 'rt-transcoding-api-key', $this->stored_api_key );
1254+
update_site_option( 'rt-transcoding-api-key', $this->stored_api_key );
12471255
esc_html_e( 'Transcoding enabled successfully.', 'transcoder' );
12481256
die();
12491257
}
@@ -1520,9 +1528,25 @@ public function get_transcoding_status( $post_id ) {
15201528
* `add_attachment` hook will do it fo PDF.
15211529
*
15221530
* @param int $post_id Attachment ID of the PDF.
1531+
*
1532+
* @return void
15231533
*/
15241534
public function after_upload_pdf( $post_id ) {
15251535

1536+
$post_id = ( ! empty( $post_id ) && 0 < intval( $post_id ) ) ? intval( $post_id ) : 0;
1537+
1538+
if ( empty( $post_id ) ) {
1539+
return;
1540+
}
1541+
1542+
$file_path = get_attached_file( $post_id );
1543+
$file_type = wp_check_filetype( $file_path );
1544+
$file_type = array_map( 'strtolower', $file_type );
1545+
1546+
if ( 'pdf' !== $file_type['ext'] ) {
1547+
return;
1548+
}
1549+
15261550
$allow_transcoding = true;
15271551

15281552
// If it have native support, skip the use of transcoder server.
@@ -1538,18 +1562,16 @@ class_exists( 'ImagickPixel', false ) &&
15381562
$allow_transcoding = true;
15391563
}
15401564

1565+
if ( false === $allow_transcoding && empty( wp_get_attachment_metadata( $post_id ) ) ) {
1566+
$allow_transcoding = true;
1567+
}
1568+
15411569
if ( false === $allow_transcoding ) {
15421570
return;
15431571
}
15441572

1545-
$file_url = wp_get_attachment_url( $post_id );
1546-
$filetype = wp_check_filetype( $file_url );
1573+
$this->wp_media_transcoding( array( 'mime_type' => 'application/pdf' ), $post_id );
15471574

1548-
$filetype['ext'] = strtolower( $filetype['ext'] );
1549-
1550-
if ( 'pdf' === $filetype['ext'] ) {
1551-
$this->wp_media_transcoding( array( 'mime_type' => 'application/pdf' ), $post_id );
1552-
}
15531575
}
15541576

15551577
/**

0 commit comments

Comments
 (0)