Good morning,
I’m unfamiliar with debugging and diagnosing PHP issues (surface-level knowledge at best). I have a client who, from a previous developer, has some custom functions setup in their theme’s functions.php file. One of these functions send an event certificate once a certain product has been purchased to the attendees of said event.
Recently, after upgrading our child theme and running through a few other updates, we’re getting a PHP warning displayed on this page. The emails still send out as expected, however I wanted to check in on this warning before it potentially became a bigger issue.
The warnings are as follows:
Warning: Use of undefined constant purchaser_name – assumed
‘purchaser_name’ (this will throw an Error in a future version of PHP)
in
/public_html/wp-content/themes/hr-advisor-child/functions.php
on line 293Warning: Use of undefined
constant purchaser_email – assumed ‘purchaser_email’ (this will throw
an Error in a future version of PHP) in
/public_html/wp-content/themes/hr-advisor-child/functions.php
on line 294Warning: Use of undefined
constant ticket_name – assumed ‘ticket_name’ (this will throw an Error
in a future version of PHP) in
/public_html/wp-content/themes/hr-advisor-child/functions.php
on line 295Warning: count(): Parameter
must be an array or an object that implements Countable in
/public_html/wp-content/plugins/wp-mail-log/classes/capture-mail.php
on line 23
-> Sent to Jordan Lovelle<redacted]>.
The code for this function is as follows:
function send_certificate($request)
{
$event_id = $request['event_id'];
$event_name = urlencode(get_the_title($event_id));
$event_date = tribe_get_start_date($event_id, false, 'jS F Y');
$wootickets = Tribe__Tickets_Plus__Commerce__WooCommerce__Main::get_instance();
$attendees = $wootickets->get_attendees_by_id( $event_id );
echo "Sending certificate. rn";
echo "============================rnrn";
foreach ( (array) $attendees as $attendee ) {
if ( $attendee['check_in'] == 1 ) {
$attendee_name = $attendee[purchaser_name];
$attendee_email = $attendee[purchaser_email];
$event_subtitle = $attendee[ticket_name];
$dataArray = array(
"name"=>$attendee_name,
"event_name"=>$event_name,
);
$url = "https://<redacted>/wp-content/themes/hr-advisor-child/certificate/getPDF.php?" . http_build_query($dataArray, '', '&', PHP_QUERY_RFC3986);
error_log($url);
$certificate = url_get_contents($url);
file_put_contents(get_stylesheet_directory() . "/certificate/certificate.pdf", $certificate);
$to = $attendee_email;
$subject = "Here's your certificate from the event";
$headers[] = 'From: <redacted> <no-reply@<redacted>>';
$headers[] = 'Content-Type: text/html; charset=UTF-8';
$message = file_get_contents(get_stylesheet_directory() . "/certificate/email.php");
wp_mail( $to, $subject, $message, $headers, get_stylesheet_directory() . "/certificate/certificate.pdf" );
echo " -> Sent to $attendee_name<$attendee_email>.rn";
}
}
echo "rnrn============================rn";
echo "All done. rn";
exit();
}
Any help to understand why these warnings occur and how to fix it would be very much appreciated.
Thanks,
Jordan.
2
Answers
The problem here is, the data you are getting is blank or not defined. Please put below condition to resolve the warning:
For the count warning, make sure to use data as an array.
As the warning says, you probably want to do what it assumed for you.
Change
to