Global variable reset in functions.php
-
I’m trying to extend my child theme’s
functions.phpwith a handler for an AJAX call:$selection_has_changed = function () { check_ajax_referer( ACTION_NAME ); $email = $_POST['email']; $checked = $_POST['checked']; $bulk_recipients[$email] = $checked; echo json_encode($bulk_recipients); die(); };Just adding or updating a key-value pair to global dict
$bulk_recipients.The dict is defined at the top of
functions.phplike so:$bulk_recipients = [];After much testing I find that
$bulk_recipientsseems to be reset each time it enters$selection_has_changed. Ie it only ever outputs 1 key-vaue pair.Is there some WordPress “magic” afoot causing this behavior?
Could it be an issue with
functions.phplifecycle?I’m a beginner dev in WordPress and PHP so sorry if this is a naive question.
TIA.
The page I need help with: [log in to see the link]
The topic ‘Global variable reset in functions.php’ is closed to new replies.