How to add location tab of Geo My WordPress plugin only for special role

If you use one of the best geo locator plugin for wordpress – Geo my WordPress (GMW) and you have different roles of users, sometimes it’s good to hide location tab for all roles, except special role. Also, maybe you want to show only special user role on map. Here simple code snippets for this

function set_only_vendors_in_gmw_results( $args, $gmw ) {
    $userargs = array('role'=>'vendor', 'fields'=> 'ID');
    $vendorids = get_users( $userargs);
    if (!empty($vendorids)){
        $vendorids = implode(',',$vendorids);
        $args['include'] = $vendorids;
        return $args;
    }
}
add_filter( 'gmw_fl_search_query_args', 'set_only_vendors_in_gmw_results', 10, 2 );

add_filter( 'gmw_fl_setup_nav', 'rh_remove_location_tab', 10, 1 );
function rh_remove_location_tab($bp){
    global $bp;
    $userobj = get_userdata($bp->displayed_user->id);
    if ( in_array( 'vendor', (array) $userobj->roles ) ) {
        return array(
            'name'                => __( 'Location', 'GMW' ),
            'slug'                => GMW_FL_SLUG,
            'position'            => 60,
            'screen_function'     => array($bp->gmw_location, 'screen_functions'),
            'default_subnav_slug' => GMW_FL_SLUG
        );
    }
    else {
        return;
    }
}

Add this code to functions.php of your theme. This code enables location only for user role “vendor” and hide for all others

3.5/5 - (11 votes)

1 Comment
  1. Love you mate. Thanks for this!

Leave a reply

Wordpress optimization, monetizing tips and tricks
Logo