latest stable versions: v150827 (changelog)

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

URI Restriction for BuddyPress profile

Home Forums Community Forum URI Restriction for BuddyPress profile

This topic contains 8 replies, has 3 voices. Last updated by  Richard Wells 4 years, 7 months ago.

Topic Author Topic
Posted: Tuesday May 22nd, 2012 at 12:45 pm #14189

I am trying to implement a URI restriction for BuddyPress profiles. I have tried /members/ but that restricts too much. I have tried /profile/ but that restricts too little. I want the Goldilocks option: show the list of members but not individual profile content.

Looking at the URL for the view I want to restrict the URI fragment would be, in effect, /members/username of displayed profile/. I have tried replacement codes like %%displayed_user_login%% but that does not work. Is there any way to do this?

List Of Topic Replies

Viewing 8 replies - 1 through 8 (of 8 total)
Author Replies
Author Replies
Posted: Wednesday May 23rd, 2012 at 11:07 am #14333

I think I have found a way to do this! But it involves a hack:

I have created my own custom Replacement Code %%displayed_username%% and added it in wp-content/plugins/s2member/includes/classes/ruris.inc.php:

$uris = (strlen ($displayed_username)) ? preg_replace ("/%%displayed_username%%/i", c_ws_plugin__s2member_utils_strings::esc_ds ($displayed_username), $uris) : $uris;

I extracted the value for $displayed_username from the URL of the page using $_SERVER[“REQUEST_URI”].

$displayed_username = str_replace("/members/", "", $_SERVER["REQUEST_URI);
$slash = strpos($displayed_username, "/");
$displayed_username = substr_replace($displayed_username, "", $slash);

There must be a neater way to do this, eg using preg_match() but I spent ages trying with no luck!

  • This reply was modified 4 years, 7 months ago by  Richard Wells.
Posted: Thursday May 24th, 2012 at 2:09 am #14396

Ah, I’m glad you could solve it. So it’s working for you now?

A preg_replace would have been better than the preg_match. You could also explode with the slashes and then put it back together.

Posted: Monday May 28th, 2012 at 8:26 am #14809

Yes, it does seem to work. Anyone can view /members/ but only chosen levels can view /members/username of displayed profile/.

I have put the edited contents of ruris.inc.php into /wp-content/mu-plugins/s2-hacks.php so it will not be overwritten when s2Member is updated.

Posted: Tuesday May 29th, 2012 at 7:05 am #14869

Cool. :)

Posted: Monday Jun 4th, 2012 at 5:41 am #15331
bob heyman
Username: bobheyman

Hello

I am new to s2member hacks and php ..I am also looking for same kind of solution . i understand to added
$uris = (strlen ($displayed_username)) ? preg_replace (“/%%displayed_username%%/i”, c_ws_plugin__s2member_utils_strings::esc_ds ($displayed_username), $uris) : $uris;

into wp-content/plugins/s2member/includes/classes/ruris.inc.php but cam you please explain where do i put the rest of the code
$displayed_username = str_replace(“/members/”, “”, $_SERVER[“REQUEST_URI);
$slash = strpos($displayed_username, “/”);
$displayed_username = substr_replace($displayed_username, “”, $slash);

Please help me … Thanks in advance

Posted: Tuesday Jun 5th, 2012 at 4:36 am #15431
bob heyman
Username: bobheyman

OK .. i solved it my self .. I have one more query .. i need to redirect 0level users to upgrade membership page when they click on the any member on Member list ..

Can you help me on this

Posted: Tuesday Jun 5th, 2012 at 7:57 pm #15592

Hi Bob.

You’d have to find a string that matches the user profile URLs and add it to the URI restriction for Level 1.

Posted: Tuesday Jun 12th, 2012 at 12:00 pm #16262

Bob

Confusingly the second bit of code should go before the first in order to set the value for $displayed_username (eg line 101 in my version of ruris.inc.php).

I have then put /members/%%displayed_username%%/ in the box for “URIs That Require Level #0 Or Higher:” in s2Member>Restriction Options>URI Restrictions.

This means when someone clicks a Member in the Member list they are redirected to the upgrade page.

Viewing 8 replies - 1 through 8 (of 8 total)

This topic is closed to new replies. Topics with no replies for 2 weeks are closed automatically.

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Contacting s2Member: Please use our Support Center for bug reports, pre-sale questions & technical assistance.