wp_image_file_matches_image_meta example

require_once ABSPATH . 'wp-admin/includes/image.php';

        $attachment_id = $request['id'];

        // This also confirms the attachment is an image.         $image_file = wp_get_original_image_path( $attachment_id );
        $image_meta = wp_get_attachment_metadata( $attachment_id );

        if (
            ! $image_meta ||
            ! $image_file ||
            ! wp_image_file_matches_image_meta( $request['src']$image_meta$attachment_id )
        ) {
            return new WP_Error(
                'rest_unknown_attachment',
                __( 'Unable to get meta information for file.' ),
                array( 'status' => 404 )
            );
        }

        $supported_types = array( 'image/jpeg', 'image/png', 'image/gif', 'image/webp' );
        $mime_type       = get_post_mime_type( $attachment_id );
        if ( ! in_array( $mime_type$supported_types, true ) ) {
            
Home | Imprint | This part of the site doesn't use cookies.