Add unit tests for `links_add_target()`. Alter the patterns in `links_add_target()` and `_links_add_target()` slightly based on learnings after running tests.
Props mdbitz. Fixes #26164. Built from https://develop.svn.wordpress.org/trunk@26328 git-svn-id: http://core.svn.wordpress.org/trunk@26230 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
28c19ec965
commit
dc01b08a5e
|
@ -3243,7 +3243,7 @@ function links_add_target( $content, $target = '_blank', $tags = array('a') ) {
|
||||||
global $_links_add_target;
|
global $_links_add_target;
|
||||||
$_links_add_target = $target;
|
$_links_add_target = $target;
|
||||||
$tags = implode('|', (array)$tags);
|
$tags = implode('|', (array)$tags);
|
||||||
return preg_replace_callback( "!<($tags)(.+?)>!i", '_links_add_target', $content );
|
return preg_replace_callback( "!<($tags)([^>]*)>!i", '_links_add_target', $content );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -3258,7 +3258,7 @@ function links_add_target( $content, $target = '_blank', $tags = array('a') ) {
|
||||||
function _links_add_target( $m ) {
|
function _links_add_target( $m ) {
|
||||||
global $_links_add_target;
|
global $_links_add_target;
|
||||||
$tag = $m[1];
|
$tag = $m[1];
|
||||||
$link = preg_replace('|(target=([\'"])(.*?)\2)|i', '', $m[2]);
|
$link = preg_replace('|( target=([\'"])(.*?)\2)|i', '', $m[2]);
|
||||||
return '<' . $tag . $link . ' target="' . esc_attr( $_links_add_target ) . '">';
|
return '<' . $tag . $link . ' target="' . esc_attr( $_links_add_target ) . '">';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue