In the user profile page I have a added a repeater ACF
with 2 subfields (select and datepicker). I want this field to be disabled if the user is not administrator. So administrators can edit this field and the other users can only view it. Is that possible?
I have tried the solution found here but it work only for simple fields and not ACF
.
If it's not possible, how I can create a table and fetch the fields from the database to render them in user profile page?
Here is the code I used to disable normal fields:
/* Disables selected fields in (profile.php) */
function atroul_profile_fields_disable_js() {
?>
<script>
jQuery(document).ready( function($) {
var fields_to_disable = ['first_name', 'last_name', 'display_name'];
for(i=0; i<fields_to_disable.length; i++) {
if ( $('#'+ fields_to_disable[i]).length ) {
$('#'+ fields_to_disable[i]).attr("disabled", "disabled");
}
}
});
</script>
<?php
}
function atroul_profile_fields_disable() {
global $pagenow;
if ($pagenow!=='profile.php')
{
return;
}
if (current_user_can('administrator'))
{
return;
}
add_action( 'admin_footer', 'atroul_profile_fields_disable_js' );
//add_action('admin_head','atroul_remove_personal_options');
}
add_action('admin_init', 'atroul_profile_fields_disable');