Version Description
- JavaScript uses window.open() (tested in FireFox Opera, Safari, Chrome and IE6+)
- Also possible to open all external links in the same new window
- Some layout changes on the Admin Options Page
Download this release
Release Info
| Developer | freelancephp |
| Plugin | |
| Version | 0.11 |
| Comparing to | |
| See all releases | |
Code changes from version 0.10 to 0.11
- js/external-links.js +56 -27
- readme.txt +8 -5
- screenshot-1.png +0 -0
- wp-external-links.php +38 -19
js/external-links.js
CHANGED
|
@@ -1,31 +1,60 @@
|
|
| 1 |
-
//
|
| 2 |
-
function
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
}
|
| 20 |
}
|
| 21 |
-
}
|
| 22 |
|
| 23 |
-
if (
|
| 24 |
-
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
| 26 |
}
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
setExternalLinks();
|
| 30 |
-
});
|
| 31 |
-
}
|
| 1 |
+
// WP External Links Plugin
|
| 2 |
+
(function( w, $ ){
|
| 3 |
+
|
| 4 |
+
var addEvt = function ( el, evt, fn ) {
|
| 5 |
+
if ( $ ) {
|
| 6 |
+
// jQuery method
|
| 7 |
+
$( el ).bind( evt, fn );
|
| 8 |
+
} else if ( el.attachEvent ) {
|
| 9 |
+
// IE method
|
| 10 |
+
el.attachEvent( 'on'+ evt, fn );
|
| 11 |
+
} else if ( el.addEventListener ) {
|
| 12 |
+
// Standard JS method
|
| 13 |
+
el.addEventListener( evt, fn, false );
|
| 14 |
+
}
|
| 15 |
+
},
|
| 16 |
+
init = function () {
|
| 17 |
+
setExtLinks();
|
| 18 |
+
};
|
| 19 |
+
|
| 20 |
+
function setExtLinks() {
|
| 21 |
+
var links = w.document.getElementsByTagName( 'a' );
|
| 22 |
+
|
| 23 |
+
// check each <a> element
|
| 24 |
+
for ( var i = 0; i < links.length; i++ ){
|
| 25 |
+
var a = links[ i ],
|
| 26 |
+
href = a.href ? a.href.toLowerCase() : '',
|
| 27 |
+
rel = a.rel ? a.rel.toLowerCase() : '';
|
| 28 |
+
|
| 29 |
+
if ( a.href && ( rel.indexOf( 'external' ) > -1
|
| 30 |
+
|| ( ( href.indexOf( gExtLinks.baseUrl ) === -1 ) &&
|
| 31 |
+
( href.substr( 0, 7 ) == 'http://'
|
| 32 |
+
|| href.substr( 0, 8 ) == 'https://'
|
| 33 |
+
|| href.substr( 0, 6 ) == 'ftp://' ) ) ) ) {
|
| 34 |
+
|
| 35 |
+
// click event
|
| 36 |
+
addEvt( a, 'click', function( a ){
|
| 37 |
+
return function( e ){
|
| 38 |
+
// open link in a new window
|
| 39 |
+
var n = w.open( a.href, gExtLinks.target );
|
| 40 |
+
n.focus();
|
| 41 |
+
|
| 42 |
+
// prevent default
|
| 43 |
+
e.returnValue = false;
|
| 44 |
+
if ( e.preventDefault )
|
| 45 |
+
e.preventDefault();
|
| 46 |
+
}
|
| 47 |
+
}( a ));
|
| 48 |
+
}
|
| 49 |
}
|
| 50 |
}
|
|
|
|
| 51 |
|
| 52 |
+
if ( $ ) {
|
| 53 |
+
// jQuery method
|
| 54 |
+
$( init );
|
| 55 |
+
} else {
|
| 56 |
+
// when jQuery is not available
|
| 57 |
+
addEvt( w, 'load', init );
|
| 58 |
}
|
| 59 |
+
|
| 60 |
+
})( window, typeof jQuery == 'undefined' ? null : jQuery );
|
|
|
|
|
|
|
|
|
readme.txt
CHANGED
|
@@ -3,7 +3,7 @@ Contributors: freelancephp
|
|
| 3 |
Tags: links, external, new window, icon, target, _blank, _new, rel, nofollow, javascript, xhtml strict
|
| 4 |
Requires at least: 2.7.0
|
| 5 |
Tested up to: 3.1.0
|
| 6 |
-
Stable tag: 0.
|
| 7 |
|
| 8 |
Manage the external links on your site: opening in a new window, set link icon, set "external", set "nofollow", set css-class.
|
| 9 |
|
|
@@ -17,13 +17,11 @@ Manage the external links on your site.
|
|
| 17 |
* Choose an icon for external links
|
| 18 |
* Add a css Class-name
|
| 19 |
* Unobtrusive JavaScript method wich is XHTML Strict compliant
|
| 20 |
-
* Supports PHP4.3+ and up to latest WP
|
| 21 |
-
|
| 22 |
-
Also see info at [FreelancePHP.net](http://www.freelancephp.net/wp-external-links-plugin)
|
| 23 |
|
| 24 |
== Installation ==
|
| 25 |
|
| 26 |
-
1. Upload `
|
| 27 |
1. Be sure the plugin is activated in the Plugin-list
|
| 28 |
|
| 29 |
== Frequently Asked Questions ==
|
|
@@ -37,6 +35,11 @@ Also see info at [FreelancePHP.net](http://www.freelancephp.net/wp-external-link
|
|
| 37 |
|
| 38 |
== Changelog ==
|
| 39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
= 0.10 =
|
| 41 |
* Features: opening in a new window, set link icon, set "external", set "nofollow", set css-class
|
| 42 |
* Replaces external links by clean XHTML <a> tags
|
| 3 |
Tags: links, external, new window, icon, target, _blank, _new, rel, nofollow, javascript, xhtml strict
|
| 4 |
Requires at least: 2.7.0
|
| 5 |
Tested up to: 3.1.0
|
| 6 |
+
Stable tag: 0.11
|
| 7 |
|
| 8 |
Manage the external links on your site: opening in a new window, set link icon, set "external", set "nofollow", set css-class.
|
| 9 |
|
| 17 |
* Choose an icon for external links
|
| 18 |
* Add a css Class-name
|
| 19 |
* Unobtrusive JavaScript method wich is XHTML Strict compliant
|
| 20 |
+
* Supports PHP4.3+ and up to latest WP versionMore info at [FreelancePHP.net](http://www.freelancephp.net/wp-external-links-plugin)
|
|
|
|
|
|
|
| 21 |
|
| 22 |
== Installation ==
|
| 23 |
|
| 24 |
+
1. Upload `wp-external-links.zip` to the `/wp-content/plugins/` directory or add the plugin with 'Add Plugins' in the admin menu
|
| 25 |
1. Be sure the plugin is activated in the Plugin-list
|
| 26 |
|
| 27 |
== Frequently Asked Questions ==
|
| 35 |
|
| 36 |
== Changelog ==
|
| 37 |
|
| 38 |
+
= 0.11 =
|
| 39 |
+
* JavaScript uses window.open() (tested in FireFox Opera, Safari, Chrome and IE6+)
|
| 40 |
+
* Also possible to open all external links in the same new window
|
| 41 |
+
* Some layout changes on the Admin Options Page
|
| 42 |
+
|
| 43 |
= 0.10 =
|
| 44 |
* Features: opening in a new window, set link icon, set "external", set "nofollow", set css-class
|
| 45 |
* Replaces external links by clean XHTML <a> tags
|
screenshot-1.png
CHANGED
|
Binary file
|
wp-external-links.php
CHANGED
|
@@ -4,7 +4,7 @@ Plugin Name: WP External Links
|
|
| 4 |
Plugin URI: http://www.freelancephp.net/
|
| 5 |
Description: Manage the external links on your site: opening in a new window, set link icon, set "external", set "nofollow", set css-class.
|
| 6 |
Author: Victor Villaverde Laan
|
| 7 |
-
Version: 0.
|
| 8 |
Author URI: http://www.freelancephp.net
|
| 9 |
License: Dual licensed under the MIT and GPL licenses
|
| 10 |
*/
|
|
@@ -30,7 +30,7 @@ class WP_External_Links {
|
|
| 30 |
* @var array
|
| 31 |
*/
|
| 32 |
var $options = array(
|
| 33 |
-
'
|
| 34 |
'external' => TRUE,
|
| 35 |
'nofollow' => TRUE,
|
| 36 |
'icon' => 1,
|
|
@@ -96,8 +96,8 @@ class WP_External_Links {
|
|
| 96 |
add_action( 'wp_head', array( $this, 'wp_head' ) );
|
| 97 |
|
| 98 |
// set js file
|
| 99 |
-
if ( $this->options[ '
|
| 100 |
-
wp_enqueue_script( 'external-links', plugins_url( 'js/external-links.js', __FILE__ ), array( 'jquery' ) );
|
| 101 |
}
|
| 102 |
}
|
| 103 |
}
|
|
@@ -107,13 +107,13 @@ class WP_External_Links {
|
|
| 107 |
*/
|
| 108 |
function wp_head() {
|
| 109 |
?>
|
| 110 |
-
<?php if ( $this->options[ '
|
| 111 |
<!-- JS External Links Plugin -->
|
| 112 |
<script language="javascript">
|
| 113 |
/* <![CDATA[ */
|
| 114 |
-
var
|
| 115 |
baseUrl: '<?php echo get_bloginfo( 'url' ) ?>',
|
| 116 |
-
|
| 117 |
};
|
| 118 |
/* ]]> */
|
| 119 |
</script>
|
|
@@ -174,7 +174,7 @@ var globNewWindowLinks = {
|
|
| 174 |
}
|
| 175 |
|
| 176 |
// set target="_blank"
|
| 177 |
-
if ( $this->options[ '
|
| 178 |
$attrs[ 'target' ] = '_blank';
|
| 179 |
}
|
| 180 |
|
|
@@ -212,7 +212,7 @@ var globNewWindowLinks = {
|
|
| 212 |
?>
|
| 213 |
<div class="wrap">
|
| 214 |
<div class="icon32" id="icon-options-custom" style="background:url( <?php echo plugins_url( 'images/icon.png', __FILE__ ) ?> ) no-repeat 50% 50%"><br></div>
|
| 215 |
-
<h2
|
| 216 |
|
| 217 |
<form method="post" action="options.php">
|
| 218 |
<?php
|
|
@@ -225,19 +225,27 @@ var globNewWindowLinks = {
|
|
| 225 |
<div style="margin:0 5px;">
|
| 226 |
<div class="postbox">
|
| 227 |
<div class="handlediv" title="<?php _e( 'Click to toggle' ) ?>"><br/></div>
|
| 228 |
-
<h3 class="hndle"><?php _e( 'Settings' ) ?></h3>
|
| 229 |
<div class="inside">
|
| 230 |
<fieldset class="options">
|
| 231 |
-
<h4><?php _e( 'External links', $this->domain ) ?></h4>
|
| 232 |
<table class="form-table">
|
| 233 |
<tr>
|
| 234 |
<th><?php _e( 'Open in new window', $this->domain ) ?></th>
|
| 235 |
-
<td><label><input type="radio" name="<?php echo $this->options_name ?>[
|
| 236 |
-
<span><?php _e( 'No, open external links in
|
| 237 |
-
<br
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 241 |
</td>
|
| 242 |
</tr>
|
| 243 |
<tr>
|
|
@@ -253,8 +261,19 @@ var globNewWindowLinks = {
|
|
| 253 |
</td>
|
| 254 |
</tr>
|
| 255 |
</table>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 256 |
|
| 257 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 258 |
<table class="form-table">
|
| 259 |
<tr>
|
| 260 |
<th><?php _e( 'Classname', $this->domain ) ?></th>
|
|
@@ -340,7 +359,7 @@ var globNewWindowLinks = {
|
|
| 340 |
|
| 341 |
if ( ! empty( $saved_options ) ) {
|
| 342 |
// set saved option values
|
| 343 |
-
$this->options['
|
| 344 |
$this->options['external'] = ! empty( $saved_options['external'] );
|
| 345 |
$this->options['nofollow'] = ! empty( $saved_options['nofollow'] );
|
| 346 |
$this->options['icon'] = $saved_options['icon'];
|
| 4 |
Plugin URI: http://www.freelancephp.net/
|
| 5 |
Description: Manage the external links on your site: opening in a new window, set link icon, set "external", set "nofollow", set css-class.
|
| 6 |
Author: Victor Villaverde Laan
|
| 7 |
+
Version: 0.11
|
| 8 |
Author URI: http://www.freelancephp.net
|
| 9 |
License: Dual licensed under the MIT and GPL licenses
|
| 10 |
*/
|
| 30 |
* @var array
|
| 31 |
*/
|
| 32 |
var $options = array(
|
| 33 |
+
'new_window' => 1,
|
| 34 |
'external' => TRUE,
|
| 35 |
'nofollow' => TRUE,
|
| 36 |
'icon' => 1,
|
| 96 |
add_action( 'wp_head', array( $this, 'wp_head' ) );
|
| 97 |
|
| 98 |
// set js file
|
| 99 |
+
if ( $this->options[ 'new_window' ] >= 4 ) {
|
| 100 |
+
wp_enqueue_script( 'external-links', plugins_url( 'js/external-links.js', __FILE__ ), array( 'jquery' ), '0.11' );
|
| 101 |
}
|
| 102 |
}
|
| 103 |
}
|
| 107 |
*/
|
| 108 |
function wp_head() {
|
| 109 |
?>
|
| 110 |
+
<?php if ( $this->options[ 'new_window' ] >= 4 ): ?>
|
| 111 |
<!-- JS External Links Plugin -->
|
| 112 |
<script language="javascript">
|
| 113 |
/* <![CDATA[ */
|
| 114 |
+
var gExtLinks = {
|
| 115 |
baseUrl: '<?php echo get_bloginfo( 'url' ) ?>',
|
| 116 |
+
target: '<?php echo ( $this->options[ 'new_window' ] == 5 ) ? '_new' : '_blank' ?>'
|
| 117 |
};
|
| 118 |
/* ]]> */
|
| 119 |
</script>
|
| 174 |
}
|
| 175 |
|
| 176 |
// set target="_blank"
|
| 177 |
+
if ( $this->options[ 'new_window' ] == 1 )
|
| 178 |
$attrs[ 'target' ] = '_blank';
|
| 179 |
}
|
| 180 |
|
| 212 |
?>
|
| 213 |
<div class="wrap">
|
| 214 |
<div class="icon32" id="icon-options-custom" style="background:url( <?php echo plugins_url( 'images/icon.png', __FILE__ ) ?> ) no-repeat 50% 50%"><br></div>
|
| 215 |
+
<h2><?php _e( 'External Links Settings' ) ?></h2>
|
| 216 |
|
| 217 |
<form method="post" action="options.php">
|
| 218 |
<?php
|
| 225 |
<div style="margin:0 5px;">
|
| 226 |
<div class="postbox">
|
| 227 |
<div class="handlediv" title="<?php _e( 'Click to toggle' ) ?>"><br/></div>
|
| 228 |
+
<h3 class="hndle"><?php _e( 'General Settings', $this->domain ) ?></h3>
|
| 229 |
<div class="inside">
|
| 230 |
<fieldset class="options">
|
|
|
|
| 231 |
<table class="form-table">
|
| 232 |
<tr>
|
| 233 |
<th><?php _e( 'Open in new window', $this->domain ) ?></th>
|
| 234 |
+
<td><label><input type="radio" name="<?php echo $this->options_name ?>[new_window]" value="1" <?php checked('1', (int) $options['new_window']); ?> />
|
| 235 |
+
<span><?php _e( '1) No, open external links in active window', $this->domain ) ?></span></label>
|
| 236 |
+
<br/>
|
| 237 |
+
<br/><label><input type="radio" name="<?php echo $this->options_name ?>[new_window]" value="2" <?php checked('2', (int) $options['new_window']); ?> />
|
| 238 |
+
<span><?php _e( '2) Yes, add <code>target="_blank"</code> to external links (every external link is loaded in a new window)', $this->domain ) ?></span></label>
|
| 239 |
+
<br/><label><input type="radio" name="<?php echo $this->options_name ?>[new_window]" value="3" <?php checked('3', (int) $options['new_window']); ?> />
|
| 240 |
+
<span><?php _e( '3) Yes, add <code>target="_new"</code> to external links (all external links will be loaded in the same new window)', $this->domain ) ?></span></label>
|
| 241 |
+
<br/>
|
| 242 |
+
<br/><label><input type="radio" name="<?php echo $this->options_name ?>[new_window]" value="4" <?php checked('4', (int) $options['new_window']); ?> />
|
| 243 |
+
<span><?php _e( '4) Yes, using JavaScript for opening every external link in a new window', $this->domain ) ?></span></label>
|
| 244 |
+
<br/><label><input type="radio" name="<?php echo $this->options_name ?>[new_window]" value="5" <?php checked('5', (int) $options['new_window']); ?> />
|
| 245 |
+
<span><?php _e( '5) Yes, using JavaScript for opening all external links in the same new window', $this->domain ) ?></span></label>
|
| 246 |
+
<br />
|
| 247 |
+
<br />
|
| 248 |
+
<p><span class="description"><?php _e( 'Note: method 2 and 3 are compliant with XHTML Transitional. The other methods are also XHTML Strict compliant.' ) ?></span></p>
|
| 249 |
</td>
|
| 250 |
</tr>
|
| 251 |
<tr>
|
| 261 |
</td>
|
| 262 |
</tr>
|
| 263 |
</table>
|
| 264 |
+
</fieldset>
|
| 265 |
+
<p class="description"><?php _e( 'This plugin automatically cleans up the code of <code><a></code> tags and makes them XHTML valid' ) ?></p>
|
| 266 |
+
<p class="submit">
|
| 267 |
+
<input class="button-primary" type="submit" value="<?php _e( 'Save Changes' ) ?>" />
|
| 268 |
+
</p>
|
| 269 |
+
</div>
|
| 270 |
+
</div>
|
| 271 |
|
| 272 |
+
<div class="postbox">
|
| 273 |
+
<div class="handlediv" title="<?php _e( 'Click to toggle' ) ?>"><br/></div>
|
| 274 |
+
<h3 class="hndle"><?php _e( 'Style Settings', $this->domain ) ?></h3>
|
| 275 |
+
<div class="inside">
|
| 276 |
+
<fieldset class="options">
|
| 277 |
<table class="form-table">
|
| 278 |
<tr>
|
| 279 |
<th><?php _e( 'Classname', $this->domain ) ?></th>
|
| 359 |
|
| 360 |
if ( ! empty( $saved_options ) ) {
|
| 361 |
// set saved option values
|
| 362 |
+
$this->options['new_window'] = $saved_options['new_window'];
|
| 363 |
$this->options['external'] = ! empty( $saved_options['external'] );
|
| 364 |
$this->options['nofollow'] = ! empty( $saved_options['nofollow'] );
|
| 365 |
$this->options['icon'] = $saved_options['icon'];
|
