Untitled
unknown
plain_text
2 years ago
1.4 kB
4
Indexable
// Add the 'User is Partner' checkbox to the user profile (admin backend)
function add_partner_user_profile_field($user) {
// Get the value of the meta key 'is_partner'
$is_partner = get_user_meta($user->ID, 'is_partner', true);
?>
<h3>Partner Status</h3>
<table class="form-table">
<tr>
<th><label for="is_partner">User is Partner</label></th>
<td>
<input type="checkbox" name="is_partner" id="is_partner" value="1" <?php checked($is_partner, 1); ?> />
<span class="description">Check if the user is a partner.</span>
</td>
</tr>
</table>
<?php
}
add_action('show_user_profile', 'add_partner_user_profile_field', 999);
add_action('edit_user_profile', 'add_partner_user_profile_field', 999);
// Save the 'User is Partner' checkbox value
function save_partner_user_profile_field($user_id) {
// Check if the current user has permission to edit the user
if (!current_user_can('edit_user', $user_id)) {
return false;
}
// Update the 'is_partner' metadata with the checkbox value
update_user_meta($user_id, 'is_partner', isset($_POST['is_partner']) ? '1' : '0');
}
add_action('personal_options_update', 'save_partner_user_profile_field');
add_action('edit_user_profile_update', 'save_partner_user_profile_field');Editor is loading...
Leave a Comment