Thread Starter
Martin
(@rastarr)
I’ve also been chatting the the developer of OIO Publisher.
While he can give me assistance in hacking some code to then hack your plugin’s database, he suggested the following as a much more elegant solution:
A cleaner solution, if the other plugin supports it, would be to exclude links based on criteria such as whether a specific class appears on the link. If it doesn’t support that kind of exclusion, it might be worth putting in a request for it.
For example, I could easily stick class=”oio-link” on to all links generated by OIO, which the plugin could then exclude.
Is this a possibility that WP External Links can simply ignore / bypass links that have a particularly configured class?
There is a possibility to exclude links that contain a certain text in the url (for example, all urls to twitter.com).
I have to think about the exclusion of certain classes. Maybe I would rather add a filter hook, so you can manipulate the output yourself on your own criteria.
I’ll get back on this one…
Thread Starter
Martin
(@rastarr)
Thanks heaps for giving it some thought. Will wait to hear back with what you consider optimal.
Thread Starter
Martin
(@rastarr)
Any updates on the filter hook – keen to get this functional in my advertising platform. Thanks for any efforts too
Hello Martin,
I’ve been working on my other plugins. WP External links needs a refactoring and I first wanted to test it on another plugin.
A quick solution if you now how to code, is implementing the filter yourself in the file:
[plugin_dir]/includes/class-wp-mailto-links.php
Add just a line of code on line 278:
$link .= '>'. $matches[ 2 ] .'</a>';
// add this code for the filter:
$link = apply_filters('wpel_external_link', $matches[0], $link, $matches[2], $attrs);
return $link;
Now you can add something to the filter in the file functions.php file of your template, like:
function own_external_link($original_link, $created_link, $label, $attrs = array()) {
return 'This is an external link: ' . $created_link;
}
apply_filters('wpel_external_link', 'own_external_link', 10, 4)
I haven’t tested this code yet.
Regards,
Victor
Thread Starter
Martin
(@rastarr)
OK, thanks for this, Victor.
I’m OK with the alterations and just confused on the triggering mechanism so have just asked the OIO Publisher author for his input.
I just had a dofollow incontent purchase today as a matter of fact and needed to apply a manual entry and prompted me to move on your wonderful work and suggestion of code alterations.
I’ll update the post on progress as it might help others in a similar situation.
Hello Martin, the filter “wpel_external_link” is added in version 1.40.
Thread Starter
Martin
(@rastarr)
Cool – so it’s just a new functions.php inclusion now?
Thread Starter
Martin
(@rastarr)
Ok, I’ll set it up on my localhost and give it a try out – will report back with findings
Thread Starter
Martin
(@rastarr)
Maybe I’ve got the usage wrong here.
I’ve got the following in my functions.php
function extra_filters($filter_callback, $object) {
add_filter('gajnfads', $filter_callback);
}
add_action('wpel_ready', 'extra_filters');
The link that I want this plugin to ignore has an added class such as:
<a class="gajnfads" target="_blank" title="dofollow testing" href="http://www.testing.com">
When this plugin is active and the functions.php snippet is there, the link is still being altered.
Have I messed up somewhere in what I’m doing?
You will need to use the filter wpel_external_link. In your case it would look like:
public function external_link_filter($created_link, $original_link, $label, $attrs = array()) {
if (isset($attrs['class']) && strpos($attrs['class'], 'gajnfads') !== false) {
return $original_link;
}
$this->external_link_filter_args = func_get_args();
return '<b>'. $created_link .'</b>';
}
add_filter('wpel_external_link', array($this, 'external_link_filter'), 10, 4);
I did found a bug though, so please update first.
Thread Starter
Martin
(@rastarr)
hmmm, using that code on my localhost, I get
Parse error: syntax error, unexpected T_PUBLIC in /Users/MartinC/Sites/gaj/wp-content/plugins/my-functionality-plugin/my-functionality-plugin.php on line 55
which is the first line of the function.
I tried removing the public however the entire URL line vanished i.e.
<a title="dofollow testing" href="http://www.testing.com"></a>
is replaced by a space.
Sorry I’m not good at code and seeing the error.
Sorry I copy/pasted from my testing code, but that’s part of a test-class. Try this:
function external_link_filter($created_link, $original_link, $label, $attrs = array()) {
if (isset($attrs['class']) && strpos($attrs['class'], 'gajnfads') !== false) {
return $original_link;
}
return '<b>'. $created_link .'</b>';
}
add_filter('wpel_external_link', array($this, 'external_link_filter'), 10, 4);
Thread Starter
Martin
(@rastarr)
hmmm, not sure what’s going on here.
I replaced with your code however the entire HTML is still being removed from the page for some reason … as in vanishing so like it’s identifying what needs to be left alone but removes it completely from the content.
Hope that makes some sense.