hypothesis / wp-hypothesis

Hypothesis WordPress plugin
https://wordpress.org/plugins/hypothesis/
Other
29 stars 14 forks source link

via-pdf regular expression should be Multisite-friendly. #27

Closed boonebgorges closed 7 years ago

boonebgorges commented 7 years ago

The regular expression used to swap out PDF links is hardcoded: wp-content/uploads.+\.pdf. This doesn't work on all installations. In Multisite, as well as in other customized setups, the upload directory (and, more importantly, the public URL of the upload directory) is different. Sometimes it's example.com/files, sometimes example.com/wp-content/sites, etc.

This PR uses wp_upload_dir() to (dynamically) fetch the base URL for the upload directory, and then uses that base to build the regular expression.

A small note that this change means that the regex checks for absolute href URLs, so won't catch relative URLs in the same way that your old one will. (It's quite a bit more complicated to write a relative-URL-sensitive regex that works on all WP setups.) But WP should always use absolute URLs when generating anchor markup from the Media Library, so it shouldn't be an issue.

greatislander commented 7 years ago

Fixes #28 (FYI @judell).

judell commented 7 years ago

@greatislander and @boonebgorges: Thanks so much!