Solved

Defining functions in the WordPress functions.php file

Posted on 2016-08-20
3
46 Views
Last Modified: 2016-08-21
I  tried to define a function in my functions.php file as below:

function here ($place) { // dbgsa
	$debug = get_post_meta( $order_id, 'debug', true );
     $debug .= $place';
	update_post_meta($order_id, 'debug', $debug);
}

Open in new window


The plan was then to call this from inside various action hook functions to have a record of how control passed through the code. So there might be something like:

here use
Then if G was in the string I knew I went through that point in the code.   But this doesn't work.  here() doesn't appear to get entered.  Does anyone see the problem?

Thanks
0
Comment
Question by:steva
3 Comments
 
LVL 35

Accepted Solution

by:
Terry Woods earned 250 total points
ID: 41764235
In your "here" function, the $order_id variable is undefined I believe. If you need it, then you need it to be passed through as another parameter.

If that still doesn't work, to help track down the problem it might be worth adding something to the start of the "here" function that's guaranteed to work, such as "die('Made it here!');". That would help you confirm the function is being called.
1
 
LVL 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 250 total points
ID: 41764242
This appears to be the relevant man page:
https://codex.wordpress.org/Functions_File_Explained

I agree with Terry -- all of the dependencies need to be injected into the function scope.  And you would want to put here()  somewhere that is not inside any conditional control structure.
0
 

Author Comment

by:steva
ID: 41764354
Yes!  Of course. $order_id needs to be passed in, and then it works.   My bad.  I thought I was fighting some corner case of the WordPress functions.php file and overlooked the simple.

BTW, I don't think "die('Made it here!');". would work because the page doesn't get displayed. That's why I can't just  echo debug comments.

And you would want to put here()  somewhere that is not inside any conditional control structure.  Actually, no. The whole point is to see if control made it through those conditional structures.

Thanks for your help.  I split the points.
0

Featured Post

Easy Project Management (No User Manual Required)

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
The purpose of this video is to demonstrate how to exclude a particular blog category from the main blog page. This is can be used when a category already has its own tab, or you simply want certain types of posts not to show up on the main blog. …

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now