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.

add_action error: help – pretty please!

Home Forums Community Forum add_action error: help – pretty please!

This topic contains 8 replies, has 3 voices. Last updated by  Suzan Romanov 3 years, 10 months ago.

Topic Author Topic
Posted: Monday Feb 11th, 2013 at 9:45 am #41400

First, I appreciate anyone that could help… 3 sleepless nights and counting – LOL! This is pretty detailed, but trying to save time by putting everything I could think of.

Thank you again for helping me out. XO.

****************************************************************************

So here’s the story…

Have 4 products that customers can buy… in any combination. So let’s say that are A, B, C, D. So a customer can buy A and C, or just A, or C, D, and A. You get the point.

So I watched the custom capabilities video this one (https://www.youtube.com/watch?v=h7zBH938VbA), added the code, and now…

I’m getting this error:

Fatal error: Call to undefined function add_action() in /home/sbsystm/public_html/member/wp-includes/functions.php on line 12

What’s going on???

Here’s the site on my working: http://member.musicindustrycontacts.biz/

And here’s the code I added to the functions.php file:

==============================================================

add_action (“wp”, “my_custom_capabilities”);

function my_custom_capabilities ()
{

if(has_tag(“A”) && !current_user_can (“access_s2member_ccap_A”))
{
header (“Location: “. S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL);
exit ();
}

else if(has_tag(“B”) && !current_user_can (“access_s2member_ccap_B”))
{
header (“Location: “. S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL);
exit ();
}

else if(has_tag(“C”) && !current_user_can (“access_s2member_ccap_C”))
{
header (“Location: “. S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL);
exit ();
}

else if(has_tag(“D”) && !current_user_can (“access_s2member_ccap_D”))
{
header (“Location: “. S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL);
exit ();
}
====================================================================

*note: (in a forum topic that said the add_action line was outdated so I used the line I saw in the forum, so it looks a bit different than what’s in the youtube video.

I know I’m a novice at the programming stuff but what is happening here??? Instructions seem pretty basic but it just not working.

Not sure… but something is missing?

Please help!!

*Kisses.

List Of Topic Replies

Viewing 8 replies - 1 through 8 (of 8 total)
Author Replies
Author Replies
Posted: Tuesday Feb 12th, 2013 at 10:07 am #41565
Eduan
Username: Eduan
Moderator

Hello Suzan,

Seems that for whatever reason a couple of users have reported this error.

Could you please tell us your WordPress version and s2Member version? It would also help a lot if you could please try all of these common troubleshooting tips: Knowledge Base » Common Troubleshooting Tips

– Eduan

Posted: Tuesday Feb 12th, 2013 at 10:48 am #41566

Hey Eduan – thanks soooo much for getting back on this.

Been pulling my hair out!

Ok so…

Wordpress Version: 3.5.1
S2 Member Version: Version 130203

If it’s any help, when I take this line out of the functions.php file, the site works as in no fatal error (although the custom capabilities don’t work either)
add_action (“template_redirect”, “my_custom_capabilities”);

But as soon as I add this line to the functions.php file, it gets the fatal error.

Again, replaced, the “template_redirect” part with “wp” based off another post, but same error.

I will check out the references you sent, and look out for your next reply.

Thanks again in advance for your help on this one.

Posted: Tuesday Feb 12th, 2013 at 12:08 pm #41573

Also Eduan, to add to my last reply – I’m using the free version if that’s what you’re asking as well.

Thanks again.

Posted: Thursday Feb 14th, 2013 at 7:38 pm #41735
Eduan
Username: Eduan
Moderator

Thanks for that Suzan. :)

I’m gonna ask Jason about this to make sure it’s not caused by s2Member.

Did you try the troubleshooting tips?

– Eduan

Posted: Thursday Feb 14th, 2013 at 8:14 pm #41741
Staff Member

Thanks for the heads up on this thread :-)

Fatal error: Call to undefined function add_action() in /home/sbsystm/public_html/member/wp-includes/functions.php on line 12

Are you opening functions.php as a stand-alone file? This file is included by WordPress®. The add_action() function is part of the WordPress® core, and it will always be available inside functions.php, so long as this file is loaded by WordPress® because it’s part of your theme.

If you want to test scripts that you write, add this line to the top of your PHP script (which includes the WordPress® core). But please note… this is NOT required inside functions.php, because that file should only be loaded by WordPress® and not opened in a browser; and thus, WordPress® is already loaded up in this case.

include_once 'wp-load.php';

See also: Knowledge Base » Protecting Non-WordPress Content with s2Member

Posted: Thursday Feb 14th, 2013 at 11:27 pm #41757

Hey Jason, and thank you Eduan. I know you’re busy guys so I appreciate the time you’ve spent on this so far.

Also, yes Eduan – I tried the trouble shooting you suggested. Tried deactivating plugins, different themes, etc… and nothing.

So Jason – I’ll be honest that I’m a bit novice, but know enough to find the files, and feel my way around.

I added the code below to the functions.php file. I located the functions.php file in the wp-includes folder through my FTP.

Just assumed it would work fine.

Here’s the code below.

Just feel like I’m missing something really BIG and obvious. Let me know what you think. I’m still trying different things, and made sure to make a backup of the functions.php file in case i really mess something up.

Thanks again guys!

P.S. Jason, whenever I take this line out from the functions.php file (add_action (“wp”, “my_custom_capabilities”);) – the fatal error goes away. but then the custom capabilities functions don’t seem to work either.

Appreciate you’re help again.

==============================================================

add_action (“wp”, “my_custom_capabilities”);

function my_custom_capabilities ()
{

if(has_tag(“A”) && !current_user_can (“access_s2member_ccap_A”))
{
header (“Location: “. S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL);
exit ();
}

else if(has_tag(“B”) && !current_user_can (“access_s2member_ccap_B”))
{
header (“Location: “. S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL);
exit ();
}

else if(has_tag(“C”) && !current_user_can (“access_s2member_ccap_C”))
{
header (“Location: “. S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL);
exit ();
}

else if(has_tag(“D”) && !current_user_can (“access_s2member_ccap_D”))
{
header (“Location: “. S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL);
exit ();
}
====================================================================

Posted: Friday Feb 22nd, 2013 at 12:02 pm #42850

Hey guys – thanks again for your help on this stuff.

Honestly I just can’t seem to figure out what to do to make this work.

I found this post that seems to have a similar logic.
http://www.s2member.com/forums/topic/custom-capabilities-assistance-please/

And in my previous post I cut and pasted the exact code I’m using…. pasted it below again.

I’m putting the code inside of the functions.php file inside of the wp_include folder through my ftp client.

****THE END GOAL****

I have 4 different products that customers can buy in any combination.

All I want to do is to be able to let them purchase one of the products, or two, or three, or all four.

If not getting all four, they should have the option of purchase 2 or 3 in any combination… or purchase just one.

I’ve labelled each product A, B, C, D.

So a customer can purshase A and B, or A, C, and D, or just D, or just C, and so on… I think you get the point.

Here’s my code below again…

***What Am I missing in my thinking???***

Thanks again!!!

****CODE INSIDE OF THE FUNCTIONS.PHP FILE*****

add_action (“wp”, “my_custom_capabilities”);

function my_custom_capabilities ()
{

if(has_tag(“A”) && !current_user_can (“access_s2member_ccap_A”))
{
header (“Location: “. S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL);
exit ();
}

else if(has_tag(“B”) && !current_user_can (“access_s2member_ccap_B”))
{
header (“Location: “. S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL);
exit ();
}

else if(has_tag(“C”) && !current_user_can (“access_s2member_ccap_C”))
{
header (“Location: “. S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL);
exit ();
}

else if(has_tag(“D”) && !current_user_can (“access_s2member_ccap_D”))
{
header (“Location: “. S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL);
exit ();
}
====================================================================

Posted: Friday Feb 22nd, 2013 at 12:08 pm #42851

Hey, I just posted this, but noticed I didn’t wrap the code lines using the code button. Thanks again!

=====================================

Hey guys – thanks again for your help on this stuff.

Honestly I just can’t seem to figure out what to do to make this work.

I found this post that seems to have a similar logic.
http://www.s2member.com/forums/topic/custom-capabilities-assistance-please/

And in my previous post I cut and pasted the exact code I’m using…. pasted it below again.

I’m putting the code inside of the functions.php file inside of the wp_include folder through my ftp client.

****THE END GOAL****

I have 4 different products that customers can buy in any combination.

All I want to do is to be able to let them purchase one of the products, or two, or three, or all four.

If not getting all four, they should have the option of purchase 2 or 3 in any combination… or purchase just one.

I’ve labelled each product A, B, C, D.

So a customer can purshase A and B, or A, C, and D, or just D, or just C, and so on… I think you get the point.

Here’s my code below again…

***What Am I missing in my thinking???***

Thanks again!!!

****CODE INSIDE OF THE FUNCTIONS.PHP FILE*****

add_action (“wp”, “my_custom_capabilities”);

function my_custom_capabilities ()
{

if(has_tag(“A”) && !current_user_can (“access_s2member_ccap_A”))
{
header (“Location: “. S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL);
exit ();
}

else if(has_tag(“B”) && !current_user_can (“access_s2member_ccap_B”))
{
header (“Location: “. S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL);
exit ();
}

else if(has_tag(“C”) && !current_user_can (“access_s2member_ccap_C”))
{
header (“Location: “. S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL);
exit ();
}

else if(has_tag(“D”) && !current_user_can (“access_s2member_ccap_D”))
{
header (“Location: “. S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL);
exit ();
}

====================================================================

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.