Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
wp_read_audio_metadata example
$metadata
= array
(
)
;
$support
= false;
$mime_type
=
get_post_mime_type
(
$attachment
)
;
if
(
preg_match
(
'!^image/!',
$mime_type
)
&&
file_is_displayable_image
(
$file
)
)
{
// Make thumbnails and other intermediate sizes.
$metadata
=
wp_create_image_subsizes
(
$file
,
$attachment_id
)
;
}
elseif
(
wp_attachment_is
(
'video',
$attachment
)
)
{
$metadata
=
wp_read_video_metadata
(
$file
)
;
$support
=
current_theme_supports
(
'post-thumbnails', 'attachment:video'
)
||
post_type_supports
(
'attachment:video', 'thumbnail'
)
;
}
elseif
(
wp_attachment_is
(
'audio',
$attachment
)
)
{
$metadata
=
wp_read_audio_metadata
(
$file
)
;
$support
=
current_theme_supports
(
'post-thumbnails', 'attachment:audio'
)
||
post_type_supports
(
'attachment:audio', 'thumbnail'
)
;
}
/* * wp_read_video_metadata() and wp_read_audio_metadata() return `false` * if the attachment does not exist in the local filesystem, * so make sure to convert the value to an array. */
if
(
!
is_array
(
$metadata
)
)
{
$metadata
= array
(
)
;
}
$ext
=
pathinfo
(
$name
, PATHINFO_EXTENSION
)
;
$name
=
wp_basename
(
$name
, ".
$ext
"
)
;
$url
=
$file
[
'url'
]
;
$type
=
$file
[
'type'
]
;
$file
=
$file
[
'file'
]
;
$title
=
sanitize_text_field
(
$name
)
;
$content
= '';
$excerpt
= '';
if
(
preg_match
(
'#^audio#',
$type
)
)
{
$meta
=
wp_read_audio_metadata
(
$file
)
;
if
(
!
empty
(
$meta
[
'title'
]
)
)
{
$title
=
$meta
[
'title'
]
;
}
if
(
!
empty
(
$title
)
)
{
if
(
!
empty
(
$meta
[
'album'
]
)
&& !
empty
(
$meta
[
'artist'
]
)
)
{
/* translators: 1: Audio track title, 2: Album title, 3: Artist name. */
$content
.=
sprintf
(
__
(
'"%1$s" from %2$s by %3$s.'
)
,
$title
,
$meta
[
'album'
]
,
$meta
[
'artist'
]
)
;
}
elseif
(
!
empty
(
$meta
[
'album'
]
)
)
{