From 271702cd27746d6652d7278add1467c4cb2fcf00 Mon Sep 17 00:00:00 2001 From: Helen Hou-Sandi Date: Mon, 16 Nov 2020 19:18:51 +0000 Subject: [PATCH] Media: Avoid fatal error in `wp_prepare_attachment_for_js(). In certain contexts, in particular on the front-end, `get_media_states()` is not availble. Props rebasaurus. Fixes #51791. git-svn-id: https://develop.svn.wordpress.org/trunk@49613 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/media.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/wp-includes/media.php b/src/wp-includes/media.php index 8b8b862e5d..3d8507ff90 100644 --- a/src/wp-includes/media.php +++ b/src/wp-includes/media.php @@ -4029,9 +4029,11 @@ function wp_prepare_attachment_for_js( $attachment ) { $response['compat'] = get_compat_media_markup( $attachment->ID, array( 'in_modal' => true ) ); } - $media_states = get_media_states( $attachment ); - if ( ! empty( $media_states ) ) { - $response['mediaStates'] = implode( ', ', $media_states ); + if ( function_exists( 'get_media_states' ) ) { + $media_states = get_media_states( $attachment ); + if ( ! empty( $media_states ) ) { + $response['mediaStates'] = implode( ', ', $media_states ); + } } /**