Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. * Open Links On New Tab.
  5. */
  6. function yzc_open_link_on_new_tab( $content ) {
  7.  
  8. if ( ! empty( $content ) ) {
  9.  
  10. $pattern = '/<a(.*?)?href=[\'"]?[\'"]?(.*?)?>/i';
  11.  
  12. $content = preg_replace_callback( $pattern, function( $m ) {
  13.  
  14. $tpl = array_shift( $m );
  15. $hrf = isset( $m[1] ) ? $m[1] : null;
  16.  
  17. if ( preg_match( '/target=[\'"]?(.*?)[\'"]?/i', $tpl ) ) {
  18. return $tpl;
  19. }
  20.  
  21. if ( trim( $hrf ) && 0 === strpos( $hrf, '#' ) ) {
  22. return $tpl;
  23. }
  24.  
  25. return preg_replace_callback( '/href=/i', function( $m2 ) {
  26. return sprintf( 'target="_blank" %s', array_shift( $m2 ) );
  27. }, $tpl );
  28.  
  29. }, $content );
  30.  
  31. }
  32.  
  33. return $content;
  34. }
  35.  
  36. add_filter( 'bp_get_profile_field_data', 'make_clickable' );
  37. add_filter( 'bp_get_profile_field_data', 'yzc_open_link_on_new_tab' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement