Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incompatible with Axis for WordPress 1.0.2 #226

Closed
aendra-rininsland opened this issue Feb 9, 2015 · 6 comments
Closed

Incompatible with Axis for WordPress 1.0.2 #226

aendra-rininsland opened this issue Feb 9, 2015 · 6 comments

Comments

@aendra-rininsland
Copy link

Hi there!

I'm the developer of Axis for WordPress, an interface for easily creating a multitude of charts for WordPress. We're using wp-amazon-s3-and-cloudfront to serve static assets, which include my Axis charts. Alas, I'm running into a weird bug wherein only the second most-recent version of a chart is uploaded to S3.

Essentially: in Axis, you create a chart in a modal window spawned via TinyMCE toolbar button, and then click a button once finished. Some AJAX stuff goes on in the background that saves the chart as a PNG on a new attachment in the media library, and an image tag is dropped into TinyMCE. The relevant bits of the AJAX callback are here.

Oddly, it seems to only update the attachment filename on the next edit/save of the chart, causing wp-amazon-s3-and-cloudfront to then push it to S3. Even more oddly, this behaviour doesn't exist locally.

Any thoughts? I'm a bit at my wit's end with this and any feedback you could give would be massively appreciated. 😄

Thanks!

@bradt
Copy link
Contributor

bradt commented Feb 9, 2015

Have you tried enabling the Object Versioning option in the plugin's settings?

@aendra-rininsland
Copy link
Author

Yep, just did. Same behaviour. Same also regardless of whether "delete local objects" is on or not. Will keep debugging and posting back.

Edit: It is uploading the relevant images to S3... Seems like the issue at this stage is updating the link in TinyMCE. Might be on my end...

Edit2: Nope, I'm pretty sure now it's an issue with wp-amazon-s3-and-cloudfront. On line 233, I first use update_attached_file() to update the attachment URL, and then get the updated URL from the attachment via wp_get_attachment_image_src() on line 234. wp_get_attachment_image_src() is returning the old attachment URL. I've tried putting a sleep(3) between those lines (in case wp-amazon-s3-and-cloudfront needs some time to upload the new images and then update the file path), but that doesn't seem to solve it — wp_get_attachment_image_src() keeps returning the old URL.

Edit3: Looking through classes/amazon-s3-and-cloudfront.php, I see there are hooks for the following functions:

a. wp_get_attachment_url
b. wp_update_attachment_metadata
c. wp_get_attachment_metadata
d. get_attached_file
e. A few unrelated others

I've since changed the snippet I linked to earlier to the following:

        } else { // Update existing attachment
            $attach_data = wp_generate_attachment_metadata( $axis_config['attachmentID'], $filename );
            wp_update_attachment_metadata( $axis_config['attachmentID'], $attach_data );
            fb($attach_data);
            $attach_url = wp_get_attachment_url( $axis_config['attachmentID'], true ); // Get full path
            $axis_config['attachmentURL'] = $attach_url;
            fb($attach_url);

For some reason, wp_update_attachment_metadata doesn't seem to be actually updating properly – all the thumbnails are updated, but the main image itself doesn't seem to be. I'll investigate a bit more tomorrow... Any input you could give would be super appreciated.

@aendra-rininsland
Copy link
Author

Let's put this a different way — as a plugin developer, how do I leverage your plugin to update images in the media library? There isn't any developer documentation AFAICT...

@aendra-rininsland
Copy link
Author

Just reading through a few more issues — as per #7, does this mean there is currently no way for outside plugins to leverage wp-amazon-s3-and-cloudfront? If so, this should be clearly stated on the WP.org plugin page because the likelihood of breaking other code as a result of this is fairly substantial.

@aendra-rininsland
Copy link
Author

I've created a hacky workaround for the issue (replaces existing image on server and adds a timestamp to the url in TinyMCE as a cache buster) but am leaving this open in case there's a not-hacky way of leveraging wp-amazon-s3-and-cloudfront that I've missed.

@aaemnnosttv
Copy link

Closing this one due to the age and lack of activity. WP Offload S3 does not have it's own plugin API at this time (other than a few filters) because it is designed to interact with the core WordPress APIs as much as possible to provide the most compatible and transparent experience.

Please re-open if there is a bug with the current version of Offload S3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants