Global variable reset in functions.php
-
I’m trying to extend my child theme’s
functions.php
with 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.php
like so:$bulk_recipients = [];
After much testing I find that
$bulk_recipients
seems 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.php
lifecycle?I’m a beginner dev in WordPress and PHP so sorry if this is a naive question.
TIA.
- This topic was modified 1 year, 10 months ago by .
- This topic was modified 1 year, 10 months ago by .
The page I need help with: [log in to see the link]
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Global variable reset in functions.php’ is closed to new replies.