WordPress.org

Ready to get started?Download WordPress

Forums

WP External Links (nofollow new window seo)
[resolved] Set up exclusion by code? (22 posts)

  1. Martin
    Member
    Posted 1 year ago #

    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/

  2. Martin
    Member
    Posted 1 year ago #

    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?

  3. freelancephp
    Member
    Plugin Author

    Posted 1 year ago #

    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...

  4. Martin
    Member
    Posted 1 year ago #

    Thanks heaps for giving it some thought. Will wait to hear back with what you consider optimal.

  5. Martin
    Member
    Posted 1 year ago #

    Any updates on the filter hook - keen to get this functional in my advertising platform. Thanks for any efforts too

  6. freelancephp
    Member
    Plugin Author

    Posted 12 months ago #

    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

  7. Martin
    Member
    Posted 11 months ago #

    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.

  8. freelancephp
    Member
    Plugin Author

    Posted 10 months ago #

    Hello Martin, the filter "wpel_external_link" is added in version 1.40.

  9. Martin
    Member
    Posted 10 months ago #

    Cool - so it's just a new functions.php inclusion now?

  10. freelancephp
    Member
    Plugin Author

    Posted 10 months ago #

    Yep :)

  11. Martin
    Member
    Posted 10 months ago #

    Ok, I'll set it up on my localhost and give it a try out - will report back with findings

  12. Martin
    Member
    Posted 10 months ago #

    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?

  13. freelancephp
    Member
    Plugin Author

    Posted 10 months ago #

    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.

  14. Martin
    Member
    Posted 10 months ago #

    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.

  15. freelancephp
    Member
    Plugin Author

    Posted 10 months ago #

    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);
  16. Martin
    Member
    Posted 10 months ago #

    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.

  17. freelancephp
    Member
    Plugin Author

    Posted 10 months ago #

    pfff...sorry still some test code...
    Now I tested it exactly the way you want to implement it. And this works on my local WP installation:

    function external_link_filter($created_link, $original_link, $label, $attrs = array()) {
    	if (isset($attrs['class']) && strpos($attrs['class'], 'gajnfads') !== false) {
    		return $original_link;
    	}
    
    	return $created_link;
    }
    add_filter('wpel_external_link', 'external_link_filter', 10, 4);
  18. Martin
    Member
    Posted 10 months ago #

    Absolutely BRILLIANT!
    A few tweaks to the OIO-Publisher plugin and now your plugin's enhancement has the links working perfectly.

    Thank you so much for a brilliant plugin! Rated 5 Stars

  19. freelancephp
    Member
    Plugin Author

    Posted 10 months ago #

    Thanks Martin!

  20. Sith Lord Goz
    Member
    Posted 10 months ago #

    This is the second support topic I've posted in for WP External Links, and the second time I've been really impressed by @freelancephp responses! :)

    I'll post my problem/solution here just in case it saves someone else the 2hrs I've spent on this today.

    My problem:
    ==========
    WP External Links produces strange mangled output of <a> tags that contain custom HTML5 attributes.

    For example:

    <a href="http://example.com" data-referer="something.com">External Link</a>

    will get output as:

    <a class="ext-link ext-icon-6" href="http://example.com" rel="external nofollow" 0="data-referer="something.com"">External Link</a>

    I'm guessing this is because when the regex rebuilds the <a> tag, it doesn't recognize the data-* attributes, so creates an array of them.. hence the extra 0=... 1=.... 2=.... etc.

    My solution:
    =============
    Using the new & excellent wpel_external_link() filter hook, it's easy to exclude this links from being processed.

    However it would be perfect if the rebuilding function could account for these custom attributes and preserve them... but I don't know the level-of-effort required for this. :P

  21. dEM0nsTAr
    Member
    Posted 8 months ago #

    I have tried that code with class name "sfx" for http://www.peleke.de/galerie/flickr/?page_id=0&albid=72157633109872572 but that doesn't seem to work.
    Can you please take a look why?
    Thanks!

  22. nata-lee
    Member
    Posted 8 months ago #

    Hello!
    I tried to use the hook to exclude a class "not-external" and place this code into functions.php

    function external_link_filter($created_link, $original_link, $label, $attrs = array()) {
    	if (isset($attrs['class']) && strpos($attrs['class'], 'not-external') !== false) {
    		return $original_link;
    	}
    	return $created_link;
    }
    add_filter('wpel_external_link', 'external_link_filter', 10, 4);

    my link is a kind of
    <a href="http://fc00.deviantart.net/fs70/i/2013/220/4/2/horo_by_mrshlapa-d6h90v5.png" class="not-external"> 12313213</a>

    But is doesn't seem to work. I don't know what's wrong. Please, any help

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.