Forked from kimcoleman/duplicate_usermeta_to_xprofile.php
Last active
May 19, 2021 11:34
-
-
Save kimwhite/7748323be0c7e4188f0b9ecf2718cbc2 to your computer and use it in GitHub Desktop.
Duplicate usermeta fields as xprofile fields. Sync BuddyPress and PMPro
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This recipe run a script to sync your PMPro Registration Fields with BuddPress xprofie fields | |
* | |
* Add this to a custom plugin then run by adding this to your domain `/wp-admin/?pmpromm_process=1` | |
* Remove when finished. | |
* You can add this recipe to your site by creating a custom plugin | |
* or using the Code Snippets plugin available for free in the WordPress repository. | |
* Read this companion article for step-by-step directions on either method. | |
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
*/ | |
function mypmpro_batch_process_buddypress_xprofile(){ | |
if( ! empty( $_REQUEST['pmpromm_process'] ) ){ | |
duplicate_usermeta_to_xprofile(); | |
} | |
} | |
add_action( 'admin_init', 'mypmpro_batch_process_buddypress_xprofile' ); | |
function duplicate_usermeta_to_xprofile( ) { | |
global $wpdb; | |
$fields = array( | |
// add your fields here | |
'brother_name'=>'7', // Add your PMPro RH variable name then point to the xprofile field ID | |
'sister_name'=>'8', // Add your PMPro RH variable name then point to the xprofile field ID | |
); | |
foreach ( $fields as $meta_key => $field_ID ) { | |
$sqlQuery = "SELECT * FROM $wpdb->usermeta WHERE meta_key = '" . esc_sql($meta_key) . "' "; | |
$fields = $wpdb->get_results( $sqlQuery ); | |
foreach ( $fields as $field ) { | |
$x_field_data = xprofile_get_field_data( $field_ID, $field->user_id ); | |
if ( empty( $x_field_data ) ) { | |
xprofile_set_field_data( $field_ID, $field->user_id, $field->meta_value ); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment