Last active
August 11, 2017 21:30
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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