Skip to content

Instantly share code, notes, and snippets.

@elvismdev
Last active August 11, 2017 21:30
Show Gist options
  • Select an option

  • Save elvismdev/daf891924479d3ee7d013cbe0d069058 to your computer and use it in GitHub Desktop.

Select an option

Save elvismdev/daf891924479d3ee7d013cbe0d069058 to your computer and use it in GitHub Desktop.
WordPress ACF - Remove / override the choices for a radio, checkbox and select fields.
<?php
/**
* Removes custom style selector for non Administrator user roles.
* Uses acf/load_field filter https://www.advancedcustomfields.com/resources/acf-load_field/
*
* @param array $field
* @return array
*/
function acf_filter_radio_choices( $field ) {
// Check if current user has not administrator capabilities.
if( !current_user_can( 'administrator' ) ) {
// Unset the admin only choice/option, so it wont display for other user roles.
unset( $field['choices']['the_removable_choice'] );
}
// return the field back.
return $field;
}
add_filter( 'acf/load_field/name=the_radio_btn_field_name', 'acf_filter_radio_choices' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment