Version Description
- Fixed bug also opening ignored URL's on other tab/window when using javascript
- Changed javascript open method (data-attribute)
Download this release
Release Info
Developer | freelancephp |
Plugin | WP External Links (nofollow new tab seo) |
Version | 1.53 |
Comparing to | |
See all releases |
Code changes from version 1.52 to 1.53
- includes/class-wp-external-links.php +32 -33
- js/src/wp-external-links.js +22 -29
- js/wp-external-links.js +1 -1
- readme.txt +27 -7
- wp-external-links.php +2 -2
includes/class-wp-external-links.php
CHANGED
@@ -63,6 +63,14 @@ final class WP_External_Links {
|
|
63 |
if ( $this->get_opt( 'use_js' ) )
|
64 |
wp_enqueue_script( 'wp-external-links', plugins_url( 'js/wp-external-links.js', WP_EXTERNAL_LINKS_FILE ), array(), WP_EXTERNAL_LINKS_VERSION, (bool) $this->get_opt( 'load_in_footer' ) );
|
65 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
// filters
|
67 |
if ( $this->get_opt( 'filter_page' ) ) {
|
68 |
// filter body
|
@@ -129,14 +137,6 @@ final class WP_External_Links {
|
|
129 |
* wp_head callback
|
130 |
*/
|
131 |
public function call_wp_head() {
|
132 |
-
// set ignored
|
133 |
-
$ignored = $this->get_opt( 'ignore' );
|
134 |
-
$ignored = trim( $ignored );
|
135 |
-
$ignored = explode( "\n", $ignored );
|
136 |
-
$ignored = array_map( 'trim', $ignored );
|
137 |
-
$ignored = array_map( 'strtolower', $ignored );
|
138 |
-
$this->ignored = $ignored;
|
139 |
-
|
140 |
$icon = $this->get_opt('icon');
|
141 |
|
142 |
if ($icon) {
|
@@ -148,19 +148,6 @@ final class WP_External_Links {
|
|
148 |
</style>
|
149 |
<?php
|
150 |
}
|
151 |
-
|
152 |
-
if ( $this->get_opt( 'use_js' ) AND $this->get_opt( 'target' ) != '_none' ):
|
153 |
-
// set exclude class
|
154 |
-
$excludeClass = ( $this->get_opt( 'no_icon_same_window' ) AND $this->get_opt( 'no_icon_class' ) )
|
155 |
-
? $this->get_opt( 'no_icon_class' )
|
156 |
-
: '';
|
157 |
-
?>
|
158 |
-
<script type="text/javascript">/* <![CDATA[ */
|
159 |
-
/* WP External Links Plugin */
|
160 |
-
var wpExtLinks = { baseUrl: '<?php echo get_bloginfo( 'wpurl' ) ?>', target: '<?php echo $this->get_opt( 'target' ) ?>', excludeClass: '<?php echo $excludeClass ?>' };
|
161 |
-
/* ]]> */</script>
|
162 |
-
<?php
|
163 |
-
endif;
|
164 |
}
|
165 |
|
166 |
/**
|
@@ -352,14 +339,17 @@ var wpExtLinks = { baseUrl: '<?php echo get_bloginfo( 'wpurl' ) ?>', target: '<?
|
|
352 |
// checks
|
353 |
$is_external = $this->is_external( $href, $rel );
|
354 |
$is_ignored = $this->is_ignored( $href );
|
|
|
355 |
|
356 |
// is an internal link?
|
357 |
// rel=external will be threaded as external link
|
358 |
-
if ( ! $is_external &&
|
359 |
return apply_filters('wpel_internal_link', $created_link, $label, $attrs);
|
360 |
}
|
361 |
|
362 |
-
|
|
|
|
|
363 |
return apply_filters('wpel_external_link', $created_link, $link, $label, $attrs, TRUE);
|
364 |
}
|
365 |
|
@@ -390,16 +380,25 @@ var wpExtLinks = { baseUrl: '<?php echo get_bloginfo( 'wpurl' ) ?>', target: '<?
|
|
390 |
$this->add_attr_value( $attrs, 'class', $icon_class );
|
391 |
}
|
392 |
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
403 |
|
404 |
// create element code
|
405 |
$created_link = '<a';
|
63 |
if ( $this->get_opt( 'use_js' ) )
|
64 |
wp_enqueue_script( 'wp-external-links', plugins_url( 'js/wp-external-links.js', WP_EXTERNAL_LINKS_FILE ), array(), WP_EXTERNAL_LINKS_VERSION, (bool) $this->get_opt( 'load_in_footer' ) );
|
65 |
|
66 |
+
// set ignored
|
67 |
+
$ignored = $this->get_opt( 'ignore' );
|
68 |
+
$ignored = trim( $ignored );
|
69 |
+
$ignored = explode( "\n", $ignored );
|
70 |
+
$ignored = array_map( 'trim', $ignored );
|
71 |
+
$ignored = array_map( 'strtolower', $ignored );
|
72 |
+
$this->ignored = $ignored;
|
73 |
+
|
74 |
// filters
|
75 |
if ( $this->get_opt( 'filter_page' ) ) {
|
76 |
// filter body
|
137 |
* wp_head callback
|
138 |
*/
|
139 |
public function call_wp_head() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
140 |
$icon = $this->get_opt('icon');
|
141 |
|
142 |
if ($icon) {
|
148 |
</style>
|
149 |
<?php
|
150 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
151 |
}
|
152 |
|
153 |
/**
|
339 |
// checks
|
340 |
$is_external = $this->is_external( $href, $rel );
|
341 |
$is_ignored = $this->is_ignored( $href );
|
342 |
+
$has_rel_external = (strpos( $rel, 'external' ) !== FALSE);
|
343 |
|
344 |
// is an internal link?
|
345 |
// rel=external will be threaded as external link
|
346 |
+
if ( ! $is_external && ! $has_rel_external) {
|
347 |
return apply_filters('wpel_internal_link', $created_link, $label, $attrs);
|
348 |
}
|
349 |
|
350 |
+
// is an ignored link?
|
351 |
+
// rel=external will be threaded as external link
|
352 |
+
if ( $is_ignored && ! $has_rel_external ) {
|
353 |
return apply_filters('wpel_external_link', $created_link, $link, $label, $attrs, TRUE);
|
354 |
}
|
355 |
|
380 |
$this->add_attr_value( $attrs, 'class', $icon_class );
|
381 |
}
|
382 |
|
383 |
+
// set target
|
384 |
+
$no_icon_class = $this->get_opt( 'no_icon_class' );
|
385 |
+
$target = $this->get_opt( 'target' );
|
386 |
+
|
387 |
+
// remove target
|
388 |
+
unset($attrs[ 'target' ]);
|
389 |
+
|
390 |
+
if ($this->get_opt( 'no_icon_same_window' )
|
391 |
+
AND $no_icon_class AND strpos( $attrs[ 'class' ], $no_icon_class ) !== FALSE) {
|
392 |
+
// open in same window
|
393 |
+
} elseif ($target && $target !== '_none') {
|
394 |
+
if ($this->get_opt( 'use_js' )) {
|
395 |
+
// add data-attr for javascript
|
396 |
+
$attrs['data-wpel-target'] = $target;
|
397 |
+
} else {
|
398 |
+
// set target value
|
399 |
+
$attrs[ 'target' ] = $this->get_opt( 'target' );
|
400 |
+
}
|
401 |
+
}
|
402 |
|
403 |
// create element code
|
404 |
$created_link = '<a';
|
js/src/wp-external-links.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
/* WP External Links Plugin */
|
2 |
-
/*global jQuery, window
|
3 |
(function () {
|
4 |
'use strict';
|
5 |
|
@@ -17,29 +17,22 @@
|
|
17 |
}
|
18 |
|
19 |
// open external link
|
20 |
-
function openExtLink(a,
|
21 |
-
var
|
22 |
-
|
23 |
-
|
24 |
-
n;
|
25 |
|
26 |
-
if (
|
27 |
-
&& (rel.indexOf('external') > -1
|
28 |
-
|| ((href.indexOf(options.baseUrl) === -1) &&
|
29 |
-
(href.substr(0, 7) === 'http://'
|
30 |
-
|| href.substr(0, 8) === 'https://'
|
31 |
-
|| href.substr(0, 6) === 'ftp://'
|
32 |
-
|| href.substr(0, 2) === '//')))) {
|
33 |
// open link in a new window
|
34 |
-
|
35 |
-
|
36 |
|
37 |
// prevent default event action
|
38 |
-
if (
|
39 |
-
if (
|
40 |
-
|
41 |
-
} else {
|
42 |
-
|
43 |
}
|
44 |
}
|
45 |
}
|
@@ -48,19 +41,19 @@
|
|
48 |
if ($ && false) {
|
49 |
// jQuery DOMready method
|
50 |
$(function () {
|
51 |
-
$('a').live('click', function (
|
52 |
-
openExtLink(this,
|
53 |
});
|
54 |
});
|
55 |
} else {
|
56 |
// use onload when jQuery not available
|
57 |
addEvt(window, 'load', function () {
|
58 |
-
var links = window.document.getElementsByTagName('a')
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
|
65 |
// check each <a> element
|
66 |
for (i = 0; i < links.length; i += 1) {
|
@@ -72,4 +65,4 @@
|
|
72 |
});
|
73 |
}
|
74 |
|
75 |
-
}());
|
1 |
/* WP External Links Plugin */
|
2 |
+
/*global jQuery, window*/
|
3 |
(function () {
|
4 |
'use strict';
|
5 |
|
17 |
}
|
18 |
|
19 |
// open external link
|
20 |
+
function openExtLink(a, evt) {
|
21 |
+
var target = a.getAttribute('data-wpel-target');
|
22 |
+
var href = a.getAttribute('href');
|
23 |
+
var win;
|
|
|
24 |
|
25 |
+
if (href && target) {
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
// open link in a new window
|
27 |
+
win = window.open(href, target);
|
28 |
+
win.focus();
|
29 |
|
30 |
// prevent default event action
|
31 |
+
if (evt) {
|
32 |
+
if (evt.preventDefault) {
|
33 |
+
evt.preventDefault();
|
34 |
+
} else if (typeof evt.returnValue !== 'undefined') {
|
35 |
+
evt.returnValue = false;
|
36 |
}
|
37 |
}
|
38 |
}
|
41 |
if ($ && false) {
|
42 |
// jQuery DOMready method
|
43 |
$(function () {
|
44 |
+
$('a').live('click', function (evt) {
|
45 |
+
openExtLink(this, evt);
|
46 |
});
|
47 |
});
|
48 |
} else {
|
49 |
// use onload when jQuery not available
|
50 |
addEvt(window, 'load', function () {
|
51 |
+
var links = window.document.getElementsByTagName('a');
|
52 |
+
var eventClick = function (evt) {
|
53 |
+
openExtLink(evt.target, evt);
|
54 |
+
};
|
55 |
+
var a;
|
56 |
+
var i;
|
57 |
|
58 |
// check each <a> element
|
59 |
for (i = 0; i < links.length; i += 1) {
|
65 |
});
|
66 |
}
|
67 |
|
68 |
+
}());
|
js/wp-external-links.js
CHANGED
@@ -1,2 +1,2 @@
|
|
1 |
/* WP External Links */
|
2 |
-
(function(){"use strict";function t(e,t,n){if(e.attachEvent){e.attachEvent("on"+t,n)}else if(e.addEventListener){e.addEventListener(t,n,false)}}function n(e,t
|
1 |
/* WP External Links */
|
2 |
+
(function(){"use strict";function t(e,t,n){if(e.attachEvent){e.attachEvent("on"+t,n)}else if(e.addEventListener){e.addEventListener(t,n,false)}}function n(e,t){var n=e.getAttribute("data-wpel-target");var r=e.getAttribute("href");var i;if(r&&n){i=window.open(r,n);i.focus();if(t){if(t.preventDefault){t.preventDefault()}else if(typeof t.returnValue!=="undefined"){t.returnValue=false}}}}var e=jQuery===undefined?null:jQuery;if(e&&false){e(function(){e("a").live("click",function(e){n(this,e)})})}else{t(window,"load",function(){var e=window.document.getElementsByTagName("a");var r=function(e){n(e.target,e)};var i;var s;for(s=0;s<e.length;s+=1){i=e[s];t(i,"click",r)}})}})()
|
readme.txt
CHANGED
@@ -2,8 +2,8 @@
|
|
2 |
Contributors: freelancephp
|
3 |
Tags: links, external, icon, target, _blank, _new, _none, rel, nofollow, new window, new tab, javascript, xhtml, seo
|
4 |
Requires at least: 3.4.0
|
5 |
-
Tested up to: 3.
|
6 |
-
Stable tag: 1.
|
7 |
|
8 |
Open external links in a new window or tab, adding "nofollow", set link icon, styling, SEO friendly options and more. Easy install and go.
|
9 |
|
@@ -21,6 +21,9 @@ Configure settings for all external links on your site.
|
|
21 |
= Easy to use =
|
22 |
After activating the plugin all options are already set to make your external links SEO friendly. Optionally you can also set the target for opening in a new window or tab or styling options, like adding an icon.
|
23 |
|
|
|
|
|
|
|
24 |
= Sources =
|
25 |
* [Documentation](http://wordpress.org/extend/plugins/wp-external-links/other_notes/)
|
26 |
* [FAQ](http://wordpress.org/extend/plugins/wp-external-links/faq/)
|
@@ -45,11 +48,11 @@ You could add `rel="external"` to those internal links that should be treated as
|
|
45 |
|
46 |
= Links to my own domain are treated as external links. Why? =
|
47 |
|
48 |
-
Links pointing to your WordPress site are internal links. All other links will be treated as external links.
|
49 |
|
50 |
-
=
|
51 |
|
52 |
-
Add your domain to the option "Ingore links (URL) containing...".
|
53 |
|
54 |
[Do you have a question? Please ask me](http://www.freelancephp.net/contact/)
|
55 |
|
@@ -62,14 +65,14 @@ Add your domain to the option "Ingore links (URL) containing...".
|
|
62 |
|
63 |
After activating the plugin all options are already set to make your external links SEO friendly. Optionally you can also set the target for opening in a new window or tab or styling options, like adding an icon.
|
64 |
|
65 |
-
= Action hook =
|
66 |
The plugin also has a hook when ready, f.e. to add extra filters:
|
67 |
`function extra_filters($filter_callback, $object) {
|
68 |
add_filter('some_filter', $filter_callback);
|
69 |
}
|
70 |
add_action('wpel_ready', 'extra_filters');`
|
71 |
|
72 |
-
= Filter hook =
|
73 |
The wpel_external_link filter gives you the possibility to manipulate output of the mailto created by the plugin, like:
|
74 |
`function special_external_link($created_link, $original_link, $label, $attrs, $is_ignored_link) {
|
75 |
// skip links that contain the class "not-external"
|
@@ -79,10 +82,23 @@ The wpel_external_link filter gives you the possibility to manipulate output of
|
|
79 |
|
80 |
return '<b>'. $created_link .'</b>';
|
81 |
}
|
|
|
82 |
add_filter('wpel_external_link', 'special_external_link', 10, 5);`
|
83 |
|
84 |
Now all external links will be processed and wrapped around a `<b>`-tag. And links containing the class "not-external" will not be processed by the plugin at all (and stay the way they are).
|
85 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
= Credits =
|
87 |
* [jQuery Tipsy Plugin](http://plugins.jquery.com/project/tipsy) made by [Jason Frame](http://onehackoranother.com/)
|
88 |
* [phpQuery](http://code.google.com/p/phpquery/) made by [Tobiasz Cudnik](http://tobiasz123.wordpress.com)
|
@@ -90,6 +106,10 @@ Now all external links will be processed and wrapped around a `<b>`-tag. And lin
|
|
90 |
|
91 |
== Changelog ==
|
92 |
|
|
|
|
|
|
|
|
|
93 |
= 1.52 =
|
94 |
* Added filter hook wpel_internal_link
|
95 |
* Fixed use_js option bug
|
2 |
Contributors: freelancephp
|
3 |
Tags: links, external, icon, target, _blank, _new, _none, rel, nofollow, new window, new tab, javascript, xhtml, seo
|
4 |
Requires at least: 3.4.0
|
5 |
+
Tested up to: 3.9.1
|
6 |
+
Stable tag: 1.53
|
7 |
|
8 |
Open external links in a new window or tab, adding "nofollow", set link icon, styling, SEO friendly options and more. Easy install and go.
|
9 |
|
21 |
= Easy to use =
|
22 |
After activating the plugin all options are already set to make your external links SEO friendly. Optionally you can also set the target for opening in a new window or tab or styling options, like adding an icon.
|
23 |
|
24 |
+
= On the fly =
|
25 |
+
The plugin will change the output of the (external) links on the fly. So when you deactivate the plugin, all contents will remain the same as it was before installing the plugin.
|
26 |
+
|
27 |
= Sources =
|
28 |
* [Documentation](http://wordpress.org/extend/plugins/wp-external-links/other_notes/)
|
29 |
* [FAQ](http://wordpress.org/extend/plugins/wp-external-links/faq/)
|
48 |
|
49 |
= Links to my own domain are treated as external links. Why? =
|
50 |
|
51 |
+
Links pointing to your WordPress site (`wp_url`) are internal links. All other links will be treated as external links.
|
52 |
|
53 |
+
= All links to my subdomains should be treated internal links. How? =
|
54 |
|
55 |
+
Add your main domain to the option "Ingore links (URL) containing..." and they will not be treated as external.
|
56 |
|
57 |
[Do you have a question? Please ask me](http://www.freelancephp.net/contact/)
|
58 |
|
65 |
|
66 |
After activating the plugin all options are already set to make your external links SEO friendly. Optionally you can also set the target for opening in a new window or tab or styling options, like adding an icon.
|
67 |
|
68 |
+
= Action hook: wpel_ready =
|
69 |
The plugin also has a hook when ready, f.e. to add extra filters:
|
70 |
`function extra_filters($filter_callback, $object) {
|
71 |
add_filter('some_filter', $filter_callback);
|
72 |
}
|
73 |
add_action('wpel_ready', 'extra_filters');`
|
74 |
|
75 |
+
= Filter hook 1: wpel_external_link =
|
76 |
The wpel_external_link filter gives you the possibility to manipulate output of the mailto created by the plugin, like:
|
77 |
`function special_external_link($created_link, $original_link, $label, $attrs, $is_ignored_link) {
|
78 |
// skip links that contain the class "not-external"
|
82 |
|
83 |
return '<b>'. $created_link .'</b>';
|
84 |
}
|
85 |
+
|
86 |
add_filter('wpel_external_link', 'special_external_link', 10, 5);`
|
87 |
|
88 |
Now all external links will be processed and wrapped around a `<b>`-tag. And links containing the class "not-external" will not be processed by the plugin at all (and stay the way they are).
|
89 |
|
90 |
+
|
91 |
+
= Filter hook 2: wpel_internal_link =
|
92 |
+
With the internal filter you can manipulate the output of the internal links on your site. F.e.:
|
93 |
+
`
|
94 |
+
function special_internal_link($link, $label, $attrs) {
|
95 |
+
return '<b>'. $link .'</b>';
|
96 |
+
}
|
97 |
+
|
98 |
+
add_filter('wpel_internal_link', 'special_internal_link', 10, 3);`
|
99 |
+
|
100 |
+
In this case all internal links will be made bold.
|
101 |
+
|
102 |
= Credits =
|
103 |
* [jQuery Tipsy Plugin](http://plugins.jquery.com/project/tipsy) made by [Jason Frame](http://onehackoranother.com/)
|
104 |
* [phpQuery](http://code.google.com/p/phpquery/) made by [Tobiasz Cudnik](http://tobiasz123.wordpress.com)
|
106 |
|
107 |
== Changelog ==
|
108 |
|
109 |
+
= 1.53 =
|
110 |
+
* Fixed bug also opening ignored URL's on other tab/window when using javascript
|
111 |
+
* Changed javascript open method (data-attribute)
|
112 |
+
|
113 |
= 1.52 =
|
114 |
* Added filter hook wpel_internal_link
|
115 |
* Fixed use_js option bug
|
wp-external-links.php
CHANGED
@@ -4,14 +4,14 @@ Plugin Name: WP External Links
|
|
4 |
Plugin URI: http://www.freelancephp.net/wp-external-links-plugin
|
5 |
Description: Open external links in a new window/tab, add "external" / "nofollow" to rel-attribute, set icon, XHTML strict, SEO friendly...
|
6 |
Author: Victor Villaverde Laan
|
7 |
-
Version: 1.
|
8 |
Author URI: http://www.freelancephp.net
|
9 |
License: Dual licensed under the MIT and GPL licenses
|
10 |
*/
|
11 |
|
12 |
// constants
|
13 |
if (!defined('WP_EXTERNAL_LINKS_FILE')) { define('WP_EXTERNAL_LINKS_FILE', __FILE__); }
|
14 |
-
if (!defined('WP_EXTERNAL_LINKS_VERSION')) { define('WP_EXTERNAL_LINKS_VERSION', '1.
|
15 |
if (!defined('WP_EXTERNAL_LINKS_KEY')) { define('WP_EXTERNAL_LINKS_KEY', 'wp_external_links'); }
|
16 |
if (!defined('WP_EXTERNAL_LINKS_DOMAIN')) { define('WP_EXTERNAL_LINKS_DOMAIN', 'wp-external-links'); }
|
17 |
if (!defined('WP_EXTERNAL_LINKS_OPTIONS_NAME')) { define('WP_EXTERNAL_LINKS_OPTIONS_NAME', 'WP_External_Links_options'); }
|
4 |
Plugin URI: http://www.freelancephp.net/wp-external-links-plugin
|
5 |
Description: Open external links in a new window/tab, add "external" / "nofollow" to rel-attribute, set icon, XHTML strict, SEO friendly...
|
6 |
Author: Victor Villaverde Laan
|
7 |
+
Version: 1.53
|
8 |
Author URI: http://www.freelancephp.net
|
9 |
License: Dual licensed under the MIT and GPL licenses
|
10 |
*/
|
11 |
|
12 |
// constants
|
13 |
if (!defined('WP_EXTERNAL_LINKS_FILE')) { define('WP_EXTERNAL_LINKS_FILE', __FILE__); }
|
14 |
+
if (!defined('WP_EXTERNAL_LINKS_VERSION')) { define('WP_EXTERNAL_LINKS_VERSION', '1.53'); }
|
15 |
if (!defined('WP_EXTERNAL_LINKS_KEY')) { define('WP_EXTERNAL_LINKS_KEY', 'wp_external_links'); }
|
16 |
if (!defined('WP_EXTERNAL_LINKS_DOMAIN')) { define('WP_EXTERNAL_LINKS_DOMAIN', 'wp-external-links'); }
|
17 |
if (!defined('WP_EXTERNAL_LINKS_OPTIONS_NAME')) { define('WP_EXTERNAL_LINKS_OPTIONS_NAME', 'WP_External_Links_options'); }
|