Skip to content

Commit 1332abf

Browse files
committed
Added condition if PDFs media doesn't have meta data then request for thumbnail
1 parent 6cf4bf5 commit 1332abf

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

admin/rt-transcoder-handler.php

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1528,9 +1528,25 @@ public function get_transcoding_status( $post_id ) {
15281528
* `add_attachment` hook will do it fo PDF.
15291529
*
15301530
* @param int $post_id Attachment ID of the PDF.
1531+
*
1532+
* @return void
15311533
*/
15321534
public function after_upload_pdf( $post_id ) {
15331535

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+
15341550
$allow_transcoding = true;
15351551

15361552
// If it have native support, skip the use of transcoder server.
@@ -1546,18 +1562,16 @@ class_exists( 'ImagickPixel', false ) &&
15461562
$allow_transcoding = true;
15471563
}
15481564

1565+
if ( false === $allow_transcoding && empty( wp_get_attachment_metadata( $post_id ) ) ) {
1566+
$allow_transcoding = true;
1567+
}
1568+
15491569
if ( false === $allow_transcoding ) {
15501570
return;
15511571
}
15521572

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 );
15571574

1558-
if ( 'pdf' === $filetype['ext'] ) {
1559-
$this->wp_media_transcoding( array( 'mime_type' => 'application/pdf' ), $post_id );
1560-
}
15611575
}
15621576

15631577
/**

0 commit comments

Comments
 (0)