Skip to:
Content
Pages
Categories
Search
Top
Bottom

links in activity content

  • Profile photo of shanebp
    shanebp
    Moderator

    @shanebp

    For updates, when a member inserts an url, I need to check whether that url takes them off-site and if so add target _blank to the href.

    Where are hrefs added to urls in activity posts?

    So far I’ve looked at:
    -bp_get_activity_content_body
    -bp_insert_activity_meta

    Anyone have a hint?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Profile photo of shanebp
    shanebp
    Moderator

    @shanebp

    I think this is the right approach, but it’s not working…

    In bp-custom –

    
    function add_target_func_callback($matches){
    if ( (parse_url($matches[1], PHP_URL_HOST) != 'my.com') && (parse_url($matches[1], PHP_URL_HOST) != 'www.my.com') ){
    $matches[0] = 'target="_blank" ' . $matches[0];
    }
    return $matches[0];
    }
    
    function add_target_blank($content) {
    $content = preg_replace_callback('#href=['"]([^'"]*)['"]#i', 'add_target_func_callback', $content);
    return $content;
    }
    
    add_filter('bp_get_activity_content_body', 'add_target_blank', 1, 1 );
    

    I’m not sure that $content is being passed to add_target_blank

    Profile photo of shanebp
    shanebp
    Moderator

    @shanebp

    Got this to work by setting add_filter priority to 12

    Remember to also filter on bp_get_activity_latest_update to handle links in member-header

    Profile photo of James
    James
    Participant

    @janismo

    @shanebp nice function, Shane, will use it.
    if you digged into all these activity things, maybe you know how could I limit (e.g., one per activity) these external links in activity updates?

    thank you.

    Profile photo of shanebp
    shanebp
    Moderator

    @shanebp

    So any update can only have one link in it?

    I don’t have a function for you, but I’d say you need to count the number of hrefs.
    For anything over 1, remove everything between and including the href open and close tags.
    Of course, the resulting update may not make sense, english-wise.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘links in activity content’ is closed to new replies.
Skip to toolbar