Skip to content

Instantly share code, notes, and snippets.

@verygoodplugins
Last active June 29, 2023 11:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save verygoodplugins/da0ef3dc536d3ed35b5091ba6d3d7532 to your computer and use it in GitHub Desktop.
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"
<?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