@@ -357,7 +357,7 @@ public function is_valid_key( $key ) {
357
357
if ( function_exists ( 'vip_safe_wp_remote_get ' ) ) {
358
358
$ validation_page = vip_safe_wp_remote_get ( $ validate_url , '' , 3 , 3 );
359
359
} else {
360
- $ validation_page = wp_remote_get ( $ validate_url ); // phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.wp_remote_get_wp_remote_get
360
+ $ validation_page = wp_safe_remote_get ( $ validate_url ); // phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.wp_remote_get_wp_remote_get
361
361
}
362
362
if ( ! is_wp_error ( $ validation_page ) ) {
363
363
$ validation_info = json_decode ( $ validation_page ['body ' ] );
@@ -385,7 +385,7 @@ public function update_usage( $key ) {
385
385
if ( function_exists ( 'vip_safe_wp_remote_get ' ) ) {
386
386
$ usage_page = vip_safe_wp_remote_get ( $ usage_url , '' , 3 , 3 );
387
387
} else {
388
- $ usage_page = wp_remote_get ( $ usage_url ); // phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.wp_remote_get_wp_remote_get
388
+ $ usage_page = wp_safe_remote_get ( $ usage_url ); // phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.wp_remote_get_wp_remote_get
389
389
}
390
390
if ( ! is_wp_error ( $ usage_page ) ) {
391
391
$ usage_info = json_decode ( $ usage_page ['body ' ] );
@@ -775,15 +775,36 @@ public function add_media_thumbnails( $post_array ) {
775
775
$ largest_thumb = false ;
776
776
$ largest_thumb_url = false ;
777
777
$ upload_thumbnail_array = array ();
778
+ $ failed_thumbnails = false ;
778
779
779
780
foreach ( $ post_thumbs_array ['thumbnail ' ] as $ thumbnail ) {
780
- $ thumbresource = function_exists ( 'vip_safe_wp_remote_get ' ) ? vip_safe_wp_remote_get ( $ thumbnail ) : wp_remote_get ( $ thumbnail ) ; // phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.wp_remote_get_wp_remote_get
781
+ $ thumbresource = function_exists ( 'vip_safe_wp_remote_get ' ) ? vip_safe_wp_remote_get ( $ thumbnail, '' , 3 , 3 ) : wp_remote_get ( $ thumbnail, array ( ' timeout ' => 120 ) ) ; // phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.wp_remote_get_wp_remote_get, WordPressVIPMinimum.Performance.RemoteRequestTimeout.timeout_timeout
781
782
$ thumbinfo = pathinfo ( $ thumbnail );
782
783
$ temp_name = $ thumbinfo ['basename ' ];
783
784
$ temp_name = urldecode ( $ temp_name );
784
785
$ temp_name_array = explode ( '/ ' , $ temp_name );
785
- $ temp_name = $ temp_name_array [ count ( $ temp_name_array ) - 1 ];
786
- $ thumbinfo ['basename ' ] = apply_filters ( 'transcoded_temp_filename ' , $ temp_name );
786
+ $ thumbinfo ['basename ' ] = $ temp_name_array [ count ( $ temp_name_array ) - 1 ];
787
+
788
+ /**
789
+ * Filter: 'transcoded_temp_filename' - Allows changes for the thumbnail name.
790
+ *
791
+ * @deprecated 1.3.2. Use the {@see 'transcoded_thumb_filename'} filter instead.
792
+ */
793
+ $ thumbinfo ['basename ' ] = apply_filters_deprecated ( 'transcoded_temp_filename ' , array ( $ thumbinfo ['basename ' ] ), '1.3.2 ' , 'transcoded_thumb_filename ' , __ ( 'Use transcoded_thumb_filename filter to modify video thumbnail name and transcoded_video_filename filter to modify video file name. ' , 'transcoder ' ) );
794
+
795
+ /**
796
+ * Allows users/plugins to filter the thumbnail Name
797
+ *
798
+ * @since 1.3.2
799
+ *
800
+ * @param string $temp_name Contains the thumbnail public name
801
+ */
802
+ $ thumbinfo ['basename ' ] = apply_filters ( 'transcoded_thumb_filename ' , $ thumbinfo ['basename ' ] );
803
+
804
+ // Verify Extension.
805
+ if ( empty ( pathinfo ( $ thumbinfo ['basename ' ], PATHINFO_EXTENSION ) ) ) {
806
+ $ thumbinfo ['basename ' ] .= '. ' . $ thumbinfo ['extension ' ];
807
+ }
787
808
788
809
if ( 'wp-media ' !== $ post_thumbs_array ['job_for ' ] ) {
789
810
add_filter ( 'upload_dir ' , array ( $ this , 'upload_dir ' ) );
@@ -792,6 +813,11 @@ public function add_media_thumbnails( $post_array ) {
792
813
// Create a file in the upload folder with given content.
793
814
$ thumb_upload_info = wp_upload_bits ( $ thumbinfo ['basename ' ], null , $ thumbresource ['body ' ] );
794
815
816
+ // Check error.
817
+ if ( ! empty ( $ thumb_upload_info ['error ' ] ) ) {
818
+ $ failed_thumbnails = $ thumb_upload_info ;
819
+ }
820
+
795
821
/**
796
822
* Allow users to filter/perform action on uploaded transcoded file.
797
823
*
@@ -802,7 +828,6 @@ public function add_media_thumbnails( $post_array ) {
802
828
* and $thumb_upload_info['file'] contains the file physical path
803
829
* @param int $post_id Contains the attachment ID for which transcoded file is uploaded
804
830
*/
805
-
806
831
$ thumb_upload_info = apply_filters ( 'transcoded_file_stored ' , $ thumb_upload_info , $ post_id );
807
832
808
833
if ( 'wp-media ' !== $ post_thumbs_array ['job_for ' ] ) {
@@ -834,6 +859,10 @@ public function add_media_thumbnails( $post_array ) {
834
859
}
835
860
}
836
861
862
+ if ( false !== $ failed_thumbnails && ! empty ( $ failed_thumbnails ['error ' ] ) ) {
863
+ $ this ->nofity_transcoding_failed ( $ post_array ['job_id ' ], sprintf ( 'Failed saving of Thumbnail for %1$s. ' , $ post_array ['file_name ' ] ) );
864
+ }
865
+
837
866
update_post_meta ( $ post_id , '_rt_media_source ' , $ post_thumbs_array ['job_for ' ] );
838
867
update_post_meta ( $ post_id , '_rt_media_thumbnails ' , $ upload_thumbnail_array );
839
868
@@ -906,8 +935,15 @@ public function add_transcoded_files( $file_post_array, $attachment_id, $job_for
906
935
$ new_wp_attached_file_pathinfo = pathinfo ( $ download_url );
907
936
$ post_mime_type = 'mp4 ' === $ new_wp_attached_file_pathinfo ['extension ' ] ? 'video/mp4 ' : 'audio/mp3 ' ;
908
937
$ attachemnt_url = wp_get_attachment_url ( $ attachment_id );
938
+
939
+ $ timeout = 5 ;
940
+
941
+ if ( 'video/mp4 ' === $ post_mime_type ) {
942
+ $ timeout = 120 ;
943
+ }
944
+
909
945
try {
910
- $ response = function_exists ( 'vip_safe_wp_remote_get ' ) ? vip_safe_wp_remote_get ( $ download_url , '' , 3 , 3 ) : wp_remote_get ( $ download_url ); // phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.wp_remote_get_wp_remote_get
946
+ $ response = function_exists ( 'vip_safe_wp_remote_get ' ) ? vip_safe_wp_remote_get ( $ download_url , '' , 3 , 3 ) : wp_remote_get ( $ download_url, array ( ' timeout ' => $ timeout ) ); // phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.wp_remote_get_wp_remote_get
911
947
} catch ( Exception $ e ) {
912
948
$ flag = $ e ->getMessage ();
913
949
}
@@ -920,7 +956,21 @@ public function add_transcoded_files( $file_post_array, $attachment_id, $job_for
920
956
add_filter ( 'upload_dir ' , array ( $ this , 'upload_dir ' ) );
921
957
}
922
958
923
- $ upload_info = wp_upload_bits ( $ new_wp_attached_file_pathinfo ['basename ' ], null , $ file_content );
959
+ /**
960
+ * Allows users/plugins to filter the transcoded file Name
961
+ *
962
+ * @since 1.3.2
963
+ *
964
+ * @param string $new_wp_attached_file_pathinfo['basename'] Contains the file public name
965
+ */
966
+ $ file_name = apply_filters ( 'transcoded_video_filename ' , $ new_wp_attached_file_pathinfo ['basename ' ] );
967
+
968
+ // Verify Extension.
969
+ if ( empty ( pathinfo ( $ file_name , PATHINFO_EXTENSION ) ) ) {
970
+ $ file_name .= '. ' . $ new_wp_attached_file_pathinfo ['extension ' ];
971
+ }
972
+
973
+ $ upload_info = wp_upload_bits ( $ file_name , null , $ file_content );
924
974
925
975
/**
926
976
* Allow users to filter/perform action on uploaded transcoded file.
@@ -991,6 +1041,7 @@ public function add_transcoded_files( $file_post_array, $attachment_id, $job_for
991
1041
} else {
992
1042
$ uploads = wp_upload_dir ();
993
1043
}
1044
+
994
1045
if ( 'video/mp4 ' === $ post_mime_type ) {
995
1046
$ media_type = 'mp4 ' ;
996
1047
} elseif ( 'audio/mp3 ' === $ post_mime_type ) {
@@ -1129,7 +1180,11 @@ public function handle_callback() {
1129
1180
die ();
1130
1181
}
1131
1182
} else {
1132
- if ( isset ( $ job_id ) && class_exists ( 'RTDBModel ' ) ) {
1183
+
1184
+ // To check if request is sumitted from the WP Job Manager plugin ( https://wordpress.org/plugins/wp-job-manager/ ).
1185
+ $ job_manager_form = transcoder_filter_input ( INPUT_POST , 'job_manager_form ' , FILTER_SANITIZE_STRING );
1186
+
1187
+ if ( isset ( $ job_id ) && ! empty ( $ job_id ) && class_exists ( 'RTDBModel ' ) && empty ( $ job_manager_form ) ) {
1133
1188
1134
1189
$ has_thumbs = isset ( $ thumbnail ) ? true : false ;
1135
1190
$ flag = false ;
@@ -1451,7 +1506,7 @@ public function get_transcoding_status( $post_id ) {
1451
1506
if ( function_exists ( 'vip_safe_wp_remote_get ' ) ) {
1452
1507
$ status_page = vip_safe_wp_remote_get ( $ status_url , '' , 3 , 3 );
1453
1508
} else {
1454
- $ status_page = wp_remote_get ( $ status_url , array ( 'timeout ' => 120 ) ); // phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.wp_remote_get_wp_remote_get, WordPressVIPMinimum.Performance.RemoteRequestTimeout.timeout_timeout
1509
+ $ status_page = wp_safe_remote_get ( $ status_url , array ( 'timeout ' => 120 ) ); // phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.wp_remote_get_wp_remote_get, WordPressVIPMinimum.Performance.RemoteRequestTimeout.timeout_timeout
1455
1510
}
1456
1511
1457
1512
if ( ! is_wp_error ( $ status_page ) ) {
0 commit comments