WordPress 5.4 – How to prevent to enter only certain values in custom field

You can make the meta data private, and not visible on the Custom Fields list, by appending underscore to the meta key. I.e. _accesstype_visibility

You can find more details in the WP Developer docs, https://developer.wordpress.org/plugins/metadata/managing-post-metadata/#hidden-custom-fields


EDIT 24.7.2020

Here’s an example how to use is_protected_meta() filter to make meta key public or private. You can read more about filters here, https://developer.wordpress.org/plugins/hooks/filters/

// first hook we're filtering, second our callback, third priority, fourth # of parameters
add_filter( 'is_protected_meta', 'my_prefix_is_protected_meta', 10, 3 );
// available parameters can be found on the filter documentation
function my_prefix_is_protected_meta( $protected, $meta_key, $meta_type ) {
    // Force custom meta key to be protected
    if ( 'my_meta_key' === $meta_key ) {
        $protected = true;
    }
    // Return filtered value so WP can continue whatever it was doing with the value
    return $protected;
}

You can use this in your theme’s functions.php file or in a custom plugin.