Quick Tip – How to fix broken links in activity stream
-
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!
- The topic ‘Quick Tip – How to fix broken links in activity stream’ is closed to new replies.