Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

pixel016 on "wp_generate_attachment_metadata does not work"

$
0
0
$filename = get_user_meta($userID, 'image_profil',true);

        $wp_filetype = wp_check_filetype(basename($filename), null );
        $wp_upload_dir = wp_upload_dir();
        $attachment = array(
           'guid' => $wp_upload_dir['url'] . '/' . basename( $filename ),
           'post_mime_type' => $wp_filetype['type'],
           'post_title' => preg_replace( '/\.[^.]+$/', '', basename( $filename ) ),
           'post_content' => '',
           'post_status' => 'inherit'
        );
        $attach_id = wp_insert_attachment( $attachment, $filename);
        require_once( ABSPATH . 'wp-admin/includes/image.php' );
        $attach_data = wp_generate_attachment_metadata( $attach_id, $filename );
        wp_update_attachment_metadata( $attach_id, $attach_data );
        set_post_thumbnail( $post_id, $attach_id );

Why the $attach_data return an empty array ? :(


Viewing all articles
Browse latest Browse all 8245

Trending Articles