Version Description
- Added option to replace "follow" values of external links with "nofollow"
- Updated FAQ with custom solutions
Download this release
Release Info
| Developer | freelancephp |
| Plugin | |
| Version | 1.60 |
| Comparing to | |
| See all releases | |
Code changes from version 1.56 to 1.60
- includes/class-admin-external-links.php +13 -8
- includes/class-wp-external-links.php +16 -6
- js/admin-wp-external-links.js +242 -1
- js/src/admin-wp-external-links.js +14 -0
- readme.txt +98 -8
- wp-external-links.php +2 -2
includes/class-admin-external-links.php
CHANGED
|
@@ -26,6 +26,7 @@ final class Admin_External_Links {
|
|
| 26 |
'seo' => array(
|
| 27 |
'external' => 1,
|
| 28 |
'nofollow' => 1,
|
|
|
|
| 29 |
'title' => '%title%',
|
| 30 |
'use_js' => 1,
|
| 31 |
'load_in_footer' => 1,
|
|
@@ -173,8 +174,8 @@ style;
|
|
| 173 |
//->add_meta_box( $this->__( 'About this Plugin' ), array( $this, 'call_box_about' ), 2 )
|
| 174 |
->add_meta_box( $this->__( 'Other Plugins' ), array( $this, 'call_box_other_plugins' ), 2 );
|
| 175 |
|
| 176 |
-
|
| 177 |
-
wp_enqueue_script( 'admin-wp-external-links', plugins_url( '/js/admin-wp-external-links.js', WP_EXTERNAL_LINKS_FILE ), array( 'jquery', 'postbox' ), WP_EXTERNAL_LINKS_VERSION );
|
| 178 |
}
|
| 179 |
|
| 180 |
/**
|
|
@@ -241,11 +242,11 @@ style;
|
|
| 241 |
<td>
|
| 242 |
<label><?php echo $this->form->checkbox( 'filter_page', 1 ); ?>
|
| 243 |
<span><?php $this->_e( 'All contents' ) ?></span> <span class="description"><?php $this->_e('(the whole <code><body></code>)') ?></span></label>
|
| 244 |
-
<br/> <label><?php echo $this->form->checkbox( 'filter_posts', 1 ); ?>
|
| 245 |
<span><?php $this->_e( 'Post contents' ) ?></span></label>
|
| 246 |
-
<br/> <label><?php echo $this->form->checkbox( 'filter_comments', 1 ); ?>
|
| 247 |
<span><?php $this->_e( 'Comments' ) ?></span></label>
|
| 248 |
-
<br/> <label><?php echo $this->form->checkbox( 'filter_widgets', 1 ); ?>
|
| 249 |
<span><?php
|
| 250 |
if ( self::check_widget_content_filter() ):
|
| 251 |
$this->_e( 'All widgets' );
|
|
@@ -284,9 +285,13 @@ style;
|
|
| 284 |
<th style="width:250px;"><?php $this->_e( 'Add to <code>rel</code>-attribute' ) ?>
|
| 285 |
<?php echo $this->tooltip_help( 'Set values for the "rel"-atribute of external links.' ) ?></th>
|
| 286 |
<td><label><?php echo $this->form->checkbox( 'nofollow', 1 ); ?>
|
| 287 |
-
<span><?php $this->_e( 'Add <code>"nofollow"</code>' ) ?></span></label>
|
| 288 |
<?php echo $this->tooltip_help( 'Add "nofollow" to the "rel"-attribute of external links (unless link already has "follow").' ) ?>
|
| 289 |
-
<br
|
|
|
|
|
|
|
|
|
|
|
|
|
| 290 |
<label><?php echo $this->form->checkbox( 'external', 1 ); ?>
|
| 291 |
<span><?php $this->_e( 'Add <code>"external"</code>' ) ?></span></label>
|
| 292 |
<?php echo $this->tooltip_help( 'Add "external" to the "rel"-attribute of external links.' ) ?>
|
|
@@ -306,7 +311,7 @@ style;
|
|
| 306 |
<label><?php echo $this->form->checkbox( 'use_js', 1, array( 'class' => 'field_use_js' ) ); ?>
|
| 307 |
<span><?php $this->_e( 'Use JavaScript for opening links' ) ?></span> <span class="description"><?php $this->_e( '(valid xhtml strict)' ) ?></span>
|
| 308 |
<br/>
|
| 309 |
-
<label><?php echo $this->form->checkbox( 'load_in_footer', 1, array( 'class' => 'load_in_footer' ) ); ?>
|
| 310 |
<span><?php $this->_e( 'Load JS file in footer' ) ?></span>
|
| 311 |
</td>
|
| 312 |
</tr>
|
| 26 |
'seo' => array(
|
| 27 |
'external' => 1,
|
| 28 |
'nofollow' => 1,
|
| 29 |
+
'overwrite_follow' => 0,
|
| 30 |
'title' => '%title%',
|
| 31 |
'use_js' => 1,
|
| 32 |
'load_in_footer' => 1,
|
| 174 |
//->add_meta_box( $this->__( 'About this Plugin' ), array( $this, 'call_box_about' ), 2 )
|
| 175 |
->add_meta_box( $this->__( 'Other Plugins' ), array( $this, 'call_box_other_plugins' ), 2 );
|
| 176 |
|
| 177 |
+
// scripts
|
| 178 |
+
wp_enqueue_script( 'admin-wp-external-links', plugins_url( '/js/admin-wp-external-links.js', WP_EXTERNAL_LINKS_FILE ), array( 'jquery', 'postbox' ), WP_EXTERNAL_LINKS_VERSION, true );
|
| 179 |
}
|
| 180 |
|
| 181 |
/**
|
| 242 |
<td>
|
| 243 |
<label><?php echo $this->form->checkbox( 'filter_page', 1 ); ?>
|
| 244 |
<span><?php $this->_e( 'All contents' ) ?></span> <span class="description"><?php $this->_e('(the whole <code><body></code>)') ?></span></label>
|
| 245 |
+
<br/> <label><?php echo $this->form->checkbox( 'filter_posts', 1 ); ?>
|
| 246 |
<span><?php $this->_e( 'Post contents' ) ?></span></label>
|
| 247 |
+
<br/> <label><?php echo $this->form->checkbox( 'filter_comments', 1 ); ?>
|
| 248 |
<span><?php $this->_e( 'Comments' ) ?></span></label>
|
| 249 |
+
<br/> <label><?php echo $this->form->checkbox( 'filter_widgets', 1 ); ?>
|
| 250 |
<span><?php
|
| 251 |
if ( self::check_widget_content_filter() ):
|
| 252 |
$this->_e( 'All widgets' );
|
| 285 |
<th style="width:250px;"><?php $this->_e( 'Add to <code>rel</code>-attribute' ) ?>
|
| 286 |
<?php echo $this->tooltip_help( 'Set values for the "rel"-atribute of external links.' ) ?></th>
|
| 287 |
<td><label><?php echo $this->form->checkbox( 'nofollow', 1 ); ?>
|
| 288 |
+
<span><?php $this->_e( 'Add <code>"nofollow"</code> to external links' ) ?></span></label>
|
| 289 |
<?php echo $this->tooltip_help( 'Add "nofollow" to the "rel"-attribute of external links (unless link already has "follow").' ) ?>
|
| 290 |
+
<br/> <label><?php echo $this->form->checkbox( 'overwrite_follow', 1 ); ?>
|
| 291 |
+
<span><?php $this->_e( 'Also apply to external links containing <code>"follow"</code>' ) ?></span></label>
|
| 292 |
+
<?php echo $this->tooltip_help( 'Also change external links with "follow" to "nofollow".' ) ?>
|
| 293 |
+
|
| 294 |
+
<br/><br/>
|
| 295 |
<label><?php echo $this->form->checkbox( 'external', 1 ); ?>
|
| 296 |
<span><?php $this->_e( 'Add <code>"external"</code>' ) ?></span></label>
|
| 297 |
<?php echo $this->tooltip_help( 'Add "external" to the "rel"-attribute of external links.' ) ?>
|
| 311 |
<label><?php echo $this->form->checkbox( 'use_js', 1, array( 'class' => 'field_use_js' ) ); ?>
|
| 312 |
<span><?php $this->_e( 'Use JavaScript for opening links' ) ?></span> <span class="description"><?php $this->_e( '(valid xhtml strict)' ) ?></span>
|
| 313 |
<br/>
|
| 314 |
+
<label><?php echo $this->form->checkbox( 'load_in_footer', 1, array( 'class' => 'load_in_footer' ) ); ?>
|
| 315 |
<span><?php $this->_e( 'Load JS file in footer' ) ?></span>
|
| 316 |
</td>
|
| 317 |
</tr>
|
includes/class-wp-external-links.php
CHANGED
|
@@ -185,10 +185,9 @@ final class WP_External_Links {
|
|
| 185 |
/**
|
| 186 |
* Check if link is external
|
| 187 |
* @param string $href
|
| 188 |
-
* @param string $rel
|
| 189 |
* @return boolean
|
| 190 |
*/
|
| 191 |
-
private function is_external( $href
|
| 192 |
return ( isset( $href ) AND ( ( strpos( $href, strtolower( get_bloginfo( 'wpurl' ) ) ) === FALSE )
|
| 193 |
AND ( substr( $href, 0, 7 ) == 'http://'
|
| 194 |
OR substr( $href, 0, 8 ) == 'https://'
|
|
@@ -341,7 +340,7 @@ final class WP_External_Links {
|
|
| 341 |
}
|
| 342 |
|
| 343 |
// checks
|
| 344 |
-
$is_external = $this->is_external( $href
|
| 345 |
$is_ignored = $this->is_ignored( $href );
|
| 346 |
$has_rel_external = (strpos( $rel, 'external' ) !== FALSE);
|
| 347 |
|
|
@@ -361,9 +360,20 @@ final class WP_External_Links {
|
|
| 361 |
if ( $this->get_opt( 'external' ) )
|
| 362 |
$this->add_attr_value( $attrs, 'rel', 'external' );
|
| 363 |
|
| 364 |
-
// set rel="nofollow"
|
| 365 |
-
if ( $this->get_opt( 'nofollow' )
|
| 366 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 367 |
|
| 368 |
// set title
|
| 369 |
$title_format = $this->get_opt( 'title' );
|
| 185 |
/**
|
| 186 |
* Check if link is external
|
| 187 |
* @param string $href
|
|
|
|
| 188 |
* @return boolean
|
| 189 |
*/
|
| 190 |
+
private function is_external( $href ) {
|
| 191 |
return ( isset( $href ) AND ( ( strpos( $href, strtolower( get_bloginfo( 'wpurl' ) ) ) === FALSE )
|
| 192 |
AND ( substr( $href, 0, 7 ) == 'http://'
|
| 193 |
OR substr( $href, 0, 8 ) == 'https://'
|
| 340 |
}
|
| 341 |
|
| 342 |
// checks
|
| 343 |
+
$is_external = $this->is_external( $href );
|
| 344 |
$is_ignored = $this->is_ignored( $href );
|
| 345 |
$has_rel_external = (strpos( $rel, 'external' ) !== FALSE);
|
| 346 |
|
| 360 |
if ( $this->get_opt( 'external' ) )
|
| 361 |
$this->add_attr_value( $attrs, 'rel', 'external' );
|
| 362 |
|
| 363 |
+
// set rel="nofollow"
|
| 364 |
+
if ( $this->get_opt( 'nofollow' ) ) {
|
| 365 |
+
$has_follow = (strpos( $rel, 'follow' ) !== FALSE);
|
| 366 |
+
|
| 367 |
+
// when doesn't have "follow" (or already "nofollow")
|
| 368 |
+
if (! $has_follow || $this->get_opt( 'overwrite_follow' )) {
|
| 369 |
+
if ($has_follow) {
|
| 370 |
+
// remove "follow"
|
| 371 |
+
//$attrs[ 'rel' ] = ;
|
| 372 |
+
}
|
| 373 |
+
|
| 374 |
+
$this->add_attr_value( $attrs, 'rel', 'nofollow' );
|
| 375 |
+
}
|
| 376 |
+
}
|
| 377 |
|
| 378 |
// set title
|
| 379 |
$title_format = $this->get_opt( 'title' );
|
js/admin-wp-external-links.js
CHANGED
|
@@ -1,2 +1,243 @@
|
|
| 1 |
/* WP External Links - Admin */
|
| 2 |
-
jQuery
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
/* WP External Links - Admin */
|
| 2 |
+
/*global jQuery, window*/
|
| 3 |
+
jQuery(function ($) {
|
| 4 |
+
'use strict';
|
| 5 |
+
|
| 6 |
+
/* Tipsy Plugin */
|
| 7 |
+
(function () {
|
| 8 |
+
$.fn.tipsy = function (options) {
|
| 9 |
+
options = $.extend({}, $.fn.tipsy.defaults, options);
|
| 10 |
+
|
| 11 |
+
return this.each(function () {
|
| 12 |
+
var opts = $.fn.tipsy.elementOptions(this, options);
|
| 13 |
+
|
| 14 |
+
$(this).hover(function () {
|
| 15 |
+
$.data(this, 'cancel.tipsy', true);
|
| 16 |
+
|
| 17 |
+
var tip = $.data(this, 'active.tipsy');
|
| 18 |
+
if (!tip) {
|
| 19 |
+
tip = $('<div class="tipsy"><div class="tipsy-inner"/></div>');
|
| 20 |
+
tip.css({position: 'absolute', zIndex: 100000});
|
| 21 |
+
$.data(this, 'active.tipsy', tip);
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
if ($(this).attr('title') || typeof $(this).attr('original-title') !== 'string') {
|
| 25 |
+
$(this).attr('original-title', $(this).attr('title') || '').removeAttr('title');
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
var title;
|
| 29 |
+
if (typeof opts.title === 'string') {
|
| 30 |
+
title = $(this).attr(opts.title === 'title' ? 'original-title' : opts.title);
|
| 31 |
+
} else if (typeof opts.title === 'function') {
|
| 32 |
+
title = opts.title.call(this);
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
tip.find('.tipsy-inner')[opts.html ? 'html' : 'text'](title || opts.fallback);
|
| 36 |
+
|
| 37 |
+
var pos = $.extend({}, $(this).offset(), {width: this.offsetWidth, height: this.offsetHeight});
|
| 38 |
+
tip.get(0).className = 'tipsy'; // reset classname in case of dynamic gravity
|
| 39 |
+
tip.remove().css({top: 0, left: 0, visibility: 'hidden', display: 'block'}).appendTo(document.body);
|
| 40 |
+
var actualWidth = tip[0].offsetWidth, actualHeight = tip[0].offsetHeight;
|
| 41 |
+
var gravity = (typeof opts.gravity == 'function') ? opts.gravity.call(this) : opts.gravity;
|
| 42 |
+
|
| 43 |
+
switch (gravity.charAt(0)) {
|
| 44 |
+
case 'n':
|
| 45 |
+
tip.css({top: pos.top + pos.height, left: pos.left + pos.width / 2 - actualWidth / 2}).addClass('tipsy-north');
|
| 46 |
+
break;
|
| 47 |
+
case 's':
|
| 48 |
+
tip.css({top: pos.top - actualHeight, left: pos.left + pos.width / 2 - actualWidth / 2}).addClass('tipsy-south');
|
| 49 |
+
break;
|
| 50 |
+
case 'e':
|
| 51 |
+
tip.css({top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left - actualWidth}).addClass('tipsy-east');
|
| 52 |
+
break;
|
| 53 |
+
case 'w':
|
| 54 |
+
tip.css({top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left + pos.width}).addClass('tipsy-west');
|
| 55 |
+
break;
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
if (opts.fade) {
|
| 59 |
+
tip.css({opacity: 0, display: 'block', visibility: 'visible'}).animate({opacity: 0.9});
|
| 60 |
+
} else {
|
| 61 |
+
tip.css({visibility: 'visible'});
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
}, function () {
|
| 65 |
+
$.data(this, 'cancel.tipsy', false);
|
| 66 |
+
var self = this;
|
| 67 |
+
setTimeout(function () {
|
| 68 |
+
if ($.data(this, 'cancel.tipsy')) return;
|
| 69 |
+
var tip = $.data(self, 'active.tipsy');
|
| 70 |
+
if (opts.fade) {
|
| 71 |
+
tip.stop().fadeOut(function () { $(this).remove(); });
|
| 72 |
+
} else {
|
| 73 |
+
tip.remove();
|
| 74 |
+
}
|
| 75 |
+
}, 100);
|
| 76 |
+
});
|
| 77 |
+
});
|
| 78 |
+
};
|
| 79 |
+
|
| 80 |
+
// Overwrite this method to provide options on a per-element basis.
|
| 81 |
+
// For example, you could store the gravity in a 'tipsy-gravity' attribute:
|
| 82 |
+
// return $.extend({}, options, {gravity: $(ele).attr('tipsy-gravity') || 'n' });
|
| 83 |
+
// (remember - do not modify 'options' in place!)
|
| 84 |
+
$.fn.tipsy.elementOptions = function (ele, options) {
|
| 85 |
+
return $.metadata ? $.extend({}, options, $(ele).metadata()) : options;
|
| 86 |
+
};
|
| 87 |
+
|
| 88 |
+
$.fn.tipsy.defaults = {
|
| 89 |
+
fade: false,
|
| 90 |
+
fallback: '',
|
| 91 |
+
gravity: 'w',
|
| 92 |
+
html: false,
|
| 93 |
+
title: 'title'
|
| 94 |
+
};
|
| 95 |
+
|
| 96 |
+
$.fn.tipsy.autoNS = function () {
|
| 97 |
+
return $(this).offset().top > ($(document).scrollTop() + $(window).height() / 2) ? 's' : 'n';
|
| 98 |
+
};
|
| 99 |
+
|
| 100 |
+
$.fn.tipsy.autoWE = function () {
|
| 101 |
+
return $(this).offset().left > ($(document).scrollLeft() + $(window).width() / 2) ? 'e' : 'w';
|
| 102 |
+
};
|
| 103 |
+
|
| 104 |
+
})(); // End Tipsy Plugin
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
$('#setting-error-settings_updated').click(function () {
|
| 108 |
+
$(this).hide();
|
| 109 |
+
});
|
| 110 |
+
|
| 111 |
+
// option filter page
|
| 112 |
+
$('input#filter_page')
|
| 113 |
+
.change(function () {
|
| 114 |
+
var $i = $('input#filter_posts, input#filter_comments, input#filter_widgets');
|
| 115 |
+
|
| 116 |
+
if ($(this).attr('checked')) {
|
| 117 |
+
$i.attr('disabled', true)
|
| 118 |
+
.attr('checked', true);
|
| 119 |
+
} else {
|
| 120 |
+
$i.attr('disabled', false);
|
| 121 |
+
}
|
| 122 |
+
})
|
| 123 |
+
.change();
|
| 124 |
+
|
| 125 |
+
// option use js
|
| 126 |
+
$('input#nofollow')
|
| 127 |
+
.change(function () {
|
| 128 |
+
var $i = $('input#overwrite_follow');
|
| 129 |
+
|
| 130 |
+
if ($(this).attr('checked')) {
|
| 131 |
+
$i.attr('disabled', false);
|
| 132 |
+
} else {
|
| 133 |
+
$i.attr('disabled', true)
|
| 134 |
+
.attr('checked', false);
|
| 135 |
+
}
|
| 136 |
+
})
|
| 137 |
+
.change();
|
| 138 |
+
|
| 139 |
+
// option use js
|
| 140 |
+
$('input#use_js')
|
| 141 |
+
.change(function () {
|
| 142 |
+
var $i = $('input#load_in_footer');
|
| 143 |
+
|
| 144 |
+
if ($(this).attr('checked')) {
|
| 145 |
+
$i.attr('disabled', false);
|
| 146 |
+
} else {
|
| 147 |
+
$i.attr('disabled', true)
|
| 148 |
+
.attr('checked', false);
|
| 149 |
+
}
|
| 150 |
+
})
|
| 151 |
+
.change();
|
| 152 |
+
|
| 153 |
+
// option filter_excl_sel
|
| 154 |
+
$('input#phpquery')
|
| 155 |
+
.change(function () {
|
| 156 |
+
if ($(this).attr('checked')) {
|
| 157 |
+
$('.filter_excl_sel').fadeIn();
|
| 158 |
+
} else {
|
| 159 |
+
$('.filter_excl_sel').fadeOut();
|
| 160 |
+
}
|
| 161 |
+
})
|
| 162 |
+
.change();
|
| 163 |
+
|
| 164 |
+
// refresh page when updated menu position
|
| 165 |
+
$('#menu_position').parents('form.ajax-form').on('ajax_saved_options', function () {
|
| 166 |
+
var s = $(this).val() || '';
|
| 167 |
+
window.location.href = s + (s.indexOf('?') > -1 ? '&' : '?') + 'page=wp_external_links&settings-updated=true';
|
| 168 |
+
});
|
| 169 |
+
|
| 170 |
+
// set tooltips
|
| 171 |
+
$('.tooltip-help').css('margin', '0 5px').tipsy({ fade: true, live: true, gravity: 'w', fallback: 'No help text.' });
|
| 172 |
+
|
| 173 |
+
// remove class to fix button background
|
| 174 |
+
$('*[type="submit"]').removeClass('submit');
|
| 175 |
+
|
| 176 |
+
// slide postbox
|
| 177 |
+
$('.postbox').find('.handlediv, .hndle').click(function () {
|
| 178 |
+
var $inside = $(this).parent().find('.inside');
|
| 179 |
+
|
| 180 |
+
if ($inside.css('display') === 'block') {
|
| 181 |
+
$inside.css({ display: 'none' });
|
| 182 |
+
} else {
|
| 183 |
+
$inside.css({ display: 'block' });
|
| 184 |
+
}
|
| 185 |
+
});
|
| 186 |
+
|
| 187 |
+
});
|
| 188 |
+
|
| 189 |
+
/* WP Options Form */
|
| 190 |
+
/*global jQuery, ajaxurl*/
|
| 191 |
+
jQuery(function ($) {
|
| 192 |
+
'use strict';
|
| 193 |
+
|
| 194 |
+
// save function
|
| 195 |
+
var saveAjaxForm = function (target) {
|
| 196 |
+
var $this = $(target),
|
| 197 |
+
$form = $this.parents('form'),
|
| 198 |
+
// get ajax post values
|
| 199 |
+
vals = $form.serializeArray();
|
| 200 |
+
|
| 201 |
+
// disable button
|
| 202 |
+
$this.attr('disabled', true);
|
| 203 |
+
|
| 204 |
+
// show ajax loader
|
| 205 |
+
$form.find('.ajax-feedback').css('visibility', 'visible');
|
| 206 |
+
|
| 207 |
+
// save option values
|
| 208 |
+
$.post(ajaxurl, vals, function (result) {
|
| 209 |
+
var $msg = $('<strong>').insertBefore($this);
|
| 210 |
+
|
| 211 |
+
if (result === '1') {
|
| 212 |
+
$msg.html('Saved');
|
| 213 |
+
} else {
|
| 214 |
+
// save options, non-ajax fallback
|
| 215 |
+
$form.find('[name="action"]').val('update');
|
| 216 |
+
// normal submit
|
| 217 |
+
$form.submit();
|
| 218 |
+
}
|
| 219 |
+
|
| 220 |
+
$msg.css({ margin: '0 5px' })
|
| 221 |
+
.delay(1000)
|
| 222 |
+
.fadeOut(function () {
|
| 223 |
+
$(this).remove();
|
| 224 |
+
});
|
| 225 |
+
|
| 226 |
+
// enable button
|
| 227 |
+
$this.attr('disabled', false);
|
| 228 |
+
|
| 229 |
+
// hide ajax loader
|
| 230 |
+
$form.find('.ajax-feedback').css('visibility', 'hidden');
|
| 231 |
+
|
| 232 |
+
// trigger ajax_saved_options
|
| 233 |
+
$form.trigger('ajax_saved_options', [result]);
|
| 234 |
+
});
|
| 235 |
+
};
|
| 236 |
+
|
| 237 |
+
// add ajax post
|
| 238 |
+
$('form.ajax-form input[type="submit"]').click(function (e) {
|
| 239 |
+
saveAjaxForm(this);
|
| 240 |
+
e.preventDefault();
|
| 241 |
+
});
|
| 242 |
+
|
| 243 |
+
});
|
js/src/admin-wp-external-links.js
CHANGED
|
@@ -122,6 +122,20 @@ jQuery(function ($) {
|
|
| 122 |
})
|
| 123 |
.change();
|
| 124 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
// option use js
|
| 126 |
$('input#use_js')
|
| 127 |
.change(function () {
|
| 122 |
})
|
| 123 |
.change();
|
| 124 |
|
| 125 |
+
// option use js
|
| 126 |
+
$('input#nofollow')
|
| 127 |
+
.change(function () {
|
| 128 |
+
var $i = $('input#overwrite_follow');
|
| 129 |
+
|
| 130 |
+
if ($(this).attr('checked')) {
|
| 131 |
+
$i.attr('disabled', false);
|
| 132 |
+
} else {
|
| 133 |
+
$i.attr('disabled', true)
|
| 134 |
+
.attr('checked', false);
|
| 135 |
+
}
|
| 136 |
+
})
|
| 137 |
+
.change();
|
| 138 |
+
|
| 139 |
// option use js
|
| 140 |
$('input#use_js')
|
| 141 |
.change(function () {
|
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: 4.1.
|
| 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 |
|
|
@@ -42,18 +42,99 @@ The plugin will change the output of the (external) links on the fly. So when yo
|
|
| 42 |
|
| 43 |
== Frequently Asked Questions ==
|
| 44 |
|
| 45 |
-
=
|
| 46 |
|
| 47 |
You could add `rel="external"` to those internal links that should be treated as external. The plugin settings will also be applied to those links.
|
| 48 |
|
| 49 |
-
=
|
| 50 |
|
| 51 |
-
|
| 52 |
|
| 53 |
-
=
|
| 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 |
|
| 59 |
== Screenshots ==
|
|
@@ -70,10 +151,11 @@ 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
|
| 77 |
`function special_external_link($created_link, $original_link, $label, $attrs, $is_ignored_link) {
|
| 78 |
// skip links that contain the class "not-external"
|
| 79 |
if (isset($attrs['class']) && strpos($attrs['class'], 'not-external') !== false) {
|
|
@@ -87,9 +169,10 @@ 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
|
| 93 |
`
|
| 94 |
function special_internal_link($link, $label, $attrs) {
|
| 95 |
return '<b>'. $link .'</b>';
|
|
@@ -99,6 +182,9 @@ 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,6 +192,10 @@ In this case all internal links will be made bold.
|
|
| 106 |
|
| 107 |
== Changelog ==
|
| 108 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
= 1.56 =
|
| 110 |
* Fixed bug jQuery as dependency for js scripts
|
| 111 |
* Fixed bug "no-icon class in same window" working with javascript
|
| 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: 4.1.1
|
| 6 |
+
Stable tag: 1.60
|
| 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 |
|
| 42 |
|
| 43 |
== Frequently Asked Questions ==
|
| 44 |
|
| 45 |
+
= How to treat internal links as external links? =
|
| 46 |
|
| 47 |
You could add `rel="external"` to those internal links that should be treated as external. The plugin settings will also be applied to those links.
|
| 48 |
|
| 49 |
+
= Why are links to my own domain treated as external links? =
|
| 50 |
|
| 51 |
+
Only links pointing to your WordPress site (`wp_url`) are internal links. All other links will be treated as external links.
|
| 52 |
|
| 53 |
+
= How to treat links to subdomains as internal links? =
|
| 54 |
|
| 55 |
Add your main domain to the option "Ingore links (URL) containing..." and they will not be treated as external.
|
| 56 |
|
| 57 |
+
= How to create a redirect for external links? =
|
| 58 |
+
|
| 59 |
+
By using the `wpel_external_link` filter. Add this code to functions.php of your theme:
|
| 60 |
+
|
| 61 |
+
`function redirect_external_link($created_link, $original_link, $label, $attrs = array()) {
|
| 62 |
+
$href = $attrs['href'];
|
| 63 |
+
|
| 64 |
+
// create redirect url
|
| 65 |
+
$href_new = get_bloginfo('wpurl') . '/redirect.php?url=' . urlencode($attrs['href']);
|
| 66 |
+
|
| 67 |
+
return str_replace($href, $href_new, $created_link);
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
add_filter('wpel_external_link', 'redirect_external_link', 10, 4);`
|
| 71 |
+
|
| 72 |
+
= Set a font icon for external links, like [Font Awesome Icons](http://fortawesome.github.io/Font-Awesome/)? =
|
| 73 |
+
|
| 74 |
+
Use the `wpel_external_link` filter and add this code to functions.php of your theme:
|
| 75 |
+
|
| 76 |
+
`function set_font_icon_on_external_link($created_link, $original_link, $label, $attrs = array()) {
|
| 77 |
+
$label_with_font = $label . ' <i class="fa fa-external-link"></i>';
|
| 78 |
+
return str_replace($label, $label_with_font, $created_link);
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
add_filter('wpel_external_link', 'set_font_icon_on_external_link', 10, 4);`
|
| 82 |
+
|
| 83 |
+
The CSS of Font Awesome Icons alse needs to be loaded. To do so also add this code:
|
| 84 |
+
|
| 85 |
+
`function add_font_awesome_style() {
|
| 86 |
+
wp_enqueue_style('font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css');
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
add_action('wp_enqueue_scripts', 'add_font_awesome_style');`
|
| 90 |
+
|
| 91 |
+
= How to open external links in popup browser window with a certain size? =
|
| 92 |
+
|
| 93 |
+
By adding this JavaScript code to your site:
|
| 94 |
+
|
| 95 |
+
`jQuery(function ($) {
|
| 96 |
+
|
| 97 |
+
$('a[rel*="external"]').click(function (e) {
|
| 98 |
+
// open link in popup window
|
| 99 |
+
window.open($(this).attr('href'), '_blank', 'width=800, height=600');
|
| 100 |
+
|
| 101 |
+
// stop default and other behaviour
|
| 102 |
+
e.preventDefault();
|
| 103 |
+
e.stopImmediatePropagation();
|
| 104 |
+
});
|
| 105 |
+
|
| 106 |
+
});`
|
| 107 |
+
|
| 108 |
+
See more information on the [window.open() method](http://www.w3schools.com/jsref/met_win_open.asp).
|
| 109 |
+
|
| 110 |
+
= How to add an confirm (or alert) when opening external links? =
|
| 111 |
+
|
| 112 |
+
Add this JavaScript code to your site:
|
| 113 |
+
|
| 114 |
+
`jQuery(function ($) {
|
| 115 |
+
|
| 116 |
+
$('a[rel*="external"]').click(function (e) {
|
| 117 |
+
if (!confirm('Are you sure you want to open this link?')) {
|
| 118 |
+
// cancelled
|
| 119 |
+
e.preventDefault();
|
| 120 |
+
e.stopImmediatePropagation();
|
| 121 |
+
}
|
| 122 |
+
});
|
| 123 |
+
|
| 124 |
+
});`
|
| 125 |
+
|
| 126 |
+
= How to make all internal links "follow"? =
|
| 127 |
+
|
| 128 |
+
By using the `wp_internal_link` filter. Add this code to functions.php of your theme:
|
| 129 |
+
|
| 130 |
+
`function set_follow_to_internal_link($link, $label, $attrs) {
|
| 131 |
+
return str_replace('nofollow', 'follow', $link);
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
add_filter('wpel_internal_link', 'set_follow_to_internal_link', 10, 3);
|
| 135 |
+
`
|
| 136 |
+
|
| 137 |
+
|
| 138 |
[Do you have a question? Please ask me](http://www.freelancephp.net/contact/)
|
| 139 |
|
| 140 |
== Screenshots ==
|
| 151 |
`function extra_filters($filter_callback, $object) {
|
| 152 |
add_filter('some_filter', $filter_callback);
|
| 153 |
}
|
| 154 |
+
|
| 155 |
add_action('wpel_ready', 'extra_filters');`
|
| 156 |
|
| 157 |
= Filter hook 1: wpel_external_link =
|
| 158 |
+
The wpel_external_link filter gives you the possibility to manipulate output of all external links, like:
|
| 159 |
`function special_external_link($created_link, $original_link, $label, $attrs, $is_ignored_link) {
|
| 160 |
// skip links that contain the class "not-external"
|
| 161 |
if (isset($attrs['class']) && strpos($attrs['class'], 'not-external') !== false) {
|
| 169 |
|
| 170 |
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).
|
| 171 |
|
| 172 |
+
See [FAQ](https://wordpress.org/plugins/wp-external-links/faq/) for more possibilities of using this filter.
|
| 173 |
|
| 174 |
= Filter hook 2: wpel_internal_link =
|
| 175 |
+
With the internal filter you can manipulate the output of all internal links on your site. F.e.:
|
| 176 |
`
|
| 177 |
function special_internal_link($link, $label, $attrs) {
|
| 178 |
return '<b>'. $link .'</b>';
|
| 182 |
|
| 183 |
In this case all internal links will be made bold.
|
| 184 |
|
| 185 |
+
See [FAQ](https://wordpress.org/plugins/wp-external-links/faq/) for more possibilities of using this filter.
|
| 186 |
+
|
| 187 |
+
|
| 188 |
= Credits =
|
| 189 |
* [jQuery Tipsy Plugin](http://plugins.jquery.com/project/tipsy) made by [Jason Frame](http://onehackoranother.com/)
|
| 190 |
* [phpQuery](http://code.google.com/p/phpquery/) made by [Tobiasz Cudnik](http://tobiasz123.wordpress.com)
|
| 192 |
|
| 193 |
== Changelog ==
|
| 194 |
|
| 195 |
+
= 1.60 =
|
| 196 |
+
* Added option to replace "follow" values of external links with "nofollow"
|
| 197 |
+
* Updated FAQ with custom solutions
|
| 198 |
+
|
| 199 |
= 1.56 =
|
| 200 |
* Fixed bug jQuery as dependency for js scripts
|
| 201 |
* Fixed bug "no-icon class in same window" working with javascript
|
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.60
|
| 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.60'); }
|
| 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'); }
|
