Skip to content

Instantly share code, notes, and snippets.

@rickalday
Last active June 19, 2024 14:39
Show Gist options
  • Save rickalday/0c93e542144d93de78fccee6413da11e to your computer and use it in GitHub Desktop.
Save rickalday/0c93e542144d93de78fccee6413da11e to your computer and use it in GitHub Desktop.
Fixes GiveWP issue with missing firstName
<?php
function give_upgrades_donor_name() {
// Adjust the number in the next line if you have more than 9999 donors
$donors = Give()->donors->get_donors(['number' => 9999,]);
if ( $donors ) {
// Loop through Donors
foreach ( $donors as $donor ) {
$donor_name = explode( ' ', $donor->name, 2 );
$donor_first_name = Give()->donor_meta->get_meta( $donor->id, '_give_donor_first_name' );
$donor_last_name = Give()->donor_meta->get_meta( $donor->id, '_give_donor_last_name' );
// If first name meta of donor is not created, then create it.
if ( ! $donor_first_name && isset( $donor_name[0] ) ) {
Give()->donor_meta->add_meta( $donor->id, '_give_donor_first_name', $donor_name[0] );
}
// If last name meta of donor is not created, then create it.
if ( ! $donor_last_name && isset( $donor_name[1] ) ) {
Give()->donor_meta->add_meta( $donor->id, '_give_donor_last_name', $donor_name[1] );
}
// If Donor is connected with WP User then update user meta.
if ( $donor->user_id ) {
if ( isset( $donor_name[0] ) ) {
update_user_meta( $donor->user_id, 'first_name', $donor_name[0] );
}
if ( isset( $donor_name[1] ) ) {
update_user_meta( $donor->user_id, 'last_name', $donor_name[1] );
}
}
}
}
}
add_action('init', 'give_upgrades_donor_name');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment