I’m added some codes to a custom template in Participants Database, a WordPress plugin and it’s giving me a critical error. I’m totally new to php, so I’m a bit clueless. Thanks for your help!
You also seem to be mixing your if/endif clauses - you use an open-brace { at the start of your if() clause, but use endif; at the end. While I only have experience of using braces, the documentation suggests that the alternate structures cannot be mixed, so you must either use if() { ... } or if() : ... endif'. You also don’t have a ; after each endif, but I’m not sure if that matters when you’re closing PHP immediately afterwards.
As you only have a single statement inside each if(), technically you don’t need braces at all, but I tend to use them because it saves remembering to add them in if I add another statement.
What difference has that made to your error message(s), whatever it was / they were?
Thanks for your help!
Originally I have another condition in there to say if the value>0 but I decided I didn’t need it because if it’s 0, it can just add the 0 to the points.
Unfortunately, there’s no change to the critical error message.
Unfortunately, there’s also no change to the fact that you haven’t told us what that critical error message says. I can’t help any further until you do that. We can try things all day, and then maybe your error message is complaining about something entirely unrelated.
Oh, that’s interesting, I hadn’t picked up on those being variable names. Come to that, spaces wouldn’t be ideal, either, if I’m reading it correctly.
shouldn’t there be () on the end to denote that these are functions? I haven’t done a massive amount with OO, and nothing with Wordpress, but I thought that the parentheses were required even when there are no parameters to be passed to the function. And presumably there are no syntax errors in the definition of those two functions.
But, we’re all guessing, when the critical error message would probably tell us (a) what the error is, and (b) what line it is on.
The You’ve encountered a critical error message is what I get if I try to link to the web page with the shortcode that points to this program. That’s all it says. The Participant Database developer said that means it found the program but there are syntax errors in it. I have the Participant Database debugger on, but it doesn’t act like it sees me linking to the program – nothing shows up in the log.
I got this idea of using field-group in the code above before the while loop for inside the group
but now I see that I can just refer to it as group, so the first line becomes:
I’ll have to see if that clears the error. My system is down right now.
I’m not sure which space is.a problem. I see spaces throughout the codes that was originally there in the template, so I think that’s ok.
I see what you mean with the (). I see now that all the print ends with a (), so it should be:
Well, thanks to everyone, the critical error message is gone.
However, it didn’t do anything I tried to get it to do. No printing of any points.
I just realized I should initiate the fields I’m calculating, so I’m putting them before the first while loop. There are 2 loops. The program loops through the field groups, and within each group is all the fields in that group.
<?php
// Beware: should not be set on live server
error_reporting(-1);
ini_set('display_errors', 'true’);
// your code
// display Objects arrays, variables, etc
echo '<pre>'; print_r($variable); echo '</pre>'; // pre adds line-feeds
die('Stopped processing here ==> ' .__line__);
It’s not clear to us, as we don’t have the full code to see it in context.
But you will use $this to make something belong to the object of the current class you are working in, be that an object’s property (variable) or an object’s method (function).
Certainly, you should have error reporting on, or we are all fumbling in the dark.
Ok, I’ll add $this-> in front of the variables where I add values.
How do I add the print definition? I thought it’s automatic when you put print_ in front of the variable.