hooks – Lock user information once fields have been filled in

Question

I think this can handle, what you want:

Here is the filter documentation http://www.advancedcustomfields.com/resources/filters/acf_update_value/

You can choose whatever filter option you want, but if you use onw of the first two

add_filter('acf/update_value', 'mr_acf_prevent_update', 10, 3);
add_filter('acf/update_value/type=text', 'mr_acf_prevent_update', 10, 3);

You’ll have to write more conditionals on the callback function.

If you use one of these two, you don’t need

// example with the field name
add_filter('acf/update_value/name=cell-phone', 'mr_acf_prevent_update', 10, 3);
// example with the field key
add_filter('acf/update_value/key=field_527bb4af7edde', 'my_acf_load_field', 10, 3);

and the callback that does the job

function mr_acf_prevent_update( $value, $post_id, $field ) {

    if ( current_user_can( 'manage_options' ) || get_field( $field['name'], $post_id ) == ''  ) {

        return $value;

    } else {
        return get_field( $field['name'], $post_id );
    }

}

It can be improved, it’s ugly, but it works!

0
SixfootJames 7 years 2013-11-07T01:00:59-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse