Solved

Defining functions in the WordPress functions.php file

Posted on 2016-08-20
3
65 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 109

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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
css issues with IE 11 8 36
PHP strings vs array errors 13 23
PHP Syntax Error 4 27
Forms that calculate points for wordpress 10 29
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The purpose of this video is to demonstrate how to Test the speed of a WordPress Website. Site Speed is an important metric of a site’s health. Slow site speed can result in viewers leaving your site quickly and not seeing your content. This…
The purpose of this video is to demonstrate how to set up the permalinks on a WordPress Website. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Go t…

831 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