@@ -315,7 +315,7 @@ protected function get_attachment() {
315315 if ( site_supports_blocks () && \has_blocks ( $ this ->item ->post_content ) ) {
316316 $ media = $ this ->get_block_attachments ( $ media , $ max_media );
317317 } else {
318- $ media = $ this ->get_classic_editor_images ( $ media , $ max_media );
318+ $ media = $ this ->get_classic_editor_image_embeds ( $ media , $ max_media );
319319 }
320320
321321 $ media = $ this ->filter_media_by_object_type ( $ media , \get_post_format ( $ this ->item ), $ this ->item );
@@ -785,47 +785,22 @@ function ( $id ) {
785785 }
786786
787787 /**
788- * Get post images from the classic editor.
789- * Note that audio/video attachments are only supported in the block editor.
788+ * Get image embeds from the classic editor by parsing HTML.
790789 *
791790 * @param array $media The media array grouped by type.
792791 * @param int $max_images The maximum number of images to return.
793792 *
794793 * @return array The attachments.
795794 */
796- protected function get_classic_editor_images ( $ media , $ max_images ) {
797- // Max images can't be negative or zero.
798- if ( $ max_images <= 0 ) {
799- return array ();
800- }
801-
802- if ( \count ( $ media ['image ' ] ) <= $ max_images ) {
803- if ( \class_exists ( '\WP_HTML_Tag_Processor ' ) ) {
804- $ media ['image ' ] = \array_merge ( $ media ['image ' ], $ this ->get_classic_editor_image_embeds ( $ max_images ) );
805- } else {
806- $ media ['image ' ] = \array_merge ( $ media ['image ' ], $ this ->get_classic_editor_image_attachments ( $ max_images ) );
807- }
808- }
809-
810- return $ media ;
811- }
812-
813- /**
814- * Get image embeds from the classic editor by parsing HTML.
815- *
816- * @param int $max_images The maximum number of images to return.
817- *
818- * @return array The attachments.
819- */
820- protected function get_classic_editor_image_embeds ( $ max_images ) {
795+ protected function get_classic_editor_image_embeds ( $ media , $ max_images ) {
821796 // If someone calls that function directly, bail.
822797 if ( ! \class_exists ( '\WP_HTML_Tag_Processor ' ) ) {
823- return array () ;
798+ return $ media ;
824799 }
825800
826801 // Max images can't be negative or zero.
827802 if ( $ max_images <= 0 ) {
828- return array () ;
803+ return $ media ;
829804 }
830805
831806 $ images = array ();
@@ -887,44 +862,11 @@ protected function get_classic_editor_image_embeds( $max_images ) {
887862 }
888863 }
889864
890- return $ images ;
891- }
892-
893- /**
894- * Get image attachments from the classic editor.
895- * This is imperfect as the contained images aren't necessarily the
896- * same as the attachments.
897- *
898- * @param int $max_images The maximum number of images to return.
899- *
900- * @return array The attachment IDs.
901- */
902- protected function get_classic_editor_image_attachments ( $ max_images ) {
903- // Max images can't be negative or zero.
904- if ( $ max_images <= 0 ) {
905- return array ();
906- }
907-
908- $ images = array ();
909- $ query = new \WP_Query (
910- array (
911- 'post_parent ' => $ this ->item ->ID ,
912- 'post_status ' => 'inherit ' ,
913- 'post_type ' => 'attachment ' ,
914- 'post_mime_type ' => 'image ' ,
915- 'order ' => 'ASC ' ,
916- 'orderby ' => 'menu_order ID ' ,
917- 'posts_per_page ' => $ max_images ,
918- )
919- );
920-
921- foreach ( $ query ->get_posts () as $ attachment ) {
922- if ( ! \in_array ( $ attachment ->ID , $ images , true ) ) {
923- $ images [] = array ( 'id ' => $ attachment ->ID );
924- }
865+ if ( \count ( $ media ['image ' ] ) <= $ max_images ) {
866+ $ media ['image ' ] = \array_merge ( $ media ['image ' ], $ images );
925867 }
926868
927- return $ images ;
869+ return $ media ;
928870 }
929871
930872 /**
0 commit comments