Skip to content

Instantly share code, notes, and snippets.

@mariokerkhof
Created January 30, 2016 08:58
Show Gist options
  • Save mariokerkhof/678da45549b544630b85 to your computer and use it in GitHub Desktop.
Save mariokerkhof/678da45549b544630b85 to your computer and use it in GitHub Desktop.
ACF Disable Editing Input Fields For User Role
function mkr_acf_disable_fields_competitie() {
// Add the role that !!can not!! edit here
$user_role = 'coordinator';
if( current_user_can( $user_role ) ) { ?>
<script type="text/javascript">
(function($) {
// Disable Fields
$("input[name='acf[field_56a9c7a50ca3d]']").prop("disabled", true); // Seizoen
$("input[name='acf[field_56a9c7a50ca57]']").prop("disabled", true); // Sport
$("input[name='acf[field_56a9c7a50ca68]']").prop("disabled", true); // Gebied
// Disbale "Stand" Repeater fields
$(" .acf-field-56a9c7a50ca78 .acf-field select").each( function() {
var fieldName = $(this).attr("name");
$( "input[name='" + fieldName + "']" ).prop("disabled", true);
});
// Disable Add button
$(".acf-field-56a9c7a50ca78").find(".acf-button").prop("disabled", true);
$(".acf-field-56a9c7a50ca78").find(".acf-button").on("click", function( event ) {
event.preventDefault();
alert("Verboden te drukken");
})
$('.acf-field-56a9c7a50ca78 .acf-hl').hide();
// Disable sorting repeater field
$('.acf-row-handle').removeClass('acf-row-handle');
$('.ui-sortable-handle').removeClass('ui-sortable-handle');
})(jQuery);
</script>
<?php }
}
add_action('admin_footer', 'mkr_acf_disable_fields_competitie');
@ddemuth
Copy link

ddemuth commented Sep 11, 2019

Came across this when attempting to do this. Found a way to do it without jQuery!
https://gist.github.com/ddemuth/065079766a8d117cbbeed3784d1c9f46

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment