Last active
June 29, 2023 11:15
-
-
Save verygoodplugins/da0ef3dc536d3ed35b5091ba6d3d7532 to your computer and use it in GitHub Desktop.
Deletes WordPress user when the "role" field is loaded from the CRM with a value of "deleted"
This file contains 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 | |
// Deletes WordPress user when the "role" field is loaded from the CRM with a value of "deleted" | |
// Works when a webhook is received or a batch Pull User Meta operation is run. | |
function my_wpf_delete_user_by_field( $user_id, $user_meta ) { | |
if ( isset( $user_meta['role'] ) && $user_meta['role'] == 'deleted' && ! user_can( $user_id, 'manage_options' ) ) { | |
require_once( ABSPATH . 'wp-admin/includes/user.php' ); | |
wp_delete_user( $user_id ); | |
wpf_log( 'info', $user_id, 'Deleted user ID ' . $user_id ); | |
} | |
} | |
add_action( 'wpf_user_updated', 'my_wpf_delete_user_by_field', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment