Make WordPress Core

Ticket #12480: 12480-2.diff

File 12480-2.diff, 1.7 KB (added by technosailor, 15 years ago)

Replaces empty, whitespace or nbsp anchor text with the sanitized URL. Improves regex to be less greedy for non href attributes

  • wp-includes/default-filters.php

     
    128128add_filter( 'comment_text', 'convert_chars'          );
    129129add_filter( 'comment_text', 'make_clickable',      9 );
    130130add_filter( 'comment_text', 'force_balance_tags', 25 );
     131add_filter( 'comment_text', 'fill_empty_links',   24 );
    131132add_filter( 'comment_text', 'convert_smilies',    20 );
    132133add_filter( 'comment_text', 'wpautop',            30 );
    133134
  • wp-includes/formatting.php

     
    10941094}
    10951095
    10961096/**
     1097 * Adds blank string to all HTML A empty elements in content.
     1098 *
     1099 * @since 3.0.0
     1100 *
     1101 * @param string $text Content that may contain HTML A elements.
     1102 * @return string Converted content.
     1103 */
     1104function fill_empty_links( $text )
     1105{
     1106        return preg_replace_callback( "#<a\s[^>]*href=(\"?)([^\" >]*?)\\1[^>]*>[\s|\&nbsp;]*<\/a>#i", 'fill_empty_links_callback', $text);
     1107}
     1108//[\s|\&nbsp;]*
     1109/**
     1110 * Callback to add a visual placeholder in comments having empty anchor text
     1111 *
     1112 * @since 3.0.0
     1113 *
     1114 * @param string $matches Single match
     1115 * @return string Returns a formatted anchor tag with the URL of the link as the anchor text on success. Returns false on failure
     1116 */
     1117function fill_empty_links_callback( $matches )
     1118{
     1119        if( !$matches[2] )
     1120                return false;
     1121
     1122        return sprintf( '<a href="%1$s">%1$s</a>', esc_url( $matches[2] ) );
     1123}
     1124
     1125/**
    10971126 * Acts on text which is about to be edited.
    10981127 *
    10991128 * Unless $richedit is set, it is simply a holder for the 'format_to_edit'