WordPress.org

Ready to get started?Download WordPress

Forums

wp_generate_attachment_metadata return value on errors (2 posts)

  1. taloweb
    Member
    Posted 9 months ago #

    Hello, in these days I worked with wp_generate_attachment_metadata function, it would be very useful if in case of some problems
    this function can return a WP_Error object and not an empty array.

    Example: if image doesn't exists or if attachment mime type is missing and in many other situation when wp_generate_attachment_metadata can't do its job, it simply fail returning an array without elements.

    What do you think about this?

  2. taloweb
    Member
    Posted 8 months ago #

    I found someone using this:

    $metadata = wp_generate_attachment_metadata( ID, $fullsizepath );
    if ( is_wp_error( $metadata ) )
    $metadata->get_error_message();
    if ( empty( $metadata ))
    die (__( 'Unknown failure reason.'));

    but it's not documented that wp_generate_attachment_metadata can return a WP_error object...

Reply

You must log in to post.

About this Topic

Tags

No tags yet.