Home Forums Backend Issues (wp-admin) current_user_can to hide fields?


current_user_can to hide fields?

  • I’ve recently noticed that I can make certain fields appear or disappear based on the user’s capabilities.


    if (current_user_can('manage_options')) {
        $fields[] = [
            "label" => "Field only visible to admin",
            "name" => "top_secret",
            "key" => $key."_top_secret",
            "required" => false,
            "type" => "text",

    I know you can restrict groups with the built-in settings, but that only works at the group level from what I can tell. Which makes it not work for e.g. parts of a flexible content layout.

    I’m just wondering – is there any reason this would be a bad idea? It doesn’t seem to be documented, but seems pretty useful, so I thought I’d check.

  • This has always been possible but the ACF documentation does not deal with it when creating fields. ACF has a filter acf/prepare_field that allows you to remove fields or modify fields in any way you want based on whatever rules you want to set up.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.