@@ -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