Last active
June 6, 2024 09:27
-
-
Save hazratbilal0079/b6a156cf18e7f997cf9ee3ac3015bdab to your computer and use it in GitHub Desktop.
Activate or Deactivate User Account through metafield and Update user Role from Frontend in WordPress with Hook or Code Snippet
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
--Hook Name | |
updateuser | |
--PHP Hook | |
add_action( 'jet-form-builder/custom-action/updateuser', function( $request, $action_handler ) { | |
$user_id = $request['quer_user_id']; | |
$role = $request['user-current-role']; | |
$user_status = $request['user-current-status']; | |
update_user_meta( $user_id, 'user-status', $user_status); | |
if(!empty($role)) | |
{ | |
wp_update_user( array( 'ID' => $user_id, 'role' => $role ) ); | |
} | |
}, 10, 2 ); | |
--Script to get current user ID for the listing in User Table to update user Status or Role | |
and assign user id to field in form in my case that field css class is 'user-current-id' | |
<script type="text/javascript" src="https://code.jquery.com/jquery-3.6.0.min.js"></script> | |
<script> | |
jQuery(document).ready(function($) { | |
// Loop through each table row with the data-item-object attribute | |
$('tr[data-item-object]').each(function() { | |
// Get the value of the data-item-object attribute | |
var itemObjectValue = $(this).data('item-object'); | |
// Find the hidden input field within the same row and set its value | |
$(this).find('.user-current-id').val(itemObjectValue); | |
}); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment