BuddyPress commone link to user/member profile

I need add static link to menu for redirect user to profile BuddyPress. But BP have only individual links for each user.

I writed short snippet for add root endpoint /my-profile/ and redirect to user profile.


//Add root endpoint /my-profile/
function wpcc_add_redirect_endpoint() {
    add_rewrite_endpoint( 'my-profile', EP_ROOT );
}
add_action( 'init', 'wpcc_add_redirect_endpoint' );

//Add redirect for endpoint
function wpcc_profile_redirect(){
  $check = get_query_var('my-profile', false);

  if($check === ''){
    wp_redirect(bp_loggedin_user_domain(get_current_user_id()));
  }
}
add_action( "template_redirect", 'wpcc_profile_redirect' );

Access control list for posts in WordPress

You can add the code in functions.php, include in plugin or copy file in /mu-plugins/

/*
* Filter posts in SQL
*/
if ( ! function_exists( 'acl_filter_posts_where' ) ) :


  function acl_filter_posts_where($where){

    global $wpdb;

    $current_user_id = get_current_user_id();

    $where .= " AND ($wpdb->posts.post_type != 'post'
                    OR $wpdb->posts.ID IN (
                      SELECT post_id
                      FROM $wpdb->postmeta
                      WHERE $wpdb->postmeta.post_id = $wpdb->posts.ID
                          AND $wpdb->postmeta.meta_key = 'cmdb_acl'
                          AND $wpdb->postmeta.meta_value like '%\"$current_user_id\"%'
                    ))";

    return $where;
  }

  add_filter('posts_where', 'acl_filter_posts_where');

endif;

Correct reset rewrite rule in WordPress

Check realtime without reactivation plugin or theme

add_filter( 'rewrite_rules_array','my_insert_rewrite_rules' );
add_filter( 'query_vars','my_insert_query_vars' );
add_action( 'wp_loaded','my_flush_rules' );

// flush_rules() if our rules are not yet included
function my_flush_rules(){
	$rules = get_option( 'rewrite_rules' );

	if ( ! isset( $rules['(project)/(\d*)$'] ) ) {
		global $wp_rewrite;
	   	$wp_rewrite->flush_rules();
	}
}

// Adding a new rule
function my_insert_rewrite_rules( $rules )
{
	$newrules = array();
	$newrules['(project)/(\d*)$'] = 'index.php?pagename=$matches[1]&id=$matches[2]';
	return $newrules + $rules;
}

// Adding the id var so that WP recognizes it
function my_insert_query_vars( $vars )
{
    array_push($vars, 'id');
    return $vars;
}

Reset rewrite rules after deactivate plugin

register_deactivation_hook( __FILE__, 'flush_rewrite_rules' );