Ticket #3318: 3318.diff
File 3318.diff, 4.3 KB (added by , 5 years ago) |
---|
-
trunk/src/includes/common/formatting.php
294 294 * @return string $text Text with rel=nofollow added to any links 295 295 */ 296 296 function bbp_rel_nofollow( $text = '' ) { 297 return preg_replace_callback( '|<a (.+?)>|i', 'bbp_rel_nofollow_callback', $text ); 297 return preg_replace_callback( 298 '|<a (.+?)>|i', 299 function( $matches ) { 300 bbp_rel_callback( $matches, 'nofollow' ); 301 }, 302 $text 303 ); 298 304 } 299 305 300 306 /** 307 * Catches links so rel="nofollow ugc" can be added (on output, not save) 308 * 309 * @param string $text Post text 310 * @return string $text Text with rel="nofollow ugc" added to any links 311 */ 312 function bbp_rel_ugc( $text = '' ) { 313 return preg_replace_callback( 314 '|<a (.+?)>|i', 315 function( $matches ) { 316 return bbp_rel_callback( $matches, 'nofollow ugc' ); 317 }, 318 $text 319 ); 320 } 321 322 /** 301 323 * Adds rel=nofollow to a link 302 324 * 303 325 * @since 2.3.0 bbPress (r4865) … … 306 328 * @return string $text Link with rel=nofollow added 307 329 */ 308 330 function bbp_rel_nofollow_callback( $matches = array() ) { 331 return bbp_rel_callback( $matches, 'nofollow' ); 332 } 333 334 /** 335 * Adds a rel attribute to a link 336 * 337 * @param array $matches 338 * @param string $rel 339 * @return string $text Link with the added rel attribute 340 */ 341 function bbp_rel_callback( $matches, $rel ) { 309 342 $text = $matches[1]; 310 343 $atts = shortcode_parse_atts( $matches[1] ); 311 $rel = 'nofollow';312 344 $home_url = home_url(); 313 345 314 346 // Bail on links that match the current domain … … 320 352 321 353 // Avoid collisions with existing "rel" attribute 322 354 if ( ! empty( $atts['rel'] ) ) { 323 $parts = array_map( 'trim', explode( ' ', $atts['rel'] ) ); 324 if ( false === array_search( 'nofollow', $parts ) ) { 325 $parts[] = 'nofollow'; 326 } 327 328 $rel = implode( ' ', $parts ); 355 $parts = array_map( 'trim', explode( ' ', $atts['rel'] ) ); 356 $rel_array = array_map( 'trim', explode( ' ', $rel ) ); 357 $parts = array_unique( array_merge( $parts, $rel_array ) ); 358 $rel = implode( ' ', $parts ); 329 359 unset( $atts['rel'] ); 330 360 331 361 $html = ''; -
trunk/src/includes/core/filters.php
168 168 add_filter( 'bbp_get_reply_content', 'force_balance_tags', 30 ); 169 169 add_filter( 'bbp_get_reply_content', 'bbp_make_clickable', 40 ); 170 170 add_filter( 'bbp_get_reply_content', 'wpautop', 50 ); 171 add_filter( 'bbp_get_reply_content', 'bbp_rel_ nofollow',60 );171 add_filter( 'bbp_get_reply_content', 'bbp_rel_ugc', 60 ); 172 172 173 173 // Run filters on topic content 174 174 add_filter( 'bbp_get_topic_content', 'wptexturize', 6 ); … … 178 178 add_filter( 'bbp_get_topic_content', 'force_balance_tags', 30 ); 179 179 add_filter( 'bbp_get_topic_content', 'bbp_make_clickable', 40 ); 180 180 add_filter( 'bbp_get_topic_content', 'wpautop', 50 ); 181 add_filter( 'bbp_get_topic_content', 'bbp_rel_ nofollow',60 );181 add_filter( 'bbp_get_topic_content', 'bbp_rel_ugc', 60 ); 182 182 183 183 // Admin-only 184 184 if ( is_admin() ) { -
trunk/src/templates/default/bbpress/user-profile.php
20 20 21 21 <?php if ( bbp_get_displayed_user_field( 'description' ) ) : ?> 22 22 23 <p class="bbp-user-description"><?php echo bbp_rel_ nofollow( bbp_get_displayed_user_field( 'description' ) ); ?></p>23 <p class="bbp-user-description"><?php echo bbp_rel_ugc( bbp_get_displayed_user_field( 'description' ) ); ?></p> 24 24 25 25 <?php endif; ?> 26 26 27 27 <?php if ( bbp_get_displayed_user_field( 'user_url' ) ) : ?> 28 28 29 <p class="bbp-user-website"><?php printf( esc_html__( 'Website: %s', 'bbpress' ), bbp_rel_ nofollow( bbp_make_clickable( bbp_get_displayed_user_field( 'user_url' ) ) ) ); ?></p>29 <p class="bbp-user-website"><?php printf( esc_html__( 'Website: %s', 'bbpress' ), bbp_rel_ugc( bbp_make_clickable( bbp_get_displayed_user_field( 'user_url' ) ) ) ); ?></p> 30 30 31 31 <?php endif; ?> 32 32