Title: Set up exclusion by code?
Last modified: August 20, 2016

---

# Set up exclusion by code?

 *  Resolved [Martin](https://wordpress.org/support/users/rastarr/)
 * (@rastarr)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/set-up-exclusion-by-code/)
 * Hi,
 * First up great plugin. I use it on all my sites and works great.
 * I’ve just installed one of the best insite Advertising platforms called OIO Publisher
   which allows automatically selling advertising including inline text links. The
   platform allows follow and nofollow as advertiser option choices.
 * I was wondering whether there’s an easy way for the developer to interface with
   your plugin so that any purchases of dofollow links can be added to your plugins
   database of exclusions? Is it just a matter of adding one to a particular database
   table and when the purchase expires, then remove the URL from the table?
 * Any help would really be appreciated.
    Martin
 * [http://wordpress.org/extend/plugins/wp-external-links/](http://wordpress.org/extend/plugins/wp-external-links/)

Viewing 15 replies - 1 through 15 (of 21 total)

1 [2](https://wordpress.org/support/topic/set-up-exclusion-by-code/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/set-up-exclusion-by-code/page/2/?output_format=md)

 *  Thread Starter [Martin](https://wordpress.org/support/users/rastarr/)
 * (@rastarr)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/set-up-exclusion-by-code/#post-3281920)
 * 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?
 *  [Pi Zi](https://wordpress.org/support/users/freelancephp/)
 * (@freelancephp)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/set-up-exclusion-by-code/#post-3281944)
 * 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](https://wordpress.org/support/users/rastarr/)
 * (@rastarr)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/set-up-exclusion-by-code/#post-3281945)
 * Thanks heaps for giving it some thought. Will wait to hear back with what you
   consider optimal.
 *  Thread Starter [Martin](https://wordpress.org/support/users/rastarr/)
 * (@rastarr)
 * [13 years ago](https://wordpress.org/support/topic/set-up-exclusion-by-code/#post-3281948)
 * Any updates on the filter hook – keen to get this functional in my advertising
   platform. Thanks for any efforts too
 *  [Pi Zi](https://wordpress.org/support/users/freelancephp/)
 * (@freelancephp)
 * [13 years ago](https://wordpress.org/support/topic/set-up-exclusion-by-code/#post-3281949)
 * 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](https://wordpress.org/support/users/rastarr/)
 * (@rastarr)
 * [13 years ago](https://wordpress.org/support/topic/set-up-exclusion-by-code/#post-3281950)
 * 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.
 *  [Pi Zi](https://wordpress.org/support/users/freelancephp/)
 * (@freelancephp)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/set-up-exclusion-by-code/#post-3281953)
 * Hello Martin, the filter “wpel_external_link” is added in version 1.40.
 *  Thread Starter [Martin](https://wordpress.org/support/users/rastarr/)
 * (@rastarr)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/set-up-exclusion-by-code/#post-3281954)
 * Cool – so it’s just a new functions.php inclusion now?
 *  [Pi Zi](https://wordpress.org/support/users/freelancephp/)
 * (@freelancephp)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/set-up-exclusion-by-code/#post-3281955)
 * Yep 🙂
 *  Thread Starter [Martin](https://wordpress.org/support/users/rastarr/)
 * (@rastarr)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/set-up-exclusion-by-code/#post-3281956)
 * Ok, I’ll set it up on my localhost and give it a try out – will report back with
   findings
 *  Thread Starter [Martin](https://wordpress.org/support/users/rastarr/)
 * (@rastarr)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/set-up-exclusion-by-code/#post-3281957)
 * 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?
 *  [Pi Zi](https://wordpress.org/support/users/freelancephp/)
 * (@freelancephp)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/set-up-exclusion-by-code/#post-3281958)
 * 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](https://wordpress.org/support/users/rastarr/)
 * (@rastarr)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/set-up-exclusion-by-code/#post-3281959)
 * 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.
 *  [Pi Zi](https://wordpress.org/support/users/freelancephp/)
 * (@freelancephp)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/set-up-exclusion-by-code/#post-3281960)
 * 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](https://wordpress.org/support/users/rastarr/)
 * (@rastarr)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/set-up-exclusion-by-code/#post-3281961)
 * 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.

Viewing 15 replies - 1 through 15 (of 21 total)

1 [2](https://wordpress.org/support/topic/set-up-exclusion-by-code/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/set-up-exclusion-by-code/page/2/?output_format=md)

The topic ‘Set up exclusion by code?’ is closed to new replies.

 * ![](https://ps.w.org/wp-external-links/assets/icon-256x256.png?rev=2103983)
 * [External Links - nofollow, noopener & new window](https://wordpress.org/plugins/wp-external-links/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-external-links/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-external-links/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-external-links/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-external-links/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-external-links/reviews/)

 * 21 replies
 * 5 participants
 * Last reply from: [nata-lee](https://wordpress.org/support/users/nata-lee/)
 * Last activity: [12 years, 9 months ago](https://wordpress.org/support/topic/set-up-exclusion-by-code/page/2/#post-3281968)
 * Status: resolved