Skip to content

Comments

Add filters to modify the cached URLs#48

Open
carlalexander wants to merge 1 commit intoberkmancenter:wordpressfrom
carlalexander:patch-1
Open

Add filters to modify the cached URLs#48
carlalexander wants to merge 1 commit intoberkmancenter:wordpressfrom
carlalexander:patch-1

Conversation

@carlalexander
Copy link
Contributor

@carlalexander carlalexander commented Jan 25, 2018

This is PR is part of a fix for #44. It adds two filters to the amber link caching process. One during the enqueue process and another during the lookup. This lets us edit links before Amber tries to cache them. We then modify those links again when Amber looks them up.

Here's an example of the use of these filters to fix the issue in #44:

function remove_twitter_url_query_string($url) {
	return preg_replace('/(https?:\/\/twitter\.com[^?]*).*/i', '$1', $url);
}
add_filter('amber_cache_link', 'remove_twitter_url_query_string');
add_filter('amber_lookup_url', 'remove_twitter_url_query_string');

@carlalexander
Copy link
Contributor Author

carlalexander commented Jan 25, 2018

Just a note on the Travis errors. It seems like the Travis config doesn't work for PHP 5.3 or HHVM. HHVM could probably be dropped since WordPress doesn't support it anymore either.

}

private static function cache_link($item, $force = false) {
$item = apply_filters('amber_cache_link', item);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$item = apply_filters('amber_cache_link', item);
$item = apply_filters('amber_cache_link', $item);

private static function cache_link($item, $force = false) {
$item = apply_filters('amber_cache_link', item);

if (empty($link)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (empty($link)) {
if (empty($item)) {

@jlicht
Copy link
Collaborator

jlicht commented Nov 1, 2018

Thanks for this pull request! Can you give us permission to make modifications, as per https://help.github.com/articles/allowing-changes-to-a-pull-request-branch-created-from-a-fork/

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

Successfully merging this pull request may close these issues.

2 participants