Skip to content
This repository was archived by the owner on Mar 26, 2021. It is now read-only.
This repository was archived by the owner on Mar 26, 2021. It is now read-only.

Broken media links when using offload media plugin #64

Open
@jwcounts

Description

@jwcounts

My colleague David Purdy at KTOO in Anchorage brought this up and I was able to replicate it in my setup.

We are both using the WP Offload Media plugin by Delicious Brains to push our media files to Amazon S3 for service. After uploading to S3, the plugin updates the attachment URL and other metadata, but leaves the attachment GUID untouched.

Any images or audio files in the body of the post are handled properly when sending to the API, since they are either untouched, or completely stripped (in the "text with HTML" and "text" versions respectively). However, the audio and image attachments created in the API all point to the attached media's GUID, which in our case returns a 404 error.

I made some changes to the NPRML.php file in my test and production environments that have sorted the problem out. Here is a link to a copy of the changed file (all changes are between lines 303 - 430):

NPRML.php

The main change is to switch $audio->guid to wp_get_attachment_url( $audio->ID ) (or $image when handling images). The benefit of this is that if no media offload plugin is being used, the GUID should be returned.

Also, I made some modifications to how filenames are pulled from the image/audio URLs using parse_url() and pathinfo().

Finally, I noticed an issue where we'd have 2 audio entries on a story in the API, because one was pulled from the post attachments and the other was pulled from an enclosure in wp_postmeta.
When processing the post attachments, I created an array of filenames, and then added a check against that array when processing enclosures.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions