{"id":35,"date":"2013-10-20T21:28:31","date_gmt":"2013-10-20T21:28:31","guid":{"rendered":"http:\/\/buddydev.com\/docs\/?p=35"},"modified":"2018-02-26T18:52:59","modified_gmt":"2018-02-26T18:52:59","slug":"redirect-users-to-specific-page-when-they-can-not-view-the-profile","status":"publish","type":"post","link":"https:\/\/buddydev.com\/docs\/bp-profile-visibility-manager\/redirect-users-to-specific-page-when-they-can-not-view-the-profile\/","title":{"rendered":"Redirect Users to specific page when they can not view the profile"},"content":{"rendered":"<p>If you are using BuddyPress Profile visibiliy manager plugin, the plugin allows users to set their profile to various privacy levels.<\/p>\n<p>If a user does not meet the visibility requirement and tries to visit other user&#8217;s profile, he gets redirected to the referrer page(last page from where he clicked the link). If the referrer page is empty, he will be redirected to the home page of the site. Additionally, \u00a0a notice message is added via BuddyPress bp_core_add_message to notify the users of the privacy limitation.<\/p>\n<p>In case you want to redirect the user to a specific page when they do not meet the visibility requirement, you can filter on \u00a0&#8216;<strong>bp_profile_visibility_redirect_location<\/strong>&#8216;.<\/p>\n<h3>Usage:-<\/h3>\n<pre class=\"lang:php decode:true\">add_filter( 'bp_profile_visibility_redirect_location', \u00a0'your_function_name' , 10, 2 );<\/pre>\n<p>where &#8220;your_function_name&#8221; is the name of the function to be called. The function is passed 2 arguments in the following order:-<\/p>\n<pre class=\"lang:php decode:true\">function your_function_name( $location, $privacy ){\r\n\r\n\/\/return your custom location\r\n\r\nreturn $location;\/\/modify and return your own location\r\n\r\n}\r\n<\/pre>\n<ul>\n<li>$location:- the location where the visitor will be redirected if you do not modify it<\/li>\n<li>$privacy:- one of the privacy levels,. Possible values are (&#8216;public&#8217;, &#8216;friends&#8217;,&#8217;self&#8217;)<\/li>\n<\/ul>\n<h3>Example 1:- Redirect to a page on site if a user can not access the profile.<\/h3>\n<pre class=\"lang:php decode:true\">function buddydev_visibility_global_redirect( $location, $privacy ) {\r\n\r\n\t$location = \"http:\/\/example.com\/some-global-page\";\/\/please change it\r\n\r\n\treturn $location;\r\n}\r\n\r\nadd_filter( 'bp_profile_visibility_redirect_location', 'buddydev_visibility_global_redirect', 10, 2 );\r\n<\/pre>\n<h3>Example 2:- Based on privacy level, Redirect to different page when the profile access is denied<\/h3>\n<pre class=\"lang:php decode:true \">\/\/ Conditionally redirect to page based on privacy.\r\nfunction buddydev_visibility_conditionally_redirect( $location, $privacy ) {\r\n\r\n\tif ( $privacy == 'loggedin' ) {\r\n\t\t$location = \"http:\/\/example.com\/explanation-page-that-user-must-be-loggedin\/\";\r\n\t} elseif ( $privacy == 'friends' ) {\r\n\t\t$location = \"http:\/\/example.com\/page-explaining-that-only-friends-can-see-this-user\";\r\n\t}\r\n\r\n\treturn $location;\r\n}\r\n\r\nadd_filter( 'bp_profile_visibility_redirect_location', 'buddydev_visibility_conditionally_redirect', 10, 2 );\r\n<\/pre>\n<p>You can put these code in your bp-custom.php or in your theme&#8217;s functions.php<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you are using BuddyPress Profile visibiliy manager plugin, the plugin allows users to set their profile to various privacy levels. If a user does not meet the visibility requirement and tries to visit other user&#8217;s profile, he gets redirected to the referrer page(last page from where he clicked the link). If the referrer page &#8230;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5691],"tags":[],"class_list":["clearfix","post-35","post","type-post","status-publish","format-standard","hentry","category-bp-profile-visibility-manager"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.9 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Redirect Users to specific page when they can not view the profile &#8226; BuddyDev Help Center<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/buddydev.com\/docs\/bp-profile-visibility-manager\/redirect-users-to-specific-page-when-they-can-not-view-the-profile\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Redirect Users to specific page when they can not view the profile &#8226; BuddyDev Help Center\" \/>\n<meta property=\"og:description\" content=\"If you are using BuddyPress Profile visibiliy manager plugin, the plugin allows users to set their profile to various privacy levels. If a user does not meet the visibility requirement and tries to visit other user&#8217;s profile, he gets redirected to the referrer page(last page from where he clicked the link). If the referrer page ...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/buddydev.com\/docs\/bp-profile-visibility-manager\/redirect-users-to-specific-page-when-they-can-not-view-the-profile\/\" \/>\n<meta property=\"og:site_name\" content=\"BuddyDev Help Center\" \/>\n<meta property=\"article:published_time\" content=\"2013-10-20T21:28:31+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-02-26T18:52:59+00:00\" \/>\n<meta name=\"author\" content=\"Brajesh Singh\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Brajesh Singh\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/buddydev.com\/docs\/bp-profile-visibility-manager\/redirect-users-to-specific-page-when-they-can-not-view-the-profile\/\",\"url\":\"https:\/\/buddydev.com\/docs\/bp-profile-visibility-manager\/redirect-users-to-specific-page-when-they-can-not-view-the-profile\/\",\"name\":\"Redirect Users to specific page when they can not view the profile &#8226; BuddyDev Help Center\",\"isPartOf\":{\"@id\":\"https:\/\/buddydev.com\/docs\/#website\"},\"datePublished\":\"2013-10-20T21:28:31+00:00\",\"dateModified\":\"2018-02-26T18:52:59+00:00\",\"author\":{\"@id\":\"https:\/\/buddydev.com\/docs\/#\/schema\/person\/4ebf5f3e519f8cbddc6583e182dbe4fb\"},\"breadcrumb\":{\"@id\":\"https:\/\/buddydev.com\/docs\/bp-profile-visibility-manager\/redirect-users-to-specific-page-when-they-can-not-view-the-profile\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/buddydev.com\/docs\/bp-profile-visibility-manager\/redirect-users-to-specific-page-when-they-can-not-view-the-profile\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/buddydev.com\/docs\/bp-profile-visibility-manager\/redirect-users-to-specific-page-when-they-can-not-view-the-profile\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/buddydev.com\/docs\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Redirect Users to specific page when they can not view the profile\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/buddydev.com\/docs\/#website\",\"url\":\"https:\/\/buddydev.com\/docs\/\",\"name\":\"BuddyDev Help Center\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/buddydev.com\/docs\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/buddydev.com\/docs\/#\/schema\/person\/4ebf5f3e519f8cbddc6583e182dbe4fb\",\"name\":\"Brajesh Singh\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/buddydev.com\/docs\/#\/schema\/person\/image\/\",\"url\":\"\/\/www.gravatar.com\/avatar\/2106622ee90d53d15ac1402806616aca?s=96&#038;r=g&#038;d=identicon\",\"contentUrl\":\"\/\/www.gravatar.com\/avatar\/2106622ee90d53d15ac1402806616aca?s=96&#038;r=g&#038;d=identicon\",\"caption\":\"Brajesh Singh\"},\"sameAs\":[\"http:\/\/buddydev.com\/members\/sbrajesh\/\",\"https:\/\/x.com\/sbrajesh\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Redirect Users to specific page when they can not view the profile &#8226; BuddyDev Help Center","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/buddydev.com\/docs\/bp-profile-visibility-manager\/redirect-users-to-specific-page-when-they-can-not-view-the-profile\/","og_locale":"en_US","og_type":"article","og_title":"Redirect Users to specific page when they can not view the profile &#8226; BuddyDev Help Center","og_description":"If you are using BuddyPress Profile visibiliy manager plugin, the plugin allows users to set their profile to various privacy levels. If a user does not meet the visibility requirement and tries to visit other user&#8217;s profile, he gets redirected to the referrer page(last page from where he clicked the link). If the referrer page ...","og_url":"https:\/\/buddydev.com\/docs\/bp-profile-visibility-manager\/redirect-users-to-specific-page-when-they-can-not-view-the-profile\/","og_site_name":"BuddyDev Help Center","article_published_time":"2013-10-20T21:28:31+00:00","article_modified_time":"2018-02-26T18:52:59+00:00","author":"Brajesh Singh","twitter_misc":{"Written by":"Brajesh Singh","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/buddydev.com\/docs\/bp-profile-visibility-manager\/redirect-users-to-specific-page-when-they-can-not-view-the-profile\/","url":"https:\/\/buddydev.com\/docs\/bp-profile-visibility-manager\/redirect-users-to-specific-page-when-they-can-not-view-the-profile\/","name":"Redirect Users to specific page when they can not view the profile &#8226; BuddyDev Help Center","isPartOf":{"@id":"https:\/\/buddydev.com\/docs\/#website"},"datePublished":"2013-10-20T21:28:31+00:00","dateModified":"2018-02-26T18:52:59+00:00","author":{"@id":"https:\/\/buddydev.com\/docs\/#\/schema\/person\/4ebf5f3e519f8cbddc6583e182dbe4fb"},"breadcrumb":{"@id":"https:\/\/buddydev.com\/docs\/bp-profile-visibility-manager\/redirect-users-to-specific-page-when-they-can-not-view-the-profile\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/buddydev.com\/docs\/bp-profile-visibility-manager\/redirect-users-to-specific-page-when-they-can-not-view-the-profile\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/buddydev.com\/docs\/bp-profile-visibility-manager\/redirect-users-to-specific-page-when-they-can-not-view-the-profile\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/buddydev.com\/docs\/"},{"@type":"ListItem","position":2,"name":"Redirect Users to specific page when they can not view the profile"}]},{"@type":"WebSite","@id":"https:\/\/buddydev.com\/docs\/#website","url":"https:\/\/buddydev.com\/docs\/","name":"BuddyDev Help Center","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/buddydev.com\/docs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/buddydev.com\/docs\/#\/schema\/person\/4ebf5f3e519f8cbddc6583e182dbe4fb","name":"Brajesh Singh","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/buddydev.com\/docs\/#\/schema\/person\/image\/","url":"\/\/www.gravatar.com\/avatar\/2106622ee90d53d15ac1402806616aca?s=96&#038;r=g&#038;d=identicon","contentUrl":"\/\/www.gravatar.com\/avatar\/2106622ee90d53d15ac1402806616aca?s=96&#038;r=g&#038;d=identicon","caption":"Brajesh Singh"},"sameAs":["http:\/\/buddydev.com\/members\/sbrajesh\/","https:\/\/x.com\/sbrajesh"]}]}},"_links":{"self":[{"href":"https:\/\/buddydev.com\/docs\/wp-json\/wp\/v2\/posts\/35","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/buddydev.com\/docs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/buddydev.com\/docs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/buddydev.com\/docs\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/buddydev.com\/docs\/wp-json\/wp\/v2\/comments?post=35"}],"version-history":[{"count":7,"href":"https:\/\/buddydev.com\/docs\/wp-json\/wp\/v2\/posts\/35\/revisions"}],"predecessor-version":[{"id":961,"href":"https:\/\/buddydev.com\/docs\/wp-json\/wp\/v2\/posts\/35\/revisions\/961"}],"wp:attachment":[{"href":"https:\/\/buddydev.com\/docs\/wp-json\/wp\/v2\/media?parent=35"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/buddydev.com\/docs\/wp-json\/wp\/v2\/categories?post=35"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/buddydev.com\/docs\/wp-json\/wp\/v2\/tags?post=35"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}