Last active
February 29, 2024 09:09
-
-
Save JarrydLong/a1b2e9fa00d6fc5f6c3c63247a2ff120 to your computer and use it in GitHub Desktop.
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 will geocode the members based on their user account only. | |
* Run /wp-admin/?pmpromm_process_users=true to run the script. | |
* | |
* 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 mypmpromm_batch_process_addresses_override_users(){ | |
if( !empty( $_REQUEST['pmpromm_process_users'] ) ){ | |
mypmpromm_batch_process_addresses_users(); | |
} | |
} | |
add_action( 'admin_init', 'mypmpromm_batch_process_addresses_override_users' ); | |
function mypmpromm_batch_process_addresses_users(){ | |
global $wpdb; | |
$api_key = pmpro_getOption( 'pmpromm_api_key' ); | |
if( !empty( $api_key ) && function_exists( 'pmpromm_geocode_address' ) ){ | |
$users = get_users(); | |
foreach( $users as $result ){ | |
$member_address = array( | |
'street' => get_user_meta( $result->ID, 'pmpro_baddress1', true ).' '.get_user_meta( $result->ID, 'pmpro_baddress2', true ), | |
'city' => get_user_meta( $result->ID, 'pmpro_bcity', true ), | |
'state' => get_user_meta( $result->ID, 'pmpro_bstate', true ), | |
'zip' => get_user_meta( $result->ID, 'pmpro_bzipcode', true ) | |
); | |
$coordinates = pmpromm_geocode_address( $member_address ); | |
if( is_array( $coordinates ) ){ | |
update_user_meta( intval( $result->ID ), 'pmpro_lat', $coordinates['lat'] ); | |
update_user_meta( intval( $result->ID ), 'pmpro_lng', $coordinates['lng'] ); | |
} | |
} | |
exit('End'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment