Skip to:
Content
Pages
Categories
Search
Top
Bottom

Quick Tip – How to fix broken links in activity stream

  • @vincent-boiardt

    Participant

    Often enough I might feel like changing the defined slugs, and/or maybe I’ll move the project to another domain. But this usually screws up all the links that are recorded in the activity stream since they’re saved as HTML in the database.

    I thought I’d share my way of keeping my activity stream free of broken links. The RegEx for the replace might be lacking, but it works for me. I haven’t tested it on all domains.

    `function mytheme_bp_insert_activity_meta( $content ) {
    global $bp;
    // Extend the array with the slugs you need to replace
    $slug_replace = array(
    ‘members’ => BP_MEMBERS_SLUG,
    ‘groups’ => BP_GROUPS_SLUG
    );
    foreach( $slug_replace as $old_slug => $new_slug ) {
    $content = preg_replace( ‘/(/’ . $old_slug . ‘/)/i’, ‘/’ . $new_slug . ‘/’, $content );
    }

    $content = preg_replace( ‘/(http://[a-z0-9.]+/(wordpress/)?)/’, $bp->root_domain . ‘/’, $content );

    return $content;
    }
    add_filter( ‘bp_insert_activity_meta’, ‘mytheme_bp_insert_activity_meta’ );`

    Just thought I should share! I post other WordPress-related tips on my blog http://wpquicktips.wordpress.com/. Maybe you will find it useful as well!

Viewing 1 replies (of 1 total)
  • @johnsoce18

    Participant

    @vincent-boiardt – Thanks for the tip! I have another question for you…I wanted to change the “group” slug on my site to “projects,” but when I do, the links to each “project” are now broken. I recently created a new language file before I changed the slug, would that have something to do with it? Everything works fine when I take out the like of code:

    define( ‘BP_GROUPS_SLUG’, ‘project’ );

    But when I add it back to wp-config.php, the links are broken again. Please help if you can! Thanks!

Viewing 1 replies (of 1 total)
  • The topic ‘Quick Tip – How to fix broken links in activity stream’ is closed to new replies.
Skip to toolbar