Solved

Defining functions in the WordPress functions.php file

Posted on 2016-08-20
3
87 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 110

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

Report: Liquid Web beats Amazon, Rackspace & More

A study by performance analyst firm Cloud Spectator finds that Liquid Web beats rivals Amazon, Rackspace and DigitalOcean when it comes to website and cloud application performance.

Question has a verified solution.

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

Suggested Solutions

I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
In order to have all security and back ups taken care of, WordPress users can sign up for services with WP Engine.
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 purpose of this video is to demonstrate how to set up basic WordPress SEO. This will be demonstrated using a Windows 8 PC. The plugin used will be WordPress SEO by Yoast. Go to your WordPress login page. This will look like the following: myw…

752 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