Skip to content

Instantly share code, notes, and snippets.

@ericnicolaas
Created December 31, 2015 03:10
Show Gist options
  • Save ericnicolaas/3a943852a5d2f216ff07 to your computer and use it in GitHub Desktop.
Save ericnicolaas/3a943852a5d2f216ff07 to your computer and use it in GitHub Desktop.
Add Charitable profile fields to admin user profiles
<?php
function pp_add_user_profile_fields( $user ) {
$skip = array( 'first_name', 'last_name', 'user_email', 'description' );
$switch_keys = array(
'address' => 'donor_address',
'address_2' => 'donor_address_2',
'city' => 'donor_city',
'state' => 'donor_state',
'postcode' => 'donor_postcode',
'country' => 'donor_country',
'phone' => 'donor_phone'
);
$profile_form = new Charitable_Profile_Form;
?>
<h3><?php _e( 'Additional profile fields', 'pp-toolkit' ) ?></h3>
<table class="widefat">
<tbody>
<?php foreach ( $profile_form->get_merged_fields() as $key => $field ) : ?>
<?php if ( in_array( $key, $skip ) ) :
continue;
endif;
$meta_key = isset( $switch_keys[ $key ] ) ? $switch_keys[ $key ] : $key;
?>
<tr>
<th><label for=""><?php echo $field[ 'label' ] ?></label></th>
<td><?php echo $user->get( $meta_key ) ?></td>
</tr>
<?php endforeach ?>
</tbody>
</table>
<?php
}
add_action( 'show_user_profile', 'pp_add_user_profile_fields' );
add_action( 'edit_user_profile', 'pp_add_user_profile_fields' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment