Make WordPress Core

Ticket #11359: 11359.diff

File 11359.diff, 9.7 KB (added by akibjorklund, 10 years ago)

Do not rel=nofollow links from authors that can edit_comment

  • wp-includes/comment-template.php

     
    185185        $url    = get_comment_author_url( $comment_ID );
    186186        $author = get_comment_author( $comment_ID );
    187187
    188         if ( empty( $url ) || 'http://' == $url )
     188        if ( empty( $url ) || 'http://' == $url ) {
    189189                $return = $author;
    190         else
    191                 $return = "<a href='$url' rel='external nofollow' class='url'>$author</a>";
     190        } else {
     191                // By default, add rel=nofollow to author links
     192                $nofollow = ' nofollow';
     193                $comment = get_comment( $comment_ID );
     194                // If the author can edit comments, no need to rel=unfollow the link
     195                if ( $comment->user_id > 0 && user_can( $comment->user_id, 'edit_comment' ) ) {
     196                        $nofollow = '';
     197                }
     198               
     199                $return = "<a href='$url' rel='external$nofollow' class='url'>$author</a>";
     200        }
    192201
    193202        /**
    194203         * Filter the comment author's link for display.
  • wp-includes/comment.php

     
    17261726         *
    17271727         * @param int $comment_content The comment content.
    17281728         */
    1729         $commentdata['comment_content'] = apply_filters( 'pre_comment_content', $commentdata['comment_content'] );
     1729        $commentdata['comment_content'] = apply_filters( 'pre_comment_content', $commentdata['comment_content'], isset( $commentdata['user_id'] ) ? $commentdata['user_id'] : null );
    17301730        /**
    17311731         * Filter the comment author's IP before it is set.
    17321732         *
  • wp-includes/default-filters.php

     
    142142add_filter( 'the_excerpt',     'shortcode_unautop');
    143143add_filter( 'get_the_excerpt', 'wp_trim_excerpt'  );
    144144
    145 add_filter( 'comment_text', 'wptexturize'            );
    146 add_filter( 'comment_text', 'convert_chars'          );
    147 add_filter( 'comment_text', 'make_clickable',      9 );
    148 add_filter( 'comment_text', 'force_balance_tags', 25 );
    149 add_filter( 'comment_text', 'convert_smilies',    20 );
    150 add_filter( 'comment_text', 'wpautop',            30 );
     145add_filter( 'comment_text', 'wptexturize'                  );
     146add_filter( 'comment_text', 'convert_chars'                );
     147add_filter( 'comment_text', 'make_comment_clickable', 9, 2 );
     148add_filter( 'comment_text', 'force_balance_tags',    25    );
     149add_filter( 'comment_text', 'convert_smilies',       20    );
     150add_filter( 'comment_text', 'wpautop',               30    );
    151151
    152152add_filter( 'comment_excerpt', 'convert_chars' );
    153153
     
    169169add_filter( 'the_author',         'ent2ncr',      8 );
    170170
    171171// Misc filters
    172 add_filter( 'option_ping_sites',        'privacy_ping_filter'                 );
    173 add_filter( 'option_blog_charset',      '_wp_specialchars'                    ); // IMPORTANT: This must not be wp_specialchars() or esc_html() or it'll cause an infinite loop
    174 add_filter( 'option_blog_charset',      '_canonical_charset'                  );
    175 add_filter( 'option_home',              '_config_wp_home'                     );
    176 add_filter( 'option_siteurl',           '_config_wp_siteurl'                  );
    177 add_filter( 'tiny_mce_before_init',     '_mce_set_direction'                  );
    178 add_filter( 'pre_kses',                 'wp_pre_kses_less_than'               );
    179 add_filter( 'sanitize_title',           'sanitize_title_with_dashes',   10, 3 );
    180 add_action( 'check_comment_flood',      'check_comment_flood_db',       10, 3 );
    181 add_filter( 'comment_flood_filter',     'wp_throttle_comment_flood',    10, 3 );
    182 add_filter( 'pre_comment_content',      'wp_rel_nofollow',              15    );
    183 add_filter( 'comment_email',            'antispambot'                         );
    184 add_filter( 'option_tag_base',          '_wp_filter_taxonomy_base'            );
    185 add_filter( 'option_category_base',     '_wp_filter_taxonomy_base'            );
    186 add_filter( 'the_posts',                '_close_comments_for_old_posts', 10, 2);
    187 add_filter( 'comments_open',            '_close_comments_for_old_post', 10, 2 );
    188 add_filter( 'pings_open',               '_close_comments_for_old_post', 10, 2 );
    189 add_filter( 'editable_slug',            'urldecode'                           );
    190 add_filter( 'editable_slug',            'esc_textarea'                        );
    191 add_filter( 'nav_menu_meta_box_object', '_wp_nav_menu_meta_box_object'        );
    192 add_filter( 'pingback_ping_source_uri', 'pingback_ping_source_uri'            );
    193 add_filter( 'xmlrpc_pingback_error',    'xmlrpc_pingback_error'               );
     172add_filter( 'option_ping_sites',        'privacy_ping_filter'                  );
     173add_filter( 'option_blog_charset',      '_wp_specialchars'                     ); // IMPORTANT: This must not be wp_specialchars() or esc_html() or it'll cause an infinite loop
     174add_filter( 'option_blog_charset',      '_canonical_charset'                   );
     175add_filter( 'option_home',              '_config_wp_home'                      );
     176add_filter( 'option_siteurl',           '_config_wp_siteurl'                   );
     177add_filter( 'tiny_mce_before_init',     '_mce_set_direction'                   );
     178add_filter( 'pre_kses',                 'wp_pre_kses_less_than'                );
     179add_filter( 'sanitize_title',           'sanitize_title_with_dashes',    10, 3 );
     180add_action( 'check_comment_flood',      'check_comment_flood_db',        10, 3 );
     181add_filter( 'comment_flood_filter',     'wp_throttle_comment_flood',     10, 3 );
     182add_filter( 'pre_comment_content',      'wp_maybe_rel_nofollow_comment', 15, 2 );
     183add_filter( 'comment_email',            'antispambot'                          );
     184add_filter( 'option_tag_base',          '_wp_filter_taxonomy_base'             );
     185add_filter( 'option_category_base',     '_wp_filter_taxonomy_base'             );
     186add_filter( 'the_posts',                '_close_comments_for_old_posts', 10, 2 );
     187add_filter( 'comments_open',            '_close_comments_for_old_post',  10, 2 );
     188add_filter( 'pings_open',               '_close_comments_for_old_post',  10, 2 );
     189add_filter( 'editable_slug',            'urldecode'                            );
     190add_filter( 'editable_slug',            'esc_textarea'                         );
     191add_filter( 'nav_menu_meta_box_object', '_wp_nav_menu_meta_box_object'         );
     192add_filter( 'pingback_ping_source_uri', 'pingback_ping_source_uri'             );
     193add_filter( 'xmlrpc_pingback_error',    'xmlrpc_pingback_error'                );
    194194
    195195add_filter( 'http_request_host_is_external', 'allowed_http_request_hosts', 10, 2 );
    196196
  • wp-includes/formatting.php

     
    18021802        if ( empty($url) )
    18031803                return $matches[0];
    18041804
    1805         return $matches[1] . "<a href=\"$url\" rel=\"nofollow\">$url</a>" . $suffix;
     1805        return $matches[1] . "<a href=\"$url\">$url</a>" . $suffix;
    18061806}
    18071807
    18081808/**
     
    18301830                $ret = substr($dest, -1);
    18311831                $dest = substr($dest, 0, strlen($dest)-1);
    18321832        }
    1833         return $matches[1] . "<a href=\"$dest\" rel=\"nofollow\">$dest</a>$ret";
     1833        return $matches[1] . "<a href=\"$dest\">$dest</a>$ret";
    18341834}
    18351835
    18361836/**
     
    19211921}
    19221922
    19231923/**
     1924 * Convert plaintext URI to HTML links in comments.
     1925 *
     1926 * @since 4.1.0
     1927 *
     1928 * @param  object $comment A comment.
     1929 * @return string Content with converted URIs.
     1930 *
     1931 */
     1932function make_comment_clickable( $text, $comment ) {
     1933        $text = make_clickable( $text );
     1934        $user_id = $maybe_comment->user_id > 0 ? $comment->user_id : null;
     1935        return wp_maybe_rel_nofollow_comment( $ret, $user_id, 'unescaped' );
     1936}
     1937
     1938/**
    19241939 * Breaks a string into chunks by splitting at whitespace characters.
    19251940 * The length of each returned chunk is as close to the specified length goal as possible,
    19261941 * with the caveat that each chunk includes its trailing delimiter.
     
    19791994}
    19801995
    19811996/**
     1997 * Controls weather there is a rel=nofollow string in all HTML A elements
     1998 * in a comment, depending on if the user can edit comments or not.
     1999 *
     2000 * @since 4.1.0
     2001 *
     2002 * @param string $text      HTML text to filter
     2003 * @param int    $author_id User ID of the author of the comment
     2004 * @param string $excaped   'escaped' if the $text is already escaped, else 'unescaped'
     2005 *
     2006 */
     2007function wp_maybe_rel_nofollow_comment( $text, $author_id = null, $escaped = 'escaped' ) {
     2008        // Test for authors that can edit comments.
     2009        if ( null != $author_id && user_can( $author_id, 'edit_comment' ) ) {
     2010                // No need to add rel=nofollow.
     2011                return $text;
     2012        }
     2013
     2014        return wp_rel_nofollow( $text, $escaped );
     2015}
     2016
     2017/**
    19822018 * Adds rel nofollow string to all HTML A elements in content.
    19832019 *
    19842020 * @since 1.5.0
     
    19862022 * @param string $text Content that may contain HTML A elements.
    19872023 * @return string Converted content.
    19882024 */
    1989 function wp_rel_nofollow( $text ) {
    1990         // This is a pre save filter, so text is already escaped.
    1991         $text = stripslashes($text);
    1992         $text = preg_replace_callback('|<a (.+?)>|i', 'wp_rel_nofollow_callback', $text);
    1993         $text = wp_slash($text);
     2025function wp_rel_nofollow( $text, $escaped = 'escaped' ) {
     2026        if ( 'escaped' == $escaped ) {
     2027                $text = stripslashes( $text );
     2028        }
     2029        $text = preg_replace_callback( '|<a (.+?)>|i', 'wp_rel_nofollow_callback', $text );
     2030        if ( 'escaped' == $escaped ) {
     2031                $text = wp_slash( $text );
     2032        }
    19942033        return $text;
    19952034}
    19962035
     
    20072046 */
    20082047function wp_rel_nofollow_callback( $matches ) {
    20092048        $text = $matches[1];
    2010         $text = str_replace(array(' rel="nofollow"', " rel='nofollow'"), '', $text);
     2049        $text = str_replace( array( ' rel="nofollow"', " rel='nofollow'" ), '', $text );
    20112050        return "<a $text rel=\"nofollow\">";
    20122051}
    20132052