This is just a reminder to say your tehillim.
add_action('rest_api_init', function () { register_rest_route('dfm/v1', '/update-reminder', [ 'methods' => 'POST', 'callback' => 'dfm_update_reminder', 'permission_callback' => 'dfm_check_auth', ]); }); function dfm_check_auth(WP_REST_Request $request) { $auth = $request->get_header('authorization'); error_log('DFM auth check | header received: ' . var_export($auth, true)); $valid = $auth === 'HA6MU-feP3cQWPK2b86TlYBSGbQenk_MPOtwCdXufcY'; error_log('DFM auth check | result: ' . ($valid ? 'PASSED' : 'FAILED')); return $valid; } function dfm_test_noauth(WP_REST_Request $request) { $email = sanitize_email($request->get_param('email')); $method = sanitize_text_field($request->get_param('method')); error_log('DFM test_noauth | email: ' . $email . ' | method: ' . $method); return new WP_REST_Response([ 'success' => true, 'received' => [ 'email' => $email, 'method' => $method, ], ], 200); } function dfm_update_reminder(WP_REST_Request $request) { global $wpdb; $email = sanitize_email($request->get_param('email')); $method = sanitize_text_field($request->get_param('method')); error_log('DFM update_reminder | incoming | email: ' . $email . ' | method: ' . $method); if (!$email || !in_array($method, ['email', 'text'], true)) { error_log('DFM update_reminder | REJECTED invalid input | email: ' . $email . ' | method: ' . $method); return new WP_REST_Response(['success' => false, 'error' => 'invalid input'], 400); } $updated = $wpdb->update( $wpdb->base_prefix . 'applyform', ['dailyReminder' => $method], ['email' => $email] ); error_log('DFM update_reminder | wpdb->update result: ' . var_export($updated, true) . ' | last_error: ' . $wpdb->last_error); if ($updated === false) { error_log('DFM update_reminder | DB ERROR for email: ' . $email . ' | ' . $wpdb->last_error); return new WP_REST_Response(['success' => false, 'error' => 'db error'], 500); } if ($updated === 0) { error_log('DFM update_reminder | NO MATCH for email: ' . $email); return new WP_REST_Response(['success' => false, 'error' => 'no matching email found'], 404); } error_log('DFM update_reminder | SUCCESS | email: ' . $email . ' | method: ' . $method . ' | rows affected: ' . $updated); return new WP_REST_Response(['success' => true], 200); }
This is just a reminder to say your tehillim.