Untitled

 avatar
unknown
plain_text
2 years ago
1.5 kB
6
Indexable
add_action('wp_head', function(){
	?>
	<script>
		jQuery(document).ready(function(){
			jQuery('#b2bking_super_user_checkbox').on('change', function(){
				if(jQuery(this).prop('checked')) {
			    	jQuery('input[name="b2bking_super_user"]').val('yes');
			    } else {      
			    	jQuery('input[name="b2bking_super_user"]').val('no');
			    }
			});
		});
	</script>
	<?php
});
add_action('b2bking_custom_new_subaccount_fields', function($user_id = 0){
	$val = 'no';
	if ($user_id !== 0){
		$val = get_user_meta($user_id,'superuser', true);
		if (empty($val)){
			$val = 'no';
		}
	}
	?>
	<br>
	<div class="b2bking_subaccounts_new_account_container_content_element">
		<div class="b2bking_subaccounts_new_account_container_content_element_label">
			<?php esc_html_e('Super User','b2bking'); ?>
		</div>
		<input type="checkbox" class="b2bking_subaccounts_new_account_container_content_element_text" id="b2bking_super_user_checkbox" <?php if ($val === 'yes'){echo 'checked';}?>>
		<input type="text" style="display:none;" class="b2bking_subaccounts_new_account_container_content_element_text" name="b2bking_super_user" value="<?php echo esc_html($val);?>">
	</div>
	<?php
});

add_filter('b2bking_custom_new_subaccount_field_names', function($fields){
	$fields = array('b2bking_super_user');
	return $fields;
}, 10, 1);

add_filter('b2bking_custom_field_meta', function($field_name){
	// you can set a custom user meta key here
	if ($field_name === 'b2bking_super_user'){
		$field_name = 'superuser';
	}
	return $field_name;
}, 10, 1);
Editor is loading...