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
This commit is contained in:
Helen Hou-Sandi 2020-11-16 19:18:51 +00:00
parent 2c7b5c37db
commit 271702cd27

View File

@ -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 );
}
}
/**