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.

Need help – very basic scripting doesnt work

Home Forums Community Forum Need help – very basic scripting doesnt work

This topic contains 4 replies, has 2 voices. Last updated by  John Asanga 3 years, 5 months ago.

Topic Author Topic
Posted: Tuesday Jul 30th, 2013 at 2:40 pm #54404
John Asanga
Username: imeea

I added this to my child theme functions.php.
Anyone knows why this will not allow the members page but block the person from seeing details of other people?
Thanks so much!

add_action (“wp”, “my_custom_capabilities”, 1);
function my_custom_capabilities() {
$allowed = TRUE;

if (fnmatch (“/members”, $_SERVER[“REQUEST_URI”]) && !current_user_can(“access_s2member_level2”)) {
$allowed = TRUE;
}

if (fnmatch (“/members/[abcdefghijklmnopqrstuvwxyz1234567890]”, $_SERVER[“REQUEST_URI”]) && !current_user_can (“access_s2member_level2”))
{
$allowed = FALSE;
}

if (fnmatch (“/members/”.S2MEMBER_CURRENT_USER_LOGIN, $_SERVER[“REQUEST_URI”]) && !current_user_can (“access_s2member_level2”))
{
$allowed = TRUE;
}

// If any of the URIs above matched, but the user did not have the necessary ccap, redirect to Membership Options.

if (FALSE === $allowed) {
header (“Location: ” . S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL);
exit (); }
}

List Of Topic Replies

Viewing 4 replies - 1 through 4 (of 4 total)
Author Replies
Author Replies
Posted: Tuesday Jul 30th, 2013 at 10:44 pm #54438
Moderator

It might be a caSe issue. Please see FNM_CASEFOLD here:
http://php.net/manual/en/function.fnmatch.php

if (fnmatch ("/members/".S2MEMBER_CURRENT_USER_LOGIN, $_SERVER["REQUEST_URI"], FNM_CASEFOLD)
 && !current_user_can (“access_s2member_level2″))
	{
		$allowed = TRUE;
	}
Posted: Wednesday Jul 31st, 2013 at 12:50 am #54452
John Asanga
Username: imeea

Thanks so much.

I just located the problem.
The constants are not working in my functions.php

echo S2MEMBER_CURRENT_USER_LOGIN; is simply outputing the string S2MEMBER_CURRENT_USER_LOGIN

please do you know how to make the constants work?

Thanks

Posted: Wednesday Jul 31st, 2013 at 8:58 am #54492
Moderator

The key with those is to be sure that you’re testing from within the action hook and not before.

In your code, this line is correct.

add_action (“wp”, “my_custom_capabilities”, 1);

Once that action is fired, and your routine runs; the s2Member® API Constants should be available. Are you sure that when you tested it was from within that function and after the action was fired by WordPress?

Posted: Thursday Aug 1st, 2013 at 2:25 am #54586
John Asanga
Username: imeea

Hi Mike,
Thanks for helping with this.
No it wasn’t. Thanks for pointing that out. But now that I try that in the function, I dont get any anything returned.
Am I supposed to make some settings elsewhere before this works?Also, do you know which one gets read first between this and the page uri restrictions settings in the admin panel?

Thanks so much

Viewing 4 replies - 1 through 4 (of 4 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.