Example #1
0
function seamless_donations_update_donor_data($old_donation_id, $new_donation_id = '')
{
    // this function creates the donor record. It takes the donation id as a parameter
    // it supports a second donation id for those cases when the donation is updated from a previous donation record,
    // as in the case of a repeating donation
    if ($new_donation_id == '') {
        $new_donation_id = $old_donation_id;
    }
    // Now build in the donor data
    $first = get_post_meta($old_donation_id, '_dgx_donate_donor_first_name', true);
    $last = get_post_meta($old_donation_id, '_dgx_donate_donor_last_name', true);
    // now move that data into a donor post type
    $donor_name = sanitize_text_field($first . ' ' . $last);
    $donor_slug = sanitize_title($donor_name);
    $donor = get_page_by_path($donor_slug, OBJECT, 'donor');
    if ($donor == NULL) {
        // create the new custom donor post
        $donor_array = array('post_title' => $donor_name, 'post_content' => '', 'post_status' => 'publish', 'post_type' => 'donor');
        $donor_id = wp_insert_post($donor_array, true);
    } else {
        $donor_id = $donor->ID;
    }
    // record the donor id in the donation record
    update_post_meta($new_donation_id, '_dgx_donate_donor_id', $donor_id);
    // update the donations to point to this donation id
    seamless_donations_add_donation_id_to_donor($new_donation_id, $donor_id);
    // update the donation total for the donor
    seamless_donations_add_donation_amount_to_donor_total($new_donation_id, $donor_id);
    // update basic donor info
    update_post_meta($donor_id, '_dgx_donate_donor_first_name', $first);
    update_post_meta($donor_id, '_dgx_donate_donor_last_name', $last);
    return $donor_id;
}
Example #2
0
function seamless_donations_rebuild_donor_index()
{
    // first clear out the donations meta items
    $args = array('post_type' => 'donor', 'post_status' => 'publish', 'nopaging' => 'true');
    $posts_array = get_posts($args);
    // loop through a list of donors
    for ($i = 0; $i < count($posts_array); ++$i) {
        // extract the donor id from the donation and fund records
        $donor_id = $posts_array[$i]->ID;
        delete_post_meta($donor_id, '_dgx_donate_donor_donations');
        delete_post_meta($donor_id, '_dgx_donate_donor_total');
    }
    // then loop through the donations
    $args = array('post_type' => 'donation', 'post_status' => 'publish', 'nopaging' => 'true');
    $posts_array = get_posts($args);
    // loop through a list of donations with funds attached
    for ($i = 0; $i < count($posts_array); ++$i) {
        // extract the donor id from the donation and donor records
        $donation_id = $posts_array[$i]->ID;
        $first = get_post_meta($donation_id, '_dgx_donate_donor_first_name', true);
        $last = get_post_meta($donation_id, '_dgx_donate_donor_last_name', true);
        // now move that data into a donor post type
        $donor_name = sanitize_text_field($first . ' ' . $last);
        if ($donor_name != '') {
            // this code, like in funds, assumes the names haven't been changed.
            // todo need additional code to go in and reconstruct ids based on possible new names
            $donor = get_page_by_title($donor_name, 'OBJECT', 'donor');
            $donor_id = $donor->ID;
            // update the donation record with the donor id -- also link the donor to the donations
            update_post_meta($donation_id, '_dgx_donate_donor_id', $donor_id);
            // update the donations list to point to this donation id
            seamless_donations_add_donation_id_to_donor($donation_id, $donor_id);
            // update the donation total for the donor
            seamless_donations_add_donation_amount_to_donor_total($donation_id, $donor_id);
        }
    }
}