Solved

Defining functions in the WordPress functions.php file

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The purpose of this video is to demonstrate how to manually back up a WordPress Database. This will be demonstrated using a Windows 8 PC. The Host used will be IPage.com Log into your Hosting account. IPage will be used for demonstration : Locat…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

790 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