Home Forums ACF PRO Cheate field visible but not editable


Cheate field visible but not editable

  • Hi!

    I want to create a field editable only by the admin on a real estate theme (Houzez on theme forest).

    The user should be able to submit a property trough front end, but on the same type of post, a field should be only editable by the admin, not the user.

    The field should be visible to the user, logged or not logged.

    Is this possible?

    If so, how?

    Im using ACF pro


    // replace with your field key
    // or adjust hook as described in above doc
    add_filter('acf/prepare_field/key=field_XYZ123', 'edit_admin_only');
    function edit_admin_only($field) {
      $readonly = true;
      if ((is_user_logged_in() && current_user_can('administrator')) ||
          (is_user_logged_in() && !$field['value'])) {
        // user is logged in  and is an admin
        // or user is logged in and the field has no value
        $readonly = false;
      $field['readonly'] = $readonly;
      return $field;
  • Running on a MAMP server – Local.

    I have tried this code using the key for the field I want to control but, with only changing the key and then logging in with a user not an admin, when I try to edit the record it casts and error. Admin has no issues.

    My field is a number and called “Stock id”

    Field name: vehicle_stock_id
    Key: field_5f115aa7bf4ef

    Fatal error: Uncaught Error: Call to undefined function is_user_logged_id() in /private/var/tmp/8-read-only-stock-id.php:10 Stack trace: #0 /Users/john/Sites/wp-agent-kaz-20/wp-includes/class-wp-hook.php(307): edit_admin_only(Array) #1 /Users/john/Sites/wp-agent-kaz-20/wp-includes/plugin.php(233): WP_Hook->apply_filters(Array, Array) #2 /Users/john/Sites/wp-agent-kaz-20/wp-content/plugins/advanced-custom-fields-pro/includes/acf-hook-functions.php(109): apply_filters_ref_array(‘acf/prepare_fie…’, Array) #3 /Users/john/Sites/wp-agent-kaz-20/wp-includes/class-wp-hook.php(307): _acf_apply_hook_variations(Array) #4 /Users/john/Sites/wp-agent-kaz-20/wp-includes/plugin.php(189): WP_Hook->apply_filters(Array, Array) #5 /Users/john/Sites/wp-agent-kaz-20/wp-content/plugins/advanced-custom-fields-pro/includes/acf-field-functions.php(556): apply_filters(‘acf/prepare_fie…’, Array) #6 /Users/john/Sites/wp-agent-kaz-20/wp-content/plugins/advanced-custom-fields-pro/includes/acf-field-functions.php(648): acf_prepare_field(Array) #7 /U in /private/var/tmp/8-read-only-stock-id.php on line 10

    Log back in as admin user, no issues but the record remains “locked” and I have to take over.

    Wordpress version 5.9

  • I’m a little bit late to the party, but the previous post is obvious, I hope @jmcbade has solved it meanwhile.

    The Fatal error says it all:
    Fatal error: Uncaught Error: Call to undefined function is_user_logged_id()

    It’s probably a mistyped function name, maybe it should’ve been is_user_logged_in?

  • Yep, edited the code above

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

You must be logged in to reply to this topic.