Changeset 2931487
- Timestamp:
- 06/27/2023 03:25:39 PM (3 years ago)
- Location:
- customize-external-links-and-add-icon/trunk
- Files:
-
- 2 edited
-
customize-external-links.php (modified) (5 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
customize-external-links-and-add-icon/trunk/customize-external-links.php
r2767240 r2931487 5 5 * Description: Add nofollow and remove noreferrer attributes in external links. Choose between different icons to show users which link is an external one. 6 6 * Author: blapps 7 * Version: 1.9.28 * Tested up to: 6. 07 * Version: 2.0 8 * Tested up to: 6.2 9 9 * Text Domain: customize-external-links 10 10 * Domain Path: /languages … … 30 30 31 31 if (str_starts_with($url, '#')) { 32 return true; 33 } 34 35 if (str_starts_with($url, '/#')) { 32 36 return true; 33 37 } … … 178 182 } 179 183 184 function cuexlinks_add_rel_noreferrer($url, $tag) 185 { 186 $no_referrer = ''; 187 // $pattern = '/rel\s*=\s*"\s*[n|d]ofollow\s*"/'; 188 // $pattern = '/rel\s*=\s*\"[a-zA-Z0-9_\s]*[n|d]ofollow[a-zA-Z0-9_\s]*\"/'; 189 $pattern = '/rel\s*=\s*\"[a-zA-Z0-9_\s]*\"/'; 190 191 $result = preg_match($pattern, $url, $match); 192 193 if ($result === 0) { 194 $no_referrer .= ' rel="noreferrer"'; 195 } else { 196 if ( 197 strpos($match[0], 'noreferrer') === false && 198 strpos($match[0], 'referrer') === false 199 ) { 200 $temp = $match[0]; 201 $temp = substr_replace($temp, ' noreferrer"', -1); 202 $tag = str_replace($match[0], $temp, $tag); 203 } 204 } 205 206 if ($no_referrer) { 207 $tag = cuexlinks_update_close_tag($tag, $no_referrer); 208 } 209 210 return $tag; 211 } 212 213 180 214 function cuexlinks_update_close_tag($tag, $no_follow) 181 215 { … … 209 243 if (cuexlinks_is_domain_not_excluded($url)) { 210 244 $tag = cuexlinks_add_rel_nofollow($url, $tag); 245 } 246 247 $content = str_replace($url, $tag, $content); 248 } // end for loop 249 250 $content = str_replace(']]>', ']]>', $content); 251 return $content; 252 } 253 254 function cuexlinks_url_parse_noreferrer($content) 255 { 256 257 $matches = cuexlinks_is_link_available($content); 258 259 if ($matches === null) { 260 return $content; 261 } 262 263 // loop through each links 264 for ($i = 0; $i < count($matches); $i++) { 265 $tag = $matches[$i][0]; 266 $url = $matches[$i][0]; 267 268 $blogurl = get_site_url(); 269 // if ( (cuexlinks_is_internal_link($url)) <> (strpos($url, $blogurl) != 0) ) { 270 271 if (cuexlinks_is_internal_link($url)) { 272 continue; 273 } 274 275 $tag = cuexlinks_add_target_blank($url, $tag); 276 277 //exclude domain or add nofollow 278 if (cuexlinks_is_domain_not_excluded($url)) { 279 $tag = cuexlinks_add_rel_noreferrer($url, $tag); 211 280 } 212 281 … … 357 426 } else { 358 427 // do nothing because Gutenberg adds noreferrer automatically 359 } 428 // new: to show it 429 add_filter('the_content', 'cuexlinks_url_parse_noreferrer'); 430 431 } 432 433 434 360 435 361 436 function cuexlinks_define_icons() -
customize-external-links-and-add-icon/trunk/readme.txt
r2767240 r2931487 3 3 Donate link: 4 4 Tags: nofollow, noreferer, icon external link, nofollow links, external links, nofollow for external links, nofollow external link, nofollow external links, custom icons, remove noreferrer 5 Requires at least: 2.8.66 Tested up to: 6. 07 Stable tag: 1.9.25 Requires at least: 4 6 Tested up to: 6.2 7 Stable tag: 2.0 8 8 License: GPL2 9 9 … … 56 56 == Changelog == 57 57 58 = 2.0 = 59 - added noreferrer 60 - fixed internal links starting with /# 61 - ready for WP 6.2 62 63 58 64 = 1.9.2 = 59 65 - fixed bugs in debug mode
Note: See TracChangeset
for help on using the changeset viewer.