WordPress.org

Make WordPress Core

Changeset 17459


Ignore:
Timestamp:
02/16/2011 07:24:18 PM (7 years ago)
Author:
ryan
Message:

Lose create_function() in links_add_target() and links_add_base_url(). esc_attr() the target to provide extra coverage for plugins. Props Justin Rainbow, nacin. For trunk

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/formatting.php

    r17228 r17459  
    27352735 */
    27362736function links_add_base_url( $content, $base, $attrs = array('src', 'href') ) {
     2737    global $_links_add_base;
     2738    $_links_add_base = $base;
    27372739    $attrs = implode('|', (array)$attrs);
    2738     return preg_replace_callback("!($attrs)=(['\"])(.+?)\\2!i",
    2739             create_function('$m', 'return _links_add_base($m, "' . $base . '");'),
    2740             $content);
     2740    return preg_replace_callback( "!($attrs)=(['\"])(.+?)\\2!i", '_links_add_base', $content );
    27412741}
    27422742
     
    27482748 *
    27492749 * @param string $m The matched link.
    2750  * @param string $base The base URL to prefix to links.
    27512750 * @return string The processed link.
    27522751 */
    2753 function _links_add_base($m, $base) {
     2752function _links_add_base($m) {
     2753    global $_links_add_base;
    27542754    //1 = attribute name  2 = quotation mark  3 = URL
    27552755    return $m[1] . '=' . $m[2] .
    27562756        (strpos($m[3], 'http://') === false ?
    2757             path_join($base, $m[3]) :
     2757            path_join($_links_add_base, $m[3]) :
    27582758            $m[3])
    27592759        . $m[2];
     
    27762776 */
    27772777function links_add_target( $content, $target = '_blank', $tags = array('a') ) {
     2778    global $_links_add_target;
     2779    $_links_add_target = $target;
    27782780    $tags = implode('|', (array)$tags);
    2779     return preg_replace_callback("!<($tags)(.+?)>!i",
    2780             create_function('$m', 'return _links_add_target($m, "' . $target . '");'),
    2781             $content);
     2781    return preg_replace_callback( "!<($tags)(.+?)>!i", '_links_add_target', $content );
    27822782}
    27832783
     
    27892789 *
    27902790 * @param string $m The matched link.
    2791  * @param string $target The Target to add to the links.
    27922791 * @return string The processed link.
    27932792 */
    2794 function _links_add_target( $m, $target ) {
     2793function _links_add_target( $m ) {
     2794    global $_links_add_target;
    27952795    $tag = $m[1];
    27962796    $link = preg_replace('|(target=[\'"](.*?)[\'"])|i', '', $m[2]);
    2797     return '<' . $tag . $link . ' target="' . $target . '">';
     2797    return '<' . $tag . $link . ' target="' . esc_attr( $_links_add_target ) . '">';
    27982798}
    27992799
Note: See TracChangeset for help on using the changeset viewer.