Support

Account

Home Forums Feature Requests Read-Only Field Reply To: Read-Only Field

  • Perhaps not the most elegant way, but hey, it works!

        
    /**
    *    Prevents a field from being updated from the panel in ACF.
    *    Useful for business-critical fields that must only by updated internally, but still need to be visible on the admin panel.
    */
    function prevents_field_from_being_updated_from_the_panel($value, $post_id, $field) {
            $backtraces = debug_backtrace();
            foreach ($backtraces as $backtrace) {
                if (!empty($backtrace['function']) && $backtrace['function'] == 'update_field') {
                    return $value;
                }
            }
            return get_field('field_5b5fcd08f9ecf', $post_id, false); # Change field_{key} to your field key/name
    }
    # If you have the field Key:
    add_filter('acf/update_value/key=YOUR_FIELD_KEY', 'prevents_field_from_being_updated_from_the_panel', 10, 3);
        
    # If you prefer to use field name:
    # add_filter('acf/update_value/name=YOUR_FIELD_NAME', 'prevents_field_from_being_updated_from_the_panel', 10, 3);