@@ -141,7 +141,7 @@ public function __construct( $no_init = false ) {
141
141
// Store api key as different db key if user disable transcoding service.
142
142
if ( ! $ this ->stored_api_key ) {
143
143
$ 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 );
145
145
}
146
146
add_filter ( 'rtmedia_allowed_types ' , array ( $ this , 'allowed_types_admin_settings ' ), 10 , 1 );
147
147
$ usage_info = get_site_option ( 'rt-transcoding-usage ' );
@@ -160,7 +160,7 @@ public function __construct( $no_init = false ) {
160
160
if ( $ usage_info [ $ this ->api_key ]->remaining < 524288000 && ! get_site_option ( 'rt-transcoding-usage-limit-mail ' ) ) {
161
161
$ this ->nearing_usage_limit ( $ usage_info );
162
162
} 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 );
164
164
}
165
165
if ( strtotime ( $ usage_info [ $ this ->api_key ]->plan ->expires ) > time () ) {
166
166
add_filter ( 'wp_generate_attachment_metadata ' , array ( $ this , 'wp_media_transcoding ' ), 21 , 2 );
@@ -393,7 +393,7 @@ public function update_usage( $key ) {
393
393
$ usage_info = null ;
394
394
}
395
395
396
- update_option ( 'rt-transcoding-usage ' , array ( $ key => $ usage_info ) );
396
+ update_site_option ( 'rt-transcoding-usage ' , array ( $ key => $ usage_info ) );
397
397
398
398
return $ usage_info ;
399
399
}
@@ -406,12 +406,15 @@ public function update_usage( $key ) {
406
406
* @param array $usage_details Usage informataion.
407
407
*/
408
408
public function nearing_usage_limit ( $ usage_details ) {
409
+
409
410
if ( defined ( 'RT_TRANSCODER_NO_MAIL ' ) ) {
410
411
return ;
411
412
}
413
+
412
414
$ subject = esc_html__ ( 'Transcoding: Nearing quota limit. ' , 'transcoder ' );
413
415
$ 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> ' ;
414
416
$ users = get_users ( array ( 'role ' => 'administrator ' ) );
417
+
415
418
if ( $ users ) {
416
419
$ admin_email_ids = array ();
417
420
foreach ( $ users as $ user ) {
@@ -421,7 +424,8 @@ public function nearing_usage_limit( $usage_details ) {
421
424
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
422
425
remove_filter ( 'wp_mail_content_type ' , array ( $ this , 'wp_mail_content_type ' ) );
423
426
}
424
- update_option ( 'rt-transcoding-usage-limit-mail ' , 1 );
427
+
428
+ update_site_option ( 'rt-transcoding-usage-limit-mail ' , 1 );
425
429
}
426
430
427
431
/**
@@ -430,10 +434,13 @@ public function nearing_usage_limit( $usage_details ) {
430
434
* @since 1.0.0
431
435
*/
432
436
public function usage_quota_over () {
437
+
433
438
if ( defined ( 'RT_TRANSCODER_NO_MAIL ' ) ) {
434
439
return ;
435
440
}
441
+
436
442
$ usage_details = get_site_option ( 'rt-transcoding-usage ' );
443
+
437
444
if ( ! $ usage_details [ $ this ->api_key ]->remaining ) {
438
445
$ subject = esc_html__ ( 'Transcoding: Usage quota over. ' , 'transcoder ' );
439
446
$ 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() {
447
454
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
448
455
remove_filter ( 'wp_mail_content_type ' , array ( $ this , 'wp_mail_content_type ' ) );
449
456
}
450
- update_option ( 'rt-transcoding-usage-limit-mail ' , 1 );
457
+
458
+ update_site_option ( 'rt-transcoding-usage-limit-mail ' , 1 );
451
459
}
452
460
}
453
461
@@ -500,8 +508,8 @@ public function save_api_key() {
500
508
die ();
501
509
}
502
510
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 );
505
513
506
514
$ usage_info = $ this ->update_usage ( $ apikey );
507
515
$ return_page = add_query_arg (
@@ -1205,8 +1213,8 @@ public function handle_callback() {
1205
1213
* @since 1.0.0
1206
1214
*/
1207
1215
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 );
1210
1218
echo true ;
1211
1219
die ();
1212
1220
}
@@ -1232,7 +1240,7 @@ public function enter_api_key() {
1232
1240
* @since 1.0.0
1233
1241
*/
1234
1242
public function disable_transcoding () {
1235
- update_option ( 'rt-transcoding-api-key ' , '' );
1243
+ update_site_option ( 'rt-transcoding-api-key ' , '' );
1236
1244
esc_html_e ( 'Transcoding disabled successfully. ' , 'transcoder ' );
1237
1245
die ();
1238
1246
}
@@ -1243,7 +1251,7 @@ public function disable_transcoding() {
1243
1251
* @since 1.0.0
1244
1252
*/
1245
1253
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 );
1247
1255
esc_html_e ( 'Transcoding enabled successfully. ' , 'transcoder ' );
1248
1256
die ();
1249
1257
}
@@ -1520,9 +1528,25 @@ public function get_transcoding_status( $post_id ) {
1520
1528
* `add_attachment` hook will do it fo PDF.
1521
1529
*
1522
1530
* @param int $post_id Attachment ID of the PDF.
1531
+ *
1532
+ * @return void
1523
1533
*/
1524
1534
public function after_upload_pdf ( $ post_id ) {
1525
1535
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
+
1526
1550
$ allow_transcoding = true ;
1527
1551
1528
1552
// If it have native support, skip the use of transcoder server.
@@ -1538,18 +1562,16 @@ class_exists( 'ImagickPixel', false ) &&
1538
1562
$ allow_transcoding = true ;
1539
1563
}
1540
1564
1565
+ if ( false === $ allow_transcoding && empty ( wp_get_attachment_metadata ( $ post_id ) ) ) {
1566
+ $ allow_transcoding = true ;
1567
+ }
1568
+
1541
1569
if ( false === $ allow_transcoding ) {
1542
1570
return ;
1543
1571
}
1544
1572
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 );
1547
1574
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
- }
1553
1575
}
1554
1576
1555
1577
/**
0 commit comments