Skip to content
This repository has been archived by the owner on Feb 23, 2019. It is now read-only.

Rewrite URLs via wp_..._for_js() filter when CDN is Enabled #336

Merged
merged 1 commit into from
Jan 30, 2017

Conversation

amiga-500
Copy link
Collaborator

What turned out to be an isolated incident where one user reported that images loaded via JavaScript generated by the Beaver Builder plugin do not get pulled from CDN, later was discovered to be a hole in W3TC. After speaking with the plugin authors it was revealed that they're using the wp_prepare_attachment_for_js() function, prior to generating JS files, to collect image URLs. Because W3TC does not hook into the associating filter when a CDN is used these URLs are not being correctly formatted.

Since many slideshow plugins appear to use wp_prepare_attachment_for_js() to load images dynamically, this issue affects more than just Beaver Builder users.

This proposed new feature corrects this problem by hooking into the wp_prepare_attachment_for_js() filter and rewriting image URLs when the CDN is enabled. It also ensures to verify that the URL is on the CDN allowed files list before being rewritten. :octocat:

@amiga-500 amiga-500 changed the title Rewrite Attachment URLs when CDN is Enabled Rewrite URLs via wp_..._for_js() filter when CDN is Enabled Jan 30, 2017
@amiga-500 amiga-500 merged commit b225070 into v0.9.5.x Jan 30, 2017
@amiga-500 amiga-500 deleted the attachment branch January 30, 2017 11:09
amiga-500 added a commit that referenced this pull request Feb 2, 2017
This is a revision to #336 that moves away from using the
wp_prepare_attachment_for_js() filter and uses wp_get_attachment_url and
attachment_link filters instead.

The change makes the code less intense since it no longer has to parse
through the large array response for urls to change.

This revision also includes a check to verify that, if logged in, the
role is permitted to use CDN.
amiga-500 added a commit that referenced this pull request Feb 3, 2017
This is a revision to #336 that moves away from using the "wp_prepare_attachment_for_js()" filter and attaches to "wp_get_attachment_url" and "attachment_link filters" instead.

It also includes a new checkbox allowing the user to specify if they want to use CDN links instead of local ones for Media Library content on admin pages.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant