@@ -1528,9 +1528,25 @@ public function get_transcoding_status( $post_id ) {
1528
1528
* `add_attachment` hook will do it fo PDF.
1529
1529
*
1530
1530
* @param int $post_id Attachment ID of the PDF.
1531
+ *
1532
+ * @return void
1531
1533
*/
1532
1534
public function after_upload_pdf ( $ post_id ) {
1533
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
+
1534
1550
$ allow_transcoding = true ;
1535
1551
1536
1552
// If it have native support, skip the use of transcoder server.
@@ -1546,18 +1562,16 @@ class_exists( 'ImagickPixel', false ) &&
1546
1562
$ allow_transcoding = true ;
1547
1563
}
1548
1564
1565
+ if ( false === $ allow_transcoding && empty ( wp_get_attachment_metadata ( $ post_id ) ) ) {
1566
+ $ allow_transcoding = true ;
1567
+ }
1568
+
1549
1569
if ( false === $ allow_transcoding ) {
1550
1570
return ;
1551
1571
}
1552
1572
1553
- $ file_url = wp_get_attachment_url ( $ post_id );
1554
- $ filetype = wp_check_filetype ( $ file_url );
1555
-
1556
- $ filetype ['ext ' ] = strtolower ( $ filetype ['ext ' ] );
1573
+ $ this ->wp_media_transcoding ( array ( 'mime_type ' => 'application/pdf ' ), $ post_id );
1557
1574
1558
- if ( 'pdf ' === $ filetype ['ext ' ] ) {
1559
- $ this ->wp_media_transcoding ( array ( 'mime_type ' => 'application/pdf ' ), $ post_id );
1560
- }
1561
1575
}
1562
1576
1563
1577
/**
0 commit comments