Support

Account

Home Forums Backend Issues (wp-admin) Problem showing Custom Fields admin menu to non-admin users

Solved

Problem showing Custom Fields admin menu to non-admin users

  • I have a need for users without full administrative privileges to be able to edit our site’s Custom Fields.

    I have added the following code from this thread to my theme’s functions.php: http://support.advancedcustomfields.com/forums/topic/restrict-editor-acf-capability/

    add_filter('acf/settings/show_admin', 'my_acf_show_admin');
    function my_acf_show_admin($show) {
    	// provide a list of usernames who can edit custom field definitions here
    	$admins = array( 
    		'user_name_1', 'user_name_2'
    	);
    
    	// get the current user
    	$current_user = wp_get_current_user();
    
    	return (in_array($current_user->user_login, $admins));
    }

    replacing user_name_1, and user_name_2 with the users I need to have access to editing the custom fields. There appears to be no change.

    I’m not wildly familiar with filters, am I missing something?

  • You need to filter the capability required to manages posts, http://www.advancedcustomfields.com/resources/acfsettings/

  • I’m not entirely sure how to do that / what that means?

    I see from the documentation that altering the capability does the following:

    “Capability used for ACF post types and if the current user can see the ACF menu item. Defaults to ‘manage_options’. Added in v5.1.9”

    And is expecting a string. What I don’t understand, is this checking to see if the current user has the capability defined by this filter and displaying / hiding the menu accordingly?

    Can someone provide me an example? Would it be something like:

    add_filter('acf/settings/capability', 'edit_posts');

    Additionally, is this all that is required or is a combination of using the capability filter along with the show_admin filter required? I’m currently testing both of these but would appreciate feedback so I can learn and understand why this does or does not work.

  • Add a filter to your functions.php file something like this.

    
    add_filter('acf/settings/capability', 'acf_allow_editors', 20);
    function acf_allow_editors($capability) {
      return 'edit_posts';
    }
    
  • Hi John,

    Thanks for the ongoing help, I’ve tried adding your code to my functions.php and still no luck.

    I had also tried with no luck:

    add_filter('acf/settings/capability', 'my_capability_function');
    
    function my_capability_function( $show ) {
      return current_user_can('edit_posts');

    Which I wasn’t sure would work since it appears the filter expects a string and my function only returns a boolean.

    What am I missing? I’m using ACF Version 4.4.3 with WordPress 4.3.1 if that’s of any help…

  • Should have asked what version of ACF you’re using. In 4 you can’t alter this. I

    In order to give editors the ability to edit this in ACF4 you’d need to alter editor capabilities to give them the ability to “manage_options” which might give them the ability to do more than you want them to be able to do.

    If this is something that you want to do I’d suggest https://wordpress.org/plugins/user-role-editor/

  • The site is running User Role Editor currently, but it’s fairly important to limit the Staff role to not having access to some of the options the “manage_options” capability gives them.

    If I were to roll back to a previous version of ACF, say 3.5.8.1 (the last before 4) would I be able to do this?

    Is there a better method or am I between a rock and a hard place?

  • You’re between a rock and a hard place.

    I did some digging around and there are no filters that you can hook into to make the change.

    I think the only way you’ll be able to do what you want to do is to upgrade the site to ACF5, or hack ACF4 to change the capability needed (acf.php line 579)

  • Hey John,

    Last question as there seems to have been some confusion on my end. I kept seeing v5 referenced places, but as my ACF lists itself as “up to date” in the plugins section of the back end I thought I was misunderstanding version numbers somehow.

    Do I understand correctly that ACF5 is only available by purchasing a Pro license?

  • ACF5 has not been released to the WordPress plugin repo. A free version of ACF5 is supposed to eventually be released there, but I don’t have any info on when that’s going to happen.

    Currently, as far as I know, the only updates happening to 4 are to deal with bugs created by updates to WP core.

    So, yes, right now the only way to get 5 is to purchase a pro license.

  • gotchya, thanks for the help!

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

You must be logged in to reply to this topic.